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

Unified Diff: src/code-stub-assembler.cc

Issue 2358263002: [builtins] migrate C++ String Iterator builtins to baseline TurboFan (Closed)
Patch Set: Adapt arguments for TFJ builtins Created 4 years, 3 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
Index: src/code-stub-assembler.cc
diff --git a/src/code-stub-assembler.cc b/src/code-stub-assembler.cc
index 80c4c77bf6f034f21cd12a2b7d90788aa2fec7d4..c5ce7b8baa9446d61379c6be687ceb4e87968a30 100644
--- a/src/code-stub-assembler.cc
+++ b/src/code-stub-assembler.cc
@@ -2429,6 +2429,56 @@ Node* CodeStubAssembler::StringFromCharCode(Node* code) {
return var_result.value();
}
+Node* CodeStubAssembler::StringFromCodePoint(compiler::Node* codepoint,
+ UnicodeEncoding encoding) {
+ Variable var_result(this, MachineRepresentation::kTagged);
+ var_result.Bind(EmptyStringConstant());
+
+ Label if_isword16(this), if_isword32(this), return_result(this);
+
+ Branch(Uint32LessThan(codepoint, Int32Constant(0x10000)), &if_isword16,
+ &if_isword32);
+
+ Bind(&if_isword16);
+ {
+ var_result.Bind(StringFromCharCode(codepoint));
+ Goto(&return_result);
+ }
+
+ Bind(&if_isword32);
+ {
+ switch (encoding) {
+ case UnicodeEncoding::UTF16:
+ break;
+ case UnicodeEncoding::UTF32: {
+ // Convert UTF32 to UTF16 code units, and store as a 32 bit word.
+ Node* lead_offset = Int32Constant(0xD800 - (0x10000 >> 10));
+
+ Node* lead =
+ Int32Add(WordShr(codepoint, Int32Constant(10)), lead_offset);
+
+ Node* trail = Int32Add(Word32And(codepoint, Int32Constant(0x3FF)),
+ Int32Constant(0xDC00));
+
+ codepoint = Word32Or(WordShl(trail, Int32Constant(16)), lead);
Benedikt Meurer 2016/09/26 18:38:22 Nit: add explicit break for readability.
caitp 2016/09/27 08:55:57 Done, although clang-format complains unless I rea
caitp 2016/09/27 09:14:18 Actually, clang-format isn't happy even with the c
Benedikt Meurer 2016/09/27 09:16:02 I mean the keyword break, not a line break.
caitp 2016/09/27 09:20:41 Oh, I see. Haven't had much coffee yet this mornin
Benedikt Meurer 2016/09/27 09:52:38 Thanks! Now grab a coffee. ;-)
+ }
+ default:
Benedikt Meurer 2016/09/26 18:38:22 Don't add default here. The C++ compiler cannot fl
caitp 2016/09/27 08:55:57 Done.
+ UNREACHABLE();
+ }
+
+ Node* value = AllocateSeqTwoByteString(2);
+ StoreNoWriteBarrier(
+ MachineRepresentation::kWord32, value,
+ IntPtrConstant(SeqTwoByteString::kHeaderSize - kHeapObjectTag),
+ codepoint);
+ var_result.Bind(value);
+ Goto(&return_result);
+ }
+
+ Bind(&return_result);
+ return var_result.value();
+}
+
Node* CodeStubAssembler::StringToNumber(Node* context, Node* input) {
Label runtime(this, Label::kDeferred);
Label end(this);

Powered by Google App Engine
This is Rietveld 408576698