comparison graal/com.oracle.truffle.api/src/com/oracle/truffle/api/ExactMath.java @ 15691:6a13c422fca4

API for high word multiplication.
author Roland Schatz <roland.schatz@oracle.com>
date Thu, 15 May 2014 19:03:16 +0200
parents 494b818b527c
children c88ab4f1f04a
comparison
equal deleted inserted replaced
15690:d3c33144cab5 15691:6a13c422fca4
89 throw new ArithmeticException("long overflow"); 89 throw new ArithmeticException("long overflow");
90 } 90 }
91 } 91 }
92 return r; 92 return r;
93 } 93 }
94
95 public static int multiplyHigh(int x, int y) {
96 long r = (long) x * (long) y;
97 return (int) (r >> 32);
98 }
99
100 public static int multiplyHighUnsigned(int x, int y) {
101 long xl = x & 0xFFFFFFFFL;
102 long yl = y & 0xFFFFFFFFL;
103 long r = xl * yl;
104 return (int) (r >> 32);
105 }
106
107 public static long multiplyHigh(long x, long y) {
108 long x0, y0, z0;
109 long x1, y1, z1, z2, t;
110
111 x0 = x & 0xFFFFFFFFL;
112 x1 = x >> 32;
113
114 y0 = y & 0xFFFFFFFFL;
115 y1 = y >> 32;
116
117 z0 = x0 * y0;
118 t = x1 * y0 + (z0 >>> 32);
119 z1 = t & 0xFFFFFFFFL;
120 z2 = t >> 32;
121 z1 += x0 * y1;
122
123 return x1 * y1 + z2 + (z1 >> 32);
124 }
125
126 public static long multiplyHighUnsigned(long x, long y) {
127 long x0, y0, z0;
128 long x1, y1, z1, z2, t;
129
130 x0 = x & 0xFFFFFFFFL;
131 x1 = x >>> 32;
132
133 y0 = y & 0xFFFFFFFFL;
134 y1 = y >>> 32;
135
136 z0 = x0 * y0;
137 t = x1 * y0 + (z0 >>> 32);
138 z1 = t & 0xFFFFFFFFL;
139 z2 = t >>> 32;
140 z1 += x0 * y1;
141
142 return x1 * y1 + z2 + (z1 >>> 32);
143 }
94 } 144 }