[pypy-svn] r10408 - in pypy/dist/pypy/translator/llvm: . test

cfbolz at codespeak.net cfbolz at codespeak.net
Thu Apr 7 18:05:40 CEST 2005


Author: cfbolz
Date: Thu Apr  7 18:05:40 2005
New Revision: 10408

Modified:
   pypy/dist/pypy/translator/llvm/funcrepr.py
   pypy/dist/pypy/translator/llvm/operations.ll
   pypy/dist/pypy/translator/llvm/representation.py
   pypy/dist/pypy/translator/llvm/test/llvmsnippet.py
   pypy/dist/pypy/translator/llvm/test/test_genllvm.py
   pypy/dist/pypy/translator/llvm/typerepr.py
Log:
Some support for doubles/floats in genllvm.

Modified: pypy/dist/pypy/translator/llvm/funcrepr.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/funcrepr.py	(original)
+++ pypy/dist/pypy/translator/llvm/funcrepr.py	Thu Apr  7 18:05:40 2005
@@ -28,7 +28,8 @@
 C_SIMPLE_TYPES = {annmodel.SomeChar: "char",
                   annmodel.SomeString: "char*",
                   annmodel.SomeBool: "unsigned char",
-                  annmodel.SomeInteger: "int"}
+                  annmodel.SomeInteger: "int",
+                  annmodel.SomeFloat: "double"}
 
 
 class BuiltinFunctionRepr(LLVMRepr):

Modified: pypy/dist/pypy/translator/llvm/operations.ll
==============================================================================
--- pypy/dist/pypy/translator/llvm/operations.ll	(original)
+++ pypy/dist/pypy/translator/llvm/operations.ll	Thu Apr  7 18:05:40 2005
@@ -72,6 +72,109 @@
 	ret int %r
 }
 
+;Basic operations for doubles
+internal double %std.add(double %a, double %b) {
+	%r = add double %a, %b
+	ret double %r
+}
+
+internal double %std.inplace_add(double %a, double %b) {
+	%r = add double %a, %b	
+	ret double %r
+}
+
+internal double %std.sub(double %a, double %b) {
+	%r = sub double %a, %b
+	ret double %r
+}
+
+internal double %std.inplace_sub(double %a, double %b) {
+	%r = sub double %a, %b
+	ret double %r
+}
+
+internal double %std.mul(double %a, double %b) {
+	%r = mul double %a, %b	
+	ret double %r
+}
+
+internal double %std.inplace_mul(double %a, double %b) {
+	%r = mul double %a, %b
+	ret double %r
+}
+
+internal double %std.div(double %a, double %b) {
+	%r = div double %a, %b
+	ret double %r
+}
+
+internal double %std.inplace_div(double %a, double %b) {
+	%r = div double %a, %b
+	ret double %r
+}
+
+internal double %std.floordiv(double %a, double %b) {
+	%r = div double %a, %b
+	ret double %r
+}
+
+internal double %std.inplace_floordiv(double %a, double %b) {
+	%r = div double %a, %b
+	ret double %r
+}
+
+internal double %std.mod(double %a, double %b) {
+	%r = rem double %a, %b	
+	ret double %r
+}
+
+internal double %std.inplace_mod(double %a, double %b) {
+	%r = rem double %a, %b	
+	ret double %r
+}
+
+;Basic comparisons for doubles
+
+internal bool %std.is(double %a, double %b) {
+	%r = seteq double %a, %b
+	ret bool %r
+}
+
+internal bool %std.is_true(double %a) {
+	%b = cast double %a to bool
+	ret bool %b
+}
+
+internal bool %std.eq(double %a, double %b) {
+	%r = seteq double %a, %b	
+	ret bool %r
+}
+
+internal bool %std.neq(double %a, double %b) {
+	%r = seteq double %a, %b	
+	%r1 = xor bool %r, true
+	ret bool %r1
+}
+
+internal bool %std.lt(double %a, double %b) {
+	%r = setlt double %a, %b	
+	ret bool %r
+}
+
+internal bool %std.gt(double %a, double %b) {
+	%r = setgt double %a, %b	
+	ret bool %r
+}
+
+internal bool %std.le(double %a, double %b) {
+	%r = setle double %a, %b	
+	ret bool %r
+}
+
+internal bool %std.ge(double %a, double %b) {
+	%r = setge double %a, %b	
+	ret bool %r
+}
 
 ;Basic comparisons for ints
 

Modified: pypy/dist/pypy/translator/llvm/representation.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/representation.py	(original)
+++ pypy/dist/pypy/translator/llvm/representation.py	Thu Apr  7 18:05:40 2005
@@ -6,7 +6,8 @@
 from pypy.annotation import model as annmodel
 
 LLVM_SIMPLE_TYPES = {annmodel.SomeChar: "sbyte",
-                     annmodel.SomeBool: "bool"}
+                     annmodel.SomeBool: "bool",
+                     annmodel.SomeFloat: "double"}
 
 debug = False
 

Modified: pypy/dist/pypy/translator/llvm/test/llvmsnippet.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/test/llvmsnippet.py	(original)
+++ pypy/dist/pypy/translator/llvm/test/llvmsnippet.py	Thu Apr  7 18:05:40 2005
@@ -42,6 +42,12 @@
         return calling1(m - 1)
     return m
 
+#float snippets
+
+def float_f1(x):
+    return x + 1.0
+
+
 #array snippets
 
 def array_simple():

Modified: pypy/dist/pypy/translator/llvm/test/test_genllvm.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/test/test_genllvm.py	(original)
+++ pypy/dist/pypy/translator/llvm/test/test_genllvm.py	Thu Apr  7 18:05:40 2005
@@ -116,6 +116,16 @@
         f = compile_function(llvmsnippet.calling1, [int])
         assert f(10) == 1
 
+class TestFloat(object):
+    def setup_method(self, method):
+        if not llvm_found:
+            py.test.skip("llvm-as not found on path.")
+
+    def test_float_f1(self):
+        f = compile_function(llvmsnippet.float_f1, [float])
+        assert f(1.0) == 2.0
+    
+
 class TestLLVMArray(object):
     def setup_method(self, method):
         if not llvm_found:

Modified: pypy/dist/pypy/translator/llvm/typerepr.py
==============================================================================
--- pypy/dist/pypy/translator/llvm/typerepr.py	(original)
+++ pypy/dist/pypy/translator/llvm/typerepr.py	Thu Apr  7 18:05:40 2005
@@ -126,12 +126,10 @@
         lblock.cast(l_tmp, l_val, l_type)
         return l_tmp
 
-
 class SimpleTypeRepr(TypeRepr):
     def get(obj, gen):
-        if obj.__class__ is annmodel.SomeInteger:
-            l_repr = SimpleTypeRepr("int", gen)
-            return l_repr
+        if obj.__class__ is annmodel.SomeFloat:
+            return SimpleTypeRepr("double", gen)
         elif obj.__class__ is annmodel.SomeBool:
             l_repr = SimpleTypeRepr("bool", gen)
             return l_repr



More information about the Pypy-commit mailing list