OLD | NEW |
1 // Copyright 2009 the V8 project authors. All rights reserved. | 1 // Copyright 2009 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 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 // This calling convention is used on Linux, with GCC, and on Mac OS, | 91 // This calling convention is used on Linux, with GCC, and on Mac OS, |
92 // with GCC. A different convention is used on 64-bit windows. | 92 // with GCC. A different convention is used on 64-bit windows. |
93 | 93 |
94 typedef int (*F0)(); | 94 typedef int (*F0)(); |
95 | 95 |
96 #define __ masm-> | 96 #define __ masm-> |
97 | 97 |
98 | 98 |
99 static void EntryCode(MacroAssembler* masm) { | 99 static void EntryCode(MacroAssembler* masm) { |
100 // Smi constant register is callee save. | 100 // Smi constant register is callee save. |
101 __ pushq(i::kSmiConstantRegister); | |
102 __ pushq(i::kRootRegister); | 101 __ pushq(i::kRootRegister); |
103 __ InitializeSmiConstantRegister(); | |
104 __ InitializeRootRegister(); | 102 __ InitializeRootRegister(); |
105 } | 103 } |
106 | 104 |
107 | 105 |
108 static void ExitCode(MacroAssembler* masm) { | 106 static void ExitCode(MacroAssembler* masm) { |
109 // Return -1 if kSmiConstantRegister was clobbered during the test. | |
110 __ Move(rdx, Smi::FromInt(1)); | |
111 __ cmpq(rdx, i::kSmiConstantRegister); | |
112 __ movq(rdx, Immediate(-1)); | |
113 __ cmovq(not_equal, rax, rdx); | |
114 __ popq(i::kRootRegister); | 107 __ popq(i::kRootRegister); |
115 __ popq(i::kSmiConstantRegister); | |
116 } | 108 } |
117 | 109 |
118 | 110 |
119 TEST(Smi) { | 111 TEST(Smi) { |
120 // Check that C++ Smi operations work as expected. | 112 // Check that C++ Smi operations work as expected. |
121 int64_t test_numbers[] = { | 113 int64_t test_numbers[] = { |
122 0, 1, -1, 127, 128, -128, -129, 255, 256, -256, -257, | 114 0, 1, -1, 127, 128, -128, -129, 255, 256, -256, -257, |
123 Smi::kMaxValue, static_cast<int64_t>(Smi::kMaxValue) + 1, | 115 Smi::kMaxValue, static_cast<int64_t>(Smi::kMaxValue) + 1, |
124 Smi::kMinValue, static_cast<int64_t>(Smi::kMinValue) - 1 | 116 Smi::kMinValue, static_cast<int64_t>(Smi::kMinValue) - 1 |
125 }; | 117 }; |
(...skipping 423 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
549 __ movq(rcx, Immediate(Smi::kMaxValue)); | 541 __ movq(rcx, Immediate(Smi::kMaxValue)); |
550 __ Integer32ToSmi(rcx, rcx); | 542 __ Integer32ToSmi(rcx, rcx); |
551 cond = masm->CheckNonNegativeSmi(rcx); // Most positive smi is positive. | 543 cond = masm->CheckNonNegativeSmi(rcx); // Most positive smi is positive. |
552 __ j(NegateCondition(cond), &exit); | 544 __ j(NegateCondition(cond), &exit); |
553 | 545 |
554 __ incq(rax); | 546 __ incq(rax); |
555 __ xorq(rcx, Immediate(kSmiTagMask)); | 547 __ xorq(rcx, Immediate(kSmiTagMask)); |
556 cond = masm->CheckNonNegativeSmi(rcx); // "Positive" non-smi. | 548 cond = masm->CheckNonNegativeSmi(rcx); // "Positive" non-smi. |
557 __ j(cond, &exit); | 549 __ j(cond, &exit); |
558 | 550 |
559 // CheckIsMinSmi | |
560 | |
561 __ incq(rax); | |
562 __ movq(rcx, Immediate(Smi::kMaxValue)); | |
563 __ Integer32ToSmi(rcx, rcx); | |
564 cond = masm->CheckIsMinSmi(rcx); | |
565 __ j(cond, &exit); | |
566 | |
567 __ incq(rax); | |
568 __ movq(rcx, Immediate(0)); | |
569 __ Integer32ToSmi(rcx, rcx); | |
570 cond = masm->CheckIsMinSmi(rcx); | |
571 __ j(cond, &exit); | |
572 | |
573 __ incq(rax); | |
574 __ movq(rcx, Immediate(Smi::kMinValue)); | |
575 __ Integer32ToSmi(rcx, rcx); | |
576 cond = masm->CheckIsMinSmi(rcx); | |
577 __ j(NegateCondition(cond), &exit); | |
578 | |
579 __ incq(rax); | |
580 __ movq(rcx, Immediate(Smi::kMinValue + 1)); | |
581 __ Integer32ToSmi(rcx, rcx); | |
582 cond = masm->CheckIsMinSmi(rcx); | |
583 __ j(cond, &exit); | |
584 | |
585 // CheckBothSmi | 551 // CheckBothSmi |
586 | 552 |
587 __ incq(rax); | 553 __ incq(rax); |
588 __ movq(rcx, Immediate(Smi::kMaxValue)); | 554 __ movq(rcx, Immediate(Smi::kMaxValue)); |
589 __ Integer32ToSmi(rcx, rcx); | 555 __ Integer32ToSmi(rcx, rcx); |
590 __ movq(rdx, Immediate(Smi::kMinValue)); | 556 __ movq(rdx, Immediate(Smi::kMinValue)); |
591 __ Integer32ToSmi(rdx, rdx); | 557 __ Integer32ToSmi(rdx, rdx); |
592 cond = masm->CheckBothSmi(rcx, rdx); | 558 cond = masm->CheckBothSmi(rcx, rdx); |
593 __ j(NegateCondition(cond), &exit); | 559 __ j(NegateCondition(cond), &exit); |
594 | 560 |
(...skipping 2144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2739 | 2705 |
2740 CodeDesc desc; | 2706 CodeDesc desc; |
2741 masm->GetCode(&desc); | 2707 masm->GetCode(&desc); |
2742 // Call the function from C++. | 2708 // Call the function from C++. |
2743 int result = FUNCTION_CAST<F0>(buffer)(); | 2709 int result = FUNCTION_CAST<F0>(buffer)(); |
2744 CHECK_EQ(0, result); | 2710 CHECK_EQ(0, result); |
2745 } | 2711 } |
2746 | 2712 |
2747 | 2713 |
2748 #undef __ | 2714 #undef __ |
OLD | NEW |