1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <stdint.h> 4 #include "sys.h" 5 #include "crisutils.h" 6 7 static always_inline int cris_bound_b(int v, int b) 8 { 9 int r = v; 10 asm ("bound.b\t%1, %0\n" : "+r" (r) : "ri" (b)); 11 return r; 12 } 13 14 static always_inline int cris_bound_w(int v, int b) 15 { 16 int r = v; 17 asm ("bound.w\t%1, %0\n" : "+r" (r) : "ri" (b)); 18 return r; 19 } 20 21 static always_inline int cris_bound_d(int v, int b) 22 { 23 int r = v; 24 asm ("bound.d\t%1, %0\n" : "+r" (r) : "ri" (b)); 25 return r; 26 } 27 28 int main(void) 29 { 30 int r; 31 32 cris_tst_cc_init(); 33 r = cris_bound_d(-1, 2); 34 cris_tst_cc(0, 0, 0, 0); 35 if (r != 2) 36 err(); 37 38 cris_tst_cc_init(); 39 r = cris_bound_d(2, 0xffffffff); 40 cris_tst_cc(0, 0, 0, 0); 41 if (r != 2) 42 err(); 43 44 cris_tst_cc_init(); 45 r = cris_bound_d(0xffff, 0xffff); 46 cris_tst_cc(0, 0, 0, 0); 47 if (r != 0xffff) 48 err(); 49 50 cris_tst_cc_init(); 51 r = cris_bound_d(-1, 0xffffffff); 52 cris_tst_cc(1, 0, 0, 0); 53 if (r != 0xffffffff) 54 err(); 55 56 cris_tst_cc_init(); 57 r = cris_bound_d(0x78134452, 0x5432f789); 58 cris_tst_cc(0, 0, 0, 0); 59 if (r != 0x5432f789) 60 err(); 61 62 cris_tst_cc_init(); 63 r = cris_bound_w(-1, 2); 64 cris_tst_cc(0, 0, 0, 0); 65 if (r != 2) 66 err(); 67 68 cris_tst_cc_init(); 69 r = cris_bound_w(-1, 0xffff); 70 cris_tst_cc(0, 0, 0, 0); 71 if (r != 0xffff) 72 err(); 73 74 cris_tst_cc_init(); 75 r = cris_bound_w(2, 0xffff); 76 cris_tst_cc(0, 0, 0, 0); 77 if (r != 2) 78 err(); 79 80 cris_tst_cc_init(); 81 r = cris_bound_w(0xfedaffff, 0xffff); 82 cris_tst_cc(0, 0, 0, 0); 83 if (r != 0xffff) 84 err(); 85 86 cris_tst_cc_init(); 87 r = cris_bound_w(0x78134452, 0xf789); 88 cris_tst_cc(0, 0, 0, 0); 89 if (r != 0xf789) 90 err(); 91 92 cris_tst_cc_init(); 93 r = cris_bound_b(-1, 2); 94 cris_tst_cc(0, 0, 0, 0); 95 if (r != 2) 96 err(); 97 98 cris_tst_cc_init(); 99 r = cris_bound_b(2, 0xff); 100 cris_tst_cc(0, 0, 0, 0); 101 if (r != 2) 102 err(); 103 104 cris_tst_cc_init(); 105 r = cris_bound_b(-1, 0xff); 106 cris_tst_cc(0, 0, 0, 0); 107 if (r != 0xff) 108 err(); 109 110 cris_tst_cc_init(); 111 r = cris_bound_b(0xff, 0xff); 112 cris_tst_cc(0, 0, 0, 0); 113 if (r != 0xff) 114 err(); 115 116 cris_tst_cc_init(); 117 r = cris_bound_b(0xfeda49ff, 0xff); 118 cris_tst_cc(0, 0, 0, 0); 119 if (r != 0xff) 120 err(); 121 122 cris_tst_cc_init(); 123 r = cris_bound_b(0x78134452, 0x89); 124 cris_tst_cc(0, 0, 0, 0); 125 if (r != 0x89) 126 err(); 127 128 cris_tst_cc_init(); 129 r = cris_bound_w(0x78134452, 0); 130 cris_tst_cc(0, 1, 0, 0); 131 if (r != 0) 132 err(); 133 134 cris_tst_cc_init(); 135 r = cris_bound_b(0xffff, -1); 136 cris_tst_cc(0, 0, 0, 0); 137 if (r != 0xff) 138 err(); 139 140 pass(); 141 return 0; 142 } 143