OLD | NEW |
1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, 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 // Check that optimizer correctly handles (x << y) & MASK_32 pattern on 32-bit | 5 // Check that optimizer correctly handles (x << y) & MASK_32 pattern on 32-bit |
6 // platforms: given the pattern | 6 // platforms: given the pattern |
7 // | 7 // |
8 // v1 <- UnboxedIntConverter([tr] mint->uint32, v0) | 8 // v1 <- UnboxedIntConverter([tr] mint->uint32, v0) |
9 // v2 <- UnboxedIntConverter(uint32->mint, v1) | 9 // v2 <- UnboxedIntConverter(uint32->mint, v1) |
10 // | 10 // |
11 // optimizer must *not* replace v2 with v0 because the first conversion is | 11 // optimizer must *not* replace v2 with v0 because the first conversion is |
12 // truncating and is erasing the high part of the mint value. | 12 // truncating and is erasing the high part of the mint value. |
13 // | 13 // |
14 // VMOptions=--optimization-counter-threshold=5 --no-background-compilation | 14 // VMOptions=--optimization-counter-threshold=5 --no-background-compilation |
15 | 15 |
16 import "package:expect/expect.dart"; | 16 import "package:expect/expect.dart"; |
17 | 17 |
18 const _MASK_32 = 0xffffffff; | 18 const _MASK_32 = 0xffffffff; |
19 int _rotl32(int val, int shift) { | 19 int _rotl32(int val, int shift) { |
20 final mod_shift = shift & 31; | 20 final mod_shift = shift & 31; |
21 return ((val << mod_shift) & _MASK_32) | | 21 return ((val << mod_shift) & _MASK_32) | |
22 ((val & _MASK_32) >> (32 - mod_shift)); | 22 ((val & _MASK_32) >> (32 - mod_shift)); |
23 } | 23 } |
24 | 24 |
25 rot8(v) => _rotl32(v, 8); | 25 rot8(v) => _rotl32(v, 8); |
26 | 26 |
27 main() { | 27 main() { |
28 // Note: value is selected in such a way that (value << 8) is not a smi - this | 28 // Note: value is selected in such a way that (value << 8) is not a smi - this |
29 // triggers emittion of BinaryMintOp instructions for shifts. | 29 // triggers emission of BinaryMintOp instructions for shifts. |
30 const value = 0xF0F00000; | 30 const value = 0xF0F00000; |
31 const rotated = 0xF00000F0; | 31 const rotated = 0xF00000F0; |
32 Expect.equals(rotated, rot8(value)); | 32 Expect.equals(rotated, rot8(value)); |
33 for (var i = 0; i < 10; i++) { | 33 for (var i = 0; i < 10; i++) { |
34 Expect.equals(rotated, rot8(value)); | 34 Expect.equals(rotated, rot8(value)); |
35 } | 35 } |
36 } | 36 } |
OLD | NEW |