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

Unified Diff: src/code-stubs.cc

Issue 1881003002: [stubs] Introduce LeftShift, SignedRightShift and UnsignedRightShift stubs. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 8 months 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/code-stubs.h ('k') | src/interpreter/interpreter.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/code-stubs.cc
diff --git a/src/code-stubs.cc b/src/code-stubs.cc
index 1acd977a061a62ea2eedc4406acd0dca647b2605..e8fa554cbbefd397484fd96142faeaf4b91a5cd0 100644
--- a/src/code-stubs.cc
+++ b/src/code-stubs.cc
@@ -1542,6 +1542,76 @@ void ModulusStub::GenerateAssembly(
}
}
+void LeftShiftStub::GenerateAssembly(
+ compiler::CodeStubAssembler* assembler) const {
+ using compiler::Node;
+
+ Node* lhs = assembler->Parameter(0);
+ Node* rhs = assembler->Parameter(1);
+ Node* context = assembler->Parameter(2);
+ Node* lhs_value = assembler->TruncateTaggedToWord32(context, lhs);
+ Node* rhs_value = assembler->TruncateTaggedToWord32(context, rhs);
+ Node* shift_count =
+ assembler->Word32And(rhs_value, assembler->Int32Constant(0x1f));
+ Node* value = assembler->Word32Shl(lhs_value, shift_count);
+ Node* result = assembler->ChangeInt32ToTagged(value);
+ assembler->Return(result);
+}
+
+void SignedRightShiftStub::GenerateAssembly(
+ compiler::CodeStubAssembler* assembler) const {
+ using compiler::Node;
+
+ Node* lhs = assembler->Parameter(0);
+ Node* rhs = assembler->Parameter(1);
+ Node* context = assembler->Parameter(2);
+ Node* lhs_value = assembler->TruncateTaggedToWord32(context, lhs);
+ Node* rhs_value = assembler->TruncateTaggedToWord32(context, rhs);
+ Node* shift_count =
+ assembler->Word32And(rhs_value, assembler->Int32Constant(0x1f));
+ Node* value = assembler->Word32Sar(lhs_value, shift_count);
+ Node* result = assembler->ChangeInt32ToTagged(value);
+ assembler->Return(result);
+}
+
+void UnsignedRightShiftStub::GenerateAssembly(
+ compiler::CodeStubAssembler* assembler) const {
+ using compiler::Node;
+ typedef compiler::CodeStubAssembler::Label Label;
+
+ Node* lhs = assembler->Parameter(0);
+ Node* rhs = assembler->Parameter(1);
+ Node* context = assembler->Parameter(2);
+ Node* lhs_value = assembler->TruncateTaggedToWord32(context, lhs);
+ Node* rhs_value = assembler->TruncateTaggedToWord32(context, rhs);
+ Node* shift_count =
+ assembler->Word32And(rhs_value, assembler->Int32Constant(0x1f));
+ Node* value = assembler->Word32Shr(lhs_value, shift_count);
+
+ Label if_smi_overflow(assembler, Label::kDeferred),
Benedikt Meurer 2016/04/12 12:55:20 Nit: Can you wrap this into ChangeUint32ToTagged?
epertoso 2016/04/12 15:10:16 Sure.
+ if_not_smi_overflow(assembler);
+ // If the sign bit on {value} is set, we always need a heap number to
+ // represent the unsigned value. This is sufficient for both 32 and 31 bit
+ // Smis, as ChangeInt32ToTagged will allocate a HeapNumber for us when tagging
+ // the Smi causes an 32-bit integer overflow.
+ assembler->Branch(
+ assembler->Int32LessThan(value, assembler->Int32Constant(0)),
+ &if_smi_overflow, &if_not_smi_overflow);
+
+ assembler->Bind(&if_not_smi_overflow);
+ {
+ Node* result = assembler->ChangeInt32ToTagged(value);
+ assembler->Return(result);
+ }
+
+ assembler->Bind(&if_smi_overflow);
+ {
+ Node* float64_value = assembler->ChangeUint32ToFloat64(value);
+ Node* result = assembler->AllocateHeapNumberWithValue(float64_value);
+ assembler->Return(result);
+ }
+}
+
void BitwiseOrStub::GenerateAssembly(
compiler::CodeStubAssembler* assembler) const {
using compiler::Node;
« no previous file with comments | « src/code-stubs.h ('k') | src/interpreter/interpreter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698