Port Math.sign and Math.clz32 to torque
Change-Id: If464c03c16e322fa4268a511fa984bb143b65a50 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1594290 Commit-Queue: Tobias Tebbi <tebbi@chromium.org> Reviewed-by: Tobias Tebbi <tebbi@chromium.org> Cr-Commit-Position: refs/heads/master@{#61254}
This commit is contained in:
parent
4528ddafce
commit
bb451bef37
@ -1783,6 +1783,7 @@ extern macro ChangeInt32ToIntPtr(int32): intptr; // Sign-extends.
|
||||
extern macro ChangeUint32ToWord(uint32): uintptr; // Doesn't sign-extend.
|
||||
extern macro LoadNativeContext(Context): NativeContext;
|
||||
extern macro TruncateFloat64ToFloat32(float64): float32;
|
||||
extern macro TruncateHeapNumberValueToWord32(Number): int32;
|
||||
extern macro LoadJSArrayElementsMap(constexpr ElementsKind, Context): Map;
|
||||
extern macro LoadJSArrayElementsMap(ElementsKind, Context): Map;
|
||||
extern macro ChangeNonnegativeNumberToUintPtr(Number): uintptr;
|
||||
|
@ -645,8 +645,6 @@ namespace internal {
|
||||
TFJ(MathAbs, 1, kReceiver, kX) \
|
||||
/* ES6 #sec-math.ceil */ \
|
||||
TFJ(MathCeil, 1, kReceiver, kX) \
|
||||
/* ES6 #sec-math.clz32 */ \
|
||||
TFJ(MathClz32, 1, kReceiver, kX) \
|
||||
/* ES6 #sec-math.floor */ \
|
||||
TFJ(MathFloor, 1, kReceiver, kX) \
|
||||
/* ES6 #sec-math.hypot */ \
|
||||
@ -663,8 +661,6 @@ namespace internal {
|
||||
TFJ(MathRandom, 0, kReceiver) \
|
||||
/* ES6 #sec-math.round */ \
|
||||
TFJ(MathRound, 1, kReceiver, kX) \
|
||||
/* ES6 #sec-math.sign */ \
|
||||
TFJ(MathSign, 1, kReceiver, kX) \
|
||||
/* ES6 #sec-math.trunc */ \
|
||||
TFJ(MathTrunc, 1, kReceiver, kX) \
|
||||
\
|
||||
|
@ -161,7 +161,6 @@ void MathBuiltinsAssembler::MathMaxMin(
|
||||
arguments.PopAndReturn(ChangeFloat64ToTagged(result.value()));
|
||||
}
|
||||
|
||||
|
||||
// ES6 #sec-math.ceil
|
||||
TF_BUILTIN(MathCeil, MathBuiltinsAssembler) {
|
||||
Node* context = Parameter(Descriptor::kContext);
|
||||
@ -169,64 +168,6 @@ TF_BUILTIN(MathCeil, MathBuiltinsAssembler) {
|
||||
MathRoundingOperation(context, x, &CodeStubAssembler::Float64Ceil);
|
||||
}
|
||||
|
||||
// ES6 #sec-math.clz32
|
||||
TF_BUILTIN(MathClz32, CodeStubAssembler) {
|
||||
Node* context = Parameter(Descriptor::kContext);
|
||||
|
||||
// Shared entry point for the clz32 operation.
|
||||
VARIABLE(var_clz32_x, MachineRepresentation::kWord32);
|
||||
Label do_clz32(this);
|
||||
|
||||
// We might need to loop once for ToNumber conversion.
|
||||
VARIABLE(var_x, MachineRepresentation::kTagged);
|
||||
Label loop(this, &var_x);
|
||||
var_x.Bind(Parameter(Descriptor::kX));
|
||||
Goto(&loop);
|
||||
BIND(&loop);
|
||||
{
|
||||
// Load the current {x} value.
|
||||
Node* x = var_x.value();
|
||||
|
||||
// Check if {x} is a Smi or a HeapObject.
|
||||
Label if_xissmi(this), if_xisnotsmi(this);
|
||||
Branch(TaggedIsSmi(x), &if_xissmi, &if_xisnotsmi);
|
||||
|
||||
BIND(&if_xissmi);
|
||||
{
|
||||
var_clz32_x.Bind(SmiToInt32(x));
|
||||
Goto(&do_clz32);
|
||||
}
|
||||
|
||||
BIND(&if_xisnotsmi);
|
||||
{
|
||||
// Check if {x} is a HeapNumber.
|
||||
Label if_xisheapnumber(this), if_xisnotheapnumber(this, Label::kDeferred);
|
||||
Branch(IsHeapNumber(x), &if_xisheapnumber, &if_xisnotheapnumber);
|
||||
|
||||
BIND(&if_xisheapnumber);
|
||||
{
|
||||
var_clz32_x.Bind(TruncateHeapNumberValueToWord32(x));
|
||||
Goto(&do_clz32);
|
||||
}
|
||||
|
||||
BIND(&if_xisnotheapnumber);
|
||||
{
|
||||
// Need to convert {x} to a Number first.
|
||||
var_x.Bind(CallBuiltin(Builtins::kNonNumberToNumber, context, x));
|
||||
Goto(&loop);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BIND(&do_clz32);
|
||||
{
|
||||
Node* x_value = var_clz32_x.value();
|
||||
Node* value = Word32Clz(x_value);
|
||||
Node* result = ChangeInt32ToTagged(value);
|
||||
Return(result);
|
||||
}
|
||||
}
|
||||
|
||||
// ES6 #sec-math.floor
|
||||
TF_BUILTIN(MathFloor, MathBuiltinsAssembler) {
|
||||
Node* context = Parameter(Descriptor::kContext);
|
||||
@ -309,26 +250,6 @@ TF_BUILTIN(MathRound, MathBuiltinsAssembler) {
|
||||
MathRoundingOperation(context, x, &CodeStubAssembler::Float64Round);
|
||||
}
|
||||
|
||||
// ES6 #sec-math.sign
|
||||
TF_BUILTIN(MathSign, CodeStubAssembler) {
|
||||
// Convert the {x} value to a Number.
|
||||
Node* context = Parameter(Descriptor::kContext);
|
||||
Node* x = Parameter(Descriptor::kX);
|
||||
Node* x_value = TruncateTaggedToFloat64(context, x);
|
||||
|
||||
// Return -1 if {x} is negative, 1 if {x} is positive, or {x} itself.
|
||||
Label if_xisnegative(this), if_xispositive(this);
|
||||
GotoIf(Float64LessThan(x_value, Float64Constant(0.0)), &if_xisnegative);
|
||||
GotoIf(Float64LessThan(Float64Constant(0.0), x_value), &if_xispositive);
|
||||
Return(ChangeFloat64ToTagged(x_value));
|
||||
|
||||
BIND(&if_xisnegative);
|
||||
Return(SmiConstant(-1));
|
||||
|
||||
BIND(&if_xispositive);
|
||||
Return(SmiConstant(1));
|
||||
}
|
||||
|
||||
// ES6 #sec-math.trunc
|
||||
TF_BUILTIN(MathTrunc, MathBuiltinsAssembler) {
|
||||
Node* context = Parameter(Descriptor::kContext);
|
||||
|
@ -76,6 +76,26 @@ namespace math {
|
||||
return Convert<Number>(Float64Cbrt(value));
|
||||
}
|
||||
|
||||
// ES6 #sec-math.clz32
|
||||
extern macro Word32Clz(int32): int32;
|
||||
|
||||
transitioning javascript builtin
|
||||
MathClz32(context: Context, receiver: Object, x: Object): Number {
|
||||
const num = ToNumber_Inline(context, x);
|
||||
|
||||
let value: int32;
|
||||
typeswitch (num) {
|
||||
case (s: Smi): {
|
||||
value = Convert<int32>(s);
|
||||
}
|
||||
case (h: HeapNumber): {
|
||||
value = TruncateHeapNumberValueToWord32(h);
|
||||
}
|
||||
}
|
||||
|
||||
return Convert<Number>(Word32Clz(value));
|
||||
}
|
||||
|
||||
// ES6 #sec-math.cos
|
||||
extern macro Float64Cos(float64): float64;
|
||||
|
||||
@ -165,6 +185,21 @@ namespace math {
|
||||
return Convert<Number>(Float64Sin(value));
|
||||
}
|
||||
|
||||
// ES6 #sec-math.sign
|
||||
transitioning javascript builtin
|
||||
MathSign(context: Context, receiver: Object, x: Object): Number {
|
||||
const num = ToNumber_Inline(context, x);
|
||||
const value = Convert<float64>(num);
|
||||
|
||||
if (value < 0) {
|
||||
return -1;
|
||||
} else if (value > 0) {
|
||||
return 1;
|
||||
} else {
|
||||
return num;
|
||||
}
|
||||
}
|
||||
|
||||
// ES6 #sec-math.sinh
|
||||
extern macro Float64Sinh(float64): float64;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user