SPARC ASIs

One, not so frequently used, yet useful feature of SPARC CPUs is ASI, or address space identifier, essentially just a 8-bit tag attached to memory address, modifying the way how memory access happens. They could be used for different purposes, two useful for non-kernel programming are non-faulting reads and hardware accelerated little-to-big endian conversion. In following example I'll use ASI to load value from variable in little endian byte order, and then will safely dereference NULL pointer.

You may find more info on ASIs in SPARCv9 manual.

#include <stdio.h>

volatile int var = 0x12345678;

volatile int as_le(int\* addr) {
  int rv;
  __asm__ (
    "lda [%0] 0x88, %1\\n\\t"
      : "=r" (rv)
      : "r"(addr)
    );
  return rv;
}

int as_le_test(int\* addr) {
  int x = \*addr;
  return 
    (((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >>  8) | 
    (((x) & 0x0000ff00) <<  8) | (((x) & 0x000000ff) << 24);
}


int load_nf(int\* addr) {
  int rv;
  __asm__ (
    "lda [%0] 0x82, %1\\n\\t"
      : "=r" (rv)
      : "r"(addr)
    );
  return rv;
}

  
int main() {
  int\* p = (int\*)&var;

  printf("var: %x as LE: %x should be: %x\\n", 
         \*p, as_le(p), as_le_test(p));
  printf("nf=%d var=%d\\n", load_nf(0), load_nf(p));
  return 0;
}
Comments:

that's SPARC not Sparc! http://sparc.org

Posted by J McLaughlin on June 30, 2007 at 12:13 PM MSD #

Thanks, I guess it's common for many acronyms to become nouns. Think Sun :).

Posted by nike on July 02, 2007 at 07:06 AM MSD #

Post a Comment:
  • HTML Syntax: NOT allowed
About

nike

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today