Bug 966957: Specialize ToString for Float32; r=h4writer

This commit is contained in:
Benjamin Bouvier 2014-02-04 15:48:05 +01:00
parent 607f85cbf4
commit a8554fd15e
11 changed files with 72 additions and 3 deletions

View File

@ -776,6 +776,32 @@ CodeGenerator::visitDoubleToString(LDoubleToString *lir)
return true;
}
typedef JSString *(*FloatToStringFn)(ThreadSafeContext *, float);
typedef JSString *(*FloatToStringParFn)(ForkJoinContext *, float);
static const VMFunctionsModal FloatToStringInfo = VMFunctionsModal(
FunctionInfo<FloatToStringFn>(FloatToString),
FunctionInfo<FloatToStringParFn>(FloatToStringPar));
bool
CodeGenerator::visitFloatToString(LFloatToString *lir)
{
FloatRegister input = ToFloatRegister(lir->input());
Register temp = ToRegister(lir->tempInt());
Register output = ToRegister(lir->output());
OutOfLineCode *ool = oolCallVM(FloatToStringInfo, lir, (ArgList(), input),
StoreRegisterTo(output));
if (!ool)
return false;
// Try float to integer conversion and run integer to string code.
masm.convertFloat32ToInt32(input, temp, ool->entry(), /* negativeCheck = */ true);
emitIntToString(temp, output, ool->entry());
masm.bind(ool->rejoin());
return true;
}
typedef JSString *(*PrimitiveToStringFn)(JSContext *, HandleValue);
typedef JSString *(*PrimitiveToStringParFn)(ForkJoinContext *, HandleValue);
static const VMFunctionsModal PrimitiveToStringInfo = VMFunctionsModal(

View File

@ -91,6 +91,7 @@ class CodeGenerator : public CodeGeneratorSpecific
void emitIntToString(Register input, Register output, Label *ool);
bool visitIntToString(LIntToString *lir);
bool visitDoubleToString(LDoubleToString *lir);
bool visitFloatToString(LFloatToString *lir);
bool visitPrimitiveToString(LPrimitiveToString *lir);
bool visitInteger(LInteger *lir);
bool visitRegExp(LRegExp *lir);

View File

@ -3146,6 +3146,25 @@ class LDoubleToString : public LInstructionHelper<1, 1, 1>
}
};
// Convert a float32 hosted on one definition to a string with a function call.
class LFloatToString : public LInstructionHelper<1, 1, 1>
{
public:
LIR_HEADER(FloatToString)
LFloatToString(const LAllocation &input, const LDefinition &temp) {
setOperand(0, input);
setTemp(0, temp);
}
const LDefinition *tempInt() {
return getTemp(0);
}
const MToString *mir() {
return mir_->toToString();
}
};
// Convert a primitive to a string with a function call.
class LPrimitiveToString : public LInstructionHelper<1, BOX_PIECES, 1>
{

View File

@ -145,6 +145,7 @@
_(BooleanToString) \
_(IntToString) \
_(DoubleToString) \
_(FloatToString) \
_(PrimitiveToString) \
_(Start) \
_(OsrEntry) \

View File

@ -1862,6 +1862,14 @@ LIRGenerator::visitToString(MToString *ins)
return assignSafepoint(lir, ins);
}
case MIRType_Float32: {
LFloatToString *lir = new(alloc()) LFloatToString(useRegister(opd), temp());
if (!define(lir, ins))
return false;
return assignSafepoint(lir, ins);
}
case MIRType_Int32: {
LIntToString *lir = new(alloc()) LIntToString(useRegister(opd));

View File

@ -3147,6 +3147,7 @@ class MToString : public MUnaryInstruction
JS_ASSERT(!input()->mightBeType(MIRType_Object));
return AliasSet::None();
}
bool canConsumeFloat32() const { return true; }
};
class MBitNot

View File

@ -663,3 +663,9 @@ jit::InitRestParameterPar(ForkJoinContext *cx, uint32_t length, Value *rest,
return res;
}
JSString *
js::jit::FloatToStringPar(ForkJoinContext *cx, float f)
{
return NumberToString<NoGC>(cx, double(f));
}

View File

@ -78,6 +78,8 @@ void TraceLIR(IonLIRTraceData *current);
void CallToUncompiledScriptPar(JSObject *obj);
JSString *FloatToStringPar(ForkJoinContext *cx, float f);
} // namespace jit
} // namespace js

View File

@ -420,9 +420,6 @@ ConvertToStringPolicy<Op>::staticAdjustInputs(TempAllocator &alloc, MInstruction
replace = MUnbox::New(alloc, in, MIRType_String, MUnbox::Fallible);
} else {
// TODO remove these two lines once 966957 has landed
EnsureOperandNotFloat32(alloc, ins, Op);
in = ins->getOperand(Op);
replace = MToString::New(alloc, in);
}

View File

@ -970,6 +970,12 @@ StringReplace(JSContext *cx, HandleString string, HandleString pattern, HandleSt
return rval.toString();
}
JSString *
FloatToString(ThreadSafeContext *cx, float f)
{
return NumberToString<CanGC>(cx, double(f));
}
bool
Recompile(JSContext *cx)
{

View File

@ -668,6 +668,8 @@ JSString *RegExpReplace(JSContext *cx, HandleString string, HandleObject regexp,
JSString *StringReplace(JSContext *cx, HandleString string, HandleString pattern,
HandleString repl);
JSString *FloatToString(ThreadSafeContext *cx, float f);
#ifdef DEBUG
void AssertValidObjectPtr(JSContext *cx, JSObject *obj);
void AssertValidStringPtr(JSContext *cx, JSString *str);