Skip to content
This repository has been archived by the owner on Apr 3, 2020. It is now read-only.

Commit

Permalink
Change Float32x4, Float64x2 and Int32x4 to JSObject.
Browse files Browse the repository at this point in the history
Change runtime implementations to JavaScript in simd128.js.
  • Loading branch information
huningxin committed Jul 22, 2014
1 parent 3ce59b1 commit 4d3c796
Show file tree
Hide file tree
Showing 46 changed files with 1,436 additions and 1,536 deletions.
6 changes: 3 additions & 3 deletions include/v8.h
Original file line number Diff line number Diff line change
Expand Up @@ -5600,7 +5600,7 @@ class Internals {
static const int kNullValueRootIndex = 7;
static const int kTrueValueRootIndex = 8;
static const int kFalseValueRootIndex = 9;
static const int kEmptyStringRootIndex = 178;
static const int kEmptyStringRootIndex = 175;

// The external allocation limit should be below 256 MB on all architectures
// to avoid that resource-constrained embedders run low on memory.
Expand All @@ -5615,10 +5615,10 @@ class Internals {
static const int kNodeIsIndependentShift = 4;
static const int kNodeIsPartiallyDependentShift = 5;

static const int kJSObjectType = 0xc4;
static const int kJSObjectType = 0xc1;
static const int kFirstNonstringType = 0x80;
static const int kOddballType = 0x83;
static const int kForeignType = 0x8a;
static const int kForeignType = 0x87;

static const int kUndefinedOddballKind = 5;
static const int kNullOddballKind = 3;
Expand Down
1 change: 1 addition & 0 deletions src/arm/assembler-arm-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ namespace internal {


bool CpuFeatures::SupportsCrankshaft() { return IsSupported(VFP3); }
bool CpuFeatures::SupportsSIMD128InCrankshaft() { return false; }


int Register::NumAllocatableRegisters() {
Expand Down
12 changes: 0 additions & 12 deletions src/arm/full-codegen-arm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4412,18 +4412,6 @@ void FullCodeGenerator::EmitLiteralCompareTypeof(Expression* expr,
__ LoadRoot(ip, Heap::kHeapNumberMapRootIndex);
__ cmp(r0, ip);
Split(eq, if_true, if_false, fall_through);
} else if (String::Equals(check, factory->float32x4_string())) {
__ JumpIfSmi(r0, if_false);
__ CompareObjectType(r0, r0, r1, FLOAT32x4_TYPE);
Split(eq, if_true, if_false, fall_through);
} else if (String::Equals(check, factory->float64x2_string())) {
__ JumpIfSmi(r0, if_false);
__ CompareObjectType(r0, r0, r1, FLOAT64x2_TYPE);
Split(eq, if_true, if_false, fall_through);
} else if (String::Equals(check, factory->int32x4_string())) {
__ JumpIfSmi(r0, if_false);
__ CompareObjectType(r0, r0, r1, INT32x4_TYPE);
Split(eq, if_true, if_false, fall_through);
} else if (String::Equals(check, factory->string_string())) {
__ JumpIfSmi(r0, if_false);
// Check for undetectable objects => false.
Expand Down
77 changes: 14 additions & 63 deletions src/arm/lithium-codegen-arm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2302,24 +2302,6 @@ void LCodeGen::DoBranch(LBranch* instr) {
__ b(eq, instr->TrueLabel(chunk_));
}

if (expected.Contains(ToBooleanStub::FLOAT32x4)) {
// Float32x4 value -> true.
__ CompareInstanceType(map, ip, FLOAT32x4_TYPE);
__ b(eq, instr->TrueLabel(chunk_));
}

if (expected.Contains(ToBooleanStub::FLOAT64x2)) {
// Float64x2 value -> true.
__ CompareInstanceType(map, ip, FLOAT64x2_TYPE);
__ b(eq, instr->TrueLabel(chunk_));
}

if (expected.Contains(ToBooleanStub::INT32x4)) {
// Int32x4 value -> true.
__ CompareInstanceType(map, ip, INT32x4_TYPE);
__ b(eq, instr->TrueLabel(chunk_));
}

if (expected.Contains(ToBooleanStub::HEAP_NUMBER)) {
// heap number -> false iff +0, -0, or NaN.
DwVfpRegister dbl_scratch = double_scratch0();
Expand Down Expand Up @@ -3204,34 +3186,27 @@ void LCodeGen::DoDeferredSIMD128ToTagged(LInstruction* instr,
template<class T>
void LCodeGen::DoLoadKeyedSIMD128ExternalArray(LLoadKeyed* instr) {
class DeferredSIMD128ToTagged V8_FINAL : public LDeferredCode {
public:
DeferredSIMD128ToTagged(LCodeGen* codegen, LInstruction* instr,
Runtime::FunctionId id)
: LDeferredCode(codegen), instr_(instr), id_(id) { }
virtual void Generate() V8_OVERRIDE {
codegen()->DoDeferredSIMD128ToTagged(instr_, id_);
}
virtual LInstruction* instr() V8_OVERRIDE { return instr_; }
private:
LInstruction* instr_;
Runtime::FunctionId id_;
public:
DeferredSIMD128ToTagged(LCodeGen* codegen, LInstruction* instr,
Runtime::FunctionId id)
: LDeferredCode(codegen), instr_(instr), id_(id) { }
virtual void Generate() V8_OVERRIDE {
codegen()->DoDeferredSIMD128ToTagged(instr_, id_);
}
virtual LInstruction* instr() V8_OVERRIDE { return instr_; }
private:
LInstruction* instr_;
Runtime::FunctionId id_;
};

// Allocate a SIMD128 object on the heap.
Register reg = ToRegister(instr->result());
Register temp = ToRegister(instr->temp());
Register temp2 = ToRegister(instr->temp2());
Register scratch = scratch0();

DeferredSIMD128ToTagged* deferred = new(zone()) DeferredSIMD128ToTagged(
this, instr, static_cast<Runtime::FunctionId>(T::kRuntimeAllocatorId()));
if (FLAG_inline_new) {
__ LoadRoot(scratch, static_cast<Heap::RootListIndex>(T::kMapRootIndex()));
__ AllocateSIMDHeapObject(T::kSize, reg, temp, temp2, scratch,
deferred->entry(), DONT_TAG_RESULT);
} else {
__ jmp(deferred->entry());
}
__ jmp(deferred->entry());
__ bind(deferred->exit());

// Copy the SIMD128 value from the external array to the heap object.
Expand All @@ -3252,11 +3227,7 @@ void LCodeGen::DoLoadKeyedSIMD128ExternalArray(LLoadKeyed* instr) {
int element_size_shift = ElementsKindToShiftSize(elements_kind);
int shift_size = (instr->hydrogen()->key()->representation().IsSmi())
? (element_size_shift - kSmiTagSize) : element_size_shift;
int additional_offset = IsFixedTypedArrayElementsKind(elements_kind)
? FixedTypedArrayBase::kDataOffset - kHeapObjectTag
: 0;
int base_offset =
(instr->additional_index() << element_size_shift) + additional_offset;
int base_offset = instr->base_offset();
Operand operand = key_is_constant
? Operand(constant_key << element_size_shift)
: Operand(key, LSL, shift_size);
Expand Down Expand Up @@ -4315,12 +4286,7 @@ void LCodeGen::DoStoreKeyedSIMD128ExternalArray(LStoreKeyed* instr) {
int element_size_shift = ElementsKindToShiftSize(elements_kind);
int shift_size = (instr->hydrogen()->key()->representation().IsSmi())
? (element_size_shift - kSmiTagSize) : element_size_shift;
int additional_offset = IsFixedTypedArrayElementsKind(elements_kind)
? FixedTypedArrayBase::kDataOffset - kHeapObjectTag
: 0;

int base_offset =
(instr->additional_index() << element_size_shift) + additional_offset;
int base_offset = instr->base_offset();
Register address = scratch0();
if (key_is_constant) {
if (constant_key != 0) {
Expand Down Expand Up @@ -5641,21 +5607,6 @@ Condition LCodeGen::EmitTypeofIs(Label* true_label,
__ CompareRoot(scratch, Heap::kHeapNumberMapRootIndex);
final_branch_condition = eq;

} else if (String::Equals(type_name, factory->float32x4_string())) {
__ JumpIfSmi(input, false_label);
__ CompareObjectType(input, scratch, no_reg, FLOAT32x4_TYPE);
final_branch_condition = eq;

} else if (String::Equals(type_name, factory->float64x2_string())) {
__ JumpIfSmi(input, false_label);
__ CompareObjectType(input, scratch, no_reg, FLOAT64x2_TYPE);
final_branch_condition = eq;

} else if (String::Equals(type_name, factory->int32x4_string())) {
__ JumpIfSmi(input, false_label);
__ CompareObjectType(input, scratch, no_reg, INT32x4_TYPE);
final_branch_condition = eq;

} else if (String::Equals(type_name, factory->string_string())) {
__ JumpIfSmi(input, false_label);
__ CompareObjectType(input, scratch, no_reg, FIRST_NONSTRING_TYPE);
Expand Down
9 changes: 1 addition & 8 deletions src/arm/macro-assembler-arm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3311,14 +3311,7 @@ void MacroAssembler::AllocateSIMDHeapObject(int size,
Register map,
Label* gc_required,
TaggingMode tagging_mode) {
Allocate(size, result, scratch1, scratch2, gc_required,
tagging_mode == TAG_RESULT ? TAG_OBJECT : NO_ALLOCATION_FLAGS);

if (tagging_mode == TAG_RESULT) {
str(map, FieldMemOperand(result, HeapObject::kMapOffset));
} else {
str(map, MemOperand(result, HeapObject::kMapOffset));
}
UNREACHABLE(); // NOTIMPLEMENTED
}


Expand Down
1 change: 1 addition & 0 deletions src/assembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ class CpuFeatures : public AllStatic {
}

static inline bool SupportsCrankshaft();
static inline bool SupportsSIMD128InCrankshaft();

static inline unsigned cache_line_size() {
ASSERT(cache_line_size_ != 0);
Expand Down
21 changes: 11 additions & 10 deletions src/bootstrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1488,37 +1488,38 @@ void Genesis::InitializeExperimentalGlobal() {
if (FLAG_simd_object) {
// --- S I M D ---
Handle<String> name = factory()->InternalizeUtf8String("SIMD");
Handle<Code> code(isolate()->builtins()->builtin(Builtins::kEmptyFunction));
Handle<JSFunction> cons =
factory()->NewFunction(name, code);
Handle<JSFunction> cons = factory()->NewFunction(name);
JSFunction::SetInstancePrototype(cons,
Handle<Object>(native_context()->initial_object_prototype(),
isolate()));
cons->SetInstanceClassName(*name);
Handle<JSObject> simd_object = factory()->NewJSObject(cons, TENURED);
ASSERT(simd_object->IsJSObject());
JSObject::SetLocalPropertyIgnoreAttributes(
JSObject::SetOwnPropertyIgnoreAttributes(
global, name, simd_object, DONT_ENUM).Check();
native_context()->set_simd_object(*simd_object);
// --- f l o a t 3 2 x 4 ---
Handle<JSFunction> float32x4_fun =
InstallFunction(simd_object, "float32x4", JS_VALUE_TYPE, JSValue::kSize,
InstallFunction(simd_object, "float32x4", FLOAT32x4_TYPE,
Float32x4::kSize,
isolate()->initial_object_prototype(),
Builtins::kIllegal, true, true);
Builtins::kIllegal);
native_context()->set_float32x4_function(*float32x4_fun);

// --- f l o a t 6 4 x 2 ---
Handle<JSFunction> float64x2_fun =
InstallFunction(simd_object, "float64x2", JS_VALUE_TYPE, JSValue::kSize,
InstallFunction(simd_object, "float64x2", FLOAT64x2_TYPE,
Float64x2::kSize,
isolate()->initial_object_prototype(),
Builtins::kIllegal, true, true);
Builtins::kIllegal);
native_context()->set_float64x2_function(*float64x2_fun);

// --- i n t 3 2 x 4 ---
Handle<JSFunction> int32x4_fun =
InstallFunction(simd_object, "int32x4", JS_VALUE_TYPE, JSValue::kSize,
InstallFunction(simd_object, "int32x4", INT32x4_TYPE,
Int32x4::kSize,
isolate()->initial_object_prototype(),
Builtins::kIllegal, true, true);
Builtins::kIllegal);
native_context()->set_int32x4_function(*int32x4_fun);

// --- F l o a t 3 2 x 4 A r r a y---
Expand Down
15 changes: 0 additions & 15 deletions src/code-stubs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -619,9 +619,6 @@ void ToBooleanStub::Types::Print(StringStream* stream) const {
if (Contains(STRING)) printer.Add("String");
if (Contains(SYMBOL)) printer.Add("Symbol");
if (Contains(HEAP_NUMBER)) printer.Add("HeapNumber");
if (Contains(FLOAT32x4)) printer.Add("Float32x4");
if (Contains(FLOAT64x2)) printer.Add("Float64x2");
if (Contains(INT32x4)) printer.Add("Int32x4");
stream->Add(")");
}

Expand Down Expand Up @@ -649,15 +646,6 @@ bool ToBooleanStub::Types::UpdateStatus(Handle<Object> object) {
} else if (object->IsSymbol()) {
Add(SYMBOL);
return true;
} else if (object->IsFloat32x4()) {
Add(FLOAT32x4);
return true;
} else if (object->IsFloat64x2()) {
Add(FLOAT64x2);
return true;
} else if (object->IsInt32x4()) {
Add(INT32x4);
return true;
} else if (object->IsHeapNumber()) {
ASSERT(!object->IsUndetectableObject());
Add(HEAP_NUMBER);
Expand All @@ -675,9 +663,6 @@ bool ToBooleanStub::Types::NeedsMap() const {
return Contains(ToBooleanStub::SPEC_OBJECT)
|| Contains(ToBooleanStub::STRING)
|| Contains(ToBooleanStub::SYMBOL)
|| Contains(ToBooleanStub::FLOAT32x4)
|| Contains(ToBooleanStub::FLOAT64x2)
|| Contains(ToBooleanStub::INT32x4)
|| Contains(ToBooleanStub::HEAP_NUMBER);
}

Expand Down
12 changes: 5 additions & 7 deletions src/code-stubs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2301,21 +2301,19 @@ class ToBooleanStub: public HydrogenCodeStub {
STRING,
SYMBOL,
HEAP_NUMBER,
FLOAT32x4,
FLOAT64x2,
INT32x4,
NUMBER_OF_TYPES
};

// At most 8 different types can be distinguished, because the Code object
// only has room for a single byte to hold a set of these types. :-P
STATIC_ASSERT(NUMBER_OF_TYPES <= 11);
STATIC_ASSERT(NUMBER_OF_TYPES <= 8);

class Types : public EnumSet<Type, int> {
class Types : public EnumSet<Type, byte> {
public:
Types() : EnumSet<Type, int>(0) {}
explicit Types(int bits) : EnumSet<Type, int>(bits) {}
Types() : EnumSet<Type, byte>(0) {}
explicit Types(byte bits) : EnumSet<Type, byte>(bits) {}

byte ToByte() const { return ToIntegral(); }
void Print(StringStream* stream) const;
bool UpdateStatus(Handle<Object> object);
bool NeedsMap() const;
Expand Down
3 changes: 0 additions & 3 deletions src/d8.js
Original file line number Diff line number Diff line change
Expand Up @@ -1979,9 +1979,6 @@ function Stringify(x, depth) {
return "undefined";
case "boolean":
case "number":
case "float32x4":
case "float64x2":
case "int32x4":
case "function":
return x.toString();
case "string":
Expand Down
29 changes: 19 additions & 10 deletions src/factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1049,25 +1049,34 @@ Handle<HeapNumber> Factory::NewHeapNumber(double value,

Handle<Float32x4> Factory::NewFloat32x4(float32x4_value_t value,
PretenureFlag pretenure) {
CALL_HEAP_FUNCTION(
isolate(),
isolate()->heap()->AllocateFloat32x4(value, pretenure), Float32x4);
Handle<JSFunction> constructor(
isolate()->native_context()->float32x4_function());
Handle<JSObject> jsobject = NewJSObject(constructor);
Handle<Float32x4> float32x4(Float32x4::cast(*jsobject));
float32x4->set_value(value);
return float32x4;
}


Handle<Float64x2> Factory::NewFloat64x2(float64x2_value_t value,
PretenureFlag pretenure) {
CALL_HEAP_FUNCTION(
isolate(),
isolate()->heap()->AllocateFloat64x2(value, pretenure), Float64x2);
Handle<JSFunction> constructor(
isolate()->native_context()->float64x2_function());
Handle<JSObject> jsobject = NewJSObject(constructor);
Handle<Float64x2> float64x2(Float64x2::cast(*jsobject));
float64x2->set_value(value);
return float64x2;
}


Handle<Int32x4> Factory::NewInt32x4(int32x4_value_t value,
PretenureFlag pretenure) {
CALL_HEAP_FUNCTION(
isolate(),
isolate()->heap()->AllocateInt32x4(value, pretenure), Int32x4);
PretenureFlag pretenure) {
Handle<JSFunction> constructor(
isolate()->native_context()->int32x4_function());
Handle<JSObject> jsobject = NewJSObject(constructor);
Handle<Int32x4> int32x4(Int32x4::cast(*jsobject));
int32x4->set_value(value);
return int32x4;
}


Expand Down
Loading

0 comments on commit 4d3c796

Please sign in to comment.