From 4ce40cb094484222f251406ebdea74be701925df Mon Sep 17 00:00:00 2001 From: Marty Rosenberg Date: Sat, 23 Aug 2014 12:58:22 +0200 Subject: [PATCH] Bug 995230 - Inline Math.clz32 on ARM. r=dougc --- js/src/jit/arm/Assembler-arm.cpp | 7 +++++++ js/src/jit/arm/Assembler-arm.h | 3 ++- js/src/jit/arm/CodeGenerator-arm.cpp | 10 ++++++++++ js/src/jit/arm/CodeGenerator-arm.h | 2 ++ js/src/jit/arm/MacroAssembler-arm.cpp | 7 ++++++- js/src/jit/arm/MacroAssembler-arm.h | 3 ++- 6 files changed, 29 insertions(+), 3 deletions(-) diff --git a/js/src/jit/arm/Assembler-arm.cpp b/js/src/jit/arm/Assembler-arm.cpp index bb69f42c3272..669ae3c40e77 100644 --- a/js/src/jit/arm/Assembler-arm.cpp +++ b/js/src/jit/arm/Assembler-arm.cpp @@ -1550,6 +1550,13 @@ Assembler::as_udiv(Register rd, Register rn, Register rm, Condition c) return writeInst(0x0730f010 | c | RN(rd) | RM(rm) | rn.code()); } +BufferOffset +Assembler::as_clz(Register dest, Register src, Condition c, Instruction *instdest) +{ + return writeInst(RD(dest) | src.code() | c | 0x016f0f10, (uint32_t*)instdest); +} + + // Data transfer instructions: ldr, str, ldrb, strb. Using an int to // differentiate between 8 bits and 32 bits is overkill, but meh. BufferOffset diff --git a/js/src/jit/arm/Assembler-arm.h b/js/src/jit/arm/Assembler-arm.h index ab004a1f7d25..a5db1f58c36e 100644 --- a/js/src/jit/arm/Assembler-arm.h +++ b/js/src/jit/arm/Assembler-arm.h @@ -1193,9 +1193,9 @@ class Assembler : public AssemblerShared // exist, when calling with a third dest parameter, a this object is still // needed. Dummy always happens to be null, but we shouldn't be looking at // it in any case. + public: static Assembler *Dummy; - public: // For the alignment fill use NOP: 0x0320f000 or (Always | InstNOP::NopInst). // For the nopFill use a branch to the next instruction: 0xeaffffff. Assembler() @@ -1370,6 +1370,7 @@ class Assembler : public AssemblerShared BufferOffset as_sdiv(Register dest, Register num, Register div, Condition c = Always); BufferOffset as_udiv(Register dest, Register num, Register div, Condition c = Always); + BufferOffset as_clz(Register dest, Register src, Condition c = Always, Instruction *instdest = nullptr); // Data transfer instructions: ldr, str, ldrb, strb. // Using an int to differentiate between 8 bits and 32 bits is overkill. diff --git a/js/src/jit/arm/CodeGenerator-arm.cpp b/js/src/jit/arm/CodeGenerator-arm.cpp index 56479e70da78..53b9fb49f13e 100644 --- a/js/src/jit/arm/CodeGenerator-arm.cpp +++ b/js/src/jit/arm/CodeGenerator-arm.cpp @@ -973,6 +973,16 @@ CodeGeneratorARM::visitUrshD(LUrshD *ins) return true; } +bool +CodeGeneratorARM::visitClzI(LClzI *ins) +{ + Register input = ToRegister(ins->input()); + Register output = ToRegister(ins->output()); + + masm.ma_clz(input, output); + return true; +} + bool CodeGeneratorARM::visitPowHalfD(LPowHalfD *ins) { diff --git a/js/src/jit/arm/CodeGenerator-arm.h b/js/src/jit/arm/CodeGenerator-arm.h index 040019a8475b..f33bb0cc8fd6 100644 --- a/js/src/jit/arm/CodeGenerator-arm.h +++ b/js/src/jit/arm/CodeGenerator-arm.h @@ -124,6 +124,8 @@ class CodeGeneratorARM : public CodeGeneratorShared virtual bool visitShiftI(LShiftI *ins); virtual bool visitUrshD(LUrshD *ins); + virtual bool visitClzI(LClzI *ins); + virtual bool visitTestIAndBranch(LTestIAndBranch *test); virtual bool visitCompare(LCompare *comp); virtual bool visitCompareAndBranch(LCompareAndBranch *comp); diff --git a/js/src/jit/arm/MacroAssembler-arm.cpp b/js/src/jit/arm/MacroAssembler-arm.cpp index 6391b0da5c9b..c9d840e1c293 100644 --- a/js/src/jit/arm/MacroAssembler-arm.cpp +++ b/js/src/jit/arm/MacroAssembler-arm.cpp @@ -1004,7 +1004,12 @@ MacroAssemblerARM::ma_udiv(Register num, Register div, Register dest, Condition { as_udiv(dest, num, div, cond); } - +// Miscelanous instructions +void +MacroAssemblerARM::ma_clz(Register src, Register dest, Condition cond) +{ + as_clz(dest, src, cond); +} // Memory. // Shortcut for when we know we're transferring 32 bits of data. void diff --git a/js/src/jit/arm/MacroAssembler-arm.h b/js/src/jit/arm/MacroAssembler-arm.h index d717bfa7f3f7..4aea6722d379 100644 --- a/js/src/jit/arm/MacroAssembler-arm.h +++ b/js/src/jit/arm/MacroAssembler-arm.h @@ -277,7 +277,8 @@ class MacroAssemblerARM : public Assembler // Division - depends on integer divide instructions being supported. void ma_sdiv(Register num, Register div, Register dest, Condition cond = Always); void ma_udiv(Register num, Register div, Register dest, Condition cond = Always); - + // Misc operations + void ma_clz(Register src, Register dest, Condition cond = Always); // Memory: // Shortcut for when we know we're transferring 32 bits of data. void ma_dtr(LoadStore ls, Register rn, Imm32 offset, Register rt,