Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | |
| 17 | public class DivTest { |
| 18 | |
| 19 | public static <T extends Number> void expectEquals(T expected, T result) { |
| 20 | if (!expected.equals(result)) { |
| 21 | throw new Error("Expected: " + expected + ", found: " + result); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | public static void main() { |
| 26 | divInt(); |
| 27 | divLong(); |
| 28 | } |
| 29 | |
| 30 | private static void divInt() { |
| 31 | expectEquals(0, $noinline$IntDivBy2(0)); |
| 32 | expectEquals(0, $noinline$IntDivBy2(1)); |
| 33 | expectEquals(0, $noinline$IntDivBy2(-1)); |
| 34 | expectEquals(1, $noinline$IntDivBy2(2)); |
| 35 | expectEquals(-1, $noinline$IntDivBy2(-2)); |
| 36 | expectEquals(1, $noinline$IntDivBy2(3)); |
| 37 | expectEquals(-1, $noinline$IntDivBy2(-3)); |
| 38 | expectEquals(3, $noinline$IntDivBy2(7)); |
| 39 | expectEquals(-3, $noinline$IntDivBy2(-7)); |
| 40 | expectEquals(4, $noinline$IntDivBy2(8)); |
| 41 | expectEquals(-4, $noinline$IntDivBy2(-8)); |
| 42 | expectEquals(7, $noinline$IntDivBy2(0x0f)); |
| 43 | expectEquals(0x007f, $noinline$IntDivBy2(0x00ff)); |
| 44 | expectEquals(0x07ff, $noinline$IntDivBy2(0x0fff)); |
| 45 | expectEquals(0x007fff, $noinline$IntDivBy2(0x00ffff)); |
| 46 | expectEquals(0x3fffffff, $noinline$IntDivBy2(Integer.MAX_VALUE)); |
| 47 | expectEquals(0xc0000000, $noinline$IntDivBy2(Integer.MIN_VALUE)); |
| 48 | |
| 49 | expectEquals(0, $noinline$IntDivByMinus2(0)); |
| 50 | expectEquals(0, $noinline$IntDivByMinus2(1)); |
| 51 | expectEquals(0, $noinline$IntDivByMinus2(-1)); |
| 52 | expectEquals(-1, $noinline$IntDivByMinus2(2)); |
| 53 | expectEquals(1, $noinline$IntDivByMinus2(-2)); |
| 54 | expectEquals(-1, $noinline$IntDivByMinus2(3)); |
| 55 | expectEquals(1, $noinline$IntDivByMinus2(-3)); |
| 56 | expectEquals(-3, $noinline$IntDivByMinus2(7)); |
| 57 | expectEquals(3, $noinline$IntDivByMinus2(-7)); |
| 58 | expectEquals(-4, $noinline$IntDivByMinus2(8)); |
| 59 | expectEquals(4, $noinline$IntDivByMinus2(-8)); |
| 60 | expectEquals(-7, $noinline$IntDivByMinus2(0x0f)); |
| 61 | expectEquals(0xffffff81, $noinline$IntDivByMinus2(0x00ff)); |
| 62 | expectEquals(0xfffff801, $noinline$IntDivByMinus2(0x0fff)); |
| 63 | expectEquals(0xffff8001, $noinline$IntDivByMinus2(0x00ffff)); |
| 64 | expectEquals(0xc0000001, $noinline$IntDivByMinus2(Integer.MAX_VALUE)); |
| 65 | expectEquals(0x40000000, $noinline$IntDivByMinus2(Integer.MIN_VALUE)); |
| 66 | |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 67 | expectEquals(0, $noinline$IntAbsDivBy2(0)); |
| 68 | expectEquals(0, $noinline$IntAbsDivBy2(1)); |
| 69 | expectEquals(0, $noinline$IntAbsDivBy2(-1)); |
| 70 | expectEquals(1, $noinline$IntAbsDivBy2(2)); |
| 71 | expectEquals(1, $noinline$IntAbsDivBy2(-2)); |
| 72 | expectEquals(1, $noinline$IntAbsDivBy2(3)); |
| 73 | expectEquals(1, $noinline$IntAbsDivBy2(-3)); |
| 74 | expectEquals(3, $noinline$IntAbsDivBy2(7)); |
| 75 | expectEquals(3, $noinline$IntAbsDivBy2(-7)); |
| 76 | expectEquals(4, $noinline$IntAbsDivBy2(8)); |
| 77 | expectEquals(4, $noinline$IntAbsDivBy2(-8)); |
| 78 | expectEquals(7, $noinline$IntAbsDivBy2(0x0f)); |
| 79 | expectEquals(0x007f, $noinline$IntAbsDivBy2(0x00ff)); |
| 80 | expectEquals(0x07ff, $noinline$IntAbsDivBy2(0x0fff)); |
| 81 | expectEquals(0x007fff, $noinline$IntAbsDivBy2(0x00ffff)); |
| 82 | expectEquals(0x3fffffff, $noinline$IntAbsDivBy2(Integer.MAX_VALUE)); |
| 83 | expectEquals(0xc0000000, $noinline$IntAbsDivBy2(Integer.MIN_VALUE)); |
| 84 | |
| 85 | expectEquals(0, $noinline$IntAbsDivByMinus2(0)); |
| 86 | expectEquals(0, $noinline$IntAbsDivByMinus2(1)); |
| 87 | expectEquals(0, $noinline$IntAbsDivByMinus2(-1)); |
| 88 | expectEquals(-1, $noinline$IntAbsDivByMinus2(2)); |
| 89 | expectEquals(-1, $noinline$IntAbsDivByMinus2(-2)); |
| 90 | expectEquals(-1, $noinline$IntAbsDivByMinus2(3)); |
| 91 | expectEquals(-1, $noinline$IntAbsDivByMinus2(-3)); |
| 92 | expectEquals(-3, $noinline$IntAbsDivByMinus2(7)); |
| 93 | expectEquals(-3, $noinline$IntAbsDivByMinus2(-7)); |
| 94 | expectEquals(-4, $noinline$IntAbsDivByMinus2(8)); |
| 95 | expectEquals(-4, $noinline$IntAbsDivByMinus2(-8)); |
| 96 | expectEquals(-7, $noinline$IntAbsDivByMinus2(0x0f)); |
| 97 | expectEquals(0xffffff81, $noinline$IntAbsDivByMinus2(0x00ff)); |
| 98 | expectEquals(0xfffff801, $noinline$IntAbsDivByMinus2(0x0fff)); |
| 99 | expectEquals(0xffff8001, $noinline$IntAbsDivByMinus2(0x00ffff)); |
| 100 | expectEquals(0xc0000001, $noinline$IntAbsDivByMinus2(Integer.MAX_VALUE)); |
| 101 | expectEquals(0x40000000, $noinline$IntAbsDivByMinus2(Integer.MIN_VALUE)); |
| 102 | |
| 103 | expectEquals(0, $noinline$IntALenDivBy2(new int[0])); |
| 104 | expectEquals(0, $noinline$IntALenDivBy2(new int[1])); |
| 105 | expectEquals(1, $noinline$IntALenDivBy2(new int[2])); |
| 106 | expectEquals(1, $noinline$IntALenDivBy2(new int[3])); |
| 107 | expectEquals(3, $noinline$IntALenDivBy2(new int[7])); |
| 108 | expectEquals(4, $noinline$IntALenDivBy2(new int[8])); |
| 109 | expectEquals(7, $noinline$IntALenDivBy2(new int[0x0f])); |
| 110 | expectEquals(0x007f, $noinline$IntALenDivBy2(new int[0x00ff])); |
| 111 | expectEquals(0x07ff, $noinline$IntALenDivBy2(new int[0x0fff])); |
| 112 | expectEquals(0x007fff, $noinline$IntALenDivBy2(new int[0x00ffff])); |
| 113 | |
| 114 | expectEquals(0, $noinline$IntALenDivByMinus2(new int[0])); |
| 115 | expectEquals(0, $noinline$IntALenDivByMinus2(new int[1])); |
| 116 | expectEquals(-1, $noinline$IntALenDivByMinus2(new int[2])); |
| 117 | expectEquals(-1, $noinline$IntALenDivByMinus2(new int[3])); |
| 118 | expectEquals(-3, $noinline$IntALenDivByMinus2(new int[7])); |
| 119 | expectEquals(-4, $noinline$IntALenDivByMinus2(new int[8])); |
| 120 | expectEquals(-7, $noinline$IntALenDivByMinus2(new int[0x0f])); |
| 121 | expectEquals(0xffffff81, $noinline$IntALenDivByMinus2(new int[0x00ff])); |
| 122 | expectEquals(0xfffff801, $noinline$IntALenDivByMinus2(new int[0x0fff])); |
| 123 | expectEquals(0xffff8001, $noinline$IntALenDivByMinus2(new int[0x00ffff])); |
| 124 | |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 125 | expectEquals(0, $noinline$IntDivBy16(0)); |
| 126 | expectEquals(1, $noinline$IntDivBy16(16)); |
| 127 | expectEquals(-1, $noinline$IntDivBy16(-16)); |
| 128 | expectEquals(2, $noinline$IntDivBy16(33)); |
| 129 | expectEquals(0x000f, $noinline$IntDivBy16(0x00ff)); |
| 130 | expectEquals(0x00ff, $noinline$IntDivBy16(0x0fff)); |
| 131 | expectEquals(0x000fff, $noinline$IntDivBy16(0x00ffff)); |
| 132 | expectEquals(0x07ffffff, $noinline$IntDivBy16(Integer.MAX_VALUE)); |
| 133 | expectEquals(0xf8000000, $noinline$IntDivBy16(Integer.MIN_VALUE)); |
| 134 | |
| 135 | expectEquals(0, $noinline$IntDivByMinus16(0)); |
| 136 | expectEquals(-1, $noinline$IntDivByMinus16(16)); |
| 137 | expectEquals(1, $noinline$IntDivByMinus16(-16)); |
| 138 | expectEquals(-2, $noinline$IntDivByMinus16(33)); |
| 139 | expectEquals(0xfffffff1, $noinline$IntDivByMinus16(0x00ff)); |
| 140 | expectEquals(0xffffff01, $noinline$IntDivByMinus16(0x0fff)); |
| 141 | expectEquals(0xfffff001, $noinline$IntDivByMinus16(0x00ffff)); |
| 142 | expectEquals(0xf8000001, $noinline$IntDivByMinus16(Integer.MAX_VALUE)); |
| 143 | expectEquals(0x08000000, $noinline$IntDivByMinus16(Integer.MIN_VALUE)); |
| 144 | |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 145 | expectEquals(0, $noinline$IntAbsDivBy16(0)); |
| 146 | expectEquals(1, $noinline$IntAbsDivBy16(16)); |
| 147 | expectEquals(1, $noinline$IntAbsDivBy16(-16)); |
| 148 | expectEquals(2, $noinline$IntAbsDivBy16(33)); |
| 149 | expectEquals(0x000f, $noinline$IntAbsDivBy16(0x00ff)); |
| 150 | expectEquals(0x00ff, $noinline$IntAbsDivBy16(0x0fff)); |
| 151 | expectEquals(0x000fff, $noinline$IntAbsDivBy16(0x00ffff)); |
| 152 | expectEquals(0x07ffffff, $noinline$IntAbsDivBy16(Integer.MAX_VALUE)); |
| 153 | expectEquals(0xf8000000, $noinline$IntAbsDivBy16(Integer.MIN_VALUE)); |
| 154 | |
| 155 | expectEquals(0, $noinline$IntAbsDivByMinus16(0)); |
| 156 | expectEquals(-1, $noinline$IntAbsDivByMinus16(16)); |
| 157 | expectEquals(-1, $noinline$IntAbsDivByMinus16(-16)); |
| 158 | expectEquals(-2, $noinline$IntAbsDivByMinus16(33)); |
| 159 | expectEquals(0xfffffff1, $noinline$IntAbsDivByMinus16(0x00ff)); |
| 160 | expectEquals(0xffffff01, $noinline$IntAbsDivByMinus16(0x0fff)); |
| 161 | expectEquals(0xfffff001, $noinline$IntAbsDivByMinus16(0x00ffff)); |
| 162 | expectEquals(0xf8000001, $noinline$IntAbsDivByMinus16(Integer.MAX_VALUE)); |
| 163 | expectEquals(0x08000000, $noinline$IntAbsDivByMinus16(Integer.MIN_VALUE)); |
| 164 | |
| 165 | expectEquals(0, $noinline$IntALenDivBy16(new int[0])); |
| 166 | expectEquals(1, $noinline$IntALenDivBy16(new int[16])); |
| 167 | expectEquals(2, $noinline$IntALenDivBy16(new int[33])); |
| 168 | expectEquals(0x000f, $noinline$IntALenDivBy16(new int[0x00ff])); |
| 169 | expectEquals(0x00ff, $noinline$IntALenDivBy16(new int[0x0fff])); |
| 170 | expectEquals(0x000fff, $noinline$IntALenDivBy16(new int[0x00ffff])); |
| 171 | |
| 172 | expectEquals(0, $noinline$IntALenDivByMinus16(new int[0])); |
| 173 | expectEquals(-1, $noinline$IntALenDivByMinus16(new int[16])); |
| 174 | expectEquals(-2, $noinline$IntALenDivByMinus16(new int[33])); |
| 175 | expectEquals(0xfffffff1, $noinline$IntALenDivByMinus16(new int[0x00ff])); |
| 176 | expectEquals(0xffffff01, $noinline$IntALenDivByMinus16(new int[0x0fff])); |
| 177 | expectEquals(0xfffff001, $noinline$IntALenDivByMinus16(new int[0x00ffff])); |
| 178 | |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 179 | expectEquals(0, $noinline$IntDivByIntMin(0)); |
| 180 | expectEquals(0, $noinline$IntDivByIntMin(1)); |
| 181 | expectEquals(0, $noinline$IntDivByIntMin(-1)); |
| 182 | expectEquals(1, $noinline$IntDivByIntMin(Integer.MIN_VALUE)); |
| 183 | expectEquals(0, $noinline$IntDivByIntMin(Integer.MAX_VALUE)); |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 184 | |
| 185 | expectEquals(0, $noinline$IntAbsDivByIntMin(0)); |
| 186 | expectEquals(0, $noinline$IntAbsDivByIntMin(1)); |
| 187 | expectEquals(0, $noinline$IntAbsDivByIntMin(-1)); |
| 188 | expectEquals(1, $noinline$IntAbsDivByIntMin(Integer.MIN_VALUE)); |
| 189 | expectEquals(0, $noinline$IntAbsDivByIntMin(Integer.MAX_VALUE)); |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 190 | } |
| 191 | |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 192 | /// CHECK-START-ARM: java.lang.Integer DivTest.$noinline$IntDivBy2(int) disassembly (after) |
| 193 | /// CHECK: add r{{\d+}}, r{{\d+}}, r{{\d+}}, lsr #31 |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 194 | /// CHECK-NEXT: asr{{s?}} r{{\d+}}, #1 |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 195 | // |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 196 | /// CHECK-START-ARM64: java.lang.Integer DivTest.$noinline$IntDivBy2(int) disassembly (after) |
| 197 | /// CHECK: add w{{\d+}}, w{{\d+}}, w{{\d+}}, lsr #31 |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 198 | /// CHECK-NEXT: asr w{{\d+}}, w{{\d+}}, #1 |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 199 | // |
Atul Bajaj | 1cc7329 | 2018-11-15 11:36:53 +0530 | [diff] [blame] | 200 | /// CHECK-START-X86_64: java.lang.Integer DivTest.$noinline$IntDivBy2(int) disassembly (after) |
| 201 | /// CHECK-NOT: cmovnl/geq |
| 202 | /// CHECK: add |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 203 | private static Integer $noinline$IntDivBy2(int v) { |
| 204 | int r = v / 2; |
| 205 | return r; |
| 206 | } |
| 207 | |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 208 | /// CHECK-START-ARM: java.lang.Integer DivTest.$noinline$IntDivByMinus2(int) disassembly (after) |
| 209 | /// CHECK: add r{{\d+}}, r{{\d+}}, r{{\d+}}, lsr #31 |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 210 | /// CHECK-NEXT: asr{{s?}} r{{\d+}}, #1 |
| 211 | /// CHECK-NEXT: rsb{{s?}} r{{\d+}}, #0 |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 212 | // |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 213 | /// CHECK-START-ARM64: java.lang.Integer DivTest.$noinline$IntDivByMinus2(int) disassembly (after) |
| 214 | /// CHECK: add w{{\d+}}, w{{\d+}}, w{{\d+}}, lsr #31 |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 215 | /// CHECK-NEXT: neg w{{\d+}}, w{{\d+}}, asr #1 |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 216 | // |
Atul Bajaj | 1cc7329 | 2018-11-15 11:36:53 +0530 | [diff] [blame] | 217 | /// CHECK-START-X86_64: java.lang.Integer DivTest.$noinline$IntDivByMinus2(int) disassembly (after) |
| 218 | /// CHECK-NOT: cmovnl/geq |
| 219 | /// CHECK: add |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 220 | private static Integer $noinline$IntDivByMinus2(int v) { |
| 221 | int r = v / -2; |
| 222 | return r; |
| 223 | } |
| 224 | |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 225 | /// CHECK-START-ARM: java.lang.Integer DivTest.$noinline$IntAbsDivBy2(int) disassembly (after) |
| 226 | /// CHECK: Div |
| 227 | /// CHECK-NEXT: asr{{s?}} r{{\d+}}, #1 |
| 228 | // |
| 229 | /// CHECK-START-ARM64: java.lang.Integer DivTest.$noinline$IntAbsDivBy2(int) disassembly (after) |
| 230 | /// CHECK: Div |
| 231 | /// CHECK-NEXT: asr w{{\d+}}, w{{\d+}}, #1 |
| 232 | private static Integer $noinline$IntAbsDivBy2(int v) { |
| 233 | int r = Math.abs(v) / 2; |
| 234 | return r; |
| 235 | } |
| 236 | |
| 237 | /// CHECK-START-ARM: java.lang.Integer DivTest.$noinline$IntAbsDivByMinus2(int) disassembly (after) |
| 238 | /// CHECK: Div |
| 239 | /// CHECK-NEXT: asr{{s?}} r{{\d+}}, #1 |
| 240 | /// CHECK-NEXT: rsb{{s?}} r{{\d+}}, #0 |
| 241 | // |
| 242 | /// CHECK-START-ARM64: java.lang.Integer DivTest.$noinline$IntAbsDivByMinus2(int) disassembly (after) |
| 243 | /// CHECK: Div |
| 244 | /// CHECK-NEXT: neg w{{\d+}}, w{{\d+}}, asr #1 |
| 245 | private static Integer $noinline$IntAbsDivByMinus2(int v) { |
| 246 | int r = Math.abs(v) / -2; |
| 247 | return r; |
| 248 | } |
| 249 | |
| 250 | /// CHECK-START-ARM: java.lang.Integer DivTest.$noinline$IntALenDivBy2(int[]) disassembly (after) |
| 251 | /// CHECK: Div |
| 252 | /// CHECK-NEXT: asr{{s?}} r{{\d+}}, #1 |
| 253 | // |
| 254 | /// CHECK-START-ARM64: java.lang.Integer DivTest.$noinline$IntALenDivBy2(int[]) disassembly (after) |
| 255 | /// CHECK: Div |
| 256 | /// CHECK-NEXT: asr w{{\d+}}, w{{\d+}}, #1 |
| 257 | private static Integer $noinline$IntALenDivBy2(int[] arr) { |
| 258 | int r = arr.length / 2; |
| 259 | return r; |
| 260 | } |
| 261 | |
| 262 | /// CHECK-START-ARM: java.lang.Integer DivTest.$noinline$IntALenDivByMinus2(int[]) disassembly (after) |
| 263 | /// CHECK: Div |
| 264 | /// CHECK-NEXT: asr{{s?}} r{{\d+}}, #1 |
| 265 | /// CHECK-NEXT: rsb{{s?}} r{{\d+}}, #0 |
| 266 | // |
| 267 | /// CHECK-START-ARM64: java.lang.Integer DivTest.$noinline$IntALenDivByMinus2(int[]) disassembly (after) |
| 268 | /// CHECK: Div |
| 269 | /// CHECK-NEXT: neg w{{\d+}}, w{{\d+}}, asr #1 |
| 270 | private static Integer $noinline$IntALenDivByMinus2(int[] arr) { |
| 271 | int r = arr.length / -2; |
| 272 | return r; |
| 273 | } |
| 274 | |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 275 | /// CHECK-START-ARM: java.lang.Integer DivTest.$noinline$IntDivBy16(int) disassembly (after) |
| 276 | /// CHECK: asr{{s?}} r{{\d+}}, r{{\d+}}, #31 |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 277 | /// CHECK-NEXT: add r{{\d+}}, r{{\d+}}, r{{\d+}}, lsr #28 |
| 278 | /// CHECK-NEXT: asr{{s?}} r{{\d+}}, #4 |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 279 | // |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 280 | /// CHECK-START-ARM64: java.lang.Integer DivTest.$noinline$IntDivBy16(int) disassembly (after) |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 281 | /// CHECK: add w{{\d+}}, w{{\d+}}, #0xf |
| 282 | /// CHECK-NEXT: cmp w{{\d+}}, #0x0 |
| 283 | /// CHECK-NEXT: csel w{{\d+}}, w{{\d+}}, w{{\d+}}, lt |
| 284 | /// CHECK-NEXT: asr w{{\d+}}, w{{\d+}}, #4 |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 285 | private static Integer $noinline$IntDivBy16(int v) { |
| 286 | int r = v / 16; |
| 287 | return r; |
| 288 | } |
| 289 | |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 290 | /// CHECK-START-ARM: java.lang.Integer DivTest.$noinline$IntDivByMinus16(int) disassembly (after) |
| 291 | /// CHECK: asr{{s?}} r{{\d+}}, r{{\d+}}, #31 |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 292 | /// CHECK-NEXT: add r{{\d+}}, r{{\d+}}, r{{\d+}}, lsr #28 |
| 293 | /// CHECK-NEXT: asr{{s?}} r{{\d+}}, #4 |
| 294 | /// CHECK-NEXT: rsb{{s?}} r{{\d+}}, #0 |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 295 | // |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 296 | /// CHECK-START-ARM64: java.lang.Integer DivTest.$noinline$IntDivByMinus16(int) disassembly (after) |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 297 | /// CHECK: add w{{\d+}}, w{{\d+}}, #0xf |
| 298 | /// CHECK-NEXT: cmp w{{\d+}}, #0x0 |
| 299 | /// CHECK-NEXT: csel w{{\d+}}, w{{\d+}}, w{{\d+}}, lt |
| 300 | /// CHECK-NEXT: neg w{{\d+}}, w{{\d+}}, asr #4 |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 301 | private static Integer $noinline$IntDivByMinus16(int v) { |
| 302 | int r = v / -16; |
| 303 | return r; |
| 304 | } |
| 305 | |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 306 | /// CHECK-START-ARM: java.lang.Integer DivTest.$noinline$IntAbsDivBy16(int) disassembly (after) |
| 307 | /// CHECK: Div |
| 308 | /// CHECK-NEXT: asr{{s?}} r{{\d+}}, #4 |
| 309 | // |
| 310 | /// CHECK-START-ARM64: java.lang.Integer DivTest.$noinline$IntAbsDivBy16(int) disassembly (after) |
| 311 | /// CHECK: Div |
| 312 | /// CHECK-NEXT: asr w{{\d+}}, w{{\d+}}, #4 |
| 313 | private static Integer $noinline$IntAbsDivBy16(int v) { |
| 314 | int r = Math.abs(v) / 16; |
| 315 | return r; |
| 316 | } |
| 317 | |
| 318 | /// CHECK-START-ARM: java.lang.Integer DivTest.$noinline$IntAbsDivByMinus16(int) disassembly (after) |
| 319 | /// CHECK: Div |
| 320 | /// CHECK-NEXT: asr{{s?}} r{{\d+}}, #4 |
| 321 | /// CHECK-NEXT: rsb{{s?}} r{{\d+}}, #0 |
| 322 | // |
| 323 | /// CHECK-START-ARM64: java.lang.Integer DivTest.$noinline$IntAbsDivByMinus16(int) disassembly (after) |
| 324 | /// CHECK: Div |
| 325 | /// CHECK-NEXT: neg w{{\d+}}, w{{\d+}}, asr #4 |
| 326 | private static Integer $noinline$IntAbsDivByMinus16(int v) { |
| 327 | int r = Math.abs(v) / -16; |
| 328 | return r; |
| 329 | } |
| 330 | |
| 331 | /// CHECK-START-ARM: java.lang.Integer DivTest.$noinline$IntALenDivBy16(int[]) disassembly (after) |
| 332 | /// CHECK: Div |
| 333 | /// CHECK-NEXT: asr{{s?}} r{{\d+}}, #4 |
| 334 | // |
| 335 | /// CHECK-START-ARM64: java.lang.Integer DivTest.$noinline$IntALenDivBy16(int[]) disassembly (after) |
| 336 | /// CHECK: Div |
| 337 | /// CHECK-NEXT: asr w{{\d+}}, w{{\d+}}, #4 |
| 338 | private static Integer $noinline$IntALenDivBy16(int[] arr) { |
| 339 | int r = arr.length / 16; |
| 340 | return r; |
| 341 | } |
| 342 | |
| 343 | /// CHECK-START-ARM: java.lang.Integer DivTest.$noinline$IntALenDivByMinus16(int[]) disassembly (after) |
| 344 | /// CHECK: Div |
| 345 | /// CHECK-NEXT: asr{{s?}} r{{\d+}}, #4 |
| 346 | /// CHECK-NEXT: rsb{{s?}} r{{\d+}}, #0 |
| 347 | // |
| 348 | /// CHECK-START-ARM64: java.lang.Integer DivTest.$noinline$IntALenDivByMinus16(int[]) disassembly (after) |
| 349 | /// CHECK: Div |
| 350 | /// CHECK-NEXT: neg w{{\d+}}, w{{\d+}}, asr #4 |
| 351 | private static Integer $noinline$IntALenDivByMinus16(int[] arr) { |
| 352 | int r = arr.length / -16; |
| 353 | return r; |
| 354 | } |
| 355 | |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 356 | /// CHECK-START-ARM: java.lang.Integer DivTest.$noinline$IntDivByIntMin(int) disassembly (after) |
| 357 | /// CHECK: asr{{s?}} r{{\d+}}, r{{\d+}}, #31 |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 358 | /// CHECK-NEXT: add r{{\d+}}, r{{\d+}}, r{{\d+}}, lsr #1 |
| 359 | /// CHECK-NEXT: asr{{s?}} r{{\d+}}, #31 |
| 360 | /// CHECK-NEXT: rsb{{s?}} r{{\d+}}, #0 |
Evgeny Astigeevich | 2d10117 | 2020-06-25 16:52:03 +0100 | [diff] [blame] | 361 | // |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 362 | /// CHECK-START-ARM64: java.lang.Integer DivTest.$noinline$IntDivByIntMin(int) disassembly (after) |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 363 | /// CHECK: mov w{{\d+}}, #0x7fffffff |
| 364 | /// CHECK-NEXT: add w{{\d+}}, w{{\d+}}, w{{\d+}} |
| 365 | /// CHECK-NEXT: cmp w{{\d+}}, #0x0 |
| 366 | /// CHECK-NEXT: csel w{{\d+}}, w{{\d+}}, w{{\d+}}, lt |
| 367 | /// CHECK-NEXT: neg w{{\d+}}, w{{\d+}}, asr #31 |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 368 | private static Integer $noinline$IntDivByIntMin(int v) { |
| 369 | int r = v / Integer.MIN_VALUE; |
| 370 | return r; |
| 371 | } |
| 372 | |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 373 | /// CHECK-START-ARM: java.lang.Integer DivTest.$noinline$IntAbsDivByIntMin(int) disassembly (after) |
| 374 | /// CHECK: Div |
| 375 | /// CHECK-NEXT: asr{{s?}} r{{\d+}}, #31 |
| 376 | /// CHECK-NEXT: rsb{{s?}} r{{\d+}}, #0 |
| 377 | // |
| 378 | /// CHECK-START-ARM64: java.lang.Integer DivTest.$noinline$IntAbsDivByIntMin(int) disassembly (after) |
| 379 | /// CHECK: Div |
| 380 | /// CHECK-NEXT: neg w{{\d+}}, w{{\d+}}, asr #31 |
| 381 | private static Integer $noinline$IntAbsDivByIntMin(int v) { |
| 382 | int r = Math.abs(v) / Integer.MIN_VALUE; |
| 383 | return r; |
| 384 | } |
| 385 | |
Evgeny Astigeevich | c679fe3 | 2020-09-14 14:02:40 +0100 | [diff] [blame] | 386 | /// CHECK-START-ARM: java.lang.Integer DivTest.unsignedDiv01(int) disassembly (after) |
| 387 | /// CHECK: Div |
| 388 | /// CHECK-NEXT: asr{{s?}} r{{\d+}}, #1 |
| 389 | // |
| 390 | /// CHECK-START-ARM64: java.lang.Integer DivTest.unsignedDiv01(int) disassembly (after) |
| 391 | /// CHECK: Div |
| 392 | /// CHECK-NEXT: asr w{{\d+}}, w{{\d+}}, #1 |
| 393 | private static Integer unsignedDiv01(int v) { |
| 394 | int l = 0; |
| 395 | for (int m = v - 1; m >= 0; m = m / 2 - 1) { |
| 396 | ++l; |
| 397 | } |
| 398 | return l; |
| 399 | } |
| 400 | |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 401 | private static void divLong() { |
| 402 | expectEquals(0L, $noinline$LongDivBy2(0L)); |
| 403 | expectEquals(0L, $noinline$LongDivBy2(1L)); |
| 404 | expectEquals(0L, $noinline$LongDivBy2(-1L)); |
| 405 | expectEquals(1L, $noinline$LongDivBy2(2L)); |
| 406 | expectEquals(-1L, $noinline$LongDivBy2(-2L)); |
| 407 | expectEquals(1L, $noinline$LongDivBy2(3L)); |
| 408 | expectEquals(-1L, $noinline$LongDivBy2(-3L)); |
| 409 | expectEquals(3L, $noinline$LongDivBy2(7L)); |
| 410 | expectEquals(-3L, $noinline$LongDivBy2(-7L)); |
| 411 | expectEquals(4L, $noinline$LongDivBy2(8L)); |
| 412 | expectEquals(-4L, $noinline$LongDivBy2(-8L)); |
| 413 | expectEquals(7L, $noinline$LongDivBy2(0x0fL)); |
| 414 | expectEquals(0x007fL, $noinline$LongDivBy2(0x00ffL)); |
| 415 | expectEquals(0x07ffL, $noinline$LongDivBy2(0x0fffL)); |
| 416 | expectEquals(0x007fffL, $noinline$LongDivBy2(0x00ffffL)); |
| 417 | expectEquals(0x3fffffffffffffffL, $noinline$LongDivBy2(Long.MAX_VALUE)); |
| 418 | expectEquals(0xc000000000000000L, $noinline$LongDivBy2(Long.MIN_VALUE)); |
| 419 | |
| 420 | expectEquals(0L, $noinline$LongDivByMinus2(0)); |
| 421 | expectEquals(0L, $noinline$LongDivByMinus2(1L)); |
| 422 | expectEquals(0L, $noinline$LongDivByMinus2(-1L)); |
| 423 | expectEquals(-1L, $noinline$LongDivByMinus2(2L)); |
| 424 | expectEquals(1L, $noinline$LongDivByMinus2(-2L)); |
| 425 | expectEquals(-1L, $noinline$LongDivByMinus2(3L)); |
| 426 | expectEquals(1L, $noinline$LongDivByMinus2(-3L)); |
| 427 | expectEquals(-3L, $noinline$LongDivByMinus2(7L)); |
| 428 | expectEquals(3L, $noinline$LongDivByMinus2(-7L)); |
| 429 | expectEquals(-4L, $noinline$LongDivByMinus2(8L)); |
| 430 | expectEquals(4L, $noinline$LongDivByMinus2(-8L)); |
| 431 | expectEquals(-7L, $noinline$LongDivByMinus2(0x0fL)); |
| 432 | expectEquals(0xffffffffffffff81L, $noinline$LongDivByMinus2(0x00ffL)); |
| 433 | expectEquals(0xfffffffffffff801L, $noinline$LongDivByMinus2(0x0fffL)); |
| 434 | expectEquals(0xffffffffffff8001L, $noinline$LongDivByMinus2(0x00ffffL)); |
| 435 | expectEquals(0xc000000000000001L, $noinline$LongDivByMinus2(Long.MAX_VALUE)); |
| 436 | expectEquals(0x4000000000000000L, $noinline$LongDivByMinus2(Long.MIN_VALUE)); |
| 437 | |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 438 | expectEquals(0L, $noinline$LongAbsDivBy2(0L)); |
| 439 | expectEquals(0L, $noinline$LongAbsDivBy2(1L)); |
| 440 | expectEquals(0L, $noinline$LongAbsDivBy2(-1L)); |
| 441 | expectEquals(1L, $noinline$LongAbsDivBy2(2L)); |
| 442 | expectEquals(1L, $noinline$LongAbsDivBy2(-2L)); |
| 443 | expectEquals(1L, $noinline$LongAbsDivBy2(3L)); |
| 444 | expectEquals(1L, $noinline$LongAbsDivBy2(-3L)); |
| 445 | expectEquals(3L, $noinline$LongAbsDivBy2(7L)); |
| 446 | expectEquals(3L, $noinline$LongAbsDivBy2(-7L)); |
| 447 | expectEquals(4L, $noinline$LongAbsDivBy2(8L)); |
| 448 | expectEquals(4L, $noinline$LongAbsDivBy2(-8L)); |
| 449 | expectEquals(7L, $noinline$LongAbsDivBy2(0x0fL)); |
| 450 | expectEquals(0x007fL, $noinline$LongAbsDivBy2(0x00ffL)); |
| 451 | expectEquals(0x07ffL, $noinline$LongAbsDivBy2(0x0fffL)); |
| 452 | expectEquals(0x007fffL, $noinline$LongAbsDivBy2(0x00ffffL)); |
| 453 | expectEquals(0x3fffffffffffffffL, $noinline$LongAbsDivBy2(Long.MAX_VALUE)); |
| 454 | expectEquals(0xc000000000000000L, $noinline$LongAbsDivBy2(Long.MIN_VALUE)); |
| 455 | |
| 456 | expectEquals(0L, $noinline$LongAbsDivByMinus2(0)); |
| 457 | expectEquals(0L, $noinline$LongAbsDivByMinus2(1L)); |
| 458 | expectEquals(0L, $noinline$LongAbsDivByMinus2(-1L)); |
| 459 | expectEquals(-1L, $noinline$LongAbsDivByMinus2(2L)); |
| 460 | expectEquals(-1L, $noinline$LongAbsDivByMinus2(-2L)); |
| 461 | expectEquals(-1L, $noinline$LongAbsDivByMinus2(3L)); |
| 462 | expectEquals(-1L, $noinline$LongAbsDivByMinus2(-3L)); |
| 463 | expectEquals(-3L, $noinline$LongAbsDivByMinus2(7L)); |
| 464 | expectEquals(-3L, $noinline$LongAbsDivByMinus2(-7L)); |
| 465 | expectEquals(-4L, $noinline$LongAbsDivByMinus2(8L)); |
| 466 | expectEquals(-4L, $noinline$LongAbsDivByMinus2(-8L)); |
| 467 | expectEquals(-7L, $noinline$LongAbsDivByMinus2(0x0fL)); |
| 468 | expectEquals(0xffffffffffffff81L, $noinline$LongAbsDivByMinus2(0x00ffL)); |
| 469 | expectEquals(0xfffffffffffff801L, $noinline$LongAbsDivByMinus2(0x0fffL)); |
| 470 | expectEquals(0xffffffffffff8001L, $noinline$LongAbsDivByMinus2(0x00ffffL)); |
| 471 | expectEquals(0xc000000000000001L, $noinline$LongAbsDivByMinus2(Long.MAX_VALUE)); |
| 472 | expectEquals(0x4000000000000000L, $noinline$LongAbsDivByMinus2(Long.MIN_VALUE)); |
| 473 | |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 474 | expectEquals(0L, $noinline$LongDivBy16(0)); |
| 475 | expectEquals(1L, $noinline$LongDivBy16(16L)); |
| 476 | expectEquals(-1L, $noinline$LongDivBy16(-16L)); |
| 477 | expectEquals(2L, $noinline$LongDivBy16(33L)); |
| 478 | expectEquals(0x000fL, $noinline$LongDivBy16(0x00ffL)); |
| 479 | expectEquals(0x00ffL, $noinline$LongDivBy16(0x0fffL)); |
| 480 | expectEquals(0x000fffL, $noinline$LongDivBy16(0x00ffffL)); |
| 481 | expectEquals(0x07ffffffffffffffL, $noinline$LongDivBy16(Long.MAX_VALUE)); |
| 482 | expectEquals(0xf800000000000000L, $noinline$LongDivBy16(Long.MIN_VALUE)); |
| 483 | |
| 484 | expectEquals(0L, $noinline$LongDivByMinus16(0)); |
| 485 | expectEquals(-1L, $noinline$LongDivByMinus16(16L)); |
| 486 | expectEquals(1L, $noinline$LongDivByMinus16(-16L)); |
| 487 | expectEquals(-2L, $noinline$LongDivByMinus16(33L)); |
| 488 | expectEquals(0xfffffffffffffff1L, $noinline$LongDivByMinus16(0x00ffL)); |
| 489 | expectEquals(0xffffffffffffff01L, $noinline$LongDivByMinus16(0x0fffL)); |
| 490 | expectEquals(0xfffffffffffff001L, $noinline$LongDivByMinus16(0x00ffffL)); |
| 491 | expectEquals(0xf800000000000001L, $noinline$LongDivByMinus16(Long.MAX_VALUE)); |
| 492 | expectEquals(0x0800000000000000L, $noinline$LongDivByMinus16(Long.MIN_VALUE)); |
| 493 | |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 494 | expectEquals(0L, $noinline$LongAbsDivBy16(0)); |
| 495 | expectEquals(1L, $noinline$LongAbsDivBy16(16L)); |
| 496 | expectEquals(1L, $noinline$LongAbsDivBy16(-16L)); |
| 497 | expectEquals(2L, $noinline$LongAbsDivBy16(33L)); |
| 498 | expectEquals(0x000fL, $noinline$LongAbsDivBy16(0x00ffL)); |
| 499 | expectEquals(0x00ffL, $noinline$LongAbsDivBy16(0x0fffL)); |
| 500 | expectEquals(0x000fffL, $noinline$LongAbsDivBy16(0x00ffffL)); |
| 501 | expectEquals(0x07ffffffffffffffL, $noinline$LongAbsDivBy16(Long.MAX_VALUE)); |
| 502 | expectEquals(0xf800000000000000L, $noinline$LongAbsDivBy16(Long.MIN_VALUE)); |
| 503 | |
| 504 | expectEquals(0L, $noinline$LongAbsDivByMinus16(0)); |
| 505 | expectEquals(-1L, $noinline$LongAbsDivByMinus16(16L)); |
| 506 | expectEquals(-1L, $noinline$LongAbsDivByMinus16(-16L)); |
| 507 | expectEquals(-2L, $noinline$LongAbsDivByMinus16(33L)); |
| 508 | expectEquals(0xfffffffffffffff1L, $noinline$LongAbsDivByMinus16(0x00ffL)); |
| 509 | expectEquals(0xffffffffffffff01L, $noinline$LongAbsDivByMinus16(0x0fffL)); |
| 510 | expectEquals(0xfffffffffffff001L, $noinline$LongAbsDivByMinus16(0x00ffffL)); |
| 511 | expectEquals(0xf800000000000001L, $noinline$LongAbsDivByMinus16(Long.MAX_VALUE)); |
| 512 | expectEquals(0x0800000000000000L, $noinline$LongAbsDivByMinus16(Long.MIN_VALUE)); |
| 513 | |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 514 | expectEquals(0L, $noinline$LongDivByLongMin(0)); |
| 515 | expectEquals(0L, $noinline$LongDivByLongMin(1)); |
| 516 | expectEquals(0L, $noinline$LongDivByLongMin(-1)); |
| 517 | expectEquals(1L, $noinline$LongDivByLongMin(Long.MIN_VALUE)); |
| 518 | expectEquals(0L, $noinline$LongDivByLongMin(Long.MAX_VALUE)); |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 519 | |
| 520 | expectEquals(0L, $noinline$LongAbsDivByLongMin(0)); |
| 521 | expectEquals(0L, $noinline$LongAbsDivByLongMin(1)); |
| 522 | expectEquals(0L, $noinline$LongAbsDivByLongMin(-1)); |
| 523 | expectEquals(1L, $noinline$LongAbsDivByLongMin(Long.MIN_VALUE)); |
| 524 | expectEquals(0L, $noinline$LongAbsDivByLongMin(Long.MAX_VALUE)); |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 525 | } |
| 526 | |
| 527 | /// CHECK-START-ARM64: java.lang.Long DivTest.$noinline$LongDivBy2(long) disassembly (after) |
| 528 | /// CHECK: add x{{\d+}}, x{{\d+}}, x{{\d+}}, lsr #63 |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 529 | /// CHECK-NEXT: asr x{{\d+}}, x{{\d+}}, #1 |
| 530 | // |
Atul Bajaj | 1cc7329 | 2018-11-15 11:36:53 +0530 | [diff] [blame] | 531 | /// CHECK-START-X86_64: java.lang.Long DivTest.$noinline$LongDivBy2(long) disassembly (after) |
| 532 | /// CHECK-NOT: cmovnl/geq |
| 533 | /// CHECK: addq |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 534 | private static Long $noinline$LongDivBy2(long v) { |
| 535 | long r = v / 2; |
| 536 | return r; |
| 537 | } |
| 538 | |
| 539 | /// CHECK-START-ARM64: java.lang.Long DivTest.$noinline$LongDivByMinus2(long) disassembly (after) |
| 540 | /// CHECK: add x{{\d+}}, x{{\d+}}, x{{\d+}}, lsr #63 |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 541 | /// CHECK-NEXT: neg x{{\d+}}, x{{\d+}}, asr #1 |
| 542 | // |
Atul Bajaj | 1cc7329 | 2018-11-15 11:36:53 +0530 | [diff] [blame] | 543 | /// CHECK-START-X86_64: java.lang.Long DivTest.$noinline$LongDivByMinus2(long) disassembly (after) |
| 544 | /// CHECK-NOT: cmovnl/geq |
| 545 | /// CHECK: addq |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 546 | private static Long $noinline$LongDivByMinus2(long v) { |
| 547 | long r = v / -2; |
| 548 | return r; |
| 549 | } |
| 550 | |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 551 | /// CHECK-START-ARM64: java.lang.Long DivTest.$noinline$LongAbsDivBy2(long) disassembly (after) |
| 552 | /// CHECK: Div |
| 553 | /// CHECK-NEXT: asr x{{\d+}}, x{{\d+}}, #1 |
| 554 | private static Long $noinline$LongAbsDivBy2(long v) { |
| 555 | long r = Math.abs(v) / 2; |
| 556 | return r; |
| 557 | } |
| 558 | |
| 559 | /// CHECK-START-ARM64: java.lang.Long DivTest.$noinline$LongAbsDivByMinus2(long) disassembly (after) |
| 560 | /// CHECK: Div |
| 561 | /// CHECK-NEXT: neg x{{\d+}}, x{{\d+}}, asr #1 |
| 562 | private static Long $noinline$LongAbsDivByMinus2(long v) { |
| 563 | long r = Math.abs(v) / -2; |
| 564 | return r; |
| 565 | } |
| 566 | |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 567 | /// CHECK-START-ARM64: java.lang.Long DivTest.$noinline$LongDivBy16(long) disassembly (after) |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 568 | /// CHECK: add x{{\d+}}, x{{\d+}}, #0xf |
| 569 | /// CHECK-NEXT: cmp x{{\d+}}, #0x0 |
| 570 | /// CHECK-NEXT: csel x{{\d+}}, x{{\d+}}, x{{\d+}}, lt |
| 571 | /// CHECK-NEXT: asr x{{\d+}}, x{{\d+}}, #4 |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 572 | private static Long $noinline$LongDivBy16(long v) { |
| 573 | long r = v / 16; |
| 574 | return r; |
| 575 | } |
| 576 | |
| 577 | /// CHECK-START-ARM64: java.lang.Long DivTest.$noinline$LongDivByMinus16(long) disassembly (after) |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 578 | /// CHECK: add x{{\d+}}, x{{\d+}}, #0xf |
| 579 | /// CHECK-NEXT: cmp x{{\d+}}, #0x0 |
| 580 | /// CHECK-NEXT: csel x{{\d+}}, x{{\d+}}, x{{\d+}}, lt |
| 581 | /// CHECK-NEXT: neg x{{\d+}}, x{{\d+}}, asr #4 |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 582 | private static Long $noinline$LongDivByMinus16(long v) { |
| 583 | long r = v / -16; |
| 584 | return r; |
| 585 | } |
| 586 | |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 587 | /// CHECK-START-ARM64: java.lang.Long DivTest.$noinline$LongAbsDivBy16(long) disassembly (after) |
| 588 | /// CHECK: Div |
| 589 | /// CHECK-NEXT: asr x{{\d+}}, x{{\d+}}, #4 |
| 590 | private static Long $noinline$LongAbsDivBy16(long v) { |
| 591 | long r = Math.abs(v) / 16; |
| 592 | return r; |
| 593 | } |
| 594 | |
| 595 | /// CHECK-START-ARM64: java.lang.Long DivTest.$noinline$LongAbsDivByMinus16(long) disassembly (after) |
| 596 | /// CHECK: Div |
| 597 | /// CHECK-NEXT: neg x{{\d+}}, x{{\d+}}, asr #4 |
| 598 | private static Long $noinline$LongAbsDivByMinus16(long v) { |
| 599 | long r = Math.abs(v) / -16; |
| 600 | return r; |
| 601 | } |
| 602 | |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 603 | /// CHECK-START-ARM64: java.lang.Long DivTest.$noinline$LongDivByLongMin(long) disassembly (after) |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 604 | /// CHECK: mov x{{\d+}}, #0x7fffffffffffffff |
| 605 | /// CHECK-NEXT: add x{{\d+}}, x{{\d+}}, x{{\d+}} |
| 606 | /// CHECK-NEXT: cmp x{{\d+}}, #0x0 |
| 607 | /// CHECK-NEXT: csel x{{\d+}}, x{{\d+}}, x{{\d+}}, lt |
| 608 | /// CHECK-NEXT: neg x{{\d+}}, x{{\d+}}, asr #63 |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 609 | private static Long $noinline$LongDivByLongMin(long v) { |
| 610 | long r = v / Long.MIN_VALUE; |
| 611 | return r; |
| 612 | } |
Evgeny Astigeevich | af92a0f | 2020-06-26 13:28:33 +0100 | [diff] [blame] | 613 | |
| 614 | /// CHECK-START-ARM64: java.lang.Long DivTest.$noinline$LongAbsDivByLongMin(long) disassembly (after) |
| 615 | /// CHECK: Div |
| 616 | /// CHECK-NEXT: neg x{{\d+}}, x{{\d+}}, asr #63 |
| 617 | private static Long $noinline$LongAbsDivByLongMin(long v) { |
| 618 | long r = Math.abs(v) / Long.MIN_VALUE; |
| 619 | return r; |
| 620 | } |
Evgeny Astigeevich | a3234e9 | 2018-06-19 23:26:15 +0100 | [diff] [blame] | 621 | } |