root / tests / tcg / cris / check_addcm.c @ c09015dd
History | View | Annotate | Download (1.9 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 | /* need to avoid acr as source here. */
|
8 | 4a6648f4 | Blue Swirl | static inline int cris_addc_m(int a, const int *b) |
9 | 4a6648f4 | Blue Swirl | { |
10 | dd43edf4 | ths | asm volatile ("addc [%1], %0\n" : "+r" (a) : "r" (b)); |
11 | dd43edf4 | ths | return a;
|
12 | dd43edf4 | ths | } |
13 | dd43edf4 | ths | |
14 | dd43edf4 | ths | /* 'b' is a crisv32 constrain to avoid postinc with $acr. */
|
15 | 4a6648f4 | Blue Swirl | static inline int cris_addc_pi_m(int a, int **b) |
16 | 4a6648f4 | Blue Swirl | { |
17 | dd43edf4 | ths | asm volatile ("addc [%1+], %0\n" : "+r" (a), "+b" (*b)); |
18 | dd43edf4 | ths | return a;
|
19 | dd43edf4 | ths | } |
20 | dd43edf4 | ths | |
21 | dd43edf4 | ths | #define verify_addc_m(a, b, res, n, z, v, c) \
|
22 | dd43edf4 | ths | { \ |
23 | dd43edf4 | ths | int r; \
|
24 | dd43edf4 | ths | r = cris_addc_m((a), (b)); \ |
25 | dd43edf4 | ths | cris_tst_cc((n), (z), (v), (c)); \ |
26 | dd43edf4 | ths | if (r != (res)) \
|
27 | dd43edf4 | ths | err(); \ |
28 | dd43edf4 | ths | } |
29 | dd43edf4 | ths | |
30 | dd43edf4 | ths | #define verify_addc_pi_m(a, b, res, n, z, v, c) \
|
31 | dd43edf4 | ths | { \ |
32 | dd43edf4 | ths | int r; \
|
33 | dd43edf4 | ths | r = cris_addc_pi_m((a), (b)); \ |
34 | dd43edf4 | ths | cris_tst_cc((n), (z), (v), (c)); \ |
35 | dd43edf4 | ths | if (r != (res)) \
|
36 | dd43edf4 | ths | err(); \ |
37 | dd43edf4 | ths | } |
38 | dd43edf4 | ths | |
39 | dd43edf4 | ths | int x[] = { 0, 0, 2, -1, 0xffff, -1, 0x5432f789}; |
40 | dd43edf4 | ths | |
41 | dd43edf4 | ths | int main(void) |
42 | dd43edf4 | ths | { |
43 | dd43edf4 | ths | int *p = (void *)&x[0]; |
44 | dd43edf4 | ths | #if 1 |
45 | dd43edf4 | ths | cris_tst_cc_init(); |
46 | dd43edf4 | ths | asm volatile ("clearf cz"); |
47 | dd43edf4 | ths | verify_addc_m(0, p, 0, 0, 0, 0, 0); |
48 | dd43edf4 | ths | |
49 | dd43edf4 | ths | cris_tst_cc_init(); |
50 | dd43edf4 | ths | asm volatile ("setf z"); |
51 | dd43edf4 | ths | verify_addc_m(0, p, 0, 0, 1, 0, 0); |
52 | dd43edf4 | ths | |
53 | dd43edf4 | ths | cris_tst_cc_init(); |
54 | dd43edf4 | ths | asm volatile ("setf c"); |
55 | dd43edf4 | ths | verify_addc_m(0, p, 1, 0, 0, 0, 0); |
56 | dd43edf4 | ths | |
57 | dd43edf4 | ths | cris_tst_cc_init(); |
58 | dd43edf4 | ths | asm volatile ("clearf c"); |
59 | dd43edf4 | ths | verify_addc_pi_m(0, &p, 0, 0, 1, 0, 0); |
60 | dd43edf4 | ths | |
61 | dd43edf4 | ths | p = &x[1];
|
62 | dd43edf4 | ths | cris_tst_cc_init(); |
63 | dd43edf4 | ths | asm volatile ("setf c"); |
64 | dd43edf4 | ths | verify_addc_pi_m(0, &p, 1, 0, 0, 0, 0); |
65 | dd43edf4 | ths | |
66 | dd43edf4 | ths | if (p != &x[2]) |
67 | dd43edf4 | ths | err(); |
68 | dd43edf4 | ths | |
69 | dd43edf4 | ths | cris_tst_cc_init(); |
70 | dd43edf4 | ths | asm volatile ("clearf c"); |
71 | dd43edf4 | ths | verify_addc_pi_m(-1, &p, 1, 0, 0, 0, 1); |
72 | dd43edf4 | ths | |
73 | dd43edf4 | ths | if (p != &x[3]) |
74 | dd43edf4 | ths | err(); |
75 | dd43edf4 | ths | #endif
|
76 | dd43edf4 | ths | p = &x[3];
|
77 | dd43edf4 | ths | /* TODO: investigate why this one fails. */
|
78 | dd43edf4 | ths | cris_tst_cc_init(); |
79 | dd43edf4 | ths | asm volatile ("setf c"); |
80 | dd43edf4 | ths | verify_addc_m(2, p, 2, 0, 0, 0, 1); |
81 | dd43edf4 | ths | p += 4;
|
82 | dd43edf4 | ths | |
83 | dd43edf4 | ths | pass(); |
84 | dd43edf4 | ths | return 0; |
85 | dd43edf4 | ths | } |