| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 9328 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9339 // non-relocatable sequences, so we check it here to make sure it works. | 9339 // non-relocatable sequences, so we check it here to make sure it works. |
| 9340 // TODO(jbramley): Once Crankshaft is complete, decide if we need to support | 9340 // TODO(jbramley): Once Crankshaft is complete, decide if we need to support |
| 9341 // non-relocatable calls at all. | 9341 // non-relocatable calls at all. |
| 9342 CHECK(return_address == | 9342 CHECK(return_address == |
| 9343 Assembler::return_address_from_call_start(call_start)); | 9343 Assembler::return_address_from_call_start(call_start)); |
| 9344 | 9344 |
| 9345 TEARDOWN(); | 9345 TEARDOWN(); |
| 9346 } | 9346 } |
| 9347 | 9347 |
| 9348 | 9348 |
| 9349 static void ECMA262ToInt32Helper(int32_t expected, double input) { | |
| 9350 SETUP(); | |
| 9351 START(); | |
| 9352 | |
| 9353 __ Fmov(d0, input); | |
| 9354 | |
| 9355 __ ECMA262ToInt32(x0, d0, x10, x11, MacroAssembler::INT32_IN_W); | |
| 9356 __ ECMA262ToInt32(x1, d0, x10, x11, MacroAssembler::INT32_IN_X); | |
| 9357 __ ECMA262ToInt32(x2, d0, x10, x11, MacroAssembler::SMI); | |
| 9358 | |
| 9359 // The upper bits of INT32_IN_W are undefined, so make sure we don't try to | |
| 9360 // test them. | |
| 9361 __ Mov(w0, w0); | |
| 9362 | |
| 9363 END(); | |
| 9364 | |
| 9365 RUN(); | |
| 9366 | |
| 9367 int64_t expected64 = expected; | |
| 9368 | |
| 9369 ASSERT_EQUAL_32(expected, w0); | |
| 9370 ASSERT_EQUAL_64(expected64, x1); | |
| 9371 ASSERT_EQUAL_64(expected64 << kSmiShift | kSmiTag, x2); | |
| 9372 | |
| 9373 TEARDOWN(); | |
| 9374 } | |
| 9375 | |
| 9376 | |
| 9377 TEST(ecma_262_to_int32) { | |
| 9378 INIT_V8(); | |
| 9379 // ==== exponent < 64 ==== | |
| 9380 | |
| 9381 ECMA262ToInt32Helper(0, 0.0); | |
| 9382 ECMA262ToInt32Helper(0, -0.0); | |
| 9383 ECMA262ToInt32Helper(1, 1.0); | |
| 9384 ECMA262ToInt32Helper(-1, -1.0); | |
| 9385 | |
| 9386 // The largest representable value that is less than 1. | |
| 9387 ECMA262ToInt32Helper(0, 0x001fffffffffffff * pow(2.0, -53)); | |
| 9388 ECMA262ToInt32Helper(0, 0x001fffffffffffff * -pow(2.0, -53)); | |
| 9389 ECMA262ToInt32Helper(0, std::numeric_limits<double>::denorm_min()); | |
| 9390 ECMA262ToInt32Helper(0, -std::numeric_limits<double>::denorm_min()); | |
| 9391 | |
| 9392 // The largest conversion which doesn't require the integer modulo-2^32 step. | |
| 9393 ECMA262ToInt32Helper(0x7fffffff, 0x7fffffff); | |
| 9394 ECMA262ToInt32Helper(-0x80000000, -0x80000000); | |
| 9395 | |
| 9396 // The largest simple conversion, requiring module-2^32, but where the fcvt | |
| 9397 // does not saturate when converting to int64_t. | |
| 9398 ECMA262ToInt32Helper(0xfffffc00, 0x7ffffffffffffc00); | |
| 9399 ECMA262ToInt32Helper(-0xfffffc00, 0x7ffffffffffffc00 * -1.0); | |
| 9400 | |
| 9401 // ==== 64 <= exponent < 84 ==== | |
| 9402 | |
| 9403 // The smallest conversion where the fcvt saturates. | |
| 9404 ECMA262ToInt32Helper(0, 0x8000000000000000); | |
| 9405 ECMA262ToInt32Helper(0, 0x8000000000000000 * -1.0); | |
| 9406 | |
| 9407 // The smallest conversion where the fcvt saturates, and where all the | |
| 9408 // mantissa bits are '1' (to check the shift logic). | |
| 9409 ECMA262ToInt32Helper(0xfffff800, 0xfffffffffffff800); | |
| 9410 ECMA262ToInt32Helper(-0xfffff800, 0xfffffffffffff800 * -1.0); | |
| 9411 | |
| 9412 // The largest conversion which doesn't produce a zero result. | |
| 9413 ECMA262ToInt32Helper(0x80000000, 0x001fffffffffffff * pow(2.0, 31)); | |
| 9414 ECMA262ToInt32Helper(-0x80000000, 0x001fffffffffffff * -pow(2.0, 31)); | |
| 9415 | |
| 9416 // Some large conversions to check the shifting function. | |
| 9417 ECMA262ToInt32Helper(0x6789abcd, 0x001123456789abcd); | |
| 9418 ECMA262ToInt32Helper(0x12345678, 0x001123456789abcd * pow(2.0, -20)); | |
| 9419 ECMA262ToInt32Helper(0x891a2b3c, 0x001123456789abcd * pow(2.0, -21)); | |
| 9420 ECMA262ToInt32Helper(0x11234567, 0x001123456789abcd * pow(2.0, -24)); | |
| 9421 ECMA262ToInt32Helper(-0x6789abcd, 0x001123456789abcd * -1.0); | |
| 9422 ECMA262ToInt32Helper(-0x12345678, 0x001123456789abcd * -pow(2.0, -20)); | |
| 9423 ECMA262ToInt32Helper(-0x891a2b3c, 0x001123456789abcd * -pow(2.0, -21)); | |
| 9424 ECMA262ToInt32Helper(-0x11234567, 0x001123456789abcd * -pow(2.0, -24)); | |
| 9425 | |
| 9426 // ==== 84 <= exponent ==== | |
| 9427 | |
| 9428 // The smallest conversion which produces a zero result by shifting the | |
| 9429 // mantissa out of the int32_t range. | |
| 9430 ECMA262ToInt32Helper(0, pow(2.0, 32)); | |
| 9431 ECMA262ToInt32Helper(0, -pow(2.0, 32)); | |
| 9432 | |
| 9433 // Some very large conversions. | |
| 9434 ECMA262ToInt32Helper(0, 0x001fffffffffffff * pow(2.0, 32)); | |
| 9435 ECMA262ToInt32Helper(0, 0x001fffffffffffff * -pow(2.0, 32)); | |
| 9436 ECMA262ToInt32Helper(0, DBL_MAX); | |
| 9437 ECMA262ToInt32Helper(0, -DBL_MAX); | |
| 9438 | |
| 9439 // ==== Special values. ==== | |
| 9440 | |
| 9441 ECMA262ToInt32Helper(0, std::numeric_limits<double>::infinity()); | |
| 9442 ECMA262ToInt32Helper(0, -std::numeric_limits<double>::infinity()); | |
| 9443 ECMA262ToInt32Helper(0, std::numeric_limits<double>::quiet_NaN()); | |
| 9444 ECMA262ToInt32Helper(0, -std::numeric_limits<double>::quiet_NaN()); | |
| 9445 ECMA262ToInt32Helper(0, std::numeric_limits<double>::signaling_NaN()); | |
| 9446 ECMA262ToInt32Helper(0, -std::numeric_limits<double>::signaling_NaN()); | |
| 9447 } | |
| 9448 | |
| 9449 | |
| 9450 static void AbsHelperX(int64_t value) { | 9349 static void AbsHelperX(int64_t value) { |
| 9451 int64_t expected; | 9350 int64_t expected; |
| 9452 | 9351 |
| 9453 SETUP(); | 9352 SETUP(); |
| 9454 START(); | 9353 START(); |
| 9455 | 9354 |
| 9456 Label fail; | 9355 Label fail; |
| 9457 Label done; | 9356 Label done; |
| 9458 | 9357 |
| 9459 __ Mov(x0, 0); | 9358 __ Mov(x0, 0); |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9566 AbsHelperX(-42); | 9465 AbsHelperX(-42); |
| 9567 AbsHelperX(kXMinInt); | 9466 AbsHelperX(kXMinInt); |
| 9568 AbsHelperX(kXMaxInt); | 9467 AbsHelperX(kXMaxInt); |
| 9569 | 9468 |
| 9570 AbsHelperW(0); | 9469 AbsHelperW(0); |
| 9571 AbsHelperW(42); | 9470 AbsHelperW(42); |
| 9572 AbsHelperW(-42); | 9471 AbsHelperW(-42); |
| 9573 AbsHelperW(kWMinInt); | 9472 AbsHelperW(kWMinInt); |
| 9574 AbsHelperW(kWMaxInt); | 9473 AbsHelperW(kWMaxInt); |
| 9575 } | 9474 } |
| OLD | NEW |