1 #include <stdio.h> 2 3 #define MAX_ARR 24 4 5 const float fs_f[] = { 6 0, 456.25, 3, -1, 7 1384.5, -7.25, 1000000000, -5786.5, 8 1752, 0.015625, 0.03125, -248562.75, 9 -45786.5, 456, 34.03125, 45786.75, 10 1752065, 107, -45667.25, -7, 11 -347856.5, 356047.5, -1.0, 23.0625 12 }; 13 14 const float ft_f[] = { 15 -4578.5, 456.25, 34.03125, 4578.75, 16 175, 107, -456.25, -7.25, 17 -3478.5, 356.5, -1.0, 23.0625, 18 0, 456.25, 3, -1, 19 1384.5, -7, 100, -5786.5, 20 1752, 0.015625, 0.03125, -248562.75 21 }; 22 23 const double fs_d[] = { 24 0, 456.25, 3, -1, 25 1384.5, -7.25, 1000000000, -5786.5, 26 1752, 0.015625, 0.03125, -248562.75, 27 -45786.5, 456, 34.03125, 45786.75, 28 1752065, 107, -45667.25, -7, 29 -347856.5, 356047.5, -1.0, 23.0625 30 }; 31 32 const double ft_d[] = { 33 -45786.5, 456.25, 34.03125, 45786.75, 34 1752065, 107, -45667.25, -7.25, 35 -347856.5, 356047.5, -1.0, 23.0625, 36 0, 456.25, 3, -1, 37 1384.5, -7, 1000000000, -5786.5, 38 1752, 0.015625, 0.03125, -248562.75 39 }; 40 41 /* Conditional macros.*/ 42 #define TESTINST1s(instruction, RDval) \ 43 { \ 44 float outf = 0; \ 45 __asm__ __volatile__( \ 46 ".set noreorder" "\n\t" \ 47 "mov.s $f0, %1" "\n\t" \ 48 "mov.s $f2, %2" "\n\t" \ 49 "c.eq.s $f0, $f2" "\n\t" \ 50 instruction" end"instruction"s"#RDval "\n\t" \ 51 "nop" "\n\t" \ 52 "add.s $f0, $f0, $f2" "\n\t" \ 53 "end"instruction"s"#RDval":" "\n\t" \ 54 "mov.s %0, $f0" "\n\t" \ 55 ".set reorder" "\n\t" \ 56 : "=f" (outf) \ 57 : "f" (fs_f[i]) , "f" (ft_f[i]) \ 58 : "$f0", "$f2" \ 59 ); \ 60 printf("%s, c.eq.s out=%f, fs=%f, ft=%f\n", \ 61 instruction, outf, fs_f[i], ft_f[i]); \ 62 } 63 64 #define TESTINST1d(instruction, RDval) \ 65 { \ 66 double outd = 0; \ 67 __asm__ __volatile__( \ 68 ".set noreorder" "\n\t" \ 69 "mov.d $f0, %1" "\n\t" \ 70 "mov.d $f2, %2" "\n\t" \ 71 "c.eq.d $f0, $f2" "\n\t" \ 72 instruction" end"instruction"d"#RDval "\n\t" \ 73 "nop" "\n\t" \ 74 "add.d $f0, $f0, $f2" "\n\t" \ 75 "end"instruction"d"#RDval":" "\n\t" \ 76 "mov.d %0, $f0" "\n\t" \ 77 ".set reorder" "\n\t" \ 78 : "=f" (outd) \ 79 : "f" (fs_d[i]) , "f" (ft_d[i]) \ 80 : "$f0", "$f1", "$f2", "$f3" \ 81 ); \ 82 printf("%s, c.eq.d out=%f, fs=%f, ft=%f\n", \ 83 instruction, outd, fs_d[i], ft_d[i]); \ 84 } 85 86 #define TESTINST2s(instruction, RDval) \ 87 { \ 88 float outf = 0; \ 89 __asm__ __volatile__( \ 90 ".set noreorder" "\n\t" \ 91 "mov.s $f0, %1" "\n\t" \ 92 "mov.s $f2, %2" "\n\t" \ 93 "c.eq.s $f0, $f2" "\n\t" \ 94 instruction" end"instruction"s"#RDval "\n\t" \ 95 "add.s $f0, $f0, $f2" "\n\t" \ 96 "end"instruction"s"#RDval":" "\n\t" \ 97 "mov.s %0, $f0" "\n\t" \ 98 ".set reorder" "\n\t" \ 99 : "=f" (outf) \ 100 : "f" (fs_f[i]) , "f" (ft_f[i]) \ 101 : "$f0", "$f2" \ 102 ); \ 103 printf("%s, c.eq.s out=%f, fs=%f, ft=%f\n", \ 104 instruction, outf, fs_f[i], ft_f[i]); \ 105 } 106 107 #define TESTINST2d(instruction, RDval) \ 108 { \ 109 double outd = 0; \ 110 __asm__ __volatile__( \ 111 ".set noreorder" "\n\t" \ 112 "mov.d $f0, %1" "\n\t" \ 113 "mov.d $f2, %2" "\n\t" \ 114 "c.eq.d $f0, $f2" "\n\t" \ 115 instruction" end"instruction"d"#RDval "\n\t" \ 116 "add.d $f0, $f0, $f2" "\n\t" \ 117 "end"instruction"d"#RDval":" "\n\t" \ 118 "mov.d %0, $f0" "\n\t" \ 119 ".set reorder" "\n\t" \ 120 : "=f" (outd) \ 121 : "f" (fs_d[i]) , "f" (ft_d[i]) \ 122 : "$f0", "$f1", "$f2", "$f3" \ 123 ); \ 124 printf("%s, c.eq.d out=%f, fs=%f, ft=%f\n", \ 125 instruction, outd, fs_d[i], ft_d[i]); \ 126 } 127 128 #define TESTINST_CONDs(instruction, RDval) \ 129 { \ 130 float outf = 0; \ 131 __asm__ __volatile__( \ 132 ".set noreorder" "\n\t" \ 133 "mov.s $f0, %1" "\n\t" \ 134 "mov.s $f2, %2" "\n\t" \ 135 instruction" $f0, $f2" "\n\t" \ 136 "bc1f end"instruction"s"#RDval "\n\t" \ 137 "nop" "\n\t" \ 138 "add.s $f0, $f0, $f2" "\n\t" \ 139 "end"instruction"s"#RDval":" "\n\t" \ 140 "mov.s %0, $f0" "\n\t" \ 141 ".set reorder" "\n\t" \ 142 : "=f" (outf) \ 143 : "f" (fs_f[i]) , "f" (ft_f[i]) \ 144 : "$f0", "$f1", "$f2" \ 145 ); \ 146 printf("%s, bc1f out=%f, fs=%f, ft=%f\n", \ 147 instruction, outf, fs_f[i], ft_f[i]); \ 148 } 149 150 #define TESTINST_CONDd(instruction, RDval) \ 151 { \ 152 double outd = 0; \ 153 __asm__ __volatile__( \ 154 ".set noreorder" "\n\t" \ 155 "mov.d $f0, %1" "\n\t" \ 156 "mov.d $f2, %2" "\n\t" \ 157 instruction" $f0, $f2" "\n\t" \ 158 "bc1f end"instruction"d"#RDval "\n\t" \ 159 "nop" "\n\t" \ 160 "add.d $f0, $f0, $f2" "\n\t" \ 161 "end"instruction"d"#RDval":" "\n\t" \ 162 "mov.d %0, $f0" "\n\t" \ 163 ".set reorder" "\n\t" \ 164 : "=f" (outd) \ 165 : "f" (fs_d[i]) , "f" (ft_d[i]) \ 166 : "$f0", "$f1", "$f2", "$f2" \ 167 ); \ 168 printf("%s, bc1f out=%f, fs=%f, ft=%f\n", \ 169 instruction, outd, fs_d[i], ft_d[i]); \ 170 } 171 172 int main() 173 { 174 int i = 0; 175 176 printf("--- BC1F --- if fs != ft then " \ 177 "out = fs else out = fs + ft\n"); 178 for (i = 0; i < MAX_ARR; i++) { 179 TESTINST1s("bc1f", i); 180 TESTINST1d("bc1f", i); 181 } 182 183 printf("--- BC1T --- if fs == ft then " \ 184 "out = fs else out = fs + ft\n"); 185 for (i = 0; i < MAX_ARR; i++) { 186 TESTINST1s("bc1t", i); 187 TESTINST1d("bc1t", i); 188 } 189 190 printf("--- BC1FL --- if fs == ft then " \ 191 "out = ft else out = fs + ft\n"); 192 for (i = 0; i < MAX_ARR; i++) { 193 TESTINST2s("bc1fl", i); 194 TESTINST2d("bc1fl", i); 195 } 196 197 printf("--- BC1TL --- if fs != ft then " \ 198 "out = fs else out = fs + ft\n"); 199 for (i = 0; i < MAX_ARR; i++) { 200 TESTINST2s("bc1tl", i); 201 TESTINST2d("bc1tl", i); 202 } 203 204 printf("--- C.F.S/D --- if false then " \ 205 "out = fs + ft else out = fs\n"); 206 for (i = 0; i < MAX_ARR; i++) { 207 TESTINST_CONDs("c.f.s", i); 208 TESTINST_CONDd("c.f.d", i); 209 } 210 211 printf("--- C.UN.S/D --- if unordered(fs, ft) then " \ 212 "out = fs + ft else out = fs\n"); 213 for (i = 0; i < MAX_ARR; i++) { 214 TESTINST_CONDs("c.un.s", i); 215 TESTINST_CONDd("c.un.d", i); 216 } 217 218 printf("--- C.EQ.S/D --- if fs == ft then " \ 219 "out = fs + ft else out = fs\n"); 220 for (i = 0; i < MAX_ARR; i++) { 221 TESTINST_CONDs("c.eq.s", i); 222 TESTINST_CONDd("c.eq.d", i); 223 } 224 225 printf("--- C.UEQ.S/D --- if (unordered(fs, ft) or (fs == ft)) then " \ 226 "out = fs + ft else out = fs\n"); 227 for (i = 0; i < MAX_ARR; i++) { 228 TESTINST_CONDs("c.ueq.s", i); 229 TESTINST_CONDd("c.ueq.d", i); 230 } 231 232 printf("--- C.OLT.S/D --- if (ordered(fs, ft) or (fs < ft)) then " \ 233 "out = fs + ft else out = fs\n"); 234 for (i = 0; i < MAX_ARR; i++) { 235 TESTINST_CONDs("c.olt.s", i); 236 TESTINST_CONDd("c.olt.d", i); 237 } 238 239 printf("--- C.ULT.S/D --- if (unordered(fs, ft) or (fs < ft)) then " \ 240 "out = fs + ft else out = fs\n"); 241 for (i = 0; i < MAX_ARR; i++) { 242 TESTINST_CONDs("c.ult.s", i); 243 TESTINST_CONDd("c.ult.d", i); 244 } 245 246 printf("--- C.OLE.S/D --- if (ordered(fs, ft) or (fs <= ft)) then " \ 247 "out = fs + ft else out = fs\n"); 248 for (i = 0; i < MAX_ARR; i++) { 249 TESTINST_CONDs("c.ole.s", i); 250 TESTINST_CONDd("c.ole.d", i); 251 } 252 253 printf("--- C.ULE.S/D --- if (unordered(fs, ft) or (fs <= ft)) then " \ 254 "out = fs + ft else out = fs\n"); 255 for (i = 0; i < MAX_ARR; i++) { 256 TESTINST_CONDs("c.ule.s", i); 257 TESTINST_CONDd("c.ule.d", i); 258 } 259 260 printf("--- C.SF.S/D --- if signaling false then " \ 261 "out = fs + ft else out = fs\n"); 262 for (i = 0; i < MAX_ARR; i++) { 263 TESTINST_CONDs("c.sf.s", i); 264 TESTINST_CONDd("c.sf.d", i); 265 } 266 267 printf("--- C.NGLE.S/D --- if not ((fs > ft) or (fs <= ft)) then " \ 268 "out = fs + ft else out = fs\n"); 269 for (i = 0; i < MAX_ARR; i++) { 270 TESTINST_CONDs("c.ngle.s", i); 271 TESTINST_CONDd("c.ngle.d", i); 272 } 273 274 printf("--- C.SEQ.S/D --- if signaling equal then " \ 275 "out = fs + ft else out = fs\n"); 276 for (i = 0; i < MAX_ARR; i++) { 277 TESTINST_CONDs("c.seq.s", i); 278 TESTINST_CONDd("c.seq.d", i); 279 } 280 281 printf("--- C.NGL.S/D --- if not ((fs > ft) or (fs < ft)) then " \ 282 "out = fs + ft else out = fs\n"); 283 for (i = 0; i < MAX_ARR; i++) { 284 TESTINST_CONDs("c.ngl.s", i); 285 TESTINST_CONDd("c.ngl.d", i); 286 } 287 288 printf("--- C.LT.S/D --- if fs < ft then " \ 289 "out = fs + ft else out = fs\n"); 290 for (i = 0; i < MAX_ARR; i++) { 291 TESTINST_CONDs("c.lt.s", i); 292 TESTINST_CONDd("c.lt.d", i); 293 } 294 295 printf("--- C.NGE.S/D --- if not (fs >= ft) then " \ 296 "out = fs + ft else out = fs\n"); 297 for (i = 0; i < MAX_ARR; i++) { 298 TESTINST_CONDs("c.nge.s", i); 299 TESTINST_CONDd("c.nge.d", i); 300 } 301 302 printf("--- C.LE.S/D --- if fs <= ft then " \ 303 "out = fs + ft else out = fs\n"); 304 for (i = 0; i < MAX_ARR; i++) { 305 TESTINST_CONDs("c.le.s", i); 306 TESTINST_CONDd("c.le.d", i); 307 } 308 309 printf("--- C.NGT.S/D --- if not (fs > ft) then " \ 310 "out = fs + ft else out = fs\n"); 311 for (i = 0; i < MAX_ARR; i++) { 312 TESTINST_CONDs("c.ngt.s", i); 313 TESTINST_CONDd("c.ngt.d", i); 314 } 315 return 0; 316 } 317 318