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

Unified Diff: runtime/vm/intermediate_language_ia32.cc

Issue 105143011: Optimize one byte string comparisons. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years 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: runtime/vm/intermediate_language_ia32.cc
===================================================================
--- runtime/vm/intermediate_language_ia32.cc (revision 31282)
+++ runtime/vm/intermediate_language_ia32.cc (working copy)
@@ -721,7 +721,7 @@
}
-LocationSummary* StringFromCharCodeInstr::MakeLocationSummary(bool opt) const {
+LocationSummary* StringCharCodeInstr::MakeLocationSummary(bool opt) const {
const intptr_t kNumInputs = 1;
// TODO(fschneider): Allow immediate operands for the char code.
return LocationSummary::Make(kNumInputs,
@@ -730,15 +730,32 @@
}
-void StringFromCharCodeInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
- Register char_code = locs()->in(0).reg();
- Register result = locs()->out().reg();
- __ movl(result,
- Immediate(reinterpret_cast<uword>(Symbols::PredefinedAddress())));
- __ movl(result, Address(result,
- char_code,
- TIMES_HALF_WORD_SIZE, // Char code is a smi.
- Symbols::kNullCharCodeSymbolOffset * kWordSize));
+void StringCharCodeInstr::EmitNativeCode(FlowGraphCompiler* compiler) {
+ if (kind() == StringCharCodeInstr::kFromCharCode) {
+ Register char_code = locs()->in(0).reg();
+ Register result = locs()->out().reg();
+ __ movl(result,
+ Immediate(reinterpret_cast<uword>(Symbols::PredefinedAddress())));
+ __ movl(result, Address(result,
+ char_code,
+ TIMES_HALF_WORD_SIZE, // Char code is a smi.
+ Symbols::kNullCharCodeSymbolOffset * kWordSize));
+ } else {
+ ASSERT(kind() == StringCharCodeInstr::kToCharCode);
+ ASSERT(cid_ == kOneByteStringCid);
+ Register str = locs()->in(0).reg();
+ Register result = locs()->out().reg();
+ Label is_one, done;
+ __ movl(result, FieldAddress(str, String::length_offset()));
+ __ cmpl(result, Immediate(Smi::RawValue(1)));
+ __ j(EQUAL, &is_one, Assembler::kNearJump);
+ __ movl(result, Immediate(Smi::RawValue(-1)));
+ __ jmp(&done);
+ __ Bind(&is_one);
+ __ movzxb(result, FieldAddress(str, OneByteString::data_offset()));
+ __ SmiTag(result);
+ __ Bind(&done);
+ }
}

Powered by Google App Engine
This is Rietveld 408576698