Skip to content

Commit f4c079d

Browse files
bmeurerCommit bot
authored andcommitted
[simd.js] Single SIMD128_VALUE_TYPE for all Simd128Values.
There's no need to have one InstanceType per SIMD primitive type (this will not scale long-term). Also reduce the amount of code duplication and make it more robust wrt adding new SIMD types. R=yangguo@chromium.org Review URL: https://codereview.chromium.org/1273353003 Cr-Commit-Position: refs/heads/master@{#30107}
1 parent ce51974 commit f4c079d

37 files changed

Lines changed: 327 additions & 844 deletions

include/v8.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6953,10 +6953,10 @@ class Internals {
69536953
static const int kNodeIsIndependentShift = 3;
69546954
static const int kNodeIsPartiallyDependentShift = 4;
69556955

6956-
static const int kJSObjectType = 0xbc;
6956+
static const int kJSObjectType = 0xb6;
69576957
static const int kFirstNonstringType = 0x80;
69586958
static const int kOddballType = 0x83;
6959-
static const int kForeignType = 0x8d;
6959+
static const int kForeignType = 0x87;
69606960

69616961
static const int kUndefinedOddballKind = 5;
69626962
static const int kNullOddballKind = 3;

src/arm/code-stubs-arm.cc

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -249,19 +249,15 @@ static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
249249
// They are both equal and they are not both Smis so both of them are not
250250
// Smis. If it's not a heap number, then return equal.
251251
if (cond == lt || cond == gt) {
252-
Label not_simd;
253252
// Call runtime on identical JSObjects.
254253
__ CompareObjectType(r0, r4, r4, FIRST_SPEC_OBJECT_TYPE);
255254
__ b(ge, slow);
256255
// Call runtime on identical symbols since we need to throw a TypeError.
257256
__ cmp(r4, Operand(SYMBOL_TYPE));
258257
__ b(eq, slow);
259258
// Call runtime on identical SIMD values since we must throw a TypeError.
260-
__ cmp(r4, Operand(FIRST_SIMD_VALUE_TYPE));
261-
__ b(lt, &not_simd);
262-
__ cmp(r4, Operand(LAST_SIMD_VALUE_TYPE));
263-
__ b(le, slow);
264-
__ bind(&not_simd);
259+
__ cmp(r4, Operand(SIMD128_VALUE_TYPE));
260+
__ b(eq, slow);
265261
if (is_strong(strength)) {
266262
// Call the runtime on anything that is converted in the semantics, since
267263
// we need to throw a TypeError. Smis have already been ruled out.
@@ -275,18 +271,14 @@ static void EmitIdenticalObjectComparison(MacroAssembler* masm, Label* slow,
275271
__ b(eq, &heap_number);
276272
// Comparing JS objects with <=, >= is complicated.
277273
if (cond != eq) {
278-
Label not_simd;
279274
__ cmp(r4, Operand(FIRST_SPEC_OBJECT_TYPE));
280275
__ b(ge, slow);
281276
// Call runtime on identical symbols since we need to throw a TypeError.
282277
__ cmp(r4, Operand(SYMBOL_TYPE));
283278
__ b(eq, slow);
284279
// Call runtime on identical SIMD values since we must throw a TypeError.
285-
__ cmp(r4, Operand(FIRST_SIMD_VALUE_TYPE));
286-
__ b(lt, &not_simd);
287-
__ cmp(r4, Operand(LAST_SIMD_VALUE_TYPE));
288-
__ b(le, slow);
289-
__ bind(&not_simd);
280+
__ cmp(r4, Operand(SIMD128_VALUE_TYPE));
281+
__ b(eq, slow);
290282
if (is_strong(strength)) {
291283
// Call the runtime on anything that is converted in the semantics,
292284
// since we need to throw a TypeError. Smis and heap numbers have

src/arm/lithium-codegen-arm.cc

Lines changed: 11 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2270,12 +2270,8 @@ void LCodeGen::DoBranch(LBranch* instr) {
22702270

22712271
if (expected.Contains(ToBooleanStub::SIMD_VALUE)) {
22722272
// SIMD value -> true.
2273-
Label not_simd;
2274-
__ CompareInstanceType(map, ip, FIRST_SIMD_VALUE_TYPE);
2275-
__ b(lt, &not_simd);
2276-
__ CompareInstanceType(map, ip, LAST_SIMD_VALUE_TYPE);
2277-
__ b(le, instr->TrueLabel(chunk_));
2278-
__ bind(&not_simd);
2273+
__ CompareInstanceType(map, ip, SIMD128_VALUE_TYPE);
2274+
__ b(eq, instr->TrueLabel(chunk_));
22792275
}
22802276

22812277
if (expected.Contains(ToBooleanStub::HEAP_NUMBER)) {
@@ -5706,40 +5702,16 @@ Condition LCodeGen::EmitTypeofIs(Label* true_label,
57065702
__ tst(scratch, Operand(1 << Map::kIsUndetectable));
57075703
final_branch_condition = eq;
57085704

5709-
} else if (String::Equals(type_name, factory->float32x4_string())) {
5710-
__ JumpIfSmi(input, false_label);
5711-
__ CompareObjectType(input, scratch, no_reg, FLOAT32X4_TYPE);
5712-
final_branch_condition = eq;
5713-
5714-
} else if (String::Equals(type_name, factory->int32x4_string())) {
5715-
__ JumpIfSmi(input, false_label);
5716-
__ CompareObjectType(input, scratch, no_reg, INT32X4_TYPE);
5717-
final_branch_condition = eq;
5718-
5719-
} else if (String::Equals(type_name, factory->bool32x4_string())) {
5720-
__ JumpIfSmi(input, false_label);
5721-
__ CompareObjectType(input, scratch, no_reg, BOOL32X4_TYPE);
5722-
final_branch_condition = eq;
5723-
5724-
} else if (String::Equals(type_name, factory->int16x8_string())) {
5725-
__ JumpIfSmi(input, false_label);
5726-
__ CompareObjectType(input, scratch, no_reg, INT16X8_TYPE);
5727-
final_branch_condition = eq;
5728-
5729-
} else if (String::Equals(type_name, factory->bool16x8_string())) {
5730-
__ JumpIfSmi(input, false_label);
5731-
__ CompareObjectType(input, scratch, no_reg, BOOL16X8_TYPE);
5732-
final_branch_condition = eq;
5733-
5734-
} else if (String::Equals(type_name, factory->int8x16_string())) {
5735-
__ JumpIfSmi(input, false_label);
5736-
__ CompareObjectType(input, scratch, no_reg, INT8X16_TYPE);
5737-
final_branch_condition = eq;
5738-
5739-
} else if (String::Equals(type_name, factory->bool8x16_string())) {
5740-
__ JumpIfSmi(input, false_label);
5741-
__ CompareObjectType(input, scratch, no_reg, BOOL8X16_TYPE);
5705+
// clang-format off
5706+
#define SIMD128_TYPE(TYPE, Type, type, lane_count, lane_type) \
5707+
} else if (String::Equals(type_name, factory->type##_string())) { \
5708+
__ JumpIfSmi(input, false_label); \
5709+
__ ldr(scratch, FieldMemOperand(input, HeapObject::kMapOffset)); \
5710+
__ CompareRoot(scratch, Heap::k##Type##MapRootIndex); \
57425711
final_branch_condition = eq;
5712+
SIMD128_TYPES(SIMD128_TYPE)
5713+
#undef SIMD128_TYPE
5714+
// clang-format on
57435715

57445716
} else {
57455717
__ b(false_label);

src/arm64/code-stubs-arm64.cc

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,19 +221,15 @@ static void EmitIdenticalObjectComparison(MacroAssembler* masm, Register left,
221221
// Smis. If it's not a heap number, then return equal.
222222
Register right_type = scratch;
223223
if ((cond == lt) || (cond == gt)) {
224-
Label not_simd;
225224
// Call runtime on identical JSObjects. Otherwise return equal.
226225
__ JumpIfObjectType(right, right_type, right_type, FIRST_SPEC_OBJECT_TYPE,
227226
slow, ge);
228227
// Call runtime on identical symbols since we need to throw a TypeError.
229228
__ Cmp(right_type, SYMBOL_TYPE);
230229
__ B(eq, slow);
231230
// Call runtime on identical SIMD values since we must throw a TypeError.
232-
__ Cmp(right_type, FIRST_SIMD_VALUE_TYPE);
233-
__ B(lt, &not_simd);
234-
__ Cmp(right_type, LAST_SIMD_VALUE_TYPE);
235-
__ B(le, slow);
236-
__ Bind(&not_simd);
231+
__ Cmp(right_type, SIMD128_VALUE_TYPE);
232+
__ B(eq, slow);
237233
if (is_strong(strength)) {
238234
// Call the runtime on anything that is converted in the semantics, since
239235
// we need to throw a TypeError. Smis have already been ruled out.
@@ -245,7 +241,6 @@ static void EmitIdenticalObjectComparison(MacroAssembler* masm, Register left,
245241
} else if (cond == eq) {
246242
__ JumpIfHeapNumber(right, &heap_number);
247243
} else {
248-
Label not_simd;
249244
__ JumpIfObjectType(right, right_type, right_type, HEAP_NUMBER_TYPE,
250245
&heap_number);
251246
// Comparing JS objects with <=, >= is complicated.
@@ -255,11 +250,8 @@ static void EmitIdenticalObjectComparison(MacroAssembler* masm, Register left,
255250
__ Cmp(right_type, SYMBOL_TYPE);
256251
__ B(eq, slow);
257252
// Call runtime on identical SIMD values since we must throw a TypeError.
258-
__ Cmp(right_type, FIRST_SIMD_VALUE_TYPE);
259-
__ B(lt, &not_simd);
260-
__ Cmp(right_type, LAST_SIMD_VALUE_TYPE);
261-
__ B(le, slow);
262-
__ Bind(&not_simd);
253+
__ Cmp(right_type, SIMD128_VALUE_TYPE);
254+
__ B(eq, slow);
263255
if (is_strong(strength)) {
264256
// Call the runtime on anything that is converted in the semantics,
265257
// since we need to throw a TypeError. Smis and heap numbers have

src/arm64/lithium-codegen-arm64.cc

Lines changed: 14 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1933,12 +1933,8 @@ void LCodeGen::DoBranch(LBranch* instr) {
19331933

19341934
if (expected.Contains(ToBooleanStub::SIMD_VALUE)) {
19351935
// SIMD value -> true.
1936-
Label not_simd;
1937-
__ CompareInstanceType(map, scratch, FIRST_SIMD_VALUE_TYPE);
1938-
__ B(lt, &not_simd);
1939-
__ CompareInstanceType(map, scratch, LAST_SIMD_VALUE_TYPE);
1940-
__ B(le, true_label);
1941-
__ Bind(&not_simd);
1936+
__ CompareInstanceType(map, scratch, SIMD128_VALUE_TYPE);
1937+
__ B(eq, true_label);
19421938
}
19431939

19441940
if (expected.Contains(ToBooleanStub::HEAP_NUMBER)) {
@@ -5997,68 +5993,19 @@ void LCodeGen::DoTypeofIsAndBranch(LTypeofIsAndBranch* instr) {
59975993
__ Ldrb(scratch, FieldMemOperand(map, Map::kBitFieldOffset));
59985994
EmitTestAndBranch(instr, eq, scratch, 1 << Map::kIsUndetectable);
59995995

6000-
} else if (String::Equals(type_name, factory->float32x4_string())) {
6001-
DCHECK((instr->temp1() != NULL) && (instr->temp2() != NULL));
6002-
Register map = ToRegister(instr->temp1());
6003-
Register scratch = ToRegister(instr->temp2());
6004-
6005-
__ JumpIfSmi(value, false_label);
6006-
__ CompareObjectType(value, map, scratch, FLOAT32X4_TYPE);
6007-
EmitBranch(instr, eq);
6008-
6009-
} else if (String::Equals(type_name, factory->int32x4_string())) {
6010-
DCHECK((instr->temp1() != NULL) && (instr->temp2() != NULL));
6011-
Register map = ToRegister(instr->temp1());
6012-
Register scratch = ToRegister(instr->temp2());
6013-
6014-
__ JumpIfSmi(value, false_label);
6015-
__ CompareObjectType(value, map, scratch, INT32X4_TYPE);
6016-
EmitBranch(instr, eq);
6017-
6018-
} else if (String::Equals(type_name, factory->bool32x4_string())) {
6019-
DCHECK((instr->temp1() != NULL) && (instr->temp2() != NULL));
6020-
Register map = ToRegister(instr->temp1());
6021-
Register scratch = ToRegister(instr->temp2());
6022-
6023-
__ JumpIfSmi(value, false_label);
6024-
__ CompareObjectType(value, map, scratch, BOOL32X4_TYPE);
6025-
EmitBranch(instr, eq);
6026-
6027-
} else if (String::Equals(type_name, factory->int16x8_string())) {
6028-
DCHECK((instr->temp1() != NULL) && (instr->temp2() != NULL));
6029-
Register map = ToRegister(instr->temp1());
6030-
Register scratch = ToRegister(instr->temp2());
6031-
6032-
__ JumpIfSmi(value, false_label);
6033-
__ CompareObjectType(value, map, scratch, INT16X8_TYPE);
6034-
EmitBranch(instr, eq);
6035-
6036-
} else if (String::Equals(type_name, factory->bool16x8_string())) {
6037-
DCHECK((instr->temp1() != NULL) && (instr->temp2() != NULL));
6038-
Register map = ToRegister(instr->temp1());
6039-
Register scratch = ToRegister(instr->temp2());
6040-
6041-
__ JumpIfSmi(value, false_label);
6042-
__ CompareObjectType(value, map, scratch, BOOL16X8_TYPE);
6043-
EmitBranch(instr, eq);
6044-
6045-
} else if (String::Equals(type_name, factory->int8x16_string())) {
6046-
DCHECK((instr->temp1() != NULL) && (instr->temp2() != NULL));
6047-
Register map = ToRegister(instr->temp1());
6048-
Register scratch = ToRegister(instr->temp2());
6049-
6050-
__ JumpIfSmi(value, false_label);
6051-
__ CompareObjectType(value, map, scratch, INT8X16_TYPE);
6052-
EmitBranch(instr, eq);
6053-
6054-
} else if (String::Equals(type_name, factory->bool8x16_string())) {
6055-
DCHECK((instr->temp1() != NULL) && (instr->temp2() != NULL));
6056-
Register map = ToRegister(instr->temp1());
6057-
Register scratch = ToRegister(instr->temp2());
6058-
6059-
__ JumpIfSmi(value, false_label);
6060-
__ CompareObjectType(value, map, scratch, BOOL8X16_TYPE);
5996+
// clang-format off
5997+
#define SIMD128_TYPE(TYPE, Type, type, lane_count, lane_type) \
5998+
} else if (String::Equals(type_name, factory->type##_string())) { \
5999+
DCHECK((instr->temp1() != NULL) && (instr->temp2() != NULL)); \
6000+
Register map = ToRegister(instr->temp1()); \
6001+
\
6002+
__ JumpIfSmi(value, false_label); \
6003+
__ Ldr(map, FieldMemOperand(value, HeapObject::kMapOffset)); \
6004+
__ CompareRoot(map, Heap::k##Type##MapRootIndex); \
60616005
EmitBranch(instr, eq);
6006+
SIMD128_TYPES(SIMD128_TYPE)
6007+
#undef SIMD128_TYPE
6008+
// clang-format on
60626009

60636010
} else {
60646011
__ B(false_label);

src/bootstrapper.cc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1981,14 +1981,14 @@ void Genesis::InitializeGlobal_harmony_simd() {
19811981

19821982
// Install SIMD type functions. Set the instance class names since
19831983
// InstallFunction only does this when we install on the GlobalObject.
1984-
#define SIMD128_INSTALL_FUNCTION(name, type, lane_count, lane_type) \
1985-
Handle<JSFunction> type##_function = InstallFunction( \
1986-
simd_object, #name, JS_VALUE_TYPE, JSValue::kSize, \
1987-
isolate->initial_object_prototype(), Builtins::kIllegal); \
1988-
native_context()->set_##type##_function(*type##_function); \
1989-
type##_function->SetInstanceClassName(*factory->name##_string());
1990-
1984+
#define SIMD128_INSTALL_FUNCTION(TYPE, Type, type, lane_count, lane_type) \
1985+
Handle<JSFunction> type##_function = InstallFunction( \
1986+
simd_object, #Type, JS_VALUE_TYPE, JSValue::kSize, \
1987+
isolate->initial_object_prototype(), Builtins::kIllegal); \
1988+
native_context()->set_##type##_function(*type##_function); \
1989+
type##_function->SetInstanceClassName(*factory->Type##_string());
19911990
SIMD128_TYPES(SIMD128_INSTALL_FUNCTION)
1991+
#undef SIMD128_INSTALL_FUNCTION
19921992
}
19931993

19941994

src/code-stubs-hydrogen.cc

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -399,53 +399,50 @@ HValue* CodeStubGraphBuilder<TypeofStub>::BuildCodeStub() {
399399
is_function.Else();
400400
{
401401
IfBuilder is_float32x4(this);
402-
is_float32x4.If<HCompareNumericAndBranch>(
403-
instance_type, Add<HConstant>(FLOAT32X4_TYPE), Token::EQ);
402+
is_float32x4.If<HCompareObjectEqAndBranch>(
403+
map, Add<HConstant>(factory->float32x4_map()));
404404
is_float32x4.Then();
405405
{ Push(Add<HConstant>(factory->float32x4_string())); }
406406
is_float32x4.Else();
407407
{
408408
IfBuilder is_int32x4(this);
409-
is_int32x4.If<HCompareNumericAndBranch>(
410-
instance_type, Add<HConstant>(INT32X4_TYPE), Token::EQ);
409+
is_int32x4.If<HCompareObjectEqAndBranch>(
410+
map, Add<HConstant>(factory->int32x4_map()));
411411
is_int32x4.Then();
412412
{ Push(Add<HConstant>(factory->int32x4_string())); }
413413
is_int32x4.Else();
414414
{
415415
IfBuilder is_bool32x4(this);
416-
is_bool32x4.If<HCompareNumericAndBranch>(
417-
instance_type, Add<HConstant>(BOOL32X4_TYPE), Token::EQ);
416+
is_bool32x4.If<HCompareObjectEqAndBranch>(
417+
map, Add<HConstant>(factory->bool32x4_map()));
418418
is_bool32x4.Then();
419419
{ Push(Add<HConstant>(factory->bool32x4_string())); }
420420
is_bool32x4.Else();
421421
{
422422
IfBuilder is_int16x8(this);
423-
is_int16x8.If<HCompareNumericAndBranch>(
424-
instance_type, Add<HConstant>(INT16X8_TYPE), Token::EQ);
423+
is_int16x8.If<HCompareObjectEqAndBranch>(
424+
map, Add<HConstant>(factory->int16x8_map()));
425425
is_int16x8.Then();
426426
{ Push(Add<HConstant>(factory->int16x8_string())); }
427427
is_int16x8.Else();
428428
{
429429
IfBuilder is_bool16x8(this);
430-
is_bool16x8.If<HCompareNumericAndBranch>(
431-
instance_type, Add<HConstant>(BOOL16X8_TYPE),
432-
Token::EQ);
430+
is_bool16x8.If<HCompareObjectEqAndBranch>(
431+
map, Add<HConstant>(factory->bool16x8_map()));
433432
is_bool16x8.Then();
434433
{ Push(Add<HConstant>(factory->bool16x8_string())); }
435434
is_bool16x8.Else();
436435
{
437436
IfBuilder is_int8x16(this);
438-
is_int8x16.If<HCompareNumericAndBranch>(
439-
instance_type, Add<HConstant>(INT8X16_TYPE),
440-
Token::EQ);
437+
is_int8x16.If<HCompareObjectEqAndBranch>(
438+
map, Add<HConstant>(factory->int8x16_map()));
441439
is_int8x16.Then();
442440
{ Push(Add<HConstant>(factory->int8x16_string())); }
443441
is_int8x16.Else();
444442
{
445443
IfBuilder is_bool8x16(this);
446-
is_bool8x16.If<HCompareNumericAndBranch>(
447-
instance_type, Add<HConstant>(BOOL8X16_TYPE),
448-
Token::EQ);
444+
is_bool8x16.If<HCompareObjectEqAndBranch>(
445+
map, Add<HConstant>(factory->bool8x16_map()));
449446
is_bool8x16.Then();
450447
{ Push(Add<HConstant>(factory->bool8x16_string())); }
451448
is_bool8x16.Else();

0 commit comments

Comments
 (0)