1 #include <stdio.h> 2 #include "const.h" 3 4 const float reg_val_f[] = { 5 -347856.475, 356047.56, -1.0, 23.04, 6 1752, 0.0024575, 0.00000001, -248562.76, 7 1384.6, -7.2945676, 1000000000, -5786.47, 8 -347856.475, 356047.56, -1.0, 23.04, 9 0, 456.2489562, 3, -1, 10 -45786.476, 456.2489562, 34.00046, 45786.476, 11 0, 456.2489562, 3, -1, 12 1384.6, -7.2945676, 1000000000, -5786.47, 13 1752, 0.0024575, 0.00000001, -248562.76, 14 -45786.476, 456.2489562, 34.00046, 45786.476, 15 1752065, 107, -45667.24, -7.2945676, 16 -347856.475, 356047.56, -1.0, 23.04, 17 -347856.475, 356047.56, -1.0, 23.04, 18 1752, 0.0024575, 0.00000001, -248562.76, 19 1384.6, -7.2945676, 1000000000, -5786.47, 20 -347856.475, 356047.56, -1.0, 23.04, 21 0, 456.2489562, 3, -1, 22 -45786.476, 456.2489562, 34.00046, 45786.476, 23 0, 456.2489562, 3, -1, 24 1384.6, -7.2945676, 1000000000, -5786.47, 25 1752, 0.0024575, 0.00000001, -248562.76, 26 -45786.476, 456.2489562, 34.00046, 45786.476, 27 1752065, 107, -45667.24, -7.2945676, 28 -347856.475, 356047.56, -1.0, 23.04 29 }; 30 31 const float fs1_f[] = { 32 0, 456.2489562, 3, -1, 33 1384.6, -7.2945676, 1000000000, -5786.47, 34 1752, 0.0024575, 0.00000001, -248562.76, 35 -45786.476, 456.2489562, 34.00046, 45786.476, 36 1752065, 107, -45667.24, -7.2945676, 37 -347856.475, 356047.56, -1.0, 23.04 38 }; 39 40 const double fs2_f[] = { 41 0, 456.2489562, 3, -1, 42 -7.2945676, 1384.6, 1000000000, -5786.47, 43 1752, 0.0024575, -248562.76, 0.00000001, 44 -45786.476, 45786.476, 456.2489562, 34.00046, 45 1752065, 107, -45667.24, -7.2945676, 46 -347856.475, 23.04 -1.0, 356047.56 47 }; 48 49 #if defined(__mips_hard_float) 50 #define TEST1(mem) \ 51 { \ 52 unsigned long long out; \ 53 __asm__ __volatile__( \ 54 ".set noreorder" "\n\t" \ 55 ".set nomacro" "\n\t" \ 56 "move $t0, %1" "\n\t" \ 57 "mtc1 $t0, $f0" "\n\t" \ 58 "mov.s $f1, $f0" "\n\t" \ 59 "mfc1 $t1, $f1" "\n\t" \ 60 "move %0, $t1" "\n\t" \ 61 ".set reorder" "\n\t" \ 62 ".set macro" "\n\t" \ 63 : "=r" (out) \ 64 : "r" (mem) \ 65 : "t0", "t1", "$f0", "$f1" \ 66 ); \ 67 printf("mtc1, mov.s, mfc1 :: mem: 0x%llx out: 0x%llx\n", \ 68 (long long)mem, out); \ 69 } 70 71 #define TEST2(mem) \ 72 { \ 73 unsigned long long out; \ 74 __asm__ __volatile__( \ 75 ".set noreorder" "\n\t" \ 76 ".set nomacro" "\n\t" \ 77 "move $t0, %1" "\n\t" \ 78 "dmtc1 $t0, $f2" "\n\t" \ 79 "mov.d $f0, $f2" "\n\t" \ 80 "dmfc1 $t1, $f0" "\n\t" \ 81 "move %0, $t1" "\n\t" \ 82 ".set reorder" "\n\t" \ 83 ".set macro" "\n\t" \ 84 : "=r" (out) \ 85 : "r" (mem) \ 86 : "t0", "t1", "$f0", "$f2" \ 87 ); \ 88 printf("dmtc1, mov.d, dmfc1 :: mem: 0x%llx out: 0x%llx\n", \ 89 (long long)mem, out); \ 90 } 91 92 /* movX.s fd, fs */ 93 #define TEST3(instruction, FD, FS, cc, offset) \ 94 { \ 95 unsigned int out; \ 96 __asm__ __volatile__( \ 97 "li $t0, 1" "\n\t" \ 98 "move $t1, %1" "\n\t" \ 99 "mtc1 $t0, $f0" "\n\t" \ 100 "mtc1 $t1, $f2" "\n\t" \ 101 "dmtc1 $zero, $"#FD "\n\t" \ 102 "dmtc1 $zero, $"#FS "\n\t" \ 103 "c.eq.s $f0, $f2" "\n\t" \ 104 "move $t0, %2" "\n\t" \ 105 "lwc1 $"#FS", "#offset"($t0)" "\n\t" \ 106 instruction "\n\t" \ 107 "mfc1 %0, $"#FD "\n\t" \ 108 : "=r" (out) \ 109 : "r" (cc), "r" (reg_val_f) \ 110 : "t0", "t1", "$"#FD, "$"#FS, "$f0", "$f2" \ 111 ); \ 112 printf("%s :: out: 0x%x, cc: %d\n", \ 113 instruction, out, cc); \ 114 } 115 116 /* movX.d fd, fs */ 117 #define TEST3d(instruction, FD, FS, cc, offset) \ 118 { \ 119 unsigned long long out; \ 120 __asm__ __volatile__( \ 121 "li $t0, 1" "\n\t" \ 122 "move $t1, %1" "\n\t" \ 123 "mtc1 $t0, $f0" "\n\t" \ 124 "mtc1 $t1, $f2" "\n\t" \ 125 "dmtc1 $zero, $"#FD "\n\t" \ 126 "c.eq.s $f0, $f2" "\n\t" \ 127 "move $t0, %2" "\n\t" \ 128 "ldc1 $"#FS", "#offset"($t0)" "\n\t" \ 129 instruction "\n\t" \ 130 "dmfc1 %0, $"#FD "\n\t" \ 131 : "=r" (out) \ 132 : "r" (cc), "r" (reg_val_f) \ 133 : "t0", "t1", "$"#FD, "$"#FS, "$f0", "$f2" \ 134 ); \ 135 printf("%s :: out: 0x%llx, cc: %d\n", \ 136 instruction, out, cc); \ 137 } 138 139 /* movX.s fd, fs, rt */ 140 #define TEST4(instruction, offset, RTval, FD, FS, RT) \ 141 { \ 142 unsigned int out; \ 143 __asm__ __volatile__( \ 144 "move $"#RT", %2" "\n\t" \ 145 "dmtc1 $zero, $"#FD "\n\t" \ 146 "dmtc1 $zero, $"#FS "\n\t" \ 147 "move $t0, %1" "\n\t" \ 148 "lwc1 $"#FS", "#offset"($t0)" "\n\t" \ 149 instruction "\n\t" \ 150 "mfc1 %0, $"#FD"\n\t" \ 151 : "=r" (out) \ 152 : "r" (reg_val_f), "r" (RTval) \ 153 : "t0", #RT, "$"#FD, "$"#FS \ 154 ); \ 155 printf("%s :: out: 0x%x\n", instruction, out); \ 156 } 157 158 /* movX.d fd, fs, rt */ 159 #define TEST4d(instruction, offset, RTval, FD, FS, RT) \ 160 { \ 161 unsigned long long out; \ 162 __asm__ __volatile__( \ 163 "move $"#RT", %2" "\n\t" \ 164 "dmtc1 $zero, $"#FD "\n\t" \ 165 "dmtc1 $zero, $"#FS "\n\t" \ 166 "move $t0, %1" "\n\t" \ 167 "ldc1 $"#FS", "#offset"($t0)" "\n\t" \ 168 instruction "\n\t" \ 169 "dmfc1 %0, $"#FD "\n\t" \ 170 : "=r" (out) \ 171 : "r" (reg_val_f), "r" (RTval) \ 172 : #RT, "t0", "$"#FD, "$"#FS \ 173 ); \ 174 printf("%s :: out: 0x%llx\n", instruction, out); \ 175 } 176 177 /* movf, movt */ 178 #define TEST5(instruction, RDval, RSval, RD, RS) \ 179 { \ 180 unsigned long out; \ 181 __asm__ __volatile__( \ 182 "c.eq.s %3, %4" "\n\t" \ 183 "move $"#RD", %1" "\n\t" \ 184 "move $"#RS", %2" "\n\t" \ 185 instruction" $"#RD", $"#RS", $fcc0" "\n\t" \ 186 "move %0, $"#RD "\n\t" \ 187 : "=r" (out) \ 188 : "r" (RDval), "r" (RSval), "f" (fs1_f[i]), "f" (fs2_f[i]) \ 189 : #RD, #RS \ 190 ); \ 191 printf("%s :: RDval: 0x%x, RSval: 0x%x, out: 0x%lx\n", \ 192 instruction, RDval, RSval, out); \ 193 } 194 #endif 195 196 int main() 197 { 198 #if defined(__mips_hard_float) 199 int i; 200 init_reg_val2(); 201 202 for (i = 0; i < N; i++) { 203 TEST1(reg_val1[i]); 204 TEST2(reg_val1[i]); 205 TEST1(reg_val2[i]); 206 TEST2(reg_val2[i]); 207 } 208 209 printf("--- MOVF.S ---\n"); 210 TEST3("movf.s $f4, $f6, $fcc0", f4, f6, 1, 0); 211 TEST3("movf.s $f4, $f6, $fcc0", f4, f6, 1, 8); 212 TEST3("movf.s $f4, $f6, $fcc0", f4, f6, 1, 16); 213 TEST3("movf.s $f4, $f6, $fcc0", f4, f6, 1, 24); 214 TEST3("movf.s $f4, $f6, $fcc0", f4, f6, 1, 32) 215 TEST3("movf.s $f4, $f6, $fcc0", f4, f6, 1, 40) 216 TEST3("movf.s $f4, $f6, $fcc0", f4, f6, 1, 48) 217 TEST3("movf.s $f4, $f6, $fcc0", f4, f6, 1, 56) 218 TEST3("movf.s $f4, $f6, $fcc0", f4, f6, 0, 0); 219 TEST3("movf.s $f4, $f6, $fcc0", f4, f6, 0, 8); 220 TEST3("movf.s $f4, $f6, $fcc0", f4, f6, 0, 16); 221 TEST3("movf.s $f4, $f6, $fcc0", f4, f6, 0, 24); 222 TEST3("movf.s $f4, $f6, $fcc0", f4, f6, 0, 32); 223 TEST3("movf.s $f4, $f6, $fcc0", f4, f6, 0, 40); 224 TEST3("movf.s $f4, $f6, $fcc0", f4, f6, 0, 48); 225 TEST3("movf.s $f4, $f6, $fcc0", f4, f6, 0, 56); 226 227 printf("--- MOVF.D ---\n"); 228 TEST3d("movf.d $f4, $f6, $fcc0", f4, f6, 1, 0); 229 TEST3d("movf.d $f4, $f6, $fcc0", f4, f6, 1, 8); 230 TEST3d("movf.d $f4, $f6, $fcc0", f4, f6, 1, 16); 231 TEST3d("movf.d $f4, $f6, $fcc0", f4, f6, 1, 24); 232 TEST3d("movf.d $f4, $f6, $fcc0", f4, f6, 1, 32); 233 TEST3d("movf.d $f4, $f6, $fcc0", f4, f6, 1, 40) 234 TEST3d("movf.d $f4, $f6, $fcc0", f4, f6, 1, 48) 235 TEST3d("movf.d $f4, $f6, $fcc0", f4, f6, 1, 56) 236 TEST3d("movf.d $f4, $f6, $fcc0", f4, f6, 0, 0); 237 TEST3d("movf.d $f4, $f6, $fcc0", f4, f6, 0, 8); 238 TEST3d("movf.d $f4, $f6, $fcc0", f4, f6, 0, 16); 239 TEST3d("movf.d $f4, $f6, $fcc0", f4, f6, 0, 24); 240 TEST3d("movf.d $f4, $f6, $fcc0", f4, f6, 0, 32); 241 TEST3d("movf.d $f4, $f6, $fcc0", f4, f6, 0, 40); 242 TEST3d("movf.d $f4, $f6, $fcc0", f4, f6, 0, 48); 243 TEST3d("movf.d $f4, $f6, $fcc0", f4, f6, 0, 56); 244 245 printf("--- MOVN.S ---\n"); 246 TEST4("movn.s $f0, $f2, $11", 0, 0, f0, f2, 11); 247 TEST4("movn.s $f0, $f2, $11", 0, 1, f0, f2, 11); 248 TEST4("movn.s $f0, $f2, $11", 8, 0xffff, f0, f2, 11); 249 TEST4("movn.s $f0, $f2, $11", 16, -1, f0, f2, 11); 250 TEST4("movn.s $f0, $f2, $11", 16, 5, f0, f2, 11); 251 TEST4("movn.s $f0, $f2, $11", 24, 0, f0, f2, 11); 252 TEST4("movn.s $f0, $f2, $11", 24, 0, f0, f2, 11); 253 TEST4("movn.s $f0, $f2, $11", 32, 5, f0, f2, 11); 254 TEST4("movn.s $f0, $f2, $11", 32, 125487, f0, f2, 11); 255 TEST4("movn.s $f0, $f2, $11", 40, 68, f0, f2, 11); 256 TEST4("movn.s $f0, $f2, $11", 40, -122544, f0, f2, 11); 257 TEST4("movn.s $f0, $f2, $11", 48, 0, f0, f2, 11); 258 TEST4("movn.s $f0, $f2, $11", 48, 0, f0, f2, 11); 259 TEST4("movn.s $f0, $f2, $11", 56, 0xffffffff, f0, f2, 11); 260 TEST4("movn.s $f0, $f2, $11", 56, 0x80000000, f0, f2, 11); 261 TEST4("movn.s $f0, $f2, $11", 64, 0x7fffffff, f0, f2, 11); 262 263 printf("--- MOVN.D ---\n"); 264 TEST4d("movn.d $f0, $f2, $11", 0, 0, f0, f2, 11); 265 TEST4d("movn.d $f0, $f2, $11", 0, 1, f0, f2, 11); 266 TEST4d("movn.d $f0, $f2, $11", 8, 0xffff, f0, f2, 11); 267 TEST4d("movn.d $f0, $f2, $11", 8, -1, f0, f2, 11); 268 TEST4d("movn.d $f0, $f2, $11", 16, 5, f0, f2, 11); 269 TEST4d("movn.d $f0, $f2, $11", 24, 0, f0, f2, 11); 270 TEST4d("movn.d $f0, $f2, $11", 24, 0, f0, f2, 11); 271 TEST4d("movn.d $f0, $f2, $11", 32, 5, f0, f2, 11); 272 TEST4d("movn.d $f0, $f2, $11", 32, 125487, f0, f2, 11); 273 TEST4d("movn.d $f0, $f2, $11", 40, 68, f0, f2, 11); 274 TEST4d("movn.d $f0, $f2, $11", 40, -122544, f0, f2, 11); 275 TEST4d("movn.d $f0, $f2, $11", 48, 0, f0, f2, 11); 276 TEST4d("movn.d $f0, $f2, $11", 48, 0, f0, f2, 11); 277 TEST4d("movn.d $f0, $f2, $11", 56, 0xffffffff, f0, f2, 11); 278 TEST4d("movn.d $f0, $f2, $11", 56, 0x80000000, f0, f2, 11); 279 TEST4d("movn.d $f0, $f2, $11", 64, 0x7fffffff, f0, f2, 11); 280 281 printf("--- MOVT.S ---\n"); 282 TEST3("movt.s $f4, $f6, $fcc0", f4, f6, 1, 0); 283 TEST3("movt.s $f4, $f6, $fcc0", f4, f6, 1, 0); 284 TEST3("movt.s $f4, $f6, $fcc0", f4, f6, 1, 8); 285 TEST3("movt.s $f4, $f6, $fcc0", f4, f6, 1, 16); 286 TEST3("movt.s $f4, $f6, $fcc0", f4, f6, 1, 24); 287 TEST3("movt.s $f4, $f6, $fcc0", f4, f6, 1, 32); 288 TEST3("movt.s $f4, $f6, $fcc0", f4, f6, 1, 40) 289 TEST3("movt.s $f4, $f6, $fcc0", f4, f6, 1, 48) 290 TEST3("movt.s $f4, $f6, $fcc0", f4, f6, 1, 56) 291 TEST3("movt.s $f4, $f6, $fcc0", f4, f6, 0, 0); 292 TEST3("movt.s $f4, $f6, $fcc0", f4, f6, 0, 8); 293 TEST3("movt.s $f4, $f6, $fcc0", f4, f6, 0, 16); 294 TEST3("movt.s $f4, $f6, $fcc0", f4, f6, 0, 24); 295 TEST3("movt.s $f4, $f6, $fcc0", f4, f6, 0, 32); 296 TEST3("movt.s $f4, $f6, $fcc0", f4, f6, 0, 40); 297 TEST3("movt.s $f4, $f6, $fcc0", f4, f6, 0, 48); 298 TEST3("movt.s $f4, $f6, $fcc0", f4, f6, 0, 56); 299 300 printf("--- MOVT.D ---\n"); 301 TEST3d("movt.d $f4, $f6, $fcc0", f4, f6, 1, 0); 302 TEST3d("movt.d $f4, $f6, $fcc0", f4, f6, 1, 0); 303 TEST3d("movt.d $f4, $f6, $fcc0", f4, f6, 1, 8); 304 TEST3d("movt.d $f4, $f6, $fcc0", f4, f6, 1, 16); 305 TEST3d("movt.d $f4, $f6, $fcc0", f4, f6, 1, 24); 306 TEST3d("movt.d $f4, $f6, $fcc0", f4, f6, 1, 32); 307 TEST3d("movt.d $f4, $f6, $fcc0", f4, f6, 1, 40) 308 TEST3d("movt.d $f4, $f6, $fcc0", f4, f6, 1, 48) 309 TEST3d("movt.d $f4, $f6, $fcc0", f4, f6, 1, 56) 310 TEST3d("movt.d $f4, $f6, $fcc0", f4, f6, 0, 0); 311 TEST3d("movt.d $f4, $f6, $fcc0", f4, f6, 0, 8); 312 TEST3d("movt.d $f4, $f6, $fcc0", f4, f6, 0, 16); 313 TEST3d("movt.d $f4, $f6, $fcc0", f4, f6, 0, 24); 314 TEST3d("movt.d $f4, $f6, $fcc0", f4, f6, 0, 32); 315 TEST3d("movt.d $f4, $f6, $fcc0", f4, f6, 0, 40); 316 TEST3d("movt.d $f4, $f6, $fcc0", f4, f6, 0, 48); 317 TEST3d("movt.d $f4, $f6, $fcc0", f4, f6, 0, 56); 318 319 printf("--- MOVZ.S ---\n"); 320 TEST4("movz.s $f0, $f2, $11", 0, 0, f0, f2, 11); 321 TEST4("movz.s $f0, $f2, $11", 8, 1, f0, f2, 11); 322 TEST4("movz.s $f0, $f2, $11", 8, 0xffff, f0, f2, 11); 323 TEST4("movz.s $f0, $f2, $11", 16, -1, f0, f2, 11); 324 TEST4("movz.s $f0, $f2, $11", 16, 5, f0, f2, 11); 325 TEST4("movz.s $f0, $f2, $11", 24, 0, f0, f2, 11); 326 TEST4("movz.s $f0, $f2, $11", 24, 0, f0, f2, 11); 327 TEST4("movz.s $f0, $f2, $11", 32, 5, f0, f2, 11); 328 TEST4("movz.s $f0, $f2, $11", 32, 125487, f0, f2, 11); 329 TEST4("movz.s $f0, $f2, $11", 40, 68, f0, f2, 11); 330 TEST4("movz.s $f0, $f2, $11", 40, -122544, f0, f2, 11); 331 TEST4("movz.s $f0, $f2, $11", 48, 0, f0, f2, 11); 332 TEST4("movz.s $f0, $f2, $11", 48, 0, f0, f2, 11); 333 TEST4("movz.s $f0, $f2, $11", 56, 0xffffffff, f0, f2, 11); 334 TEST4("movz.s $f0, $f2, $11", 56, 0x80000000, f0, f2, 11); 335 TEST4("movz.s $f0, $f2, $11", 64, 0x7fffffff, f0, f2, 11); 336 337 printf("--- MOVZ.D ---\n"); 338 TEST4d("movz.d $f0, $f2, $11", 0, 0, f0, f2, 11); 339 TEST4d("movz.d $f0, $f2, $11", 0, 1, f0, f2, 11); 340 TEST4d("movz.d $f0, $f2, $11", 8, 0xffff, f0, f2, 11); 341 TEST4d("movz.d $f0, $f2, $11", 16, -1, f0, f2, 11); 342 TEST4d("movz.d $f0, $f2, $11", 16, 5, f0, f2, 11); 343 TEST4d("movz.d $f0, $f2, $11", 24, 0, f0, f2, 11); 344 TEST4d("movz.d $f0, $f2, $11", 24, 0, f0, f2, 11); 345 TEST4d("movz.d $f0, $f2, $11", 32, 5, f0, f2, 11); 346 TEST4d("movz.d $f0, $f2, $11", 32, 125487, f0, f2, 11); 347 TEST4d("movz.d $f0, $f2, $11", 40, 68, f0, f2, 11); 348 TEST4d("movz.d $f0, $f2, $11", 40, -122544, f0, f2, 11); 349 TEST4d("movz.d $f0, $f2, $11", 48, 0, f0, f2, 11); 350 TEST4d("movz.d $f0, $f2, $11", 48, 0, f0, f2, 11); 351 TEST4d("movz.d $f0, $f2, $11", 56, 0xffffffff, f0, f2, 11); 352 TEST4d("movz.d $f0, $f2, $11", 56, 0x80000000, f0, f2, 11); 353 TEST4d("movz.d $f0, $f2, $11", 64, 0x7fffffff, f0, f2, 11); 354 355 printf("--- MOVF --- if FPConditionalCode(cc) == 0 then " 356 "out = RSval else out = RDval\n"); 357 for (i = 0; i < 24; i++) { 358 TEST5("movf", 0xaaaaaaaa, 0x80000000, t0, t1); 359 TEST5("movf", 0xccccffff, 0xffffffff, t1, t2); 360 TEST5("movf", 0xffffaaaa, 0xaaaaffff, t3, t1); 361 TEST5("movf", 0x0, 0xffffffff, t3, t0); 362 } 363 364 printf("--- MOVT --- if FPConditionalCode(cc) == 1 then " 365 "out = RSval else out = RDval\n"); 366 for (i = 0; i < 24; i++) { 367 TEST5("movt", 0x0, 0xffffffff, t0, t1); 368 TEST5("movt", 0x11111111, 0xeeeeffff, t1, t2); 369 TEST5("movt", 0x5555ffff, 0xffffffff, t3, t1); 370 TEST5("movt", 0xeeeeeeee, 0xffffeeee, t3, t0); 371 } 372 #endif 373 return 0; 374 } 375