[pypy-svn] r46234 - in pypy/dist/pypy/translator/jvm: . src/pypy test
antocuni at codespeak.net
antocuni at codespeak.net
Sat Sep 1 14:28:48 CEST 2007
Author: antocuni
Date: Sat Sep 1 14:28:46 2007
New Revision: 46234
Modified:
pypy/dist/pypy/translator/jvm/generator.py
pypy/dist/pypy/translator/jvm/opcodes.py
pypy/dist/pypy/translator/jvm/src/pypy/PyPy.java
pypy/dist/pypy/translator/jvm/test/test_op.py
Log:
correct implementation of uint_mul and uint_div
Modified: pypy/dist/pypy/translator/jvm/generator.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/generator.py (original)
+++ pypy/dist/pypy/translator/jvm/generator.py Sat Sep 1 14:28:46 2007
@@ -394,6 +394,8 @@
PYPYUINTCMP = Method.s(jPyPy, 'uint_cmp', (jInt,jInt,), jInt)
PYPYULONGCMP = Method.s(jPyPy, 'ulong_cmp', (jLong,jLong), jInt)
PYPYUINTMOD = Method.s(jPyPy, 'uint_mod', (jInt, jInt), jInt)
+PYPYUINTMUL = Method.s(jPyPy, 'uint_mul', (jInt, jInt), jInt)
+PYPYUINTDIV = Method.s(jPyPy, 'uint_div', (jInt, jInt), jInt)
PYPYULONGMOD = Method.s(jPyPy, 'ulong_mod', (jLong, jLong), jLong)
PYPYUINTTODOUBLE = Method.s(jPyPy, 'uint_to_double', (jInt,), jDouble)
PYPYDOUBLETOUINT = Method.s(jPyPy, 'double_to_uint', (jDouble,), jInt)
Modified: pypy/dist/pypy/translator/jvm/opcodes.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/opcodes.py (original)
+++ pypy/dist/pypy/translator/jvm/opcodes.py Sat Sep 1 14:28:46 2007
@@ -137,10 +137,10 @@
'uint_add': jvmgen.IADD,
'uint_sub': jvmgen.ISUB,
- 'uint_mul': jvmgen.IMUL,
- 'uint_div': jvmgen.IDIV, # valid?
- 'uint_truediv': None, # TODO
- 'uint_floordiv': jvmgen.IDIV, # valid?
+ 'uint_mul': jvmgen.PYPYUINTMUL,
+# 'uint_div': jvmgen.IDIV, # valid?
+# 'uint_truediv': None, # TODO
+ 'uint_floordiv': jvmgen.PYPYUINTDIV,
'uint_mod': jvmgen.PYPYUINTMOD,
'uint_lt': 'u_less_than',
'uint_le': 'u_less_equals',
Modified: pypy/dist/pypy/translator/jvm/src/pypy/PyPy.java
==============================================================================
--- pypy/dist/pypy/translator/jvm/src/pypy/PyPy.java (original)
+++ pypy/dist/pypy/translator/jvm/src/pypy/PyPy.java Sat Sep 1 14:28:46 2007
@@ -73,6 +73,20 @@
return (int)modulo;
}
+ public static int uint_mul(int x, int y)
+ {
+ long xx = uint_to_long(x);
+ long yy = uint_to_long(y);
+ return long_to_uint(xx * yy);
+ }
+
+ public static int uint_div(int x, int y)
+ {
+ long xx = uint_to_long(x);
+ long yy = uint_to_long(y);
+ return long_to_uint(xx / yy);
+ }
+
public static long ulong_mod(long x, long y) {
double dx = ulong_to_double(x);
double modulo = Math.IEEEremainder(dx, y);
@@ -113,14 +127,7 @@
public static final double BITS16 = (double)0xFFFF;
public static double uint_to_double(int value) {
- if (value >= 0)
- return value;
- else {
- long loword = value & 0xFFFF;
- long hiword = value >>> 16;
- double result = (hiword << 16) | loword;
- return result;
- }
+ return (double)uint_to_long(value);
}
public static double ulong_to_double(long value) {
@@ -137,13 +144,24 @@
public static int double_to_uint(double value) {
if (value <= Integer.MAX_VALUE)
return (int)value;
+ return long_to_uint((long)value);
+ }
- long v = (long)value;
- int loword = (int)(v & 0xFFFF);
- int hiword = (int)(v >>> 16);
+ public static int long_to_uint(long value)
+ {
+ int loword = (int)(value & 0xFFFF);
+ int hiword = (int)(value >>> 16);
return (hiword << 16) | loword;
}
+ public static long uint_to_long(int value)
+ {
+ long loword = value & 0xFFFF;
+ long hiword = value >>> 16;
+ long res = (hiword << 16) | loword;
+ return res;
+ }
+
public static long double_to_long(double value)
{
//if (value <= LONG_MAX)
@@ -259,12 +277,8 @@
public static String serialize_uint(int i) {
if (i >= 0)
return Integer.toString(i);
- else {
- long loword = i & 0xFFFF;
- long hiword = i >>> 16;
- long res = (hiword << 16) | loword;
- return Long.toString(res);
- }
+ else
+ return Long.toString(uint_to_long(i));
}
public static String serialize_ulonglong(long value)
Modified: pypy/dist/pypy/translator/jvm/test/test_op.py
==============================================================================
--- pypy/dist/pypy/translator/jvm/test/test_op.py (original)
+++ pypy/dist/pypy/translator/jvm/test/test_op.py Sat Sep 1 14:28:46 2007
@@ -6,9 +6,6 @@
class TestOperations(JvmTest, BaseTestOperations):
- def test_operations(self):
- py.test.skip("Backend lacks appropriate precision")
-
def test_abs(self):
py.test.skip("Backend lacks appropriate precision")
More information about the pypy-svn
mailing list