Statistics
| Branch: | Revision:

root / tests / cris / check_swap.c @ 076d2471

History | View | Annotate | Download (2.4 kB)

1 dd43edf4 ths
#include <stdio.h>
2 dd43edf4 ths
#include <stdlib.h>
3 dd43edf4 ths
#include <stdint.h>
4 dd43edf4 ths
#include "sys.h"
5 dd43edf4 ths
#include "crisutils.h"
6 dd43edf4 ths
7 dd43edf4 ths
#define N 8
8 dd43edf4 ths
#define W 4
9 dd43edf4 ths
#define B 2
10 dd43edf4 ths
#define R 1
11 dd43edf4 ths
12 dd43edf4 ths
extern inline int cris_swap(const int mode, int x)
13 dd43edf4 ths
{
14 dd43edf4 ths
        switch (mode)
15 dd43edf4 ths
        {
16 dd43edf4 ths
                case N: asm ("swapn\t%0\n" : "+r" (x) : "0" (x)); break;
17 dd43edf4 ths
                case W: asm ("swapw\t%0\n" : "+r" (x) : "0" (x)); break;
18 dd43edf4 ths
                case B: asm ("swapb\t%0\n" : "+r" (x) : "0" (x)); break;
19 dd43edf4 ths
                case R: asm ("swapr\t%0\n" : "+r" (x) : "0" (x)); break;
20 dd43edf4 ths
                case B|R: asm ("swapbr\t%0\n" : "+r" (x) : "0" (x)); break;
21 dd43edf4 ths
                case W|R: asm ("swapwr\t%0\n" : "+r" (x) : "0" (x)); break;
22 dd43edf4 ths
                case W|B: asm ("swapwb\t%0\n" : "+r" (x) : "0" (x)); break;
23 dd43edf4 ths
                case W|B|R: asm ("swapwbr\t%0\n" : "+r" (x) : "0" (x)); break;
24 dd43edf4 ths
                case N|R: asm ("swapnr\t%0\n" : "+r" (x) : "0" (x)); break;
25 dd43edf4 ths
                case N|B: asm ("swapnb\t%0\n" : "+r" (x) : "0" (x)); break;
26 dd43edf4 ths
                case N|B|R: asm ("swapnbr\t%0\n" : "+r" (x) : "0" (x)); break;
27 dd43edf4 ths
                case N|W: asm ("swapnw\t%0\n" : "+r" (x) : "0" (x)); break;
28 dd43edf4 ths
                default:
29 dd43edf4 ths
                        err();
30 dd43edf4 ths
                        break;
31 dd43edf4 ths
        }
32 dd43edf4 ths
        return x;
33 dd43edf4 ths
}
34 dd43edf4 ths
35 dd43edf4 ths
/* Made this a macro to be able to pick up the location of the errors.  */
36 dd43edf4 ths
#define verify_swap(mode, val, expected, n, z)          \
37 dd43edf4 ths
do {                                                    \
38 dd43edf4 ths
        int r;                                          \
39 dd43edf4 ths
        cris_tst_cc_init();                             \
40 dd43edf4 ths
        r = cris_swap(mode, val);                       \
41 dd43edf4 ths
        cris_tst_mov_cc(n, z);                          \
42 dd43edf4 ths
        if (r != expected)                              \
43 dd43edf4 ths
                err();                                  \
44 dd43edf4 ths
} while(0);
45 dd43edf4 ths
46 dd43edf4 ths
void check_swap(void)
47 dd43edf4 ths
{
48 dd43edf4 ths
        /* Some of these numbers are borrowed from GDB's cris sim
49 dd43edf4 ths
           testsuite.  */
50 dd43edf4 ths
        if (cris_swap(N, 0) != 0xffffffff)
51 dd43edf4 ths
                err();
52 dd43edf4 ths
        if (cris_swap(W, 0x12345678) != 0x56781234)
53 dd43edf4 ths
                err();
54 dd43edf4 ths
        if (cris_swap(B, 0x12345678) != 0x34127856)
55 dd43edf4 ths
                err();
56 dd43edf4 ths
57 dd43edf4 ths
        verify_swap(R, 0x78134452, 0x1ec8224a, 0, 0);
58 dd43edf4 ths
        verify_swap(B, 0x78134452, 0x13785244, 0, 0);
59 dd43edf4 ths
        verify_swap(B|R, 0x78134452, 0xc81e4a22, 1, 0);
60 dd43edf4 ths
        verify_swap(W, 0x78134452, 0x44527813, 0, 0);
61 dd43edf4 ths
        verify_swap(W|R, 0x78134452, 0x224a1ec8, 0, 0);
62 dd43edf4 ths
        verify_swap(W|B|R, 0x78134452, 0x4a22c81e, 0, 0);
63 dd43edf4 ths
        verify_swap(N, 0x78134452, 0x87ecbbad, 1, 0);
64 dd43edf4 ths
        verify_swap(N|R, 0x78134452, 0xe137ddb5, 1, 0);
65 dd43edf4 ths
        verify_swap(N|B, 0x78134452, 0xec87adbb, 1, 0);
66 dd43edf4 ths
        verify_swap(N|B|R, 0x78134452, 0x37e1b5dd, 0, 0);
67 dd43edf4 ths
        verify_swap(N|W, 0x78134452, 0xbbad87ec, 1, 0);
68 dd43edf4 ths
        verify_swap(N|B|R, 0xffffffff, 0, 0, 1);
69 dd43edf4 ths
}
70 dd43edf4 ths
71 dd43edf4 ths
int main(void)
72 dd43edf4 ths
{
73 dd43edf4 ths
        check_swap();
74 dd43edf4 ths
        pass();
75 bd3a8454 edgar_igl
        return 0;
76 dd43edf4 ths
}