Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
Vladimir Marko | f66b67f | 2018-03-28 13:32:18 +0100 | [diff] [blame] | 17 | public class ShiftsTest { |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 18 | |
| 19 | public static void expectEquals(int expected, int result) { |
| 20 | if (expected != result) { |
| 21 | throw new Error("Expected: " + expected + ", found: " + result); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | public static void expectEquals(long expected, long result) { |
| 26 | if (expected != result) { |
| 27 | throw new Error("Expected: " + expected + ", found: " + result); |
| 28 | } |
| 29 | } |
| 30 | |
Vladimir Marko | f66b67f | 2018-03-28 13:32:18 +0100 | [diff] [blame] | 31 | public static void main() { |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 32 | testShlInt(); |
| 33 | testShlLong(); |
| 34 | testShrInt(); |
| 35 | testShrLong(); |
| 36 | testUShrInt(); |
| 37 | testUShrLong(); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 38 | } |
| 39 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 40 | private static void testShlInt() { |
| 41 | expectEquals(48, $opt$ShlIntConst2(12)); |
| 42 | expectEquals(12, $opt$ShlIntConst0(12)); |
| 43 | expectEquals(-48, $opt$ShlInt(-12, 2)); |
| 44 | expectEquals(1024, $opt$ShlInt(32, 5)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 45 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 46 | expectEquals(7, $opt$ShlInt(7, 0)); |
| 47 | expectEquals(14, $opt$ShlInt(7, 1)); |
| 48 | expectEquals(0, $opt$ShlInt(0, 30)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 49 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 50 | expectEquals(1073741824L, $opt$ShlInt(1, 30)); |
| 51 | expectEquals(Integer.MIN_VALUE, $opt$ShlInt(1, 31)); // overflow |
| 52 | expectEquals(Integer.MIN_VALUE, $opt$ShlInt(1073741824, 1)); // overflow |
| 53 | expectEquals(1073741824, $opt$ShlInt(268435456, 2)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 54 | |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 55 | // Only the 5 lower bits should be used for shifting (& 0x1f). |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 56 | expectEquals(7, $opt$ShlInt(7, 32)); // 32 & 0x1f = 0 |
| 57 | expectEquals(14, $opt$ShlInt(7, 33)); // 33 & 0x1f = 1 |
| 58 | expectEquals(32, $opt$ShlInt(1, 101)); // 101 & 0x1f = 5 |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 59 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 60 | expectEquals(Integer.MIN_VALUE, $opt$ShlInt(1, -1)); // -1 & 0x1f = 31 |
| 61 | expectEquals(14, $opt$ShlInt(7, -31)); // -31 & 0x1f = 1 |
| 62 | expectEquals(7, $opt$ShlInt(7, -32)); // -32 & 0x1f = 0 |
| 63 | expectEquals(-536870912, $opt$ShlInt(7, -3)); // -3 & 0x1f = 29 |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 64 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 65 | expectEquals(Integer.MIN_VALUE, $opt$ShlInt(7, Integer.MAX_VALUE)); |
| 66 | expectEquals(7, $opt$ShlInt(7, Integer.MIN_VALUE)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 67 | } |
| 68 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 69 | private static void testShlLong() { |
| 70 | expectEquals(48L, $opt$ShlLongConst2(12L)); |
| 71 | expectEquals(12L, $opt$ShlLongConst0(12L)); |
| 72 | expectEquals(-48L, $opt$ShlLong(-12L, 2)); |
| 73 | expectEquals(1024L, $opt$ShlLong(32L, 5)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 74 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 75 | expectEquals(7L, $opt$ShlLong(7L, 0)); |
| 76 | expectEquals(14L, $opt$ShlLong(7L, 1)); |
| 77 | expectEquals(0L, $opt$ShlLong(0L, 30)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 78 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 79 | expectEquals(1073741824L, $opt$ShlLong(1L, 30)); |
| 80 | expectEquals(2147483648L, $opt$ShlLong(1L, 31)); |
| 81 | expectEquals(2147483648L, $opt$ShlLong(1073741824L, 1)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 82 | |
| 83 | // Long shifts can use up to 6 lower bits. |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 84 | expectEquals(4294967296L, $opt$ShlLong(1L, 32)); |
| 85 | expectEquals(60129542144L, $opt$ShlLong(7L, 33)); |
| 86 | expectEquals(Long.MIN_VALUE, $opt$ShlLong(1L, 63)); // overflow |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 87 | |
| 88 | // Only the 6 lower bits should be used for shifting (& 0x3f). |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 89 | expectEquals(7L, $opt$ShlLong(7L, 64)); // 64 & 0x3f = 0 |
| 90 | expectEquals(14L, $opt$ShlLong(7L, 65)); // 65 & 0x3f = 1 |
| 91 | expectEquals(137438953472L, $opt$ShlLong(1L, 101)); // 101 & 0x3f = 37 |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 92 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 93 | expectEquals(Long.MIN_VALUE, $opt$ShlLong(1L, -1)); // -1 & 0x3f = 63 |
| 94 | expectEquals(14L, $opt$ShlLong(7L, -63)); // -63 & 0x3f = 1 |
| 95 | expectEquals(7L, $opt$ShlLong(7L, -64)); // -64 & 0x3f = 0 |
| 96 | expectEquals(2305843009213693952L, $opt$ShlLong(1L, -3)); // -3 & 0x3f = 61 |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 97 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 98 | expectEquals(Long.MIN_VALUE, $opt$ShlLong(7L, Integer.MAX_VALUE)); |
| 99 | expectEquals(7L, $opt$ShlLong(7L, Integer.MIN_VALUE)); |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 100 | |
| 101 | // Exercise some special cases handled by backends/simplifier. |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 102 | expectEquals(24L, $opt$ShlLongConst1(12L)); |
| 103 | expectEquals(0x2345678900000000L, $opt$ShlLongConst32(0x123456789L)); |
| 104 | expectEquals(0x2490249000000000L, $opt$ShlLongConst33(0x12481248L)); |
| 105 | expectEquals(0x4920492000000000L, $opt$ShlLongConst34(0x12481248L)); |
| 106 | expectEquals(0x9240924000000000L, $opt$ShlLongConst35(0x12481248L)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 107 | } |
| 108 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 109 | private static void testShrInt() { |
| 110 | expectEquals(3, $opt$ShrIntConst2(12)); |
| 111 | expectEquals(12, $opt$ShrIntConst0(12)); |
| 112 | expectEquals(-3, $opt$ShrInt(-12, 2)); |
| 113 | expectEquals(1, $opt$ShrInt(32, 5)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 114 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 115 | expectEquals(7, $opt$ShrInt(7, 0)); |
| 116 | expectEquals(3, $opt$ShrInt(7, 1)); |
| 117 | expectEquals(0, $opt$ShrInt(0, 30)); |
| 118 | expectEquals(0, $opt$ShrInt(1, 30)); |
| 119 | expectEquals(-1, $opt$ShrInt(-1, 30)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 120 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 121 | expectEquals(0, $opt$ShrInt(Integer.MAX_VALUE, 31)); |
| 122 | expectEquals(-1, $opt$ShrInt(Integer.MIN_VALUE, 31)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 123 | |
| 124 | // Only the 5 lower bits should be used for shifting (& 0x1f). |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 125 | expectEquals(7, $opt$ShrInt(7, 32)); // 32 & 0x1f = 0 |
| 126 | expectEquals(3, $opt$ShrInt(7, 33)); // 33 & 0x1f = 1 |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 127 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 128 | expectEquals(0, $opt$ShrInt(1, -1)); // -1 & 0x1f = 31 |
| 129 | expectEquals(3, $opt$ShrInt(7, -31)); // -31 & 0x1f = 1 |
| 130 | expectEquals(7, $opt$ShrInt(7, -32)); // -32 & 0x1f = 0 |
| 131 | expectEquals(-4, $opt$ShrInt(Integer.MIN_VALUE, -3)); // -3 & 0x1f = 29 |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 132 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 133 | expectEquals(0, $opt$ShrInt(7, Integer.MAX_VALUE)); |
| 134 | expectEquals(7, $opt$ShrInt(7, Integer.MIN_VALUE)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 137 | private static void testShrLong() { |
| 138 | expectEquals(3L, $opt$ShrLongConst2(12L)); |
| 139 | expectEquals(12L, $opt$ShrLongConst0(12L)); |
| 140 | expectEquals(-3L, $opt$ShrLong(-12L, 2)); |
| 141 | expectEquals(1, $opt$ShrLong(32, 5)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 142 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 143 | expectEquals(7L, $opt$ShrLong(7L, 0)); |
| 144 | expectEquals(3L, $opt$ShrLong(7L, 1)); |
| 145 | expectEquals(0L, $opt$ShrLong(0L, 30)); |
| 146 | expectEquals(0L, $opt$ShrLong(1L, 30)); |
| 147 | expectEquals(-1L, $opt$ShrLong(-1L, 30)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 148 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 149 | expectEquals(1L, $opt$ShrLong(1073741824L, 30)); |
| 150 | expectEquals(1L, $opt$ShrLong(2147483648L, 31)); |
| 151 | expectEquals(1073741824L, $opt$ShrLong(2147483648L, 1)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 152 | |
| 153 | // Long shifts can use up to 6 lower bits. |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 154 | expectEquals(1L, $opt$ShrLong(4294967296L, 32)); |
| 155 | expectEquals(7L, $opt$ShrLong(60129542144L, 33)); |
| 156 | expectEquals(0L, $opt$ShrLong(Long.MAX_VALUE, 63)); |
| 157 | expectEquals(-1L, $opt$ShrLong(Long.MIN_VALUE, 63)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 158 | |
| 159 | // Only the 6 lower bits should be used for shifting (& 0x3f). |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 160 | expectEquals(7L, $opt$ShrLong(7L, 64)); // 64 & 0x3f = 0 |
| 161 | expectEquals(3L, $opt$ShrLong(7L, 65)); // 65 & 0x3f = 1 |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 162 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 163 | expectEquals(-1L, $opt$ShrLong(Long.MIN_VALUE, -1)); // -1 & 0x3f = 63 |
| 164 | expectEquals(3L, $opt$ShrLong(7L, -63)); // -63 & 0x3f = 1 |
| 165 | expectEquals(7L, $opt$ShrLong(7L, -64)); // -64 & 0x3f = 0 |
| 166 | expectEquals(1L, $opt$ShrLong(2305843009213693952L, -3)); // -3 & 0x3f = 61 |
| 167 | expectEquals(-1L, $opt$ShrLong(Integer.MIN_VALUE, -3)); // -3 & 0x1f = 29 |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 168 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 169 | expectEquals(0L, $opt$ShrLong(7L, Integer.MAX_VALUE)); |
| 170 | expectEquals(7L, $opt$ShrLong(7L, Integer.MIN_VALUE)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 171 | } |
| 172 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 173 | private static void testUShrInt() { |
| 174 | expectEquals(3, $opt$UShrIntConst2(12)); |
| 175 | expectEquals(12, $opt$UShrIntConst0(12)); |
| 176 | expectEquals(1073741821, $opt$UShrInt(-12, 2)); |
| 177 | expectEquals(1, $opt$UShrInt(32, 5)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 178 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 179 | expectEquals(7, $opt$UShrInt(7, 0)); |
| 180 | expectEquals(3, $opt$UShrInt(7, 1)); |
| 181 | expectEquals(0, $opt$UShrInt(0, 30)); |
| 182 | expectEquals(0, $opt$UShrInt(1, 30)); |
| 183 | expectEquals(3, $opt$UShrInt(-1, 30)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 184 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 185 | expectEquals(0, $opt$UShrInt(Integer.MAX_VALUE, 31)); |
| 186 | expectEquals(1, $opt$UShrInt(Integer.MIN_VALUE, 31)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 187 | |
| 188 | // Only the 5 lower bits should be used for shifting (& 0x1f). |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 189 | expectEquals(7, $opt$UShrInt(7, 32)); // 32 & 0x1f = 0 |
| 190 | expectEquals(3, $opt$UShrInt(7, 33)); // 33 & 0x1f = 1 |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 191 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 192 | expectEquals(0, $opt$UShrInt(1, -1)); // -1 & 0x1f = 31 |
| 193 | expectEquals(3, $opt$UShrInt(7, -31)); // -31 & 0x1f = 1 |
| 194 | expectEquals(7, $opt$UShrInt(7, -32)); // -32 & 0x1f = 0 |
| 195 | expectEquals(4, $opt$UShrInt(Integer.MIN_VALUE, -3)); // -3 & 0x1f = 29 |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 196 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 197 | expectEquals(0, $opt$UShrInt(7, Integer.MAX_VALUE)); |
| 198 | expectEquals(7, $opt$UShrInt(7, Integer.MIN_VALUE)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 199 | } |
| 200 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 201 | private static void testUShrLong() { |
| 202 | expectEquals(3L, $opt$UShrLongConst2(12L)); |
| 203 | expectEquals(12L, $opt$UShrLongConst0(12L)); |
| 204 | expectEquals(4611686018427387901L, $opt$UShrLong(-12L, 2)); |
| 205 | expectEquals(1, $opt$UShrLong(32, 5)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 206 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 207 | expectEquals(7L, $opt$UShrLong(7L, 0)); |
| 208 | expectEquals(3L, $opt$UShrLong(7L, 1)); |
| 209 | expectEquals(0L, $opt$UShrLong(0L, 30)); |
| 210 | expectEquals(0L, $opt$UShrLong(1L, 30)); |
| 211 | expectEquals(17179869183L, $opt$UShrLong(-1L, 30)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 212 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 213 | expectEquals(1L, $opt$UShrLong(1073741824L, 30)); |
| 214 | expectEquals(1L, $opt$UShrLong(2147483648L, 31)); |
| 215 | expectEquals(1073741824L, $opt$UShrLong(2147483648L, 1)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 216 | |
Calin Juravle | 8c3961a | 2014-11-24 16:36:44 +0000 | [diff] [blame] | 217 | // Long shifts can use use up to 6 lower bits. |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 218 | expectEquals(1L, $opt$UShrLong(4294967296L, 32)); |
| 219 | expectEquals(7L, $opt$UShrLong(60129542144L, 33)); |
| 220 | expectEquals(0L, $opt$UShrLong(Long.MAX_VALUE, 63)); |
| 221 | expectEquals(1L, $opt$UShrLong(Long.MIN_VALUE, 63)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 222 | |
| 223 | // Only the 6 lower bits should be used for shifting (& 0x3f). |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 224 | expectEquals(7L, $opt$UShrLong(7L, 64)); // 64 & 0x3f = 0 |
| 225 | expectEquals(3L, $opt$UShrLong(7L, 65)); // 65 & 0x3f = 1 |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 226 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 227 | expectEquals(1L, $opt$UShrLong(Long.MIN_VALUE, -1)); // -1 & 0x3f = 63 |
| 228 | expectEquals(3L, $opt$UShrLong(7L, -63)); // -63 & 0x3f = 1 |
| 229 | expectEquals(7L, $opt$UShrLong(7L, -64)); // -64 & 0x3f = 0 |
| 230 | expectEquals(1L, $opt$UShrLong(2305843009213693952L, -3)); // -3 & 0x3f = 61 |
| 231 | expectEquals(4L, $opt$UShrLong(Long.MIN_VALUE, -3)); // -3 & 0x3f = 61 |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 232 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 233 | expectEquals(0L, $opt$UShrLong(7L, Integer.MAX_VALUE)); |
| 234 | expectEquals(7L, $opt$UShrLong(7L, Integer.MIN_VALUE)); |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 235 | } |
| 236 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 237 | |
| 238 | static int $opt$ShlInt(int value, int distance) { |
| 239 | return value << distance; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 240 | } |
| 241 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 242 | static long $opt$ShlLong(long value, int distance) { |
| 243 | return value << distance; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 244 | } |
| 245 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 246 | static int $opt$ShrInt(int value, int distance) { |
| 247 | return value >> distance; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 248 | } |
| 249 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 250 | static long $opt$ShrLong(long value, int distance) { |
| 251 | return value >> distance; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 252 | } |
| 253 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 254 | static int $opt$UShrInt(int value, int distance) { |
| 255 | return value >>> distance; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 256 | } |
| 257 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 258 | static long $opt$UShrLong(long value, int distance) { |
| 259 | return value >>> distance; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 260 | } |
| 261 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 262 | static int $opt$ShlIntConst2(int value) { |
| 263 | return value << 2; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 264 | } |
| 265 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 266 | static long $opt$ShlLongConst2(long value) { |
| 267 | return value << 2; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 268 | } |
| 269 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 270 | static int $opt$ShrIntConst2(int value) { |
| 271 | return value >> 2; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 274 | static long $opt$ShrLongConst2(long value) { |
| 275 | return value >> 2; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 276 | } |
| 277 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 278 | static int $opt$UShrIntConst2(int value) { |
| 279 | return value >>> 2; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 280 | } |
| 281 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 282 | static long $opt$UShrLongConst2(long value) { |
| 283 | return value >>> 2; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 284 | } |
| 285 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 286 | static int $opt$ShlIntConst0(int value) { |
| 287 | return value << 0; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 288 | } |
| 289 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 290 | static long $opt$ShlLongConst0(long value) { |
| 291 | return value << 0; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 292 | } |
| 293 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 294 | static int $opt$ShrIntConst0(int value) { |
| 295 | return value >> 0; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 296 | } |
| 297 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 298 | static long $opt$ShrLongConst0(long value) { |
| 299 | return value >> 0; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 300 | } |
| 301 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 302 | static int $opt$UShrIntConst0(int value) { |
| 303 | return value >>> 0; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 304 | } |
| 305 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 306 | static long $opt$UShrLongConst0(long value) { |
| 307 | return value >>> 0; |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 308 | } |
| 309 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 310 | static long $opt$ShlLongConst1(long value) { |
| 311 | return value << 1; |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 312 | } |
| 313 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 314 | static long $opt$ShlLongConst32(long value) { |
| 315 | return value << 32; |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 316 | } |
| 317 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 318 | static long $opt$ShlLongConst33(long value) { |
| 319 | return value << 33; |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 320 | } |
| 321 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 322 | static long $opt$ShlLongConst34(long value) { |
| 323 | return value << 34; |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 324 | } |
| 325 | |
Roland Levillain | 9b57966 | 2016-03-18 18:29:58 +0000 | [diff] [blame] | 326 | static long $opt$ShlLongConst35(long value) { |
| 327 | return value << 35; |
Mark Mendell | ba56d06 | 2015-05-05 21:34:03 -0400 | [diff] [blame] | 328 | } |
| 329 | |
Calin Juravle | 9aec02f | 2014-11-18 23:06:35 +0000 | [diff] [blame] | 330 | } |