[pypy-svn] r16448 - in pypy/dist/pypy/translator/llvm2: module test

rxe at codespeak.net rxe at codespeak.net
Thu Aug 25 11:21:17 CEST 2005


Author: rxe
Date: Thu Aug 25 11:21:15 2005
New Revision: 16448

Modified:
   pypy/dist/pypy/translator/llvm2/module/ll_math.py
   pypy/dist/pypy/translator/llvm2/module/support.py
   pypy/dist/pypy/translator/llvm2/test/test_extfunc.py
Log:
Generated code to make test_math_frexp work.  Added helpers
prepare_and_raise_xxx llvm functions to be called from c code
(once compiled to llvm).




Modified: pypy/dist/pypy/translator/llvm2/module/ll_math.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/module/ll_math.py	(original)
+++ pypy/dist/pypy/translator/llvm2/module/ll_math.py	Thu Aug 25 11:21:15 2005
@@ -47,12 +47,12 @@
     for function in functions:
         extfunctions["%ll_math_" + function] = ((), simple_function_template % locals())
 
-extfunctions["%ll_math_frexp"] = (("%__debug",), """
-internal fastcc %RPyFREXP_RESULT* %ll_math_frexp(double %x) {
-    call fastcc void %__debug([12 x sbyte]* %__ll_math_frexp) ; XXX: TODO: ll_math_frexp
-    ret %RPyFREXP_RESULT* null
-}
-""")
+#extfunctions["%ll_math_frexp"] = (("%__debug",), """
+#internal fastcc %RPyFREXP_RESULT* %ll_math_frexp(double %x) {
+#    call fastcc void %__debug([12 x sbyte]* %__ll_math_frexp) ; XXX: TODO: ll_math_frexp
+#    ret %RPyFREXP_RESULT* null
+#}
+#""")
 
 extfunctions["%ll_math_hypot"] = (("%__debug",), """
 internal fastcc double %ll_math_hypot(double %x, double %y) {
@@ -81,3 +81,122 @@
     ret double 0.0
 }
 """)
