1#include <unistd.h> 2 3#ifdef TEST_CMOV 4 5#define TEST_COND(N) \ 6int test_##N (long a) \ 7{ \ 8 int res = 1; \ 9 \ 10 asm ("cmov"#N" %1,$31,%0" \ 11 : "+r" (res) : "r" (a)); \ 12 return !res; \ 13} 14 15#else 16 17#define TEST_COND(N) \ 18int test_##N (long a) \ 19{ \ 20 int res = 1; \ 21 \ 22 asm ("b"#N" %1,1f\n\t" \ 23 "addq $31,$31,%0\n\t" \ 24 "1: unop\n" \ 25 : "+r" (res) : "r" (a)); \ 26 return res; \ 27} 28 29#endif 30 31TEST_COND(eq) 32TEST_COND(ne) 33TEST_COND(ge) 34TEST_COND(gt) 35TEST_COND(lbc) 36TEST_COND(lbs) 37TEST_COND(le) 38TEST_COND(lt) 39 40static struct { 41 int (*func)(long); 42 long v; 43 int r; 44} vectors[] = 45 { 46 {test_eq, 0, 1}, 47 {test_eq, 1, 0}, 48 49 {test_ne, 0, 0}, 50 {test_ne, 1, 1}, 51 52 {test_ge, 0, 1}, 53 {test_ge, 1, 1}, 54 {test_ge, -1, 0}, 55 56 {test_gt, 0, 0}, 57 {test_gt, 1, 1}, 58 {test_gt, -1, 0}, 59 60 {test_lbc, 0, 1}, 61 {test_lbc, 1, 0}, 62 {test_lbc, -1, 0}, 63 64 {test_lbs, 0, 0}, 65 {test_lbs, 1, 1}, 66 {test_lbs, -1, 1}, 67 68 {test_le, 0, 1}, 69 {test_le, 1, 0}, 70 {test_le, -1, 1}, 71 72 {test_lt, 0, 0}, 73 {test_lt, 1, 0}, 74 {test_lt, -1, 1}, 75 }; 76 77int main (void) 78{ 79 int i; 80 81 for (i = 0; i < sizeof (vectors)/sizeof(vectors[0]); i++) 82 if ((*vectors[i].func)(vectors[i].v) != vectors[i].r) { 83 write(1, "Failed\n", 7); 84 return 1; 85 } 86 write(1, "OK\n", 3); 87 return 0; 88} 89