1 #include <stdio.h> 2 3 #define get_cc() \ 4 ({ \ 5 char __cc; \ 6 /* don't use IPM to better test spechelpers */ \ 7 asm volatile( "brc 8,1f\n\t" \ 8 "brc 4,2f\n\t" \ 9 "brc 2,3f\n\t" \ 10 "brc 1,4f\n\t" \ 11 "mvi %0,4\n\t" \ 12 "j 0f\n\t" \ 13 "1: mvi %0,0\n\t" \ 14 "j 0f\n\t" \ 15 "2: mvi %0,1\n\t" \ 16 "j 0f\n\t" \ 17 "3: mvi %0,2\n\t" \ 18 "j 0f\n\t" \ 19 "4: mvi %0,3\n\t" \ 20 "j 0f\n\t" \ 21 "0: /* nop */ brc 0,0\n\t" \ 22 : "=m" (__cc) : : "memory"); \ 23 __cc; \ 24 }) 25 26 void check_cc(int value, int cc) 27 { 28 if (cc != value) { 29 printf("wrong cc: "); 30 if (value == 0) printf("expected 0 "); 31 if (value == 1) printf("expected 1 "); 32 if (value == 2) printf("expected 2 "); 33 if (value == 3) printf("expected 3 "); 34 if (cc == 0) printf("got 0"); 35 if (cc == 1) printf("got 1"); 36 if (cc == 2) printf("got 2"); 37 if (cc == 3) printf("got 3"); 38 } else { 39 printf("OK"); 40 } 41 printf("\n"); 42 } 43 44 void tmll(void) 45 { 46 unsigned long v; 47 48 /* test #1: value is zero, all bits selected */ 49 v = 0; 50 asm volatile( "tmll %[v],0xFFFF\n\t" : : [v] "d"(v) : "cc"); 51 check_cc(0, get_cc()); 52 53 /* test #2: value is all-ones, mask is zero */ 54 v = 0xFFFF; 55 asm volatile( "tmll %[v],0\n\t" : : [v] "d"(v) : "cc"); 56 check_cc(0, get_cc()); 57 58 /* test #3: selected bits are 0 */ 59 v = 0x0F; 60 asm volatile( "tmll %[v],0xf0\n\t" : : [v] "d"(v) : "cc"); 61 check_cc(0, get_cc()); 62 63 /* test #4: selected bits are all 1 */ 64 v = 0xF0; 65 asm volatile( "tmll %[v],0x70\n\t" : : [v] "d"(v) : "cc"); 66 check_cc(3, get_cc()); 67 68 /* test #5: selected bits are mixed, leftmost bit is 0 */ 69 v = 0x0F; 70 asm volatile( "tmll %[v],0x81\n\t" : : [v] "d"(v) : "cc"); 71 check_cc(1, get_cc()); 72 73 /* test #6: selected bits are mixed, leftmost bit is 1 */ 74 v = 0xF0; 75 asm volatile( "tmll %[v],0x81\n\t" : : [v] "d"(v) : "cc"); 76 check_cc(2, get_cc()); 77 } 78 79 int main(void) 80 { 81 tmll(); 82 83 return 0; 84 } 85