Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(455)

Side by Side Diff: runtime/vm/intermediate_language_ia32.cc

Issue 23072044: Fix corner cases for double pow operation. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/vm/intermediate_language_arm.cc ('k') | runtime/vm/intermediate_language_mips.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32. 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_IA32.
6 #if defined(TARGET_ARCH_IA32) 6 #if defined(TARGET_ARCH_IA32)
7 7
8 #include "vm/intermediate_language.h" 8 #include "vm/intermediate_language.h"
9 9
10 #include "vm/dart_entry.h" 10 #include "vm/dart_entry.h"
(...skipping 4170 matching lines...) Expand 10 before | Expand all | Expand 10 after
4181 4181
4182 LocationSummary* InvokeMathCFunctionInstr::MakeLocationSummary() const { 4182 LocationSummary* InvokeMathCFunctionInstr::MakeLocationSummary() const {
4183 ASSERT((InputCount() == 1) || (InputCount() == 2)); 4183 ASSERT((InputCount() == 1) || (InputCount() == 2));
4184 const intptr_t kNumTemps = 0; 4184 const intptr_t kNumTemps = 0;
4185 LocationSummary* result = 4185 LocationSummary* result =
4186 new LocationSummary(InputCount(), kNumTemps, LocationSummary::kCall); 4186 new LocationSummary(InputCount(), kNumTemps, LocationSummary::kCall);
4187 result->set_in(0, Location::FpuRegisterLocation(XMM1)); 4187 result->set_in(0, Location::FpuRegisterLocation(XMM1));
4188 if (InputCount() == 2) { 4188 if (InputCount() == 2) {
4189 result->set_in(1, Location::FpuRegisterLocation(XMM2)); 4189 result->set_in(1, Location::FpuRegisterLocation(XMM2));
4190 } 4190 }
4191 result->set_out(Location::FpuRegisterLocation(XMM1)); 4191 if (recognized_kind() == MethodRecognizer::kMathDoublePow) {
4192 result->AddTemp(Location::RegisterLocation(EAX));
4193 result->AddTemp(Location::FpuRegisterLocation(XMM4));
4194 }
4195 result->set_out(Location::FpuRegisterLocation(XMM3));
4192 return result; 4196 return result;
4193 } 4197 }
4194 4198
4195 4199
4196 void InvokeMathCFunctionInstr::EmitNativeCode(FlowGraphCompiler* compiler) { 4200 void InvokeMathCFunctionInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
4197 __ EnterFrame(0); 4201 __ EnterFrame(0);
4198 __ ReserveAlignedFrameSpace(kDoubleSize * InputCount()); 4202 __ ReserveAlignedFrameSpace(kDoubleSize * InputCount());
4199 for (intptr_t i = 0; i < InputCount(); i++) { 4203 for (intptr_t i = 0; i < InputCount(); i++) {
4200 __ movsd(Address(ESP, kDoubleSize * i), locs()->in(i).fpu_reg()); 4204 __ movsd(Address(ESP, kDoubleSize * i), locs()->in(i).fpu_reg());
4201 } 4205 }
4202 // For pow-function return NaN if exponent is NaN.
4203 Label do_call, skip_call; 4206 Label do_call, skip_call;
4204 if (recognized_kind() == MethodRecognizer::kMathDoublePow) { 4207 if (recognized_kind() == MethodRecognizer::kMathDoublePow) {
4208 // Pseudo code:
4209 // if (exponent == 0.0) return 1.0;
4210 // if (base == 1.0) return 1.0;
4211 // if (base.isNaN || exponent.isNaN) {
4212 // return double.NAN;
4213 // }
4214 XmmRegister base = locs()->in(0).fpu_reg();
4205 XmmRegister exp = locs()->in(1).fpu_reg(); 4215 XmmRegister exp = locs()->in(1).fpu_reg();
4206 __ comisd(exp, exp); 4216 XmmRegister result = locs()->out().fpu_reg();
4207 __ j(PARITY_ODD, &do_call, Assembler::kNearJump); // NaN -> false; 4217 Register temp = locs()->temp(0).reg();
4208 // Exponent is NaN, return NaN. 4218 XmmRegister zero_temp = locs()->temp(1).fpu_reg();
4209 __ movsd(locs()->out().fpu_reg(), exp); 4219
4220 Label check_base_is_one;
4221 // Check if exponent is 0.0 -> return 1.0;
4222 __ LoadObject(temp, Double::ZoneHandle(Double::NewCanonical(0)));
4223 __ movsd(zero_temp, FieldAddress(temp, Double::value_offset()));
4224 __ LoadObject(temp, Double::ZoneHandle(Double::NewCanonical(1)));
4225 __ movsd(result, FieldAddress(temp, Double::value_offset()));
4226 // 'result' contains 1.0.
4227 __ comisd(exp, zero_temp);
4228 __ j(PARITY_EVEN, &check_base_is_one, Assembler::kNearJump); // NaN.
4229 __ j(EQUAL, &skip_call, Assembler::kNearJump); // exp is 0, result is 1.0.
4230
4231 Label base_is_nan;
4232 __ Bind(&check_base_is_one);
4233 __ comisd(base, result);
4234 __ j(PARITY_EVEN, &base_is_nan, Assembler::kNearJump);
4235 __ j(EQUAL, &skip_call, Assembler::kNearJump); // base and result are 1.0
4236 __ jmp(&do_call, Assembler::kNearJump);
4237
4238 __ Bind(&base_is_nan);
4239 // Returns NaN.
4240 __ movsd(result, base);
4210 __ jmp(&skip_call, Assembler::kNearJump); 4241 __ jmp(&skip_call, Assembler::kNearJump);
4242 // exp is Nan case is handled correctly in the C-library.
4211 } 4243 }
4212 __ Bind(&do_call); 4244 __ Bind(&do_call);
4213 __ CallRuntime(TargetFunction()); 4245 __ CallRuntime(TargetFunction());
4214 __ fstpl(Address(ESP, 0)); 4246 __ fstpl(Address(ESP, 0));
4215 __ movsd(locs()->out().fpu_reg(), Address(ESP, 0)); 4247 __ movsd(locs()->out().fpu_reg(), Address(ESP, 0));
4216 __ Bind(&skip_call); 4248 __ Bind(&skip_call);
4217 __ leave(); 4249 __ leave();
4218 } 4250 }
4219 4251
4220 4252
(...skipping 958 matching lines...) Expand 10 before | Expand all | Expand 10 after
5179 PcDescriptors::kOther, 5211 PcDescriptors::kOther,
5180 locs()); 5212 locs());
5181 __ Drop(2); // Discard type arguments and receiver. 5213 __ Drop(2); // Discard type arguments and receiver.
5182 } 5214 }
5183 5215
5184 } // namespace dart 5216 } // namespace dart
5185 5217
5186 #undef __ 5218 #undef __
5187 5219
5188 #endif // defined TARGET_ARCH_IA32 5220 #endif // defined TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « runtime/vm/intermediate_language_arm.cc ('k') | runtime/vm/intermediate_language_mips.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698