|
1 /* Test the proper operation of the arithmetic right shift operator. This is |
|
2 * especially important on ARM as an explicit mask is required at the native |
|
3 * instruction level. */ |
|
4 |
|
5 load(libdir + 'range.js'); |
|
6 |
|
7 /* Test different combinations of literals/variables. */ |
|
8 var s = 4; |
|
9 var t = 100; |
|
10 assertEq(42 >> s, 2); |
|
11 assertEq(s >> 1, 2); |
|
12 assertEq(23 >> 3, 2); |
|
13 assertEq(t >> s, 6); |
|
14 |
|
15 |
|
16 function testShiftRightArithmetic() |
|
17 { |
|
18 var r = []; |
|
19 var i = 0; |
|
20 var j = 0; |
|
21 |
|
22 var shifts = [0,1,7,8,15,16,23,24,31]; |
|
23 |
|
24 /* Samples from the simple shift range. */ |
|
25 for (i = 0; i < shifts.length; i++) |
|
26 r[j++] = -2147483648 >> shifts[i]; |
|
27 |
|
28 /* Samples outside the normal shift range. */ |
|
29 for (i = 0; i < shifts.length; i++) |
|
30 r[j++] = -2147483648 >> (shifts[i] + 32); |
|
31 |
|
32 /* Samples far outside the normal shift range. */ |
|
33 for (i = 0; i < shifts.length; i++) |
|
34 r[j++] = -2147483648 >> (shifts[i] + 224); |
|
35 for (i = 0; i < shifts.length; i++) |
|
36 r[j++] = -2147483648 >> (shifts[i] + 256); |
|
37 |
|
38 return r.join(","); |
|
39 } |
|
40 assertEq(testShiftRightArithmetic(), |
|
41 "-2147483648,-1073741824,-16777216,-8388608,-65536,-32768,-256,-128,-1,"+ |
|
42 "-2147483648,-1073741824,-16777216,-8388608,-65536,-32768,-256,-128,-1,"+ |
|
43 "-2147483648,-1073741824,-16777216,-8388608,-65536,-32768,-256,-128,-1,"+ |
|
44 "-2147483648,-1073741824,-16777216,-8388608,-65536,-32768,-256,-128,-1"); |