• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2015 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 Main {
18 
assertIntEquals(int expected, int result)19   public static void assertIntEquals(int expected, int result) {
20     if (expected != result) {
21       throw new Error("Expected: " + expected + ", found: " + result);
22     }
23   }
24 
assertLongEquals(long expected, long result)25   public static void assertLongEquals(long expected, long result) {
26     if (expected != result) {
27       throw new Error("Expected: " + expected + ", found: " + result);
28     }
29   }
30 
31   /// CHECK-START-ARM: int Main.and255(int) disassembly (after)
32   /// CHECK-NOT:            movs {{r\d+}}, #255
33   /// CHECK:                and {{r\d+}}, {{r\d+}}, #255
34 
and255(int arg)35   public static int and255(int arg) {
36     return arg & 255;
37   }
38 
39   /// CHECK-START-ARM: int Main.and511(int) disassembly (after)
40   /// CHECK:                movw {{r\d+}}, #511
41   /// CHECK:                and{{(\.w)?}} {{r\d+}}, {{r\d+}}, {{r\d+}}
42 
and511(int arg)43   public static int and511(int arg) {
44     return arg & 511;
45   }
46 
47   /// CHECK-START-ARM: int Main.andNot15(int) disassembly (after)
48   /// CHECK-NOT:            mvn {{r\d+}}, #15
49   /// CHECK:                bic {{r\d+}}, {{r\d+}}, #15
50 
andNot15(int arg)51   public static int andNot15(int arg) {
52     return arg & ~15;
53   }
54 
55   /// CHECK-START-ARM: int Main.or255(int) disassembly (after)
56   /// CHECK-NOT:            movs {{r\d+}}, #255
57   /// CHECK:                orr {{r\d+}}, {{r\d+}}, #255
58 
or255(int arg)59   public static int or255(int arg) {
60     return arg | 255;
61   }
62 
63   /// CHECK-START-ARM: int Main.or511(int) disassembly (after)
64   /// CHECK:                movw {{r\d+}}, #511
65   /// CHECK:                orr{{(\.w)?}} {{r\d+}}, {{r\d+}}, {{r\d+}}
66 
or511(int arg)67   public static int or511(int arg) {
68     return arg | 511;
69   }
70 
71   /// CHECK-START-ARM: int Main.orNot15(int) disassembly (after)
72   /// CHECK-NOT:            mvn {{r\d+}}, #15
73   /// CHECK:                orn {{r\d+}}, {{r\d+}}, #15
74 
orNot15(int arg)75   public static int orNot15(int arg) {
76     return arg | ~15;
77   }
78 
79   /// CHECK-START-ARM: int Main.xor255(int) disassembly (after)
80   /// CHECK-NOT:            movs {{r\d+}}, #255
81   /// CHECK:                eor {{r\d+}}, {{r\d+}}, #255
82 
xor255(int arg)83   public static int xor255(int arg) {
84     return arg ^ 255;
85   }
86 
87   /// CHECK-START-ARM: int Main.xor511(int) disassembly (after)
88   /// CHECK:                movw {{r\d+}}, #511
89   /// CHECK:                eor{{(\.w)?}} {{r\d+}}, {{r\d+}}, {{r\d+}}
90 
xor511(int arg)91   public static int xor511(int arg) {
92     return arg ^ 511;
93   }
94 
95   /// CHECK-START-ARM: int Main.xorNot15(int) disassembly (after)
96   /// CHECK:                mvn {{r\d+}}, #15
97   /// CHECK:                eor{{(\.w)?}} {{r\d+}}, {{r\d+}}, {{r\d+}}
98 
xorNot15(int arg)99   public static int xorNot15(int arg) {
100     return arg ^ ~15;
101   }
102 
103   /// CHECK-START-ARM: long Main.and255(long) disassembly (after)
104   /// CHECK-NOT:            movs {{r\d+}}, #255
105   /// CHECK-NOT:            and
106   /// CHECK-NOT:            bic
107   /// CHECK-DAG:            and {{r\d+}}, {{r\d+}}, #255
108   /// CHECK-DAG:            movs {{r\d+}}, #0
109   /// CHECK-NOT:            and
110   /// CHECK-NOT:            bic
111 
and255(long arg)112   public static long and255(long arg) {
113     return arg & 255L;
114   }
115 
116   /// CHECK-START-ARM: long Main.and511(long) disassembly (after)
117   /// CHECK:                movw {{r\d+}}, #511
118   /// CHECK-NOT:            and
119   /// CHECK-NOT:            bic
120   /// CHECK-DAG:            and{{(\.w)?}} {{r\d+}}, {{r\d+}}, {{r\d+}}
121   /// CHECK-DAG:            movs {{r\d+}}, #0
122   /// CHECK-NOT:            and
123   /// CHECK-NOT:            bic
124 
and511(long arg)125   public static long and511(long arg) {
126     return arg & 511L;
127   }
128 
129   /// CHECK-START-ARM: long Main.andNot15(long) disassembly (after)
130   /// CHECK-NOT:            mvn {{r\d+}}, #15
131   /// CHECK-NOT:            and
132   /// CHECK-NOT:            bic
133   /// CHECK:                bic {{r\d+}}, {{r\d+}}, #15
134   /// CHECK-NOT:            and
135   /// CHECK-NOT:            bic
136 
andNot15(long arg)137   public static long andNot15(long arg) {
138     return arg & ~15L;
139   }
140 
141   /// CHECK-START-ARM: long Main.and0xfffffff00000000f(long) disassembly (after)
142   /// CHECK-NOT:            movs {{r\d+}}, #15
143   /// CHECK-NOT:            mvn {{r\d+}}, #15
144   /// CHECK-NOT:            and
145   /// CHECK-NOT:            bic
146   /// CHECK-DAG:            and {{r\d+}}, {{r\d+}}, #15
147   /// CHECK-DAG:            bic {{r\d+}}, {{r\d+}}, #15
148   /// CHECK-NOT:            and
149   /// CHECK-NOT:            bic
150 
and0xfffffff00000000f(long arg)151   public static long and0xfffffff00000000f(long arg) {
152     return arg & 0xfffffff00000000fL;
153   }
154 
155   /// CHECK-START-ARM: long Main.or255(long) disassembly (after)
156   /// CHECK-NOT:            movs {{r\d+}}, #255
157   /// CHECK-NOT:            orr
158   /// CHECK-NOT:            orn
159   /// CHECK:                orr {{r\d+}}, {{r\d+}}, #255
160   /// CHECK-NOT:            orr
161   /// CHECK-NOT:            orn
162 
or255(long arg)163   public static long or255(long arg) {
164     return arg | 255L;
165   }
166 
167   /// CHECK-START-ARM: long Main.or511(long) disassembly (after)
168   /// CHECK:                movw {{r\d+}}, #511
169   /// CHECK-NOT:            orr
170   /// CHECK-NOT:            orn
171   /// CHECK:                orr{{(\.w)?}} {{r\d+}}, {{r\d+}}, {{r\d+}}
172   /// CHECK-NOT:            orr
173   /// CHECK-NOT:            orn
174 
or511(long arg)175   public static long or511(long arg) {
176     return arg | 511L;
177   }
178 
179   /// CHECK-START-ARM: long Main.orNot15(long) disassembly (after)
180   /// CHECK-NOT:            mvn {{r\d+}}, #15
181   /// CHECK-NOT:            orr
182   /// CHECK-NOT:            orn
183   /// CHECK-DAG:            orn {{r\d+}}, {{r\d+}}, #15
184   /// CHECK-DAG:            mvn {{r\d+}}, #0
185   /// CHECK-NOT:            orr
186   /// CHECK-NOT:            orn
187 
orNot15(long arg)188   public static long orNot15(long arg) {
189     return arg | ~15L;
190   }
191 
192   /// CHECK-START-ARM: long Main.or0xfffffff00000000f(long) disassembly (after)
193   /// CHECK-NOT:            movs {{r\d+}}, #15
194   /// CHECK-NOT:            mvn {{r\d+}}, #15
195   /// CHECK-NOT:            orr
196   /// CHECK-NOT:            orn
197   /// CHECK-DAG:            orr {{r\d+}}, {{r\d+}}, #15
198   /// CHECK-DAG:            orn {{r\d+}}, {{r\d+}}, #15
199   /// CHECK-NOT:            orr
200   /// CHECK-NOT:            orn
201 
or0xfffffff00000000f(long arg)202   public static long or0xfffffff00000000f(long arg) {
203     return arg | 0xfffffff00000000fL;
204   }
205 
206   /// CHECK-START-ARM: long Main.xor255(long) disassembly (after)
207   /// CHECK-NOT:            movs {{r\d+}}, #255
208   /// CHECK-NOT:            eor
209   /// CHECK:                eor {{r\d+}}, {{r\d+}}, #255
210   /// CHECK-NOT:            eor
211 
xor255(long arg)212   public static long xor255(long arg) {
213     return arg ^ 255L;
214   }
215 
216   /// CHECK-START-ARM: long Main.xor511(long) disassembly (after)
217   /// CHECK:                movw {{r\d+}}, #511
218   /// CHECK-NOT:            eor
219   /// CHECK-DAG:            eor{{(\.w)?}} {{r\d+}}, {{r\d+}}, {{r\d+}}
220   /// CHECK-NOT:            eor
221 
xor511(long arg)222   public static long xor511(long arg) {
223     return arg ^ 511L;
224   }
225 
226   /// CHECK-START-ARM: long Main.xorNot15(long) disassembly (after)
227   /// CHECK-DAG:            mvn {{r\d+}}, #15
228   /// CHECK-DAG:            mov.w {{r\d+}}, #-1
229   /// CHECK-NOT:            eor
230   /// CHECK-DAG:            eor{{(\.w)?}} {{r\d+}}, {{r\d+}}, {{r\d+}}
231   /// CHECK-DAG:            eor{{(\.w)?}} {{r\d+}}, {{r\d+}}, {{r\d+}}
232   /// CHECK-NOT:            eor
233 
xorNot15(long arg)234   public static long xorNot15(long arg) {
235     return arg ^ ~15L;
236   }
237 
238   // Note: No support for partial long constant embedding.
239   /// CHECK-START-ARM: long Main.xor0xfffffff00000000f(long) disassembly (after)
240   /// CHECK-DAG:            movs {{r\d+}}, #15
241   /// CHECK-DAG:            mvn {{r\d+}}, #15
242   /// CHECK-NOT:            eor
243   /// CHECK-DAG:            eor{{(\.w)?}} {{r\d+}}, {{r\d+}}, {{r\d+}}
244   /// CHECK-DAG:            eor{{(\.w)?}} {{r\d+}}, {{r\d+}}, {{r\d+}}
245   /// CHECK-NOT:            eor
246 
xor0xfffffff00000000f(long arg)247   public static long xor0xfffffff00000000f(long arg) {
248     return arg ^ 0xfffffff00000000fL;
249   }
250 
251   /// CHECK-START-ARM: long Main.xor0xf00000000000000f(long) disassembly (after)
252   /// CHECK-NOT:            movs {{r\d+}}, #15
253   /// CHECK-NOT:            mov.w {{r\d+}}, #-268435456
254   /// CHECK-NOT:            eor
255   /// CHECK-DAG:            eor {{r\d+}}, {{r\d+}}, #15
256   /// CHECK-DAG:            eor {{r\d+}}, {{r\d+}}, #-268435456
257   /// CHECK-NOT:            eor
258 
xor0xf00000000000000f(long arg)259   public static long xor0xf00000000000000f(long arg) {
260     return arg ^ 0xf00000000000000fL;
261   }
262 
263   /// CHECK-START-ARM: long Main.shl1(long) disassembly (after)
264   /// CHECK:                lsls{{(\.w)?}} {{r\d+}}, {{r\d+}}, #1
265   /// CHECK:                adc{{(\.w)?}} {{r\d+}}, {{r\d+}}, {{r\d+}}
266 
267   /// CHECK-START-ARM: long Main.shl1(long) disassembly (after)
268   /// CHECK-NOT:            lsl{{s?|\.w}} {{r\d+}}, {{r\d+}}, {{r\d+}}
269 
270   /// CHECK-START-X86: long Main.shl1(long) disassembly (after)
271   /// CHECK:                add
272   /// CHECK:                adc
273 
274   /// CHECK-START-X86: long Main.shl1(long) disassembly (after)
275   /// CHECK-NOT:            shl
276 
shl1(long arg)277   public static long shl1(long arg) {
278     return arg << 1;
279   }
280 
281   /// CHECK-START-ARM: long Main.shl2(long) disassembly (after)
282   /// CHECK:                lsl{{s?|\.w}} <<oh:r\d+>>, {{r\d+}}, #2
283   /// CHECK:                orr.w <<oh>>, <<oh>>, <<low:r\d+>>, lsr #30
284   /// CHECK:                lsl{{s?|\.w}} {{r\d+}}, <<low>>, #2
285 
286   /// CHECK-START-ARM: long Main.shl2(long) disassembly (after)
287   /// CHECK-NOT:            lsl{{s?|\.w}} {{r\d+}}, {{r\d+}}, {{r\d+}}
288 
shl2(long arg)289   public static long shl2(long arg) {
290     return arg << 2;
291   }
292 
293   /// CHECK-START-ARM: long Main.shl31(long) disassembly (after)
294   /// CHECK:                lsl{{s?|\.w}} <<oh:r\d+>>, {{r\d+}}, #31
295   /// CHECK:                orr.w <<oh>>, <<oh>>, <<low:r\d+>>, lsr #1
296   /// CHECK:                lsl{{s?|\.w}} {{r\d+}}, <<low>>, #31
297 
298   /// CHECK-START-ARM: long Main.shl31(long) disassembly (after)
299   /// CHECK-NOT:            lsl{{s?|\.w}} {{r\d+}}, {{r\d+}}, {{r\d+}}
300 
shl31(long arg)301   public static long shl31(long arg) {
302     return arg << 31;
303   }
304 
305   /// CHECK-START-ARM: long Main.shl32(long) disassembly (after)
306   /// CHECK-DAG:            mov {{r\d+}}, {{r\d+}}
307   /// CHECK-DAG:            mov{{s?|\.w}} {{r\d+}}, #0
308 
309   /// CHECK-START-ARM: long Main.shl32(long) disassembly (after)
310   /// CHECK-NOT:            lsl{{s?|\.w}}
311 
shl32(long arg)312   public static long shl32(long arg) {
313     return arg << 32;
314   }
315 
316   /// CHECK-START-ARM: long Main.shl33(long) disassembly (after)
317   /// CHECK-DAG:            lsl{{s?|\.w}} {{r\d+}}, <<high:r\d+>>, #1
318   /// CHECK-DAG:            mov{{s?|\.w}} {{r\d+}}, #0
319 
320   /// CHECK-START-ARM: long Main.shl33(long) disassembly (after)
321   /// CHECK-NOT:            lsl{{s?|\.w}} {{r\d+}}, {{r\d+}}, {{r\d+}}
322 
shl33(long arg)323   public static long shl33(long arg) {
324     return arg << 33;
325   }
326 
327   /// CHECK-START-ARM: long Main.shl63(long) disassembly (after)
328   /// CHECK-DAG:            lsl{{s?|\.w}} {{r\d+}}, <<high:r\d+>>, #31
329   /// CHECK-DAG:            mov{{s?|\.w}} {{r\d+}}, #0
330 
331   /// CHECK-START-ARM: long Main.shl63(long) disassembly (after)
332   /// CHECK-NOT:            lsl{{s?|\.w}} {{r\d+}}, {{r\d+}}, {{r\d+}}
333 
shl63(long arg)334   public static long shl63(long arg) {
335     return arg << 63;
336   }
337 
338   /// CHECK-START-ARM: long Main.shr1(long) disassembly (after)
339   /// CHECK:                asrs{{(\.w)?}} {{r\d+}}, {{r\d+}}, #1
340   /// CHECK:                mov.w {{r\d+}}, {{r\d+}}, rrx
341 
342   /// CHECK-START-ARM: long Main.shr1(long) disassembly (after)
343   /// CHECK-NOT:            asr{{s?|\.w}} {{r\d+}}, {{r\d+}}, {{r\d+}}
344 
shr1(long arg)345   public static long shr1(long arg) {
346     return arg >> 1;
347   }
348 
349   /// CHECK-START-ARM: long Main.shr2(long) disassembly (after)
350   /// CHECK:                lsr{{s?|\.w}} <<ol:r\d+>>, {{r\d+}}, #2
351   /// CHECK:                orr.w <<ol>>, <<ol>>, <<high:r\d+>>, lsl #30
352   /// CHECK-DAG:            asr{{s?|\.w}} {{r\d+}}, <<high>>, #2
353 
354   /// CHECK-START-ARM: long Main.shr2(long) disassembly (after)
355   /// CHECK-NOT:            asr{{s?|\.w}} {{r\d+}}, {{r\d+}}, {{r\d+}}
356 
shr2(long arg)357   public static long shr2(long arg) {
358     return arg >> 2;
359   }
360 
361   /// CHECK-START-ARM: long Main.shr31(long) disassembly (after)
362   /// CHECK:                lsr{{s?|\.w}} <<ol:r\d+>>, {{r\d+}}, #31
363   /// CHECK:                orr.w <<ol>>, <<ol>>, <<high:r\d+>>, lsl #1
364   /// CHECK:                asr{{s?|\.w}} {{r\d+}}, <<high>>, #31
365 
366   /// CHECK-START-ARM: long Main.shr31(long) disassembly (after)
367   /// CHECK-NOT:            asr{{s?|\.w}} {{r\d+}}, {{r\d+}}, {{r\d+}}
368 
shr31(long arg)369   public static long shr31(long arg) {
370     return arg >> 31;
371   }
372 
373   /// CHECK-START-ARM: long Main.shr32(long) disassembly (after)
374   /// CHECK-DAG:            asr{{s?|\.w}} {{r\d+}}, <<high:r\d+>>, #31
375   /// CHECK-DAG:            mov {{r\d+}}, <<high>>
376 
377   /// CHECK-START-ARM: long Main.shr32(long) disassembly (after)
378   /// CHECK-NOT:            asr{{s?|\.w}} {{r\d+}}, {{r\d+}}, {{r\d+}}
379   /// CHECK-NOT:            lsr{{s?|\.w}}
380 
shr32(long arg)381   public static long shr32(long arg) {
382     return arg >> 32;
383   }
384 
385   /// CHECK-START-ARM: long Main.shr33(long) disassembly (after)
386   /// CHECK-DAG:            asr{{s?|\.w}} {{r\d+}}, <<high:r\d+>>, #1
387   /// CHECK-DAG:            asr{{s?|\.w}} {{r\d+}}, <<high>>, #31
388 
389   /// CHECK-START-ARM: long Main.shr33(long) disassembly (after)
390   /// CHECK-NOT:            asr{{s?|\.w}} {{r\d+}}, {{r\d+}}, {{r\d+}}
391 
shr33(long arg)392   public static long shr33(long arg) {
393     return arg >> 33;
394   }
395 
396   /// CHECK-START-ARM: long Main.shr63(long) disassembly (after)
397   /// CHECK-DAG:            asr{{s?|\.w}} {{r\d+}}, <<high:r\d+>>, #31
398   /// CHECK-DAG:            asr{{s?|\.w}} {{r\d+}}, <<high>>, #31
399 
400   /// CHECK-START-ARM: long Main.shr63(long) disassembly (after)
401   /// CHECK-NOT:            asr{{s?|\.w}} {{r\d+}}, {{r\d+}}, {{r\d+}}
402 
shr63(long arg)403   public static long shr63(long arg) {
404     return arg >> 63;
405   }
406 
407   /// CHECK-START-ARM: long Main.ushr1(long) disassembly (after)
408   /// CHECK:                lsrs{{|.w}} {{r\d+}}, {{r\d+}}, #1
409   /// CHECK:                mov.w {{r\d+}}, {{r\d+}}, rrx
410 
411   /// CHECK-START-ARM: long Main.ushr1(long) disassembly (after)
412   /// CHECK-NOT:            lsr{{s?|\.w}} {{r\d+}}, {{r\d+}}, {{r\d+}}
413 
ushr1(long arg)414   public static long ushr1(long arg) {
415     return arg >>> 1;
416   }
417 
418   /// CHECK-START-ARM: long Main.ushr2(long) disassembly (after)
419   /// CHECK:                lsr{{s?|\.w}} <<ol:r\d+>>, {{r\d+}}, #2
420   /// CHECK:                orr.w <<ol>>, <<ol>>, <<high:r\d+>>, lsl #30
421   /// CHECK-DAG:            lsr{{s?|\.w}} {{r\d+}}, <<high>>, #2
422 
423   /// CHECK-START-ARM: long Main.ushr2(long) disassembly (after)
424   /// CHECK-NOT:            lsr{{s?|\.w}} {{r\d+}}, {{r\d+}}, {{r\d+}}
425 
ushr2(long arg)426   public static long ushr2(long arg) {
427     return arg >>> 2;
428   }
429 
430   /// CHECK-START-ARM: long Main.ushr31(long) disassembly (after)
431   /// CHECK:                lsr{{s?|\.w}} <<ol:r\d+>>, {{r\d+}}, #31
432   /// CHECK:                orr.w <<ol>>, <<ol>>, <<high:r\d+>>, lsl #1
433   /// CHECK:                lsr{{s?|\.w}} {{r\d+}}, <<high>>, #31
434 
435   /// CHECK-START-ARM: long Main.ushr31(long) disassembly (after)
436   /// CHECK-NOT:            lsr{{s?|\.w}} {{r\d+}}, {{r\d+}}, {{r\d+}}
437 
ushr31(long arg)438   public static long ushr31(long arg) {
439     return arg >>> 31;
440   }
441 
442   /// CHECK-START-ARM: long Main.ushr32(long) disassembly (after)
443   /// CHECK-DAG:            mov {{r\d+}}, {{r\d+}}
444   /// CHECK-DAG:            mov{{s?|\.w}} {{r\d+}}, #0
445 
446   /// CHECK-START-ARM: long Main.ushr32(long) disassembly (after)
447   /// CHECK-NOT:            lsr{{s?|\.w}}
448 
ushr32(long arg)449   public static long ushr32(long arg) {
450     return arg >>> 32;
451   }
452 
453   /// CHECK-START-ARM: long Main.ushr33(long) disassembly (after)
454   /// CHECK-DAG:            lsr{{s?|\.w}} {{r\d+}}, {{r\d+}}, #1
455   /// CHECK-DAG:            mov{{s?|\.w}} {{r\d+}}, #0
456 
457   /// CHECK-START-ARM: long Main.ushr33(long) disassembly (after)
458   /// CHECK-NOT:            lsr{{s?|\.w}} {{r\d+}}, {{r\d+}}, {{r\d+}}
459 
ushr33(long arg)460   public static long ushr33(long arg) {
461     return arg >>> 33;
462   }
463 
464   /// CHECK-START-ARM: long Main.ushr63(long) disassembly (after)
465   /// CHECK-DAG:            lsr{{s?|\.w}} {{r\d+}}, {{r\d+}}, #31
466   /// CHECK-DAG:            mov{{s?|\.w}} {{r\d+}}, #0
467 
468   /// CHECK-START-ARM: long Main.ushr63(long) disassembly (after)
469   /// CHECK-NOT:            lsr{{s?|\.w}} {{r\d+}}, {{r\d+}}, {{r\d+}}
470 
ushr63(long arg)471   public static long ushr63(long arg) {
472     return arg >>> 63;
473   }
474 
475   /**
476    * Test that the `-1` constant is not synthesized in a register and that we
477    * instead simply switch between `add` and `sub` instructions with the
478    * constant embedded.
479    * We need two uses (or more) of the constant because the compiler always
480    * defers to immediate value handling to VIXL when it has only one use.
481    */
482 
483   /// CHECK-START-ARM64: long Main.addM1(long) register (after)
484   /// CHECK:     <<Arg:j\d+>>       ParameterValue
485   /// CHECK:     <<ConstM1:j\d+>>   LongConstant -1
486   /// CHECK-NOT:                    ParallelMove
487   /// CHECK:                        Add [<<Arg>>,<<ConstM1>>]
488   /// CHECK:                        Sub [<<Arg>>,<<ConstM1>>]
489 
490   /// CHECK-START-ARM64: long Main.addM1(long) disassembly (after)
491   /// CHECK:                        sub x{{\d+}}, x{{\d+}}, #0x1
492   /// CHECK:                        add x{{\d+}}, x{{\d+}}, #0x1
493 
addM1(long arg)494   public static long addM1(long arg) {
495     return (arg + (-1)) | (arg - (-1));
496   }
497 
main(String[] args)498   public static void main(String[] args) {
499     int arg = 0x87654321;
500     assertIntEquals(and255(arg), 0x21);
501     assertIntEquals(and511(arg), 0x121);
502     assertIntEquals(andNot15(arg), 0x87654320);
503     assertIntEquals(or255(arg), 0x876543ff);
504     assertIntEquals(or511(arg), 0x876543ff);
505     assertIntEquals(orNot15(arg), 0xfffffff1);
506     assertIntEquals(xor255(arg), 0x876543de);
507     assertIntEquals(xor511(arg), 0x876542de);
508     assertIntEquals(xorNot15(arg), 0x789abcd1);
509 
510     long longArg = 0x1234567887654321L;
511     assertLongEquals(and255(longArg), 0x21L);
512     assertLongEquals(and511(longArg), 0x121L);
513     assertLongEquals(andNot15(longArg), 0x1234567887654320L);
514     assertLongEquals(and0xfffffff00000000f(longArg), 0x1234567000000001L);
515     assertLongEquals(or255(longArg), 0x12345678876543ffL);
516     assertLongEquals(or511(longArg), 0x12345678876543ffL);
517     assertLongEquals(orNot15(longArg), 0xfffffffffffffff1L);
518     assertLongEquals(or0xfffffff00000000f(longArg), 0xfffffff88765432fL);
519     assertLongEquals(xor255(longArg), 0x12345678876543deL);
520     assertLongEquals(xor511(longArg), 0x12345678876542deL);
521     assertLongEquals(xorNot15(longArg), 0xedcba987789abcd1L);
522     assertLongEquals(xor0xfffffff00000000f(longArg), 0xedcba9888765432eL);
523     assertLongEquals(xor0xf00000000000000f(longArg), 0xe23456788765432eL);
524 
525     assertLongEquals(14, addM1(7));
526 
527     assertLongEquals(shl1(longArg), 0x2468acf10eca8642L);
528     assertLongEquals(shl2(longArg), 0x48d159e21d950c84L);
529     assertLongEquals(shl31(longArg), 0x43b2a19080000000L);
530     assertLongEquals(shl32(longArg), 0x8765432100000000L);
531     assertLongEquals(shl33(longArg), 0x0eca864200000000L);
532     assertLongEquals(shl63(longArg), 0x8000000000000000L);
533     assertLongEquals(shl1(~longArg), 0xdb97530ef13579bcL);
534     assertLongEquals(shl2(~longArg), 0xb72ea61de26af378L);
535     assertLongEquals(shl31(~longArg), 0xbc4d5e6f00000000L);
536     assertLongEquals(shl32(~longArg), 0x789abcde00000000L);
537     assertLongEquals(shl33(~longArg), 0xf13579bc00000000L);
538     assertLongEquals(shl63(~longArg), 0x0000000000000000L);
539 
540     assertLongEquals(shr1(longArg), 0x091a2b3c43b2a190L);
541     assertLongEquals(shr2(longArg), 0x048d159e21d950c8L);
542     assertLongEquals(shr31(longArg), 0x000000002468acf1L);
543     assertLongEquals(shr32(longArg), 0x0000000012345678L);
544     assertLongEquals(shr33(longArg), 0x00000000091a2b3cL);
545     assertLongEquals(shr63(longArg), 0x0000000000000000L);
546     assertLongEquals(shr1(~longArg), 0xf6e5d4c3bc4d5e6fL);
547     assertLongEquals(shr2(~longArg), 0xfb72ea61de26af37L);
548     assertLongEquals(shr31(~longArg), 0xffffffffdb97530eL);
549     assertLongEquals(shr32(~longArg), 0xffffffffedcba987L);
550     assertLongEquals(shr33(~longArg), 0xfffffffff6e5d4c3L);
551     assertLongEquals(shr63(~longArg), 0xffffffffffffffffL);
552 
553     assertLongEquals(ushr1(longArg), 0x091a2b3c43b2a190L);
554     assertLongEquals(ushr2(longArg), 0x048d159e21d950c8L);
555     assertLongEquals(ushr31(longArg), 0x000000002468acf1L);
556     assertLongEquals(ushr32(longArg), 0x0000000012345678L);
557     assertLongEquals(ushr33(longArg), 0x00000000091a2b3cL);
558     assertLongEquals(ushr63(longArg), 0x0000000000000000L);
559     assertLongEquals(ushr1(~longArg), 0x76e5d4c3bc4d5e6fL);
560     assertLongEquals(ushr2(~longArg), 0x3b72ea61de26af37L);
561     assertLongEquals(ushr31(~longArg), 0x00000001db97530eL);
562     assertLongEquals(ushr32(~longArg), 0x00000000edcba987L);
563     assertLongEquals(ushr33(~longArg), 0x0000000076e5d4c3L);
564     assertLongEquals(ushr63(~longArg), 0x0000000000000001L);
565   }
566 }
567