Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 // | |
| 5 // Tests optimizing (a << b) & c if c is a Smi constant. | |
| 6 | |
| 7 main() { | |
| 8 checkshiftAnd32(); | |
| 9 checkShiftAnd64(); | |
| 10 // Optimize shiftAnd32. | |
| 11 for (int i = 0; i < 10000; i++) { | |
| 12 A.shiftAnd32(12, 17); | |
| 13 A.shiftAnd64(12, 17); | |
| 14 } | |
| 15 checkshiftAnd32(); | |
| 16 checkShiftAnd64(); | |
| 17 | |
| 18 Expect.throws(() => A.shiftAnd32(12, -5)); | |
| 19 } | |
| 20 | |
| 21 | |
| 22 checkshiftAnd32() { | |
| 23 Expect.equals(1572864, A.shiftAnd32(12, 17)); | |
| 24 Expect.equals(12, A.shiftAnd32(12, 0)); | |
| 25 Expect.equals(285212672, A.shiftAnd32(16779392, 17)); | |
| 26 } | |
| 27 | |
| 28 | |
| 29 checkShiftAnd64() { | |
| 30 Expect.equals(1125936481173504, A.shiftAnd64(4611694814806147072, 7)); | |
| 31 } | |
| 32 | |
| 33 | |
| 34 class A { | |
|
Vyacheslav Egorov (Google)
2013/02/20 00:37:06
Please add a test that tests when (a << c) has mul
| |
| 35 static const int MASK_32 = (1 << 30) - 1; | |
| 36 static const int MASK_64 = (1 << 62) - 1; | |
| 37 | |
| 38 static shiftAnd32(a, c) { | |
| 39 return (a << c) & MASK_32; | |
| 40 } | |
| 41 | |
| 42 static shiftAnd64(a, c) { | |
| 43 return (a << c) & MASK_64; | |
| 44 } | |
| 45 } | |
| OLD | NEW |