| OLD | NEW |
| 1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 t.b = 2.75; | 276 t.b = 2.75; |
| 277 t.c = 17.17; | 277 t.c = 17.17; |
| 278 Object* dummy = CALL_GENERATED_CODE(f, &t, 0, 0, 0, 0); | 278 Object* dummy = CALL_GENERATED_CODE(f, &t, 0, 0, 0, 0); |
| 279 USE(dummy); | 279 USE(dummy); |
| 280 CHECK_EQ(4.25, t.c); | 280 CHECK_EQ(4.25, t.c); |
| 281 CHECK_EQ(4.25, t.b); | 281 CHECK_EQ(4.25, t.b); |
| 282 CHECK_EQ(1.5, t.a); | 282 CHECK_EQ(1.5, t.a); |
| 283 } | 283 } |
| 284 } | 284 } |
| 285 | 285 |
| 286 |
| 287 static void TestImmediate(uint32_t imm) { |
| 288 v8::HandleScope scope; |
| 289 |
| 290 // Each section uses Operand(imm) and should end with imm in r2. |
| 291 // If not, we exit with the number of the test that failed. |
| 292 Assembler assm(NULL, 0); |
| 293 Label done; |
| 294 __ eor(r3, r3, Operand(r3)); |
| 295 __ mvn(r3, Operand(r3)); // Set all bits in r3. Use leading zeros as counter. |
| 296 // 1. MOV. |
| 297 __ mov(r3, Operand(r3, LSR, 1)); // Count without using immediate. |
| 298 __ mov(r2, Operand(imm)); |
| 299 __ cmp(r2, Operand(r0)); |
| 300 __ b(ne, &done); |
| 301 // 2. MVN. |
| 302 __ mov(r3, Operand(r3, LSR, 1)); |
| 303 __ mvn(r2, Operand(imm)); // Load negated |
| 304 __ mvn(r2, Operand(r2)); // Negate back. |
| 305 __ cmp(r2, Operand(r0)); |
| 306 __ b(ne, &done); |
| 307 // 3. ADD. |
| 308 __ mov(r3, Operand(r3, LSR, 1)); |
| 309 __ eor(r2, r2, Operand(r2)); |
| 310 __ add(r2, r2, Operand(imm)); |
| 311 __ cmp(r2, Operand(r0)); |
| 312 __ b(ne, &done); |
| 313 // 4. AND. |
| 314 __ mov(r3, Operand(r3, LSR, 1)); |
| 315 __ eor(r2, r2, Operand(r2)); |
| 316 __ mvn(r2, Operand(r2)); |
| 317 __ and_(r2, r2, Operand(imm)); |
| 318 __ cmp(r2, Operand(r0)); |
| 319 __ b(ne, &done); |
| 320 // 5. BIC |
| 321 __ mov(r3, Operand(r3, LSR, 1)); |
| 322 // Set all bits, clear the bits in imm, then flip all bits. |
| 323 __ eor(r2, r2, Operand(r2)); |
| 324 __ mvn(r2, Operand(r2)); |
| 325 __ bic(r2, r2, Operand(imm)); |
| 326 __ mvn(r2, Operand(r2)); |
| 327 __ cmp(r2, Operand(r0)); |
| 328 __ b(ne, &done); |
| 329 // Put more tests here. |
| 330 |
| 331 // Reset counter to zero. |
| 332 __ eor(r3, r3, Operand(r3)); |
| 333 __ mvn(r3, Operand(r3)); |
| 334 __ bind(&done); |
| 335 __ clz(r0, r3); |
| 336 __ str(r2, MemOperand(r1)); |
| 337 __ mov(pc, lr); |
| 338 |
| 339 CodeDesc desc; |
| 340 assm.GetCode(&desc); |
| 341 Object* code = Heap::CreateCode(desc, |
| 342 NULL, |
| 343 Code::ComputeFlags(Code::STUB), |
| 344 Handle<Object>(Heap::undefined_value())); |
| 345 F2 f = FUNCTION_CAST<F2>(Code::cast(code)->entry()); |
| 346 int32_t bad_result = imm; |
| 347 int32_t res = reinterpret_cast<int32_t >( |
| 348 CALL_GENERATED_CODE(f, imm, |
| 349 reinterpret_cast<int32_t>(&bad_result), 0, 0, 0)); |
| 350 if (res != 0) { |
| 351 #ifdef DEBUG |
| 352 Code::cast(code)->Print(); |
| 353 #endif |
| 354 printf("Test %d.\n", res); |
| 355 } |
| 356 CHECK_EQ(imm, bad_result); |
| 357 } |
| 358 |
| 359 |
| 360 TEST(Immediates) { |
| 361 InitializeVM(); |
| 362 |
| 363 TestImmediate(0); |
| 364 TestImmediate(~0); |
| 365 for (int i = 0; i < 32; i++) { |
| 366 TestImmediate(1u << i); |
| 367 TestImmediate(~(1u << i)); |
| 368 } |
| 369 for (int i = 0; i <= 25; i++) { |
| 370 TestImmediate(65u << i); |
| 371 TestImmediate(~(65u << i)); |
| 372 } |
| 373 for (int i = 0; i <= 24; i++) { |
| 374 TestImmediate(255u << i); |
| 375 TestImmediate(~(255u << i)); |
| 376 } |
| 377 |
| 378 for (int i = 0; i <= 16; i++) { |
| 379 for (int j = i + 8; j <= 24 ; j++) { |
| 380 TestImmediate((255u << i) | (255u << j)); |
| 381 } |
| 382 } |
| 383 // Wrapped. |
| 384 for (int i = 1; i <= 7; i++) { |
| 385 TestImmediate((0x255u >> i) | (0x255u << (32 - i))); |
| 386 } |
| 387 for (int i = 1; i <= 7; i++) { |
| 388 for (int j = 8 - i; j < 24 + i; j++) { |
| 389 TestImmediate((0x255u >> i) | (0x255u << (32 - i)) | (255u << j)); |
| 390 } |
| 391 } |
| 392 TestImmediate(0x55555555u); |
| 393 TestImmediate(0xAAAAAAAAu); |
| 394 TestImmediate(0x33333333u); |
| 395 TestImmediate(0xCCCCCCCCu); |
| 396 TestImmediate(0x0F0F0F0Fu); |
| 397 TestImmediate(0x00F0F0F0u); |
| 398 TestImmediate(0xF00FF00Fu); |
| 399 TestImmediate(0xFF00FF00u); |
| 400 TestImmediate(0x0FF00FF0u); |
| 401 TestImmediate(0x00FF00FFu); |
| 402 TestImmediate(0xFFFF0000u); |
| 403 TestImmediate(0x00FFFF00u); |
| 404 TestImmediate(0x0000FFFFu); |
| 405 TestImmediate(0xFF0000FFu); |
| 406 } |
| 407 |
| 286 #undef __ | 408 #undef __ |
| OLD | NEW |