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}
This commit is contained in:
zhengxing.li 2015-10-28 04:34:06 -07:00 committed by Commit bot
parent 200315cb26
commit 4e00456471
2 changed files with 23 additions and 16 deletions

View File

@ -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: {

View File

@ -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);
}