root / tests / tcg / cris / check_abs.c @ c09015dd
History | View | Annotate | Download (794 Bytes)
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 | 4a6648f4 | Blue Swirl | static inline int cris_abs(int n) |
8 | 4a6648f4 | Blue Swirl | { |
9 | dd43edf4 | ths | int r;
|
10 | dd43edf4 | ths | asm ("abs\t%1, %0\n" : "=r" (r) : "r" (n)); |
11 | dd43edf4 | ths | return r;
|
12 | dd43edf4 | ths | } |
13 | dd43edf4 | ths | |
14 | 4a6648f4 | Blue Swirl | static inline void |
15 | dd43edf4 | ths | verify_abs(int val, int res, |
16 | dd43edf4 | ths | const int n, const int z, const int v, const int c) |
17 | dd43edf4 | ths | { |
18 | dd43edf4 | ths | int r;
|
19 | dd43edf4 | ths | |
20 | dd43edf4 | ths | cris_tst_cc_init(); |
21 | dd43edf4 | ths | r = cris_abs(val); |
22 | dd43edf4 | ths | cris_tst_cc(n, z, v, c); |
23 | dd43edf4 | ths | if (r != res)
|
24 | dd43edf4 | ths | err(); |
25 | dd43edf4 | ths | } |
26 | dd43edf4 | ths | |
27 | dd43edf4 | ths | int main(void) |
28 | dd43edf4 | ths | { |
29 | dd43edf4 | ths | verify_abs(-1, 1, 0, 0, 0, 0); |
30 | dd43edf4 | ths | verify_abs(0x80000000, 0x80000000, 1, 0, 0, 0); |
31 | dd43edf4 | ths | verify_abs(0x7fffffff, 0x7fffffff, 0, 0, 0, 0); |
32 | dd43edf4 | ths | verify_abs(42, 42, 0, 0, 0, 0); |
33 | dd43edf4 | ths | verify_abs(1, 1, 0, 0, 0, 0); |
34 | dd43edf4 | ths | verify_abs(0xffff, 0xffff, 0, 0, 0, 0); |
35 | dd43edf4 | ths | verify_abs(0xffff, 0xffff, 0, 0, 0, 0); |
36 | dd43edf4 | ths | verify_abs(-31, 0x1f, 0, 0, 0, 0); |
37 | dd43edf4 | ths | verify_abs(0, 0, 0, 1, 0, 0); |
38 | dd43edf4 | ths | pass(); |
39 | dd43edf4 | ths | return 0; |
40 | dd43edf4 | ths | } |