| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 // | 4 // |
| 5 // Tests optimizing (a << b) & c if c is a Smi constant. | 5 // Tests optimizing (a << b) & c if c is a Smi constant. |
| 6 | 6 |
| 7 import "package:expect/expect.dart"; | 7 import "package:expect/expect.dart"; |
| 8 | 8 |
| 9 main() { | 9 main() { |
| 10 checkshiftAnd32(); | 10 checkshiftAnd32(); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 Expect.throws(() => A.shiftAnd32(12, -5)); | 22 Expect.throws(() => A.shiftAnd32(12, -5)); |
| 23 | 23 |
| 24 // Check environment dependency. | 24 // Check environment dependency. |
| 25 final a = new A(), b = new B(); | 25 final a = new A(), b = new B(); |
| 26 for (var i = 0; i < 10000; i++) { | 26 for (var i = 0; i < 10000; i++) { |
| 27 Expect.equals(0, bar(a)); | 27 Expect.equals(0, bar(a)); |
| 28 } | 28 } |
| 29 Expect.equals(4294967296, bar(b)); | 29 Expect.equals(4294967296, bar(b)); |
| 30 } | 30 } |
| 31 | 31 |
| 32 | |
| 33 checkshiftAnd32() { | 32 checkshiftAnd32() { |
| 34 Expect.equals(1572864, A.shiftAnd32(12, 17)); | 33 Expect.equals(1572864, A.shiftAnd32(12, 17)); |
| 35 Expect.equals(12, A.shiftAnd32(12, 0)); | 34 Expect.equals(12, A.shiftAnd32(12, 0)); |
| 36 Expect.equals(285212672, A.shiftAnd32(16779392, 17)); | 35 Expect.equals(285212672, A.shiftAnd32(16779392, 17)); |
| 37 } | 36 } |
| 38 | 37 |
| 39 | |
| 40 checkShiftAnd64() { | 38 checkShiftAnd64() { |
| 41 Expect.equals(1125936481173504, A.shiftAnd64(4611694814806147072, 7)); | 39 Expect.equals(1125936481173504, A.shiftAnd64(4611694814806147072, 7)); |
| 42 } | 40 } |
| 43 | 41 |
| 44 | |
| 45 class A { | 42 class A { |
| 46 static const int MASK_32 = (1 << 30) - 1; | 43 static const int MASK_32 = (1 << 30) - 1; |
| 47 static const int MASK_64 = (1 << 62) - 1; | 44 static const int MASK_64 = (1 << 62) - 1; |
| 48 | 45 |
| 49 static shiftAnd32(a, c) { | 46 static shiftAnd32(a, c) { |
| 50 return (a << c) & MASK_32; | 47 return (a << c) & MASK_32; |
| 51 } | 48 } |
| 52 | 49 |
| 53 static shiftAnd64(a, c) { | 50 static shiftAnd64(a, c) { |
| 54 return (a << c) & MASK_64; | 51 return (a << c) & MASK_64; |
| 55 } | 52 } |
| 56 | 53 |
| 57 static multipleConstantUses(a, c) { | 54 static multipleConstantUses(a, c) { |
| 58 var j = (a << c) & 0xFF; | 55 var j = (a << c) & 0xFF; |
| 59 var k = (a << 3) & 0xFF; | 56 var k = (a << 3) & 0xFF; |
| 60 return j + k; | 57 return j + k; |
| 61 } | 58 } |
| 62 | 59 |
| 63 // Make sure that left shift is nor marked as truncating. | 60 // Make sure that left shift is nor marked as truncating. |
| 64 static multipleShiftUse(a, c) { | 61 static multipleShiftUse(a, c) { |
| 65 var y = (a << c); | 62 var y = (a << c); |
| 66 var x = y & 0x7F; | 63 var x = y & 0x7F; |
| 67 return y + x; | 64 return y + x; |
| 68 } | 65 } |
| 69 | 66 |
| 70 foo(x) { return x & 0xf; } | 67 foo(x) { |
| 68 return x & 0xf; |
| 69 } |
| 71 } | 70 } |
| 72 | 71 |
| 73 class B { foo(x) { return x; } } | 72 class B { |
| 73 foo(x) { |
| 74 return x; |
| 75 } |
| 76 } |
| 74 | 77 |
| 75 bar (o) { | 78 bar(o) { |
| 76 return o.foo(1 << 32); | 79 return o.foo(1 << 32); |
| 77 } | 80 } |
| OLD | NEW |