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

Unified Diff: runtime/vm/intrinsifier_x64.cc

Issue 867383002: Implement bitLength intrinsic on x64. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 5 years, 11 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
« runtime/vm/assembler_x64_test.cc ('K') | « runtime/vm/disassembler_x64.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/intrinsifier_x64.cc
===================================================================
--- runtime/vm/intrinsifier_x64.cc (revision 43118)
+++ runtime/vm/intrinsifier_x64.cc (working copy)
@@ -794,7 +794,18 @@
void Intrinsifier::Smi_bitLength(Assembler* assembler) {
- // TODO(sra): Implement using bsrq.
+ ASSERT(kSmiTagShift == 1);
+ __ movq(RAX, Address(RSP, + 1 * kWordSize)); // Index.
+ // XOR with sign bit to complement bits if value is negative.
+ __ movq(RCX, RAX);
+ __ sarq(RCX, Immediate(63)); // All 0 or all 1.
Lasse Reichstein Nielsen 2015/01/25 11:26:53 If you shift RAX instead of RCX here, would the de
srdjan 2015/01/26 18:43:18 Thanks for the comment. In theory yes, but with In
+ __ xorq(RAX, RCX);
+ // BSR does not write the destination register if source is zero. Put a 1 in
+ // the Smi tag bit to ensure BSR writes to destination register.
+ __ orq(RAX, Immediate(kSmiTagMask));
+ __ bsrq(RAX, RAX);
+ __ SmiTag(RAX);
+ __ ret();
}
« runtime/vm/assembler_x64_test.cc ('K') | « runtime/vm/disassembler_x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698