1#include <stdio.h> 2 3#define branch(mask,i2,_v1) \ 4 ({ \ 5 unsigned char taken; \ 6 unsigned long v1 = _v1; \ 7 asm volatile( " tmll %[v]," #i2 "\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 : [v] "d"(v1) \ 15 : "cc"); \ 16 taken; \ 17 }) 18 19void 20tmll_mask_0(void) 21{ 22 int wrong, ok; 23 unsigned long v; 24 25 printf("Test #1 mask == 0, value == ~0 --> cc == 0\n"); 26 27 v = ~0ULL; 28 wrong = ok = 0; 29 30 if (branch(0, 0, v)) ++wrong; else ++ok; 31 if (branch(1, 0, v)) ++wrong; else ++ok; 32 if (branch(2, 0, v)) ++wrong; else ++ok; 33 if (branch(3, 0, v)) ++wrong; else ++ok; 34 if (branch(4, 0, v)) ++wrong; else ++ok; 35 if (branch(5, 0, v)) ++wrong; else ++ok; 36 if (branch(6, 0, v)) ++wrong; else ++ok; 37 if (branch(7, 0, v)) ++wrong; else ++ok; 38 if (branch(8, 0, v)) ++ok; else ++wrong; 39 if (branch(9, 0, v)) ++ok; else ++wrong; 40 if (branch(10, 0, v)) ++ok; else ++wrong; 41 if (branch(11, 0, v)) ++ok; else ++wrong; 42 if (branch(12, 0, v)) ++ok; else ++wrong; 43 if (branch(13, 0, v)) ++ok; else ++wrong; 44 if (branch(14, 0, v)) ++ok; else ++wrong; 45 if (branch(15, 0, v)) ++ok; else ++wrong; 46 47 if (wrong != 0 || ok != 16) 48 printf("FAILED\n"); 49 else 50 printf("OK\n"); 51} 52 53void 54tmll_value_0(void) 55{ 56 int wrong, ok; 57 unsigned long v; 58 59 printf("Test #2 mask == 0xFFF, value == 0 --> cc == 0\n"); 60 61 v = 0; 62 wrong = ok = 0; 63 64 if (branch(0, 0xFFFF, v)) ++wrong; else ++ok; 65 if (branch(1, 0xFFFF, v)) ++wrong; else ++ok; 66 if (branch(2, 0xFFFF, v)) ++wrong; else ++ok; 67 if (branch(3, 0xFFFF, v)) ++wrong; else ++ok; 68 if (branch(4, 0xFFFF, v)) ++wrong; else ++ok; 69 if (branch(5, 0xFFFF, v)) ++wrong; else ++ok; 70 if (branch(6, 0xFFFF, v)) ++wrong; else ++ok; 71 if (branch(7, 0xFFFF, v)) ++wrong; else ++ok; 72 if (branch(8, 0xFFFF, v)) ++ok; else ++wrong; 73 if (branch(9, 0xFFFF, v)) ++ok; else ++wrong; 74 if (branch(10, 0xFFFF, v)) ++ok; else ++wrong; 75 if (branch(11, 0xFFFF, v)) ++ok; else ++wrong; 76 if (branch(12, 0xFFFF, v)) ++ok; else ++wrong; 77 if (branch(13, 0xFFFF, v)) ++ok; else ++wrong; 78 if (branch(14, 0xFFFF, v)) ++ok; else ++wrong; 79 if (branch(15, 0xFFFF, v)) ++ok; else ++wrong; 80 81 if (wrong != 0 || ok != 16) 82 printf("FAILED\n"); 83 else 84 printf("OK\n"); 85} 86 87void 88tmll_all_selected_bits_set_1(void) 89{ 90 int wrong, ok; 91 unsigned long v; 92 93 printf("Test #3 mask == 0xFFFF, value == 0xFFFF --> cc == 3\n"); 94 95 v = 0xFFFF; 96 wrong = ok = 0; 97 98 if (branch(0, 0xFFFF, v)) ++wrong; else ++ok; 99 if (branch(1, 0xFFFF, v)) ++ok; else ++wrong; 100 if (branch(2, 0xFFFF, v)) ++wrong; else ++ok; 101 if (branch(3, 0xFFFF, v)) ++ok; else ++wrong; 102 if (branch(4, 0xFFFF, v)) ++wrong; else ++ok; 103 if (branch(5, 0xFFFF, v)) ++ok; else ++wrong; 104 if (branch(6, 0xFFFF, v)) ++wrong; else ++ok; 105 if (branch(7, 0xFFFF, v)) ++ok; else ++wrong; 106 if (branch(8, 0xFFFF, v)) ++wrong; else ++ok; 107 if (branch(9, 0xFFFF, v)) ++ok; else ++wrong; 108 if (branch(10, 0xFFFF, v)) ++wrong; else ++ok; 109 if (branch(11, 0xFFFF, v)) ++ok; else ++wrong; 110 if (branch(12, 0xFFFF, v)) ++wrong; else ++ok; 111 if (branch(13, 0xFFFF, v)) ++ok; else ++wrong; 112 if (branch(14, 0xFFFF, v)) ++wrong; else ++ok; 113 if (branch(15, 0xFFFF, v)) ++ok; else ++wrong; 114 115 if (wrong != 0 || ok != 16) 116 printf("FAILED\n"); 117 else 118 printf("OK\n"); 119} 120 121void 122tmll_all_selected_bits_set_2(void) 123{ 124 int wrong, ok; 125 unsigned long v; 126 127 printf("Test #4 mask == 0x8000, value == 0x8000 --> cc == 3\n"); 128 129 v = 0x8000; 130 wrong = ok = 0; 131 132 if (branch(0, 0x8000, v)) ++wrong; else ++ok; 133 if (branch(1, 0x8000, v)) ++ok; else ++wrong; 134 if (branch(2, 0x8000, v)) ++wrong; else ++ok; 135 if (branch(3, 0x8000, v)) ++ok; else ++wrong; 136 if (branch(4, 0x8000, v)) ++wrong; else ++ok; 137 if (branch(5, 0x8000, v)) ++ok; else ++wrong; 138 if (branch(6, 0x8000, v)) ++wrong; else ++ok; 139 if (branch(7, 0x8000, v)) ++ok; else ++wrong; 140 if (branch(8, 0x8000, v)) ++wrong; else ++ok; 141 if (branch(9, 0x8000, v)) ++ok; else ++wrong; 142 if (branch(10, 0x8000, v)) ++wrong; else ++ok; 143 if (branch(11, 0x8000, v)) ++ok; else ++wrong; 144 if (branch(12, 0x8000, v)) ++wrong; else ++ok; 145 if (branch(13, 0x8000, v)) ++ok; else ++wrong; 146 if (branch(14, 0x8000, v)) ++wrong; else ++ok; 147 if (branch(15, 0x8000, v)) ++ok; else ++wrong; 148 149 if (wrong != 0 || ok != 16) 150 printf("FAILED\n"); 151 else 152 printf("OK\n"); 153} 154 155void 156tmll_some_selected_bits_set_msb_set(void) 157{ 158 int wrong, ok; 159 unsigned long v; 160 161 printf("Test #5 mask == 0xF000, value == 0x9000 --> cc == 2\n"); 162 163 v = 0x9000; 164 wrong = ok = 0; 165 166 if (branch(0, 0xF000, v)) ++wrong; else ++ok; 167 if (branch(1, 0xF000, v)) ++wrong; else ++ok; 168 if (branch(2, 0xF000, v)) ++ok; else ++wrong; 169 if (branch(3, 0xF000, v)) ++ok; else ++wrong; 170 if (branch(4, 0xF000, v)) ++wrong; else ++ok; 171 if (branch(5, 0xF000, v)) ++wrong; else ++ok; 172 if (branch(6, 0xF000, v)) ++ok; else ++wrong; 173 if (branch(7, 0xF000, v)) ++ok; else ++wrong; 174 if (branch(8, 0xF000, v)) ++wrong; else ++ok; 175 if (branch(9, 0xF000, v)) ++wrong; else ++ok; 176 if (branch(10, 0xF000, v)) ++ok; else ++wrong; 177 if (branch(11, 0xF000, v)) ++ok; else ++wrong; 178 if (branch(12, 0xF000, v)) ++wrong; else ++ok; 179 if (branch(13, 0xF000, v)) ++wrong; else ++ok; 180 if (branch(14, 0xF000, v)) ++ok; else ++wrong; 181 if (branch(15, 0xF000, v)) ++ok; else ++wrong; 182 183 if (wrong != 0 || ok != 16) 184 printf("FAILED\n"); 185 else 186 printf("OK\n"); 187} 188 189void 190tmll_some_selected_bits_set_msb_not_set(void) 191{ 192 int wrong, ok; 193 unsigned long v; 194 195 printf("Test #6 mask == 0xF000, value == 0x3000 --> cc == 1\n"); 196 197 v = 0x3000; 198 wrong = ok = 0; 199 200 if (branch(0, 0xF000, v)) ++wrong; else ++ok; 201 if (branch(1, 0xF000, v)) ++wrong; else ++ok; 202 if (branch(2, 0xF000, v)) ++wrong; else ++ok; 203 if (branch(3, 0xF000, v)) ++wrong; else ++ok; 204 if (branch(4, 0xF000, v)) ++ok; else ++wrong; 205 if (branch(5, 0xF000, v)) ++ok; else ++wrong; 206 if (branch(6, 0xF000, v)) ++ok; else ++wrong; 207 if (branch(7, 0xF000, v)) ++ok; else ++wrong; 208 if (branch(8, 0xF000, v)) ++wrong; else ++ok; 209 if (branch(9, 0xF000, v)) ++wrong; else ++ok; 210 if (branch(10, 0xF000, v)) ++wrong; else ++ok; 211 if (branch(11, 0xF000, v)) ++wrong; else ++ok; 212 if (branch(12, 0xF000, v)) ++ok; else ++wrong; 213 if (branch(13, 0xF000, v)) ++ok; else ++wrong; 214 if (branch(14, 0xF000, v)) ++ok; else ++wrong; 215 if (branch(15, 0xF000, v)) ++ok; else ++wrong; 216 217 if (wrong != 0 || ok != 16) 218 printf("FAILED\n"); 219 else 220 printf("OK\n"); 221} 222 223 224int main() 225{ 226 tmll_mask_0(); 227 tmll_value_0(); 228 tmll_all_selected_bits_set_1(); 229 tmll_all_selected_bits_set_2(); 230 tmll_some_selected_bits_set_msb_set(); 231 tmll_some_selected_bits_set_msb_not_set(); 232 233 return 0; 234} 235