1 public class IntLogicTests { 2 3 private static int test_and(int a, int b) { 4 return a & b; 5 } 6 7 private static int test_andc1(int a) { 8 // Generates immediate instruction. 9 return a & 0xf0f0f0f0; 10 } 11 12 private static int test_andc2(int a) { 13 // Generates non-immediate instruction. 14 return a & 0x123456d5; 15 } 16 17 private static int test_or(int a, int b) { 18 return a | b; 19 } 20 21 private static int test_orc1(int a) { 22 // Generates immediate instruction. 23 return a | 0xf0f0f0f0; 24 } 25 26 private static int test_orc2(int a) { 27 // Generates non-immediate instruction. 28 return a | 0x123456d5; 29 } 30 31 private static int test_xor(int a, int b) { 32 return a ^ b; 33 } 34 35 private static int test_xorc1(int a) { 36 // Generates immediate instruction. 37 return a ^ 0xf0f0f0f0; 38 } 39 40 private static int test_xorc2(int a) { 41 // Generates non-immediate instruction. 42 return a ^ 0x123456d5; 43 } 44 45 private static void assertThat(boolean assertion) { 46 if (! assertion) { 47 throw new AssertionError(); 48 } 49 } 50 51 public static void main(String[] args) { 52 53 assertThat(test_and(0x21, 0x31) == 0x21); 54 assertThat(test_andc1(0xaaaaaaaa) == 0xa0a0a0a0); 55 assertThat(test_andc2(0xaaaaaaaa) == 0x02200280); 56 57 assertThat(test_or(0x21, 0x31) == 0x31); 58 assertThat(test_orc1(0xaaaaaaaa) == 0xfafafafa); 59 assertThat(test_orc2(0xaaaaaaaa) == 0xbabefeff); 60 61 assertThat(test_xor(0x21, 0x31) == 16); 62 assertThat(test_xorc1(0xaaaaaaaa) == 0x5a5a5a5a); 63 assertThat(test_xorc2(0xaaaaaaaa) == 0xb89efc7f); 64 } 65 } 66