[pypy-svn] r68281 - in pypy/trunk/pypy: jit/backend/cli jit/backend/cli/test jit/metainterp/test translator/cli/src
antocuni at codespeak.net
antocuni at codespeak.net
Fri Oct 9 17:02:24 CEST 2009
Author: antocuni
Date: Fri Oct 9 17:02:24 2009
New Revision: 68281
Modified:
pypy/trunk/pypy/jit/backend/cli/method.py
pypy/trunk/pypy/jit/backend/cli/methodfactory.py
pypy/trunk/pypy/jit/backend/cli/runner.py
pypy/trunk/pypy/jit/backend/cli/test/test_basic.py
pypy/trunk/pypy/jit/backend/cli/test/test_runner.py
pypy/trunk/pypy/jit/metainterp/test/test_basic.py
pypy/trunk/pypy/translator/cli/src/pypylib.cs
Log:
add float supports to cli jit backend
Modified: pypy/trunk/pypy/jit/backend/cli/method.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/cli/method.py (original)
+++ pypy/trunk/pypy/jit/backend/cli/method.py Fri Oct 9 17:02:24 2009
@@ -6,7 +6,7 @@
from pypy.translator.cli.dotnet import CLR
from pypy.translator.cli import opcodes
from pypy.jit.metainterp import history
-from pypy.jit.metainterp.history import (AbstractValue, Const, ConstInt,
+from pypy.jit.metainterp.history import (AbstractValue, Const, ConstInt, ConstFloat,
ConstObj, BoxInt, LoopToken)
from pypy.jit.metainterp.resoperation import rop, opname
from pypy.jit.metainterp.typesystem import oohelper
@@ -32,6 +32,8 @@
if self.type == history.INT:
return dotnet.typeof(System.Int32)
+ elif self.type == history.FLOAT:
+ return dotnet.typeof(System.Double)
elif self.type == history.REF:
return dotnet.typeof(System.Object)
else:
@@ -68,6 +70,16 @@
meth.il.Emit(OpCodes.Ldc_I4, self.value)
+class __extend__(ConstFloat):
+ __metaclass__ = extendabletype
+
+ def load(self, meth):
+ # we cannot invoke il.Emit(Ldc_R8, self.value) directly because
+ # pythonnet would select the wrong overload. The C# version works
+ # arond it
+ Utils.Emit_Ldc_R8(meth.il, self.value);
+
+
class ConstFunction(Const):
def __init__(self, name):
@@ -274,6 +286,8 @@
t = dotnet.typeof(InputArgs)
if type == history.INT:
fieldname = 'ints'
+ elif type == history.FLOAT:
+ fieldname = 'floats'
elif type == history.REF:
fieldname = 'objs'
else:
@@ -739,6 +753,8 @@
lines.append('self.store_result(op)')
elif isinstance(instr, opcodes.PushArg):
lines.append('self.push_arg(op, %d)' % instr.n)
+ elif instr == 'ldc.r8 0':
+ lines.append('Utils.Emit_Ldc_R8(self.il, 0.0)')
else:
assert isinstance(instr, str), 'unknown instruction %s' % instr
if instr.startswith('call '):
@@ -751,6 +767,7 @@
src = body.putaround('def %s(self, op):' % methname)
dic = {'OpCodes': OpCodes,
'System': System,
+ 'Utils': Utils,
'dotnet': dotnet}
exec src.compile() in dic
return dic[methname]
Modified: pypy/trunk/pypy/jit/backend/cli/methodfactory.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/cli/methodfactory.py (original)
+++ pypy/trunk/pypy/jit/backend/cli/methodfactory.py Fri Oct 9 17:02:24 2009
@@ -71,7 +71,7 @@
def create_delegate(self, delegatetype, consts):
t = self.typeBuilder.CreateType()
methinfo = t.GetMethod("invoke")
-## if self.name == 'Loop #0(r1)_2':
+## if self.name == 'Loop1(r0)_1':
## assemblyData.auto_save_assembly.Save()
return System.Delegate.CreateDelegate(delegatetype,
consts,
Modified: pypy/trunk/pypy/jit/backend/cli/runner.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/cli/runner.py (original)
+++ pypy/trunk/pypy/jit/backend/cli/runner.py Fri Oct 9 17:02:24 2009
@@ -39,7 +39,8 @@
class CliCPU(model.AbstractCPU):
-
+
+ supports_floats = True
ts = oohelper
def __init__(self, rtyper, stats, translate_support_code=False,
@@ -139,6 +140,9 @@
def set_future_value_int(self, index, intvalue):
self.get_inputargs().set_int(index, intvalue)
+ def set_future_value_float(self, index, intvalue):
+ self.get_inputargs().set_float(index, intvalue)
+
def set_future_value_ref(self, index, objvalue):
obj = dotnet.cast_to_native_object(objvalue)
self.get_inputargs().set_obj(index, obj)
@@ -146,6 +150,9 @@
def get_latest_value_int(self, index):
return self.get_inputargs().get_int(index)
+ def get_latest_value_float(self, index):
+ return self.get_inputargs().get_float(index)
+
def get_latest_value_ref(self, index):
obj = self.get_inputargs().get_obj(index)
return dotnet.cast_from_native_object(obj)
Modified: pypy/trunk/pypy/jit/backend/cli/test/test_basic.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/cli/test/test_basic.py (original)
+++ pypy/trunk/pypy/jit/backend/cli/test/test_basic.py Fri Oct 9 17:02:24 2009
@@ -15,9 +15,6 @@
def skip(self):
py.test.skip("works only after translation")
- def _skip(self):
- py.test.skip("in-progress")
-
test_string = skip
test_chr2str = skip
test_unicode = skip
Modified: pypy/trunk/pypy/jit/backend/cli/test/test_runner.py
==============================================================================
--- pypy/trunk/pypy/jit/backend/cli/test/test_runner.py (original)
+++ pypy/trunk/pypy/jit/backend/cli/test/test_runner.py Fri Oct 9 17:02:24 2009
@@ -30,6 +30,9 @@
test_field_basic = skip
test_ooops = skip
+ def test_unused_result_float(self):
+ py.test.skip('fixme! max 32 inputargs so far')
+
def test_ovf_operations(self, reversed=False):
self.skip()
Modified: pypy/trunk/pypy/jit/metainterp/test/test_basic.py
==============================================================================
--- pypy/trunk/pypy/jit/metainterp/test/test_basic.py (original)
+++ pypy/trunk/pypy/jit/metainterp/test/test_basic.py Fri Oct 9 17:02:24 2009
@@ -493,6 +493,25 @@
res = self.meta_interp(f, [-5])
assert res == 5+4+3+2+1+0+1+2+3+4+5+6+7+8+9
+ def test_float(self):
+ myjitdriver = JitDriver(greens = [], reds = ['x', 'y', 'res'])
+ def f(x, y):
+ x = float(x)
+ y = float(y)
+ res = 0.0
+ while y > 0.0:
+ myjitdriver.can_enter_jit(x=x, y=y, res=res)
+ myjitdriver.jit_merge_point(x=x, y=y, res=res)
+ res += x
+ y -= 1.0
+ return res
+ res = self.meta_interp(f, [6, 7])
+ assert res == 42.0
+ self.check_loop_count(1)
+ self.check_loops({'guard_true': 1,
+ 'float_add': 1, 'float_sub': 1, 'float_gt': 1,
+ 'jump': 1})
+
def test_print(self):
myjitdriver = JitDriver(greens = [], reds = ['n'])
def f(n):
Modified: pypy/trunk/pypy/translator/cli/src/pypylib.cs
==============================================================================
--- pypy/trunk/pypy/translator/cli/src/pypylib.cs (original)
+++ pypy/trunk/pypy/translator/cli/src/pypylib.cs Fri Oct 9 17:02:24 2009
@@ -114,7 +114,7 @@
public class InputArgs {
public int[] ints = new int[32];
- public float[] floats = new float[32];
+ public double[] floats = new double[32];
public object[] objs = new object[32];
public object exc_value = null;
public int failed_op = -1;
@@ -129,6 +129,16 @@
ints[i] = n;
}
+ public double get_float(int i)
+ {
+ return floats[i];
+ }
+
+ public void set_float(int i, double n)
+ {
+ floats[i] = n;
+ }
+
public object get_obj(int i)
{
return objs[i];
@@ -163,7 +173,7 @@
public void ensure_floats(int n)
{
if (floats.Length < n)
- floats = new float[n];
+ floats = new double[n];
}
public void ensure_objs(int n)
@@ -402,6 +412,14 @@
return new DynamicMethod(name, res, args, typeof(Utils).Module);
}
+ // if you call il.Emit(OpCodes.Ldc_R8, mydouble) from pythonnet, it
+ // selects the wrong overload. To work around it, we call it from C# and
+ // live happy
+ public static void Emit_Ldc_R8(ILGenerator il, double val)
+ {
+ il.Emit(OpCodes.Ldc_R8, val);
+ }
+
public static object RuntimeNew(Type t)
{
return t.GetConstructor(new Type[0]).Invoke(new object[0]);
More information about the Pypy-commit
mailing list