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

Unified Diff: tests/standalone/left_shift_bit_and_op_test.dart

Issue 12218181: Recognize pattern (a << b) & c with c being a positive Smi and allow left shift to truncate the res… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 10 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: tests/standalone/left_shift_bit_and_op_test.dart
===================================================================
--- tests/standalone/left_shift_bit_and_op_test.dart (revision 0)
+++ tests/standalone/left_shift_bit_and_op_test.dart (revision 0)
@@ -0,0 +1,45 @@
+// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+//
+// Tests optimizing (a << b) & c if c is a Smi constant.
+
+main() {
+ checkshiftAnd32();
+ checkShiftAnd64();
+ // Optimize shiftAnd32.
+ for (int i = 0; i < 10000; i++) {
+ A.shiftAnd32(12, 17);
+ A.shiftAnd64(12, 17);
+ }
+ checkshiftAnd32();
+ checkShiftAnd64();
+
+ Expect.throws(() => A.shiftAnd32(12, -5));
+}
+
+
+checkshiftAnd32() {
+ Expect.equals(1572864, A.shiftAnd32(12, 17));
+ Expect.equals(12, A.shiftAnd32(12, 0));
+ Expect.equals(285212672, A.shiftAnd32(16779392, 17));
+}
+
+
+checkShiftAnd64() {
+ Expect.equals(1125936481173504, A.shiftAnd64(4611694814806147072, 7));
+}
+
+
+class A {
Vyacheslav Egorov (Google) 2013/02/20 00:37:06 Please add a test that tests when (a << c) has mul
+ static const int MASK_32 = (1 << 30) - 1;
+ static const int MASK_64 = (1 << 62) - 1;
+
+ static shiftAnd32(a, c) {
+ return (a << c) & MASK_32;
+ }
+
+ static shiftAnd64(a, c) {
+ return (a << c) & MASK_64;
+ }
+}
« runtime/vm/intermediate_language_ia32.cc ('K') | « runtime/vm/intermediate_language_x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698