Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/test/aarch64/IntArithTests.java
32282 views
public class IntArithTests {12private static final int IIMM12_0 = 0x1; // first imm value3private static final int IIMM12_1 = 0xfff; // last 12bit imm value4private static final int IIMM12_2 = 0x1001; // Should not encode as imm5private static final int IIMM24_3 = 0x1000; // first 12 bit shifted imm6private static final int IIMM24_4 = 0xfff000; // Last 12 bit shifted imm7private static final int IIMM24_5 = 0x1001000; // Should not encode as imm89private static int test_neg(int a) {10return -a;11}1213private static int test_addi(int a, int b) {14return a + b;15}1617private static int test_addic0(int a) {18return a + IIMM12_0;19}2021private static int test_addic1(int a) {22return a + IIMM12_1;23}2425private static int test_addic2(int a) {26return a + IIMM12_2;27}2829private static int test_addic3(int a) {30return a + IIMM24_3;31}3233private static int test_addic4(int a) {34return a + IIMM24_4;35}3637private static int test_addic5(int a) {38return a + IIMM24_5;39}4041private static int test_subi(int a, int b) {42return a - b;43}4445private static int test_subc1(int a) {46return a - 11;47}4849private static int test_mulic1(int a) {50// Generates shl.51return a * 8;52}5354private static int test_mulic2(int a) {55// Generates shl followed by add.56return a * 9;57}5859private static int test_mulic3(int a) {60// Generates shl followed by sub.61return a * 7;62}6364private static int test_mulic4(int a) {65// Generates normal mul.66return a * 10;67}6869private static int test_muli(int a, int b) {70// Generates normal mul.71return a * b;72}7374private static int test_divi(int a, int b) {75return a / b;76}7778private static int test_remi(int a, int b) {79return a % b;80}8182private static void assertThat(boolean assertion) {83if (! assertion) {84throw new AssertionError();85}86}8788public static void main(String[] args) {89assertThat(test_neg(10) == -10);90assertThat(test_addi(3, 2) == 5);91assertThat(test_addi(Integer.MAX_VALUE, 1) == Integer.MIN_VALUE);92assertThat(test_addic0(3) == 4);93assertThat(test_addic1(3) == 0x1002);94assertThat(test_addic2(3) == 0x1004);95assertThat(test_addic3(3) == 0x1003);96assertThat(test_addic4(3) == 0xfff003);97assertThat(test_addic5(3) == 0x1001003);9899assertThat(test_subi(40, 13) == 27);100assertThat(test_subi(Integer.MIN_VALUE, 1) == Integer.MAX_VALUE);101assertThat(test_subc1(40) == 29);102103assertThat(test_mulic1(5) == 40);104assertThat(test_mulic2(5) == 45);105assertThat(test_mulic3(5) == 35);106assertThat(test_mulic4(5) == 50);107assertThat(test_muli(5, 200) == 1000);108109assertThat(test_divi(30, 3) == 10);110assertThat(test_divi(29, 3) == 9);111assertThat(test_divi(Integer.MIN_VALUE, -1) == Integer.MIN_VALUE);112try {113test_divi(30, 0);114throw new AssertionError();115} catch (ArithmeticException ex) {116// Pass.117}118119assertThat(test_remi(30, 3) == 0);120assertThat(test_remi(29, 3) == 2);121assertThat(test_remi(Integer.MIN_VALUE, -1) == 0);122try {123test_remi(30, 0);124throw new AssertionError();125} catch (ArithmeticException ex) {126// Pass.127}128}129}130131132