Skip to content

Commit

Permalink
Merge pull request crosswalk-project#2 from cdai2/simd-m41-turbofan
Browse files Browse the repository at this point in the history
add the int32x4 support.   add / and / mul / sub / or / xor / get x/y/z/...
  • Loading branch information
lionsky committed Mar 11, 2015
2 parents c9488cd + be44650 commit b0c33e9
Show file tree
Hide file tree
Showing 35 changed files with 1,063 additions and 7 deletions.
14 changes: 14 additions & 0 deletions src/code-factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,13 @@ Callable CodeFactory::ToFloat32x4Obj(Isolate* isolate) {
}


// static
Callable CodeFactory::ToInt32x4Obj(Isolate* isolate) {
ToInt32x4Stub stub(isolate);
return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}


// static
Callable CodeFactory::ToFloat64x2Obj(Isolate* isolate) {
ToFloat64x2Stub stub(isolate);
Expand Down Expand Up @@ -131,6 +138,13 @@ Callable CodeFactory::AllocateFloat32x4(Isolate* isolate) {
}


// static
Callable CodeFactory::AllocateInt32x4(Isolate* isolate) {
AllocateInt32x4Stub stub(isolate);
return Callable(stub.GetCode(), stub.GetCallInterfaceDescriptor());
}


// static
Callable CodeFactory::AllocateFloat64x2(Isolate* isolate) {
AllocateFloat64x2Stub stub(isolate);
Expand Down
4 changes: 4 additions & 0 deletions src/code-factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class CodeFactory FINAL {

static Callable ToFloat32x4Obj(Isolate* isolate);

static Callable ToInt32x4Obj(Isolate* isolate);

static Callable ToFloat64x2Obj(Isolate* isolate);

static Callable StringAdd(Isolate* isolate, StringAddFlags flags,
Expand All @@ -63,6 +65,8 @@ class CodeFactory FINAL {

static Callable AllocateFloat32x4(Isolate* isolate);

static Callable AllocateInt32x4(Isolate* isolate);

static Callable AllocateFloat64x2(Isolate* isolate);

static Callable CallFunction(Isolate* isolate, int argc,
Expand Down
34 changes: 34 additions & 0 deletions src/code-stubs-hydrogen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,40 @@ Handle<Code> AllocateFloat32x4Stub::GenerateCode() {
}


template <>
HValue* CodeStubGraphBuilder<AllocateInt32x4Stub>::BuildCodeStub() {
HValue* result =
Add<HAllocate>(Add<HConstant>(Int32x4::kSize), HType::Int32x4(),
NOT_TENURED, INT32x4_TYPE);
HInstruction* int32x4_fun =
Add<HConstant>(handle(isolate()->native_context()->int32x4_function()));
HObjectAccess map_access = HObjectAccess::ForPrototypeOrInitialMap();
HInstruction* int32x4_map = Add<HLoadNamedField>(
int32x4_fun, static_cast<HValue*>(NULL), map_access);
Add<HStoreNamedField>(result, HObjectAccess::ForMap(), int32x4_map);
HInstruction* empty_fixed_array =
Add<HConstant>(isolate()->factory()->empty_fixed_array());
Add<HStoreNamedField>(result, HObjectAccess::ForPropertiesPointer(),
empty_fixed_array);
Add<HStoreNamedField>(result, HObjectAccess::ForElementsPointer(),
empty_fixed_array);

HValue* value = Add<HAllocate>(
Add<HConstant>(FixedTypedArrayBase::kDataOffset + kInt32x4Size),
HType::HeapObject(), NOT_TENURED, FIXED_INT32x4_ARRAY_TYPE);
Add<HStoreNamedField>(result, HObjectAccess::ForSIMD128Value(), value);
AddStoreMapConstant(value, isolate()->factory()->fixed_int32x4_array_map());
Add<HStoreNamedField>(value, HObjectAccess::ForFixedArrayLength(),
Add<HConstant>(1));
return result;
}


Handle<Code> AllocateInt32x4Stub::GenerateCode() {
return DoGenerateCode(this);
}


template <>
HValue* CodeStubGraphBuilder<AllocateFloat64x2Stub>::BuildCodeStub() {
HValue* result =
Expand Down
6 changes: 6 additions & 0 deletions src/code-stubs.cc
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,12 @@ void AllocateFloat32x4Stub::InitializeDescriptor(
}


void AllocateInt32x4Stub::InitializeDescriptor(
CodeStubDescriptor* descriptor) {
descriptor->Initialize(
Runtime::FunctionForId(Runtime::kAllocateInt32x4)->entry);
}

void AllocateFloat64x2Stub::InitializeDescriptor(
CodeStubDescriptor* descriptor) {
descriptor->Initialize(
Expand Down
22 changes: 22 additions & 0 deletions src/code-stubs.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ namespace internal {
V(SubString) \
V(ToNumber) \
V(ToFloat32x4) \
V(ToInt32x4) \
V(ToFloat64x2) \
/* HydrogenCodeStubs */ \
V(AllocateHeapNumber) \
V(AllocateFloat32x4) \
V(AllocateInt32x4) \
V(AllocateFloat64x2) \
V(ArrayNArgumentsConstructor) \
V(ArrayNoArgumentConstructor) \
Expand Down Expand Up @@ -2164,6 +2166,17 @@ class AllocateFloat32x4Stub FINAL : public HydrogenCodeStub {
};


class AllocateInt32x4Stub FINAL : public HydrogenCodeStub {
public:
explicit AllocateInt32x4Stub(Isolate* isolate)
: HydrogenCodeStub(isolate) {}

private:
DEFINE_CALL_INTERFACE_DESCRIPTOR(AllocateInt32x4);
DEFINE_HYDROGEN_CODE_STUB(AllocateInt32x4, HydrogenCodeStub);
};


class AllocateFloat64x2Stub FINAL : public HydrogenCodeStub {
public:
explicit AllocateFloat64x2Stub(Isolate* isolate)
Expand Down Expand Up @@ -2601,6 +2614,15 @@ class ToFloat32x4Stub FINAL : public PlatformCodeStub {
};


class ToInt32x4Stub FINAL : public PlatformCodeStub {
public:
explicit ToInt32x4Stub(Isolate* isolate) : PlatformCodeStub(isolate) {}

DEFINE_CALL_INTERFACE_DESCRIPTOR(ToInt32x4);
DEFINE_PLATFORM_CODE_STUB(ToInt32x4, PlatformCodeStub);
};


class ToFloat64x2Stub FINAL : public PlatformCodeStub {
public:
explicit ToFloat64x2Stub(Isolate* isolate) : PlatformCodeStub(isolate) {}
Expand Down
71 changes: 71 additions & 0 deletions src/compiler/change-lowering.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ Reduction ChangeLowering::Reduce(Node* node) {
return ChangeFloat32x4ToTagged(node->InputAt(0), control);
case IrOpcode::kChangeTaggedToFloat32x4:
return ChangeTaggedToFloat32x4(node->InputAt(0), control);
case IrOpcode::kChangeInt32x4ToTagged:
return ChangeInt32x4ToTagged(node->InputAt(0), control);
case IrOpcode::kChangeTaggedToInt32x4:
return ChangeTaggedToInt32x4(node->InputAt(0), control);
case IrOpcode::kChangeFloat64x2ToTagged:
return ChangeFloat64x2ToTagged(node->InputAt(0), control);
case IrOpcode::kChangeTaggedToFloat64x2:
Expand Down Expand Up @@ -69,6 +73,14 @@ Node* ChangeLowering::Float32x4ValueIndexConstant() {
}


Node* ChangeLowering::Int32x4ValueIndexConstant() {
STATIC_ASSERT(Int32x4::kValueOffset % kPointerSize == 0);
const int value_offset =
((Int32x4::kValueOffset / kPointerSize) * (machine()->Is64() ? 8 : 4));
return jsgraph()->IntPtrConstant(value_offset - kHeapObjectTag);
}


Node* ChangeLowering::Float64x2ValueIndexConstant() {
STATIC_ASSERT(Float64x2::kValueOffset % kPointerSize == 0);
const int value_offset =
Expand Down Expand Up @@ -131,6 +143,27 @@ Node* ChangeLowering::AllocateFloat32x4WithValue(Node* value, Node* control) {
}


Node* ChangeLowering::AllocateInt32x4WithValue(Node* value, Node* control) {
Callable callable = CodeFactory::AllocateInt32x4(isolate());
CallDescriptor* descriptor = linkage()->GetStubCallDescriptor(
callable.descriptor(), 0, CallDescriptor::kNoFlags);
Node* target = jsgraph()->HeapConstant(callable.code());
Node* context = jsgraph()->NoContextConstant();
Node* effect = graph()->NewNode(common()->ValueEffect(1), value);
Node* int32x4_obj = graph()->NewNode(common()->Call(descriptor), target,
context, effect, control);
Node* val_obj =
graph()->NewNode(machine()->Load(kRepTagged), int32x4_obj,
Int32x4ValueIndexConstant(), int32x4_obj, control);
Node* stored_bytes = jsgraph()->Int32Constant(16);
Node* store = graph()->NewNode(
machine()->Store(StoreRepresentation(kRepInt32x4, kNoWriteBarrier)),
val_obj, jsgraph()->IntPtrConstant(FixedTypedArrayBase::kDataOffset - 1),
value, stored_bytes, val_obj, control);
return graph()->NewNode(common()->Finish(1), int32x4_obj, store);
}


Node* ChangeLowering::AllocateFloat64x2WithValue(Node* value, Node* control) {
Callable callable = CodeFactory::AllocateFloat64x2(isolate());
CallDescriptor* descriptor = linkage()->GetStubCallDescriptor(
Expand Down Expand Up @@ -228,6 +261,11 @@ Reduction ChangeLowering::ChangeFloat32x4ToTagged(Node* val, Node* control) {
}


Reduction ChangeLowering::ChangeInt32x4ToTagged(Node* val, Node* control) {
return Replace(AllocateInt32x4WithValue(val, control));
}


Reduction ChangeLowering::ChangeFloat64x2ToTagged(Node* val, Node* control) {
return Replace(AllocateFloat64x2WithValue(val, control));
}
Expand Down Expand Up @@ -361,6 +399,39 @@ Reduction ChangeLowering::ChangeTaggedToFloat32x4(Node* value, Node* control) {
}


Reduction ChangeLowering::ChangeTaggedToInt32x4(Node* value, Node* control) {
if (CanCover(value, IrOpcode::kJSToInt32x4Obj)) {
Node* const object = NodeProperties::GetValueInput(value, 0);
Node* const effect = NodeProperties::GetEffectInput(value);
Node* const control = NodeProperties::GetControlInput(value);

Node* val_obj =
graph()->NewNode(machine()->Load(kRepTagged), object,
Int32x4ValueIndexConstant(), effect, control);

Node* loaded_bytes = jsgraph()->Int32Constant(16);
Node* load = graph()->NewNode(
machine()->Load(kRepInt32x4), val_obj,
jsgraph()->IntPtrConstant(FixedTypedArrayBase::kDataOffset - 1),
loaded_bytes, effect, control);

return Replace(load);
} else {
Node* val_obj = graph()->NewNode(machine()->Load(kRepTagged), value,
Int32x4ValueIndexConstant(),
graph()->start(), control);

Node* loaded_bytes = jsgraph()->Int32Constant(16);
Node* load = graph()->NewNode(
machine()->Load(kRepInt32x4), val_obj,
jsgraph()->IntPtrConstant(FixedTypedArrayBase::kDataOffset - 1),
loaded_bytes, graph()->start(), control);

return Replace(load);
}
}


Reduction ChangeLowering::ChangeTaggedToFloat64x2(Node* value, Node* control) {
if (CanCover(value, IrOpcode::kJSToFloat64x2Obj)) {
Node* const object = NodeProperties::GetValueInput(value, 0);
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/change-lowering.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ class ChangeLowering FINAL : public Reducer {
private:
Node* HeapNumberValueIndexConstant();
Node* Float32x4ValueIndexConstant();
Node* Int32x4ValueIndexConstant();
Node* Float64x2ValueIndexConstant();
Node* SmiMaxValueConstant();
Node* SmiShiftBitsConstant();

Node* AllocateHeapNumberWithValue(Node* value, Node* control);
Node* AllocateFloat32x4WithValue(Node* value, Node* control);
Node* AllocateInt32x4WithValue(Node* value, Node* control);
Node* AllocateFloat64x2WithValue(Node* value, Node* control);
Node* ChangeInt32ToFloat64(Node* value);
Node* ChangeSmiToFloat64(Node* value);
Expand All @@ -48,10 +50,12 @@ class ChangeLowering FINAL : public Reducer {
Reduction ChangeBoolToBit(Node* value);
Reduction ChangeFloat64ToTagged(Node* value, Node* control);
Reduction ChangeFloat32x4ToTagged(Node* value, Node* control);
Reduction ChangeInt32x4ToTagged(Node* value, Node* control);
Reduction ChangeFloat64x2ToTagged(Node* value, Node* control);
Reduction ChangeInt32ToTagged(Node* value, Node* control);
Reduction ChangeTaggedToFloat64(Node* value, Node* control);
Reduction ChangeTaggedToFloat32x4(Node* value, Node* control);
Reduction ChangeTaggedToInt32x4(Node* value, Node* control);
Reduction ChangeTaggedToFloat64x2(Node* value, Node* control);
Reduction ChangeTaggedToUI32(Node* value, Node* control,
Signedness signedness);
Expand Down
11 changes: 11 additions & 0 deletions src/compiler/instruction-codes.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ namespace compiler {
V(Float32x4WithW) \
V(Float32x4Clamp) \
V(Float32x4Swizzle) \
V(Int32x4Add) \
V(Int32x4And) \
V(Int32x4Mul) \
V(Int32x4Sub) \
V(Int32x4Or) \
V(Int32x4Xor) \
V(Int32x4Constructor) \
V(Int32x4GetX) \
V(Int32x4GetY) \
V(Int32x4GetZ) \
V(Int32x4GetW) \
V(LoadSIMD128) \
V(CheckedLoadSIMD128) \
V(StoreSIMD128) \
Expand Down
22 changes: 22 additions & 0 deletions src/compiler/instruction-selector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -956,6 +956,28 @@ void InstructionSelector::VisitNode(Node* node) {
return MarkAsFloat32x4(node), VisitFloat32x4Clamp(node);
case IrOpcode::kFloat32x4Swizzle:
return MarkAsFloat32x4(node), VisitFloat32x4Swizzle(node);
case IrOpcode::kInt32x4Add:
return MarkAsInt32x4(node), VisitInt32x4Add(node);
case IrOpcode::kInt32x4And:
return MarkAsInt32x4(node), VisitInt32x4And(node);
case IrOpcode::kInt32x4Sub:
return MarkAsInt32x4(node), VisitInt32x4Sub(node);
case IrOpcode::kInt32x4Mul:
return MarkAsInt32x4(node), VisitInt32x4Mul(node);
case IrOpcode::kInt32x4Or:
return MarkAsInt32x4(node), VisitInt32x4Or(node);
case IrOpcode::kInt32x4Xor:
return MarkAsInt32x4(node), VisitInt32x4Xor(node);
case IrOpcode::kInt32x4Constructor:
return MarkAsInt32x4(node), VisitInt32x4Constructor(node);
case IrOpcode::kInt32x4GetX:
return VisitInt32x4GetX(node);
case IrOpcode::kInt32x4GetY:
return VisitInt32x4GetY(node);
case IrOpcode::kInt32x4GetZ:
return VisitInt32x4GetZ(node);
case IrOpcode::kInt32x4GetW:
return VisitInt32x4GetW(node);
case IrOpcode::kFloat64x2Add:
return MarkAsFloat64x2(node), VisitFloat64x2Add(node);
case IrOpcode::kFloat64x2Sub:
Expand Down
Loading

0 comments on commit b0c33e9

Please sign in to comment.