+#;;;XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
+
+
+extfunctions["%ll_math_frexp"] = (("%prepare_and_raise_OverflowError",
+                                   "%prepare_and_raise_ValueError"), """
+declare int* %__errno_location()
+
+internal fastcc int %ll_math_is_error(double %x) {  
+entry:
+	%x_addr = alloca double		 ; ty=double*
+	%result = alloca int		 ; ty=int*
+	store double %x, double* %x_addr
+	%tmp.0 = call int* ()* %__errno_location()		 ; ty=int*
+	%tmp.1 = load int* %tmp.0		 ; ty=int
+	%tmp.2 = seteq int %tmp.1, 34		 ; ty=bool
+	%tmp.3 = cast bool %tmp.2 to int		 ; ty=int
+	br bool %tmp.2, label %then.0, label %else
+then.0:
+	%tmp.4 = load double* %x_addr		 ; ty=double
+	%tmp.5 = seteq double %tmp.4, 0x0000000000000000		 ; ty=bool
+	%tmp.6 = cast bool %tmp.5 to int		 ; ty=int
+	br bool %tmp.5, label %then.1, label %endif.1
+then.1:
+	store int 0, int* %result
+	br label %return
+after_ret.0:
+	br label %endif.1
+endif.1:
+	call fastcc void (sbyte*)* %prepare_and_raise_OverflowError(sbyte* getelementptr ([17 x sbyte]* %.str_1, int 0, int 0))
+	br label %endif.0
+else:
+	call fastcc void (sbyte*)* %prepare_and_raise_ValueError(sbyte* getelementptr ([18 x sbyte]* %.str_2, int 0, int 0))
+	br label %endif.0
+endif.0:
+	store int 1, int* %result
+	br label %return
+after_ret.1:
+	br label %return
+return:
+	%tmp.9 = load int* %result		 ; ty=int
+	ret int %tmp.9
+}
+
+internal fastcc %RPyFREXP_RESULT* %ll_math_frexp(double %x) {  
+entry:
+	%x_addr = alloca double		 ; ty=double*
+	%result = alloca %RPyFREXP_RESULT*		 ; ty=%RPyFREXP_RESULT**
+	%expo = alloca int		 ; ty=int*
+	%m = alloca double		 ; ty=double*
+	store double %x, double* %x_addr
+	%tmp.0 = call int* ()* %__errno_location()		 ; ty=int*
+	store int 0, int* %tmp.0
+	%tmp.2 = load double* %x_addr		 ; ty=double
+	%tmp.1 = call double (double, int*)* %frexp(double %tmp.2, int* %expo)		 ; ty=double
+	store double %tmp.1, double* %m
+	%tmp.3 = call int* ()* %__errno_location()		 ; ty=int*
+	%tmp.4 = load int* %tmp.3		 ; ty=int
+	%tmp.5 = seteq int %tmp.4, 0		 ; ty=bool
+	%tmp.6 = cast bool %tmp.5 to int		 ; ty=int
+	br bool %tmp.5, label %shortcirc_next.0, label %shortcirc_done.0
+shortcirc_next.0:
+	%tmp.7 = load double* %m		 ; ty=double
+	%tmp.8 = setgt double %tmp.7, 0x7FEFFFFFFFFFFFFF		 ; ty=bool
+	%tmp.9 = cast bool %tmp.8 to int		 ; ty=int
+	br bool %tmp.8, label %shortcirc_done.1, label %shortcirc_next.1
+shortcirc_next.1:
+	%tmp.10 = load double* %m		 ; ty=double
+	%tmp.11 = setlt double %tmp.10, 0xFFEFFFFFFFFFFFFF		 ; ty=bool
+	%tmp.12 = cast bool %tmp.11 to int		 ; ty=int
+	br label %shortcirc_done.1
+shortcirc_done.1:
+	%shortcirc_val.0 = phi bool [ true, %shortcirc_next.0 ], [ %tmp.11, %shortcirc_next.1 ]		 ; ty=bool
+	%tmp.13 = cast bool %shortcirc_val.0 to int		 ; ty=int
+	br label %shortcirc_done.0
+shortcirc_done.0:
+	%shortcirc_val.1 = phi bool [ false, %entry ], [ %shortcirc_val.0, %shortcirc_done.1 ]		 ; ty=bool
+	%tmp.14 = cast bool %shortcirc_val.1 to int		 ; ty=int
+	br bool %shortcirc_val.1, label %then.0, label %endif.0
+then.0:
+	%tmp.15 = call int* ()* %__errno_location()		 ; ty=int*
+	store int 34, int* %tmp.15
+	br label %endif.0
+endif.0:
+	%tmp.16 = call int* ()* %__errno_location()		 ; ty=int*
+	%tmp.17 = load int* %tmp.16		 ; ty=int
+	%tmp.18 = setne int %tmp.17, 0		 ; ty=bool
+	%tmp.19 = cast bool %tmp.18 to int		 ; ty=int
+	br bool %tmp.18, label %shortcirc_next.2, label %shortcirc_done.2
+shortcirc_next.2:
+	%tmp.21 = load double* %m		 ; ty=double
+	%tmp.20 = call fastcc int (double)* %ll_math_is_error(double %tmp.21)		 ; ty=int
+	%tmp.22 = setne int %tmp.20, 0		 ; ty=bool
+	%tmp.23 = cast bool %tmp.22 to int		 ; ty=int
+	br label %shortcirc_done.2
+shortcirc_done.2:
+	%shortcirc_val.2 = phi bool [ false, %endif.0 ], [ %tmp.22, %shortcirc_next.2 ]		 ; ty=bool
+	%tmp.24 = cast bool %shortcirc_val.2 to int		 ; ty=int
+	br bool %shortcirc_val.2, label %then.1, label %endif.1
+then.1:
+	store %RPyFREXP_RESULT* null, %RPyFREXP_RESULT** %result
+	br label %return
+after_ret.0:
+	br label %endif.1
+endif.1:
+	%tmp.26 = load double* %m		 ; ty=double
+	%tmp.27 = load int* %expo		 ; ty=int
+	%tmp.25 = call fastcc %RPyFREXP_RESULT* (double, int)* %ll_frexp_result__Float_Signed(double %tmp.26, int %tmp.27)		 ; ty=%RPyFREXP_RESULT*
+	store %RPyFREXP_RESULT* %tmp.25, %RPyFREXP_RESULT** %result
+	br label %return
+after_ret.1:
+	br label %return
+return:
+	%tmp.28 = load %RPyFREXP_RESULT** %result		 ; ty=%RPyFREXP_RESULT*
+	ret %RPyFREXP_RESULT* %tmp.28
+}
+
+""")
+
+

