Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(371)

Unified Diff: src/compiler/simplified-lowering.cc

Issue 2489563004: [turbofan] Add support for accessing Uint8ClampedArrays. (Closed)
Patch Set: Fix typing rule. Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler/simplified-lowering.h ('k') | src/compiler/simplified-operator.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/simplified-lowering.cc
diff --git a/src/compiler/simplified-lowering.cc b/src/compiler/simplified-lowering.cc
index 9555a3fe00a5dc9e46884420bf488e2d68311957..ca3ed1f75909630d9ae5f3a7757ad90c181f9203 100644
--- a/src/compiler/simplified-lowering.cc
+++ b/src/compiler/simplified-lowering.cc
@@ -2111,6 +2111,31 @@ class RepresentationSelector {
if (lower()) DeferReplacement(node, node->InputAt(0));
return;
}
+ case IrOpcode::kNumberToUint8Clamped: {
+ Type* const input_type = TypeOf(node->InputAt(0));
+ if (input_type->Is(type_cache_.kUint8OrMinusZeroOrNaN)) {
+ VisitUnop(node, UseInfo::TruncatingWord32(),
+ MachineRepresentation::kWord32);
+ if (lower()) DeferReplacement(node, node->InputAt(0));
+ } else if (input_type->Is(Type::Unsigned32OrMinusZeroOrNaN())) {
+ VisitUnop(node, UseInfo::TruncatingWord32(),
+ MachineRepresentation::kWord32);
+ if (lower()) lowering->DoUnsigned32ToUint8Clamped(node);
+ } else if (input_type->Is(Type::Signed32OrMinusZeroOrNaN())) {
+ VisitUnop(node, UseInfo::TruncatingWord32(),
+ MachineRepresentation::kWord32);
+ if (lower()) lowering->DoSigned32ToUint8Clamped(node);
+ } else if (input_type->Is(type_cache_.kIntegerOrMinusZeroOrNaN)) {
+ VisitUnop(node, UseInfo::TruncatingFloat64(),
+ MachineRepresentation::kFloat64);
+ if (lower()) lowering->DoIntegerToUint8Clamped(node);
+ } else {
+ VisitUnop(node, UseInfo::TruncatingFloat64(),
+ MachineRepresentation::kFloat64);
+ if (lower()) lowering->DoNumberToUint8Clamped(node);
+ }
+ return;
+ }
case IrOpcode::kReferenceEqual: {
VisitBinop(node, UseInfo::AnyTagged(), MachineRepresentation::kBit);
if (lower()) {
@@ -3294,6 +3319,71 @@ void SimplifiedLowering::DoNumberToBit(Node* node) {
NodeProperties::ChangeOp(node, machine()->Float64LessThan());
}
+void SimplifiedLowering::DoIntegerToUint8Clamped(Node* node) {
+ Node* const input = node->InputAt(0);
+ Node* const min = jsgraph()->Float64Constant(0.0);
+ Node* const max = jsgraph()->Float64Constant(255.0);
+
+ node->ReplaceInput(
+ 0, graph()->NewNode(machine()->Float64LessThan(), min, input));
+ node->AppendInput(
+ graph()->zone(),
+ graph()->NewNode(
+ common()->Select(MachineRepresentation::kFloat64),
+ graph()->NewNode(machine()->Float64LessThan(), input, max), input,
+ max));
+ node->AppendInput(graph()->zone(), min);
+ NodeProperties::ChangeOp(node,
+ common()->Select(MachineRepresentation::kFloat64));
+}
+
+void SimplifiedLowering::DoNumberToUint8Clamped(Node* node) {
+ Node* const input = node->InputAt(0);
+ Node* const min = jsgraph()->Float64Constant(0.0);
+ Node* const max = jsgraph()->Float64Constant(255.0);
+
+ node->ReplaceInput(
+ 0, graph()->NewNode(
+ common()->Select(MachineRepresentation::kFloat64),
+ graph()->NewNode(machine()->Float64LessThan(), min, input),
+ graph()->NewNode(
+ common()->Select(MachineRepresentation::kFloat64),
+ graph()->NewNode(machine()->Float64LessThan(), input, max),
+ input, max),
+ min));
+ NodeProperties::ChangeOp(node,
+ machine()->Float64RoundTiesEven().placeholder());
+}
+
+void SimplifiedLowering::DoSigned32ToUint8Clamped(Node* node) {
+ Node* const input = node->InputAt(0);
+ Node* const min = jsgraph()->Int32Constant(0);
+ Node* const max = jsgraph()->Int32Constant(255);
+
+ node->ReplaceInput(
+ 0, graph()->NewNode(machine()->Int32LessThanOrEqual(), input, max));
+ node->AppendInput(
+ graph()->zone(),
+ graph()->NewNode(common()->Select(MachineRepresentation::kWord32),
+ graph()->NewNode(machine()->Int32LessThan(), input, min),
+ min, input));
+ node->AppendInput(graph()->zone(), max);
+ NodeProperties::ChangeOp(node,
+ common()->Select(MachineRepresentation::kWord32));
+}
+
+void SimplifiedLowering::DoUnsigned32ToUint8Clamped(Node* node) {
+ Node* const input = node->InputAt(0);
+ Node* const max = jsgraph()->Uint32Constant(255u);
+
+ node->ReplaceInput(
+ 0, graph()->NewNode(machine()->Uint32LessThanOrEqual(), input, max));
+ node->AppendInput(graph()->zone(), input);
+ node->AppendInput(graph()->zone(), max);
+ NodeProperties::ChangeOp(node,
+ common()->Select(MachineRepresentation::kWord32));
+}
+
Node* SimplifiedLowering::ToNumberCode() {
if (!to_number_code_.is_set()) {
Callable callable = CodeFactory::ToNumber(isolate());
« no previous file with comments | « src/compiler/simplified-lowering.h ('k') | src/compiler/simplified-operator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698