From b63855033866c56bb7e2c71da7afb3ad4c4d3711 Mon Sep 17 00:00:00 2001 From: "chunyang.dai" Date: Tue, 24 Mar 2015 23:41:10 -0700 Subject: [PATCH] X87: [turbofan] Turn Math.clz32 into an inlinable builtin. port 3aa206b86560da94f895625186295bf07a0301d8 (r27329) original commit message: BUG= Review URL: https://codereview.chromium.org/1022523005 Cr-Commit-Position: refs/heads/master@{#27429} --- src/x87/lithium-codegen-x87.cc | 8 +------- src/x87/macro-assembler-x87.cc | 11 +++++++++++ src/x87/macro-assembler-x87.h | 3 +++ 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/x87/lithium-codegen-x87.cc b/src/x87/lithium-codegen-x87.cc index 80ab9ba6e..05944f9f4 100644 --- a/src/x87/lithium-codegen-x87.cc +++ b/src/x87/lithium-codegen-x87.cc @@ -4265,14 +4265,8 @@ void LCodeGen::DoMathLog(LMathLog* instr) { void LCodeGen::DoMathClz32(LMathClz32* instr) { Register input = ToRegister(instr->value()); Register result = ToRegister(instr->result()); - Label not_zero_input; - __ bsr(result, input); - __ j(not_zero, ¬_zero_input); - __ Move(result, Immediate(63)); // 63^31 == 32 - - __ bind(¬_zero_input); - __ xor_(result, Immediate(31)); // for x in [0..31], 31^x == 31-x. + __ Lzcnt(result, input); } diff --git a/src/x87/macro-assembler-x87.cc b/src/x87/macro-assembler-x87.cc index fc067348e..b6befebf6 100644 --- a/src/x87/macro-assembler-x87.cc +++ b/src/x87/macro-assembler-x87.cc @@ -2355,6 +2355,17 @@ void MacroAssembler::Move(const Operand& dst, const Immediate& x) { } +void MacroAssembler::Lzcnt(Register dst, const Operand& src) { + // TODO(intel): Add support for LZCNT (with ABM/BMI1). + Label not_zero_src; + bsr(dst, src); + j(not_zero, ¬_zero_src, Label::kNear); + Move(dst, Immediate(63)); // 63^31 == 32 + bind(¬_zero_src); + xor_(dst, Immediate(31)); // for x in [0..31], 31^x == 31-x. +} + + void MacroAssembler::SetCounter(StatsCounter* counter, int value) { if (FLAG_native_code_counters && counter->Enabled()) { mov(Operand::StaticVariable(ExternalReference(counter)), Immediate(value)); diff --git a/src/x87/macro-assembler-x87.h b/src/x87/macro-assembler-x87.h index 061709be9..e801bf52f 100644 --- a/src/x87/macro-assembler-x87.h +++ b/src/x87/macro-assembler-x87.h @@ -776,6 +776,9 @@ class MacroAssembler: public Assembler { void Push(Register src) { push(src); } void Pop(Register dst) { pop(dst); } + void Lzcnt(Register dst, Register src) { Lzcnt(dst, Operand(src)); } + void Lzcnt(Register dst, const Operand& src); + // Emit call to the code we are currently generating. void CallSelf() { Handle self(reinterpret_cast(CodeObject().location())); -- 2.34.1