| OLD | NEW |
| 1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 the V8 project authors. All rights reserved. |
| 2 // Rrdistribution and use in source and binary forms, with or without | 2 // Rrdistribution 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 // * Rrdistributions of source code must retain the above copyright | 6 // * Rrdistributions 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 // * Rrdistributions in binary form must reproduce the above | 8 // * Rrdistributions 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 14 matching lines...) Expand all Loading... |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #include <stdlib.h> | 28 #include <stdlib.h> |
| 29 | 29 |
| 30 #include "v8.h" | 30 #include "v8.h" |
| 31 | 31 |
| 32 #include "cctest.h" | 32 #include "cctest.h" |
| 33 #include "code-stubs.h" | 33 #include "code-stubs.h" |
| 34 #include "test-code-stubs.h" | 34 #include "test-code-stubs.h" |
| 35 #include "mips/constants-mips.h" |
| 35 #include "factory.h" | 36 #include "factory.h" |
| 36 #include "macro-assembler.h" | 37 #include "macro-assembler.h" |
| 37 #include "platform.h" | 38 #include "platform.h" |
| 38 #include "simulator.h" | 39 #include "simulator.h" |
| 39 | 40 |
| 40 using namespace v8::internal; | 41 using namespace v8::internal; |
| 41 | 42 |
| 42 #define __ masm. | 43 #define __ masm. |
| 43 | 44 |
| 44 ConvertDToIFunc MakeConvertDToIFuncTrampoline(Isolate* isolate, | 45 ConvertDToIFunc MakeConvertDToIFuncTrampoline(Isolate* isolate, |
| 45 Register source_reg, | 46 Register source_reg, |
| 46 Register destination_reg, | 47 Register destination_reg, |
| 47 bool inline_fastpath) { | 48 bool inline_fastpath) { |
| 48 // Allocate an executable page of memory. | 49 // Allocate an executable page of memory. |
| 49 size_t actual_size; | 50 size_t actual_size; |
| 50 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 51 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, |
| 51 &actual_size, | 52 &actual_size, |
| 52 true)); | 53 true)); |
| 53 CHECK(buffer); | 54 CHECK(buffer); |
| 54 HandleScope handles(isolate); | 55 HandleScope handles(isolate); |
| 55 MacroAssembler masm(isolate, buffer, static_cast<int>(actual_size)); | 56 MacroAssembler masm(isolate, buffer, static_cast<int>(actual_size)); |
| 56 DoubleToIStub stub(source_reg, destination_reg, 0, true, inline_fastpath); | 57 DoubleToIStub stub(source_reg, destination_reg, 0, true, inline_fastpath); |
| 57 | 58 |
| 58 byte* start = stub.GetCode(isolate)->instruction_start(); | 59 byte* start = stub.GetCode(isolate)->instruction_start(); |
| 59 Label done; | 60 Label done; |
| 60 | 61 |
| 61 // Save callee save registers. | 62 // Save callee save registers. |
| 62 __ Push(r7, r6, r5, r4); | 63 __ MultiPush(kCalleeSaved | ra.bit()); |
| 63 __ Push(lr); | |
| 64 | 64 |
| 65 // For softfp, move the input value into d0. | 65 // For softfp, move the input value into f12. |
| 66 if (!masm.use_eabi_hardfloat()) { | 66 if (IsMipsSoftFloatABI) { |
| 67 __ vmov(d0, r0, r1); | 67 __ Move(f12, a0, a1); |
| 68 } | 68 } |
| 69 // Push the double argument. | 69 // Push the double argument. |
| 70 __ sub(sp, sp, Operand(kDoubleSize)); | 70 __ Subu(sp, sp, Operand(kDoubleSize)); |
| 71 __ vstr(d0, sp, 0); | 71 __ sdc1(f12, MemOperand(sp)); |
| 72 if (!source_reg.is(sp)) { | 72 __ Move(source_reg, sp); |
| 73 __ mov(source_reg, sp); | |
| 74 } | |
| 75 | 73 |
| 76 // Save registers make sure they don't get clobbered. | 74 // Save registers make sure they don't get clobbered. |
| 77 int source_reg_offset = kDoubleSize; | 75 int source_reg_offset = kDoubleSize; |
| 78 int reg_num = 0; | 76 int reg_num = 2; |
| 79 for (;reg_num < Register::NumAllocatableRegisters(); ++reg_num) { | 77 for (;reg_num < Register::NumAllocatableRegisters(); ++reg_num) { |
| 80 Register reg = Register::from_code(reg_num); | 78 Register reg = Register::from_code(reg_num); |
| 81 if (!reg.is(destination_reg)) { | 79 if (!reg.is(destination_reg)) { |
| 82 __ push(reg); | 80 __ push(reg); |
| 83 source_reg_offset += kPointerSize; | 81 source_reg_offset += kPointerSize; |
| 84 } | 82 } |
| 85 } | 83 } |
| 86 | 84 |
| 87 // Re-push the double argument. | 85 // Re-push the double argument. |
| 88 __ sub(sp, sp, Operand(kDoubleSize)); | 86 __ Subu(sp, sp, Operand(kDoubleSize)); |
| 89 __ vstr(d0, sp, 0); | 87 __ sdc1(f12, MemOperand(sp)); |
| 90 | 88 |
| 91 // Call through to the actual stub | 89 // Call through to the actual stub |
| 92 if (inline_fastpath) { | 90 if (inline_fastpath) { |
| 93 __ vldr(d0, MemOperand(source_reg)); | 91 __ ldc1(f12, MemOperand(source_reg)); |
| 94 __ TryInlineTruncateDoubleToI(destination_reg, d0, &done); | 92 __ TryInlineTruncateDoubleToI(destination_reg, f12, &done); |
| 95 if (destination_reg.is(source_reg) && !source_reg.is(sp)) { | 93 if (destination_reg.is(source_reg) && !source_reg.is(sp)) { |
| 96 // Restore clobbered source_reg. | 94 // Restore clobbered source_reg. |
| 97 __ add(source_reg, sp, Operand(source_reg_offset)); | 95 __ Addu(source_reg, sp, Operand(source_reg_offset)); |
| 98 } | 96 } |
| 99 } | 97 } |
| 100 __ Call(start, RelocInfo::EXTERNAL_REFERENCE); | 98 __ Call(start, RelocInfo::EXTERNAL_REFERENCE); |
| 101 __ bind(&done); | 99 __ bind(&done); |
| 102 | 100 |
| 103 __ add(sp, sp, Operand(kDoubleSize)); | 101 __ Addu(sp, sp, Operand(kDoubleSize)); |
| 104 | 102 |
| 105 // Make sure no registers have been unexpectedly clobbered | 103 // Make sure no registers have been unexpectedly clobbered |
| 106 for (--reg_num; reg_num >= 0; --reg_num) { | 104 for (--reg_num; reg_num >= 2; --reg_num) { |
| 107 Register reg = Register::from_code(reg_num); | 105 Register reg = Register::from_code(reg_num); |
| 108 if (!reg.is(destination_reg)) { | 106 if (!reg.is(destination_reg)) { |
| 109 __ ldr(ip, MemOperand(sp, 0)); | 107 __ lw(at, MemOperand(sp, 0)); |
| 110 __ cmp(reg, ip); | 108 __ Assert(eq, kRegisterWasClobbered, reg, Operand(at)); |
| 111 __ Assert(eq, kRegisterWasClobbered); | 109 __ Addu(sp, sp, Operand(kPointerSize)); |
| 112 __ add(sp, sp, Operand(kPointerSize)); | |
| 113 } | 110 } |
| 114 } | 111 } |
| 115 | 112 |
| 116 __ add(sp, sp, Operand(kDoubleSize)); | 113 __ Addu(sp, sp, Operand(kDoubleSize)); |
| 117 | 114 |
| 118 if (!destination_reg.is(r0)) | 115 __ Move(v0, destination_reg); |
| 119 __ mov(r0, destination_reg); | 116 Label ok; |
| 117 __ Branch(&ok, eq, v0, Operand(zero_reg)); |
| 118 __ bind(&ok); |
| 120 | 119 |
| 121 // Restore callee save registers. | 120 // Restore callee save registers. |
| 122 __ Pop(lr); | 121 __ MultiPop(kCalleeSaved | ra.bit()); |
| 123 __ Pop(r7, r6, r5, r4); | |
| 124 | 122 |
| 125 __ Ret(0); | 123 Label ok1; |
| 124 __ Branch(&ok1, eq, v0, Operand(zero_reg)); |
| 125 __ bind(&ok1); |
| 126 __ Ret(); |
| 126 | 127 |
| 127 CodeDesc desc; | 128 CodeDesc desc; |
| 128 masm.GetCode(&desc); | 129 masm.GetCode(&desc); |
| 129 CPU::FlushICache(buffer, actual_size); | 130 CPU::FlushICache(buffer, actual_size); |
| 130 return (reinterpret_cast<ConvertDToIFunc>( | 131 return (reinterpret_cast<ConvertDToIFunc>( |
| 131 reinterpret_cast<intptr_t>(buffer))); | 132 reinterpret_cast<intptr_t>(buffer))); |
| 132 } | 133 } |
| 133 | 134 |
| 134 #undef __ | 135 #undef __ |
| 135 | 136 |
| 136 | 137 |
| 137 static Isolate* GetIsolateFrom(LocalContext* context) { | 138 static Isolate* GetIsolateFrom(LocalContext* context) { |
| 138 return reinterpret_cast<Isolate*>((*context)->GetIsolate()); | 139 return reinterpret_cast<Isolate*>((*context)->GetIsolate()); |
| 139 } | 140 } |
| 140 | 141 |
| 141 | 142 |
| 142 int32_t RunGeneratedCodeCallWrapper(ConvertDToIFunc func, | 143 int32_t RunGeneratedCodeCallWrapper(ConvertDToIFunc func, |
| 143 double from) { | 144 double from) { |
| 144 #ifdef USE_SIMULATOR | 145 #ifdef USE_SIMULATOR |
| 145 return CALL_GENERATED_FP_INT(func, from, 0); | 146 Simulator::current(Isolate::Current())->CallFP(FUNCTION_ADDR(func), from, 0.); |
| 147 return Simulator::current(Isolate::Current())->get_register(v0.code()); |
| 146 #else | 148 #else |
| 147 return (*func)(from); | 149 return (*func)(from); |
| 148 #endif | 150 #endif |
| 149 } | 151 } |
| 150 | 152 |
| 151 | 153 |
| 152 TEST(ConvertDToI) { | 154 TEST(ConvertDToI) { |
| 153 CcTest::InitializeVM(); | 155 CcTest::InitializeVM(); |
| 154 LocalContext context; | 156 LocalContext context; |
| 155 Isolate* isolate = GetIsolateFrom(&context); | 157 Isolate* isolate = GetIsolateFrom(&context); |
| 156 HandleScope scope(isolate); | 158 HandleScope scope(isolate); |
| 157 | 159 |
| 158 #if DEBUG | 160 #if DEBUG |
| 159 // Verify that the tests actually work with the C version. In the release | 161 // Verify that the tests actually work with the C version. In the release |
| 160 // code, the compiler optimizes it away because it's all constant, but does it | 162 // code, the compiler optimizes it away because it's all constant, but does it |
| 161 // wrong, triggering an assert on gcc. | 163 // wrong, triggering an assert on gcc. |
| 162 RunAllTruncationTests(&ConvertDToICVersion); | 164 RunAllTruncationTests(&ConvertDToICVersion); |
| 163 #endif | 165 #endif |
| 164 | 166 |
| 165 Register source_registers[] = {sp, r0, r1, r2, r3, r4, r5, r6, r7}; | 167 Register source_registers[] = { |
| 166 Register dest_registers[] = {r0, r1, r2, r3, r4, r5, r6, r7}; | 168 sp, v0, v1, a0, a1, a2, a3, t0, t1, t2, t3, t4, t5}; |
| 169 Register dest_registers[] = { |
| 170 v0, v1, a0, a1, a2, a3, t0, t1, t2, t3, t4, t5}; |
| 167 | 171 |
| 168 for (size_t s = 0; s < sizeof(source_registers) / sizeof(Register); s++) { | 172 for (size_t s = 0; s < sizeof(source_registers) / sizeof(Register); s++) { |
| 169 for (size_t d = 0; d < sizeof(dest_registers) / sizeof(Register); d++) { | 173 for (size_t d = 0; d < sizeof(dest_registers) / sizeof(Register); d++) { |
| 170 RunAllTruncationTests( | 174 RunAllTruncationTests( |
| 171 RunGeneratedCodeCallWrapper, | 175 RunGeneratedCodeCallWrapper, |
| 172 MakeConvertDToIFuncTrampoline(isolate, | 176 MakeConvertDToIFuncTrampoline(isolate, |
| 173 source_registers[s], | 177 source_registers[s], |
| 174 dest_registers[d], | 178 dest_registers[d], |
| 175 false)); | 179 false)); |
| 176 RunAllTruncationTests( | 180 RunAllTruncationTests( |
| 177 RunGeneratedCodeCallWrapper, | 181 RunGeneratedCodeCallWrapper, |
| 178 MakeConvertDToIFuncTrampoline(isolate, | 182 MakeConvertDToIFuncTrampoline(isolate, |
| 179 source_registers[s], | 183 source_registers[s], |
| 180 dest_registers[d], | 184 dest_registers[d], |
| 181 true)); | 185 true)); |
| 182 } | 186 } |
| 183 } | 187 } |
| 184 } | 188 } |
| OLD | NEW |