Commit 4e004564 authored by zhengxing.li's avatar zhengxing.li Committed by Commit bot

X87: Fix the sqrt precision issue.

  In order to resolve the sqrt precision issue described in https://codereview.chromium.org/1425763002/.
  we change the implementation of CreateSqrtFunction() implementation of X87 so that the optimize compiler
  and full-compiler implementation are unified.

R=weiliang.lin@intel.com
BUG=

Review URL: https://codereview.chromium.org/1417553007

Cr-Commit-Position: refs/heads/master@{#31625}
parent 200315cb
......@@ -972,24 +972,12 @@ void CodeGenerator::AssembleArchInstruction(Instruction* instr) {
break;
}
case kX87Float64Sqrt: {
__ X87SetFPUCW(0x027F);
__ fstp(0);
__ fld_d(MemOperand(esp, 0));
#if V8_GLIBC_PREREQ(2, 19)
__ push(edx);
__ sub(esp, Immediate(2 * kIntSize));
__ fnstcw(MemOperand(esp, 4));
__ mov(edx, Immediate(0xfeff));
__ and_(edx, MemOperand(esp, 4));
__ mov(MemOperand(esp, 0), edx);
__ fldcw(MemOperand(esp, 0));
#endif
__ fsqrt();
#if V8_GLIBC_PREREQ(2, 19)
__ fldcw(MemOperand(esp, 4));
__ lea(esp, Operand(esp, 2 * kIntSize));
__ pop(edx);
#endif
__ lea(esp, Operand(esp, kDoubleSize));
__ X87SetFPUCW(0x037F);
break;
}
case kX87Float64Round: {
......
......@@ -41,8 +41,27 @@ UnaryMathFunction CreateExpFunction() {
UnaryMathFunction CreateSqrtFunction() {
// No SSE2 support
return &std::sqrt;
size_t actual_size;
// Allocate buffer in executable space.
byte* buffer =
static_cast<byte*>(base::OS::Allocate(1 * KB, &actual_size, true));
if (buffer == NULL) return &std::sqrt;
MacroAssembler masm(NULL, buffer, static_cast<int>(actual_size));
// Load double input into registers.
__ fld_d(MemOperand(esp, 4));
__ X87SetFPUCW(0x027F);
__ fsqrt();
__ X87SetFPUCW(0x037F);
__ Ret();
CodeDesc desc;
masm.GetCode(&desc);
DCHECK(!RelocInfo::RequiresRelocation(desc));
Assembler::FlushICacheWithoutIsolate(buffer, actual_size);
base::OS::ProtectCode(buffer, actual_size);
return FUNCTION_CAST<UnaryMathFunction>(buffer);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment