drd/tests/swapcontext: Improve the portability of this test further
[valgrind.git] / none / tests / ppc32 / ldstrev.c
blobb29ed6e5012391b068b250f4ff5aa8b83b05541a
2 #include <stdio.h>
4 typedef unsigned int UInt;
5 typedef unsigned short UShort;
7 UInt read16le ( void* a )
9 UInt res;
10 __asm volatile(
11 " lhbrx %0,0,%1 \n" // Get half word and reverse the bytes
12 : "=b" (res) // %0 - Output operand
13 : "b" (a) // %1 - Input operand
14 : "memory" // Consider memory clobberred for aliasing
16 return res;
19 UInt read16be ( void* a )
21 UInt res;
22 __asm volatile(
23 " lhzx %0,0,%1 \n" // Get half word and reverse the bytes
24 : "=b" (res) // %0 - Output operand
25 : "b" (a) // %1 - Input operand
26 : "memory" // Consider memory clobberred for aliasing
28 return res;
31 UInt read32le ( void* a )
33 UInt res;
34 __asm volatile(
35 " lwbrx %0,0,%1 \n" // Get half word and reverse the bytes
36 : "=b" (res) // %0 - Output operand
37 : "b" (a) // %1 - Input operand
38 : "memory" // Consider memory clobberred for aliasing
40 return res;
43 UInt read32be ( void* a )
45 UInt res;
46 __asm volatile(
47 " lwzx %0,0,%1 \n" // Get half word and reverse the bytes
48 : "=b" (res) // %0 - Output operand
49 : "b" (a) // %1 - Input operand
50 : "memory" // Consider memory clobberred for aliasing
52 return res;
55 void write16be ( void* a, UInt data )
57 __asm volatile(
58 " sthx %0,0,%1\n"
60 : "b" (data), "b" (a)
61 : "memory"
65 void write16le ( void* a, UInt data )
67 __asm volatile(
68 " sthbrx %0,0,%1\n"
70 : "b" (data), "b" (a)
71 : "memory"
75 void write32be ( void* a, UInt data )
77 __asm volatile(
78 " stwx %0,0,%1\n"
80 : "b" (data), "b" (a)
81 : "memory"
85 void write32le ( void* a, UInt data )
87 __asm volatile(
88 " stwbrx %0,0,%1\n"
90 : "b" (data), "b" (a)
91 : "memory"
95 int main ( void )
97 UInt foo = 0x12345678;
98 printf("ld be16 0x%08x\n", read16be( &foo ));
99 printf("ld le16 0x%08x\n", read16le( &foo ));
100 printf("ld be32 0x%08x\n", read32be( &foo ));
101 printf("ld le32 0x%08x\n", read32le( &foo ));
103 foo = 0x12345678; write16be( &foo, 0xABCD );
104 printf("st be16 0x%08x\n", foo);
106 foo = 0x12345678; write16le( &foo, 0xABCD );
107 printf("st le16 0x%08x\n", foo);
109 foo = 0x12345678; write32be( &foo, 0xABCD1425 );
110 printf("st be32 0x%08x\n", foo);
112 foo = 0x12345678; write32le( &foo, 0xABCD1425 );
113 printf("st le32 0x%08x\n", foo);
115 return 0;