1 #include <stdio.h> 2 3 #define branch(mask,_v1,_v2) \ 4 ({ \ 5 unsigned char taken; \ 6 unsigned b1 = _v1, b2 = _v2; \ 7 asm volatile( " cr %[b1],%[b2]\n\t" \ 8 " brc " #mask " ,1f\n\t" \ 9 " mvi %[taken],0\n\t" \ 10 " j 0f\n\t" \ 11 "1: mvi %[taken],1\n\t" \ 12 "0: bcr 0,0 /* nop */\n\t" \ 13 : [taken] "=Q" (taken) \ 14 : [b1] "d"(b1), [b2] "d"(b2) \ 15 : "cc"); \ 16 taken; \ 17 }) 18 19 void 20 cr_1(void) 21 { 22 int wrong, ok, v1, v2; 23 24 printf("Test #1 op1 == op2\n"); 25 26 v1 = v2 = 42; 27 wrong = ok = 0; 28 29 if (branch(0, v1, v2)) ++wrong; else ++ok; 30 if (branch(1, v1, v2)) ++wrong; else ++ok; 31 if (branch(2, v1, v2)) ++wrong; else ++ok; 32 if (branch(3, v1, v2)) ++wrong; else ++ok; 33 if (branch(4, v1, v2)) ++wrong; else ++ok; 34 if (branch(5, v1, v2)) ++wrong; else ++ok; 35 if (branch(6, v1, v2)) ++wrong; else ++ok; 36 if (branch(7, v1, v2)) ++wrong; else ++ok; 37 if (branch(8, v1, v2)) ++ok; else ++wrong; 38 if (branch(9, v1, v2)) ++ok; else ++wrong; 39 if (branch(10, v1, v2)) ++ok; else ++wrong; 40 if (branch(11, v1, v2)) ++ok; else ++wrong; 41 if (branch(12, v1, v2)) ++ok; else ++wrong; 42 if (branch(13, v1, v2)) ++ok; else ++wrong; 43 if (branch(14, v1, v2)) ++ok; else ++wrong; 44 if (branch(15, v1, v2)) ++ok; else ++wrong; 45 46 if (wrong != 0 || ok != 16) 47 printf("FAILED\n"); 48 else 49 printf("OK\n"); 50 } 51 52 void 53 cr_2(void) 54 { 55 int wrong, ok, v1, v2; 56 57 printf("Test #2 op1 > op2\n"); 58 v1 = 100; 59 v2 = -10; 60 wrong = ok = 0; 61 62 if (branch(0, v1, v2)) ++wrong; else ++ok; 63 if (branch(1, v1, v2)) ++wrong; else ++ok; 64 if (branch(2, v1, v2)) ++ok; else ++wrong; 65 if (branch(3, v1, v2)) ++ok; else ++wrong; 66 if (branch(4, v1, v2)) ++wrong; else ++ok; 67 if (branch(5, v1, v2)) ++wrong; else ++ok; 68 if (branch(6, v1, v2)) ++ok; else ++wrong; 69 if (branch(7, v1, v2)) ++ok; else ++wrong; 70 if (branch(8, v1, v2)) ++wrong; else ++ok; 71 if (branch(9, v1, v2)) ++wrong; else ++ok; 72 if (branch(10, v1, v2)) ++ok; else ++wrong; 73 if (branch(11, v1, v2)) ++ok; else ++wrong; 74 if (branch(12, v1, v2)) ++wrong; else ++ok; 75 if (branch(13, v1, v2)) ++wrong; else ++ok; 76 if (branch(14, v1, v2)) ++ok; else ++wrong; 77 if (branch(15, v1, v2)) ++ok; else ++wrong; 78 79 if (wrong != 0 || ok != 16) 80 printf("FAILED\n"); 81 else 82 printf("OK\n"); 83 } 84 85 void 86 cr_3(void) 87 { 88 int wrong, ok, v1, v2; 89 90 printf("Test #3 op1 < op2\n"); 91 v1 = -100; 92 v2 = -10; 93 wrong = ok = 0; 94 95 if (branch(0, v1, v2)) ++wrong; else ++ok; 96 if (branch(1, v1, v2)) ++wrong; else ++ok; 97 if (branch(2, v1, v2)) ++wrong; else ++ok; 98 if (branch(3, v1, v2)) ++wrong; else ++ok; 99 if (branch(4, v1, v2)) ++ok; else ++wrong; 100 if (branch(5, v1, v2)) ++ok; else ++wrong; 101 if (branch(6, v1, v2)) ++ok; else ++wrong; 102 if (branch(7, v1, v2)) ++ok; else ++wrong; 103 if (branch(8, v1, v2)) ++wrong; else ++ok; 104 if (branch(9, v1, v2)) ++wrong; else ++ok; 105 if (branch(10, v1, v2)) ++wrong; else ++ok; 106 if (branch(11, v1, v2)) ++wrong; else ++ok; 107 if (branch(12, v1, v2)) ++ok; else ++wrong; 108 if (branch(13, v1, v2)) ++ok; else ++wrong; 109 if (branch(14, v1, v2)) ++ok; else ++wrong; 110 if (branch(15, v1, v2)) ++ok; else ++wrong; 111 112 if (wrong != 0 || ok != 16) 113 printf("FAILED\n"); 114 else 115 printf("OK\n"); 116 } 117 118 int main() 119 { 120 cr_1(); 121 cr_2(); 122 cr_3(); 123 return 0; 124 } 125