Modified: pypy/dist/pypy/translator/llvm2/module/support.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/module/support.py	(original)
+++ pypy/dist/pypy/translator/llvm2/module/support.py	Thu Aug 25 11:21:15 2005
@@ -5,9 +5,12 @@
 declare ccc INT %strlen(sbyte*)
 declare ccc INT %strcmp(sbyte*, sbyte*)
 declare ccc sbyte* %memset(sbyte*, INT, UINT)
+declare ccc double %frexp(double, int*)
 
 %__print_debug_info         = internal global bool false
 %__print_debug_info_option  = internal constant [19 x sbyte] c"--print-debug-info\\00"
+%.str_1 = internal constant [17 x sbyte] c"math range error\\00"
+%.str_2 = internal constant [18 x sbyte] c"math domain error\\00"
 """
 
 
@@ -84,6 +87,7 @@
 """)
 
 
+
 #prepare exceptions
 for exc in "ZeroDivisionError OverflowError ValueError".split():    #_ZER _OVF _VAL
     extfunctions["%%__prepare_%(exc)s" % locals()] = ((), """
@@ -97,6 +101,20 @@
 }
 """ % locals())
 
+#prepare exceptions
+for exc in "ZeroDivisionError OverflowError ValueError".split():    #_ZER _OVF _VAL
+    extfunctions["%%prepare_and_raise_%(exc)s" % locals()] = ((), """
+internal fastcc void %%prepare_and_raise_%(exc)s(sbyte* %%msg) {
+    ;XXX %%msg not used right now!
+    %%exception_value = call fastcc %%RPYTHON_EXCEPTION* %%instantiate_%(exc)s()
+    %%tmp             = getelementptr %%RPYTHON_EXCEPTION* %%exception_value, int 0, uint 0
+    %%exception_type  = load %%RPYTHON_EXCEPTION_VTABLE** %%tmp
+    store %%RPYTHON_EXCEPTION_VTABLE* %%exception_type, %%RPYTHON_EXCEPTION_VTABLE** %%last_exception_type
+    store %%RPYTHON_EXCEPTION* %%exception_value, %%RPYTHON_EXCEPTION** %%last_exception_value
+    unwind
+}
+""" % locals())
+
 
 #error-checking-code
 

Modified: pypy/dist/pypy/translator/llvm2/test/test_extfunc.py
==============================================================================
--- pypy/dist/pypy/translator/llvm2/test/test_extfunc.py	(original)
+++ pypy/dist/pypy/translator/llvm2/test/test_extfunc.py	Thu Aug 25 11:21:15 2005
@@ -147,12 +147,13 @@
     assert f1()
 
 def test_math_frexp():
-    py.test.skip("ll_math_frexp not implemented")
     from math import frexp
     def fn(x):
-        return frexp(x)
+        res = frexp(x)
+        return res[0] + float(res[1])
     f = compile_function(fn, [float])
-    assert f(10.123) == frexp(10.123)
+    res = f(10.123)
+    assert res == fn(10.123)
 
 def test_math_modf():
     py.test.skip("ll_math_modf not implemented (next)")



More information about the Pypy-commit mailing list