63 public static int int_index_mul(sun.misc.Unsafe unsafe, long base, int index) throws Exception {
64 return unsafe.getInt(base + (index * 4));
65 }
66 public static int long_index_mul(sun.misc.Unsafe unsafe, long base, long index) throws Exception {
67 return unsafe.getInt(base + (index * 4));
68 }
69 public static int int_index_mul_scale_16(sun.misc.Unsafe unsafe, long base, int index) throws Exception {
70 return unsafe.getInt(base + (index * 16));
71 }
72 public static int long_index_mul_scale_16(sun.misc.Unsafe unsafe, long base, long index) throws Exception {
73 return unsafe.getInt(base + (index * 16));
74 }
75 }
76
77 public static void main(String[] args) throws Exception {
78 sun.misc.Unsafe unsafe = Utils.getUnsafe();
79 final int array_size = 128;
80 final int element_size = 4;
81 final int magic = 0x12345678;
82
83 Random rnd = new Random();
84
85 long array = unsafe.allocateMemory(array_size * element_size); // 128 ints
86 long addr = array + array_size * element_size / 2; // something in the middle to work with
87 unsafe.putInt(addr, magic);
88 for (int j = 0; j < 100000; j++) {
89 if (Tests.int_index(unsafe, addr, 0) != magic) throw new Exception();
90 if (Tests.long_index(unsafe, addr, 0) != magic) throw new Exception();
91 if (Tests.int_index_mul(unsafe, addr, 0) != magic) throw new Exception();
92 if (Tests.long_index_mul(unsafe, addr, 0) != magic) throw new Exception();
93 {
94 long idx1 = rnd.nextLong();
95 long addr1 = addr - (idx1 << 2);
96 if (Tests.long_index(unsafe, addr1, idx1) != magic) throw new Exception();
97 }
98 {
99 long idx2 = rnd.nextLong();
100 long addr2 = addr - (idx2 >> 2);
101 if (Tests.long_index_back_ashift(unsafe, addr2, idx2) != magic) throw new Exception();
102 }
103 {
|
63 public static int int_index_mul(sun.misc.Unsafe unsafe, long base, int index) throws Exception {
64 return unsafe.getInt(base + (index * 4));
65 }
66 public static int long_index_mul(sun.misc.Unsafe unsafe, long base, long index) throws Exception {
67 return unsafe.getInt(base + (index * 4));
68 }
69 public static int int_index_mul_scale_16(sun.misc.Unsafe unsafe, long base, int index) throws Exception {
70 return unsafe.getInt(base + (index * 16));
71 }
72 public static int long_index_mul_scale_16(sun.misc.Unsafe unsafe, long base, long index) throws Exception {
73 return unsafe.getInt(base + (index * 16));
74 }
75 }
76
77 public static void main(String[] args) throws Exception {
78 sun.misc.Unsafe unsafe = Utils.getUnsafe();
79 final int array_size = 128;
80 final int element_size = 4;
81 final int magic = 0x12345678;
82
83 Random rnd = Utils.getRandomInstance();
84
85 long array = unsafe.allocateMemory(array_size * element_size); // 128 ints
86 long addr = array + array_size * element_size / 2; // something in the middle to work with
87 unsafe.putInt(addr, magic);
88 for (int j = 0; j < 100000; j++) {
89 if (Tests.int_index(unsafe, addr, 0) != magic) throw new Exception();
90 if (Tests.long_index(unsafe, addr, 0) != magic) throw new Exception();
91 if (Tests.int_index_mul(unsafe, addr, 0) != magic) throw new Exception();
92 if (Tests.long_index_mul(unsafe, addr, 0) != magic) throw new Exception();
93 {
94 long idx1 = rnd.nextLong();
95 long addr1 = addr - (idx1 << 2);
96 if (Tests.long_index(unsafe, addr1, idx1) != magic) throw new Exception();
97 }
98 {
99 long idx2 = rnd.nextLong();
100 long addr2 = addr - (idx2 >> 2);
101 if (Tests.long_index_back_ashift(unsafe, addr2, idx2) != magic) throw new Exception();
102 }
103 {
|