drd/tests/swapcontext: Improve the portability of this test further
[valgrind.git] / none / tests / ppc32 / mftocrf.c
blob916b9ada7354a1ab4e7a4023509c17f71e8076d0
2 #include <stdio.h>
3 #include <config.h>
5 static
6 int try_mtocrf ( int x )
8 int base = 0x31415927;
9 int res;
10 #ifdef HAVE_AS_PPC_MFTOCRF
11 /* pre-set CR */
12 __asm__ __volatile__(
13 "mtcr %0"
14 : /*w*/ : /*r*/ "b"(base) : /*trash*/"cc" );
16 /* do it */
17 __asm__ __volatile__(
18 "mtocrf 4, %0"
19 : /*w*/ : /*r*/ "b"(x) : /*trash*/"cc" );
21 /* get CR */
22 __asm__ __volatile__(
23 "mfcr %0"
24 : /*w*/"=b"(res) : /*r*/ );
25 #else
26 res = 42;
27 #endif
28 return res;
31 static
32 int try_mfocrf ( int x )
34 int res;
35 #ifdef HAVE_AS_PPC_MFTOCRF
36 /* CR = x */
37 __asm__ __volatile__(
38 "mtcr %0"
39 : /*w*/ : /*r*/ "b"(x) : /*trash*/"cc" );
41 /* do it */
42 __asm__ __volatile__(
43 "li %0,0\n\t"
44 "mfocrf %0,64"
45 : /*w*/"=b"(res) : /*r*/ );
46 #else
47 res = 42;
48 #endif
49 return res;
52 /* This is a bit of a kludge since mfocrf reads the spec'd CR field,
53 but the remaining returned bits are undefined. It seems like on
54 MPC7447A (Apple Mac Mini) mfocrf just reads the entire CR, which is
55 an acceptable implementation, but is not necessarily what other
56 implementations are going to do. */
58 int main ( void )
60 int i, j;
61 for (i = 0; i < 32; i++) {
62 printf("0x%08x\n", try_mtocrf( 1<<i ));
64 printf("\n");
65 j = 1;
66 for (i = 0; i < 32; i++) {
67 printf("0x%08x\n", try_mfocrf( j ));
68 j *= 3;
71 return 0;