| 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 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 using namespace v8::internal; | 40 using namespace v8::internal; |
| 41 | 41 |
| 42 #define __ masm. | 42 #define __ masm. |
| 43 | 43 |
| 44 ConvertDToIFunc MakeConvertDToIFuncTrampoline(Isolate* isolate, | 44 ConvertDToIFunc MakeConvertDToIFuncTrampoline(Isolate* isolate, |
| 45 Register source_reg, | 45 Register source_reg, |
| 46 Register destination_reg, | 46 Register destination_reg, |
| 47 bool inline_fastpath) { | 47 bool inline_fastpath) { |
| 48 // Allocate an executable page of memory. | 48 // Allocate an executable page of memory. |
| 49 size_t actual_size; | 49 size_t actual_size = 2 * Assembler::kMinimalBufferSize; |
| 50 byte* buffer = static_cast<byte*>(OS::Allocate(Assembler::kMinimalBufferSize, | 50 byte* buffer = static_cast<byte*>(OS::Allocate(actual_size, |
| 51 &actual_size, | 51 &actual_size, |
| 52 true)); | 52 true)); |
| 53 CHECK(buffer); | 53 CHECK(buffer); |
| 54 HandleScope handles(isolate); | 54 HandleScope handles(isolate); |
| 55 MacroAssembler masm(isolate, buffer, static_cast<int>(actual_size)); | 55 MacroAssembler masm(isolate, buffer, static_cast<int>(actual_size)); |
| 56 DoubleToIStub stub(source_reg, destination_reg, 0, true, inline_fastpath); | 56 DoubleToIStub stub(source_reg, destination_reg, 0, true, inline_fastpath); |
| 57 | 57 |
| 58 byte* start = stub.GetCode(isolate)->instruction_start(); | 58 byte* start = stub.GetCode(isolate)->instruction_start(); |
| 59 Label done; | 59 Label done; |
| 60 | 60 |
| 61 // Save callee save registers. | 61 __ SetStackPointer(csp); |
| 62 __ Push(r7, r6, r5, r4); | 62 __ PushCalleeSavedRegisters(); |
| 63 __ Push(lr); | 63 __ Mov(jssp, csp); |
| 64 __ SetStackPointer(jssp); |
| 64 | 65 |
| 65 // For softfp, move the input value into d0. | |
| 66 if (!masm.use_eabi_hardfloat()) { | |
| 67 __ vmov(d0, r0, r1); | |
| 68 } | |
| 69 // Push the double argument. | 66 // Push the double argument. |
| 70 __ sub(sp, sp, Operand(kDoubleSize)); | 67 __ Push(d0); |
| 71 __ vstr(d0, sp, 0); | 68 __ Mov(source_reg, jssp); |
| 72 if (!source_reg.is(sp)) { | 69 |
| 73 __ mov(source_reg, sp); | 70 MacroAssembler::PushPopQueue queue(&masm); |
| 74 } | |
| 75 | 71 |
| 76 // Save registers make sure they don't get clobbered. | 72 // Save registers make sure they don't get clobbered. |
| 77 int source_reg_offset = kDoubleSize; | 73 int source_reg_offset = kDoubleSize; |
| 78 int reg_num = 0; | 74 int reg_num = 0; |
| 79 for (;reg_num < Register::NumAllocatableRegisters(); ++reg_num) { | 75 for (;reg_num < Register::NumAllocatableRegisters(); ++reg_num) { |
| 80 Register reg = Register::from_code(reg_num); | 76 Register reg = Register::from_code(reg_num); |
| 81 if (!reg.is(destination_reg)) { | 77 if (!reg.is(destination_reg)) { |
| 82 __ push(reg); | 78 queue.Queue(reg); |
| 83 source_reg_offset += kPointerSize; | 79 source_reg_offset += kPointerSize; |
| 84 } | 80 } |
| 85 } | 81 } |
| 82 // Re-push the double argument. |
| 83 queue.Queue(d0); |
| 86 | 84 |
| 87 // Re-push the double argument. | 85 queue.PushQueued(); |
| 88 __ sub(sp, sp, Operand(kDoubleSize)); | |
| 89 __ vstr(d0, sp, 0); | |
| 90 | 86 |
| 91 // Call through to the actual stub | 87 // Call through to the actual stub |
| 92 if (inline_fastpath) { | 88 if (inline_fastpath) { |
| 93 __ vldr(d0, MemOperand(source_reg)); | 89 __ Ldr(d0, MemOperand(source_reg)); |
| 94 __ TryInlineTruncateDoubleToI(destination_reg, d0, &done); | 90 __ TryConvertDoubleToInt64(destination_reg, d0, &done); |
| 95 if (destination_reg.is(source_reg) && !source_reg.is(sp)) { | 91 if (destination_reg.is(source_reg)) { |
| 96 // Restore clobbered source_reg. | 92 // Restore clobbered source_reg. |
| 97 __ add(source_reg, sp, Operand(source_reg_offset)); | 93 __ add(source_reg, jssp, Operand(source_reg_offset)); |
| 98 } | 94 } |
| 99 } | 95 } |
| 100 __ Call(start, RelocInfo::EXTERNAL_REFERENCE); | 96 __ Call(start, RelocInfo::EXTERNAL_REFERENCE); |
| 101 __ bind(&done); | 97 __ bind(&done); |
| 102 | 98 |
| 103 __ add(sp, sp, Operand(kDoubleSize)); | 99 __ Drop(1, kDoubleSize); |
| 104 | 100 |
| 105 // Make sure no registers have been unexpectedly clobbered | 101 // // Make sure no registers have been unexpectedly clobbered |
| 106 for (--reg_num; reg_num >= 0; --reg_num) { | 102 for (--reg_num; reg_num >= 0; --reg_num) { |
| 107 Register reg = Register::from_code(reg_num); | 103 Register reg = Register::from_code(reg_num); |
| 108 if (!reg.is(destination_reg)) { | 104 if (!reg.is(destination_reg)) { |
| 109 __ ldr(ip, MemOperand(sp, 0)); | 105 __ Pop(ip0); |
| 110 __ cmp(reg, ip); | 106 __ cmp(reg, ip0); |
| 111 __ Assert(eq, kRegisterWasClobbered); | 107 __ Assert(eq, kRegisterWasClobbered); |
| 112 __ add(sp, sp, Operand(kPointerSize)); | |
| 113 } | 108 } |
| 114 } | 109 } |
| 115 | 110 |
| 116 __ add(sp, sp, Operand(kDoubleSize)); | 111 __ Drop(1, kDoubleSize); |
| 117 | 112 |
| 118 if (!destination_reg.is(r0)) | 113 if (!destination_reg.is(x0)) |
| 119 __ mov(r0, destination_reg); | 114 __ Mov(x0, destination_reg); |
| 120 | 115 |
| 121 // Restore callee save registers. | 116 // Restore callee save registers. |
| 122 __ Pop(lr); | 117 __ Mov(csp, jssp); |
| 123 __ Pop(r7, r6, r5, r4); | 118 __ SetStackPointer(csp); |
| 119 __ PopCalleeSavedRegisters(); |
| 124 | 120 |
| 125 __ Ret(0); | 121 __ Ret(); |
| 126 | 122 |
| 127 CodeDesc desc; | 123 CodeDesc desc; |
| 128 masm.GetCode(&desc); | 124 masm.GetCode(&desc); |
| 129 CPU::FlushICache(buffer, actual_size); | 125 CPU::FlushICache(buffer, actual_size); |
| 130 return (reinterpret_cast<ConvertDToIFunc>( | 126 return (reinterpret_cast<ConvertDToIFunc>( |
| 131 reinterpret_cast<intptr_t>(buffer))); | 127 reinterpret_cast<intptr_t>(buffer))); |
| 132 } | 128 } |
| 133 | 129 |
| 134 #undef __ | 130 #undef __ |
| 135 | 131 |
| 136 | 132 |
| 137 static Isolate* GetIsolateFrom(LocalContext* context) { | 133 static Isolate* GetIsolateFrom(LocalContext* context) { |
| 138 return reinterpret_cast<Isolate*>((*context)->GetIsolate()); | 134 return reinterpret_cast<Isolate*>((*context)->GetIsolate()); |
| 139 } | 135 } |
| 140 | 136 |
| 141 | 137 |
| 142 int32_t RunGeneratedCodeCallWrapper(ConvertDToIFunc func, | 138 int32_t RunGeneratedCodeCallWrapper(ConvertDToIFunc func, |
| 143 double from) { | 139 double from) { |
| 144 #ifdef USE_SIMULATOR | 140 #ifdef USE_SIMULATOR |
| 145 return CALL_GENERATED_FP_INT(func, from, 0); | 141 Simulator::CallArgument args[] = { |
| 142 Simulator::CallArgument(from), |
| 143 Simulator::CallArgument::End() |
| 144 }; |
| 145 return Simulator::current(Isolate::Current())->CallInt64( |
| 146 FUNCTION_ADDR(func), args); |
| 146 #else | 147 #else |
| 147 return (*func)(from); | 148 return (*func)(from); |
| 148 #endif | 149 #endif |
| 149 } | 150 } |
| 150 | 151 |
| 151 | 152 |
| 152 TEST(ConvertDToI) { | 153 TEST(ConvertDToI) { |
| 153 CcTest::InitializeVM(); | 154 CcTest::InitializeVM(); |
| 154 LocalContext context; | 155 LocalContext context; |
| 155 Isolate* isolate = GetIsolateFrom(&context); | 156 Isolate* isolate = GetIsolateFrom(&context); |
| 156 HandleScope scope(isolate); | 157 HandleScope scope(isolate); |
| 157 | 158 |
| 158 #if DEBUG | 159 #if DEBUG |
| 159 // Verify that the tests actually work with the C version. In the release | 160 // 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 | 161 // code, the compiler optimizes it away because it's all constant, but does it |
| 161 // wrong, triggering an assert on gcc. | 162 // wrong, triggering an assert on gcc. |
| 162 RunAllTruncationTests(&ConvertDToICVersion); | 163 RunAllTruncationTests(&ConvertDToICVersion); |
| 163 #endif | 164 #endif |
| 164 | 165 |
| 165 Register source_registers[] = {sp, r0, r1, r2, r3, r4, r5, r6, r7}; | 166 Register source_registers[] = {jssp, x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, |
| 166 Register dest_registers[] = {r0, r1, r2, r3, r4, r5, r6, r7}; | 167 x10, x11, x12, x13, x14, x15, x18, x19, x20, |
| 168 x21, x22, x23, x24}; |
| 169 Register dest_registers[] = {x0, x1, x2, x3, x4, x5, x6, x7, x8, x9, x10, x11, |
| 170 x12, x13, x14, x15, x18, x19, x20, x21, x22, x23, |
| 171 x24}; |
| 167 | 172 |
| 168 for (size_t s = 0; s < sizeof(source_registers) / sizeof(Register); s++) { | 173 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++) { | 174 for (size_t d = 0; d < sizeof(dest_registers) / sizeof(Register); d++) { |
| 170 RunAllTruncationTests( | 175 RunAllTruncationTests( |
| 171 RunGeneratedCodeCallWrapper, | 176 RunGeneratedCodeCallWrapper, |
| 172 MakeConvertDToIFuncTrampoline(isolate, | 177 MakeConvertDToIFuncTrampoline(isolate, |
| 173 source_registers[s], | 178 source_registers[s], |
| 174 dest_registers[d], | 179 dest_registers[d], |
| 175 false)); | 180 false)); |
| 176 RunAllTruncationTests( | 181 RunAllTruncationTests( |
| 177 RunGeneratedCodeCallWrapper, | 182 RunGeneratedCodeCallWrapper, |
| 178 MakeConvertDToIFuncTrampoline(isolate, | 183 MakeConvertDToIFuncTrampoline(isolate, |
| 179 source_registers[s], | 184 source_registers[s], |
| 180 dest_registers[d], | 185 dest_registers[d], |
| 181 true)); | 186 true)); |
| 182 } | 187 } |
| 183 } | 188 } |
| 184 } | 189 } |
| OLD | NEW |