Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/aarch64/LongArithTests.java
32282 views
public class LongArithTests {123private static final long IIMM12_0 = 0x1; // first imm value4private static final long IIMM12_1 = 0xfff; // last 12bit imm value5private static final long IIMM12_2 = 0x1001; // Should not encode as imm6private static final long IIMM24_3 = 0x1000; // first 12 bit shifted imm7private static final long IIMM24_4 = 0xfff000; // Last 12 bit shifted imm8private static final long IIMM24_5 = 0x1001000; // Should not encode as imm910private static long test_neg(long a) {11return -a;12}1314private static long test_add(long a, long b) {15return a + b;16}1718private static long test_addc0(long a) {19return a + IIMM12_0;20}2122private static long test_addc1(long a) {23return a + IIMM12_1;24}2526private static long test_addc2(long a) {27return a + IIMM12_2;28}2930private static long test_addc3(long a) {31return a + IIMM24_3;32}3334private static long test_addc4(long a) {35return a + IIMM24_4;36}3738private static long test_addc5(long a) {39return a + IIMM24_5;40}4142private static long test_sub(long a, long b) {43return a - b;44}4546private static long test_subc1(long a) {47return a - 11;48}4950private static long test_mulc1(long a) {51// Generates shl.52return a * 8;53}5455private static long test_mulc2(long a) {56// Generates shl followed by add.57return a * 9;58}5960private static long test_mulc3(long a) {61// Generates shl followed by sub.62return a * 7;63}6465private static long test_mulc4(long a) {66// Generates normal mul.67return a * 10;68}6970private static long test_mul(long a, long b) {71// Generates normal mul.72return a * b;73}7475private static long test_div(long a, long b) {76return a / b;77}7879private static long test_rem(long a, long b) {80return a % b;81}8283private static void assertThat(boolean assertion) {84if (! assertion) {85throw new AssertionError();86}87}8889public static void main(String[] args) {90assertThat(test_neg(10) == -10);91assertThat(test_add(3, 2) == 5);92assertThat(test_add(Long.MAX_VALUE, 1) == Long.MIN_VALUE);93assertThat(test_addc0(3) == 4);94assertThat(test_addc1(3) == 0x1002);95assertThat(test_addc2(3) == 0x1004);96assertThat(test_addc3(3) == 0x1003);97assertThat(test_addc4(3) == 0xfff003);98assertThat(test_addc5(3) == 0x1001003);99100assertThat(test_sub(40, 13) == 27);101assertThat(test_sub(Long.MIN_VALUE, 1) == Long.MAX_VALUE);102assertThat(test_subc1(40) == 29);103104assertThat(test_mulc1(5) == 40);105assertThat(test_mulc2(5) == 45);106assertThat(test_mulc3(5) == 35);107assertThat(test_mulc4(5) == 50);108assertThat(test_mul(5, 200) == 1000);109110assertThat(test_div(30, 3) == 10);111assertThat(test_div(29, 3) == 9);112assertThat(test_div(Long.MIN_VALUE, -1) == Long.MIN_VALUE);113try {114test_div(30, 0);115throw new AssertionError();116} catch (ArithmeticException ex) {117// Pass.118}119120assertThat(test_rem(30, 3) == 0);121assertThat(test_rem(29, 3) == 2);122assertThat(test_rem(Long.MIN_VALUE, -1) == 0);123try {124test_rem(30, 0);125throw new AssertionError();126} catch (ArithmeticException ex) {127// Pass.128}129130}131}132133134