[pypy-dev] Floating point computation
Hi pypy list, I'd like to prototype an interpreter in rpython. But this interpreter must feature floating point support. Something like the context in the decimal module of python : (decimal is basically a floating point unit in python) import decimal # do an operation decimal.Decimal(6e4565465) * decimal.Decimal(6e67654) # Verify overflow decimal.getcontext().flags[decimal.Overflow] # leads 1 = overflow ! My interpreter must provide access to the flags field (OverFlow, Inexact, DivisionByZero...) Currently I have a prototype in c and I directly use the intrinsics of X86 (sse2) to retrieve theses flags : // compute a sqrt using intrinsics __builtin_ia32_sqrtss(...); // get status register of sse2 fpu int mxcsr = __builtin_ia32_stmxcsr(); // extract overflow bit : overflow = (mxcsr 0x8); // extract ... If I want to implement this in rpython, I see 2 solutions : 1. Porting decimal to rpython : seems to be a lot of work and I wonder about the performances. 2. Wrapping floating in a c library and use ctype : code clarity and jit integration will be bad. Do you see another possibility ? Any advices on this ? Thanks ! Zariko. ___ pypy-dev mailing list pypy-dev@python.org http://mail.python.org/mailman/listinfo/pypy-dev
Re: [pypy-dev] Floating point computation
Hi, On Fri, Jul 1, 2011 at 2:57 PM, Maciej Fijalkowski fij...@gmail.com wrote: But it won't become an assembler instruction in the JIT, it'll still be a call. Indeed. But fixing this is not too hard. Grep for math_sqrt and MATH_SQRT in pypy/jit/*/*.py for an example of how we turn sqrt_nonneg(x) into a single assembler instruction. The function sqrt_nonneg() is defined in pypy/rpython/lltypesystem/module/ll_math.py, and is (indirectly) used when we call math.sqrt() in RPython. Of course if the idea introduced by math_sqrt is going to be used for a lot of other functions, like the ones you'll need to introduce, then we can also think of a general solution that would do mostly everything for you with just a keyword argument to llexternal(). A bientôt, Armin. ___ pypy-dev mailing list pypy-dev@python.org http://mail.python.org/mailman/listinfo/pypy-dev
Re: [pypy-dev] stuck with translation error
Hi Amaury, [v1 = call_args((function free), ((1, ('flavor', 'track_... False)), v0, ('raw'), (False)), v2 = simple_call((type error), ('out of resources'))] Hm, it can also be the next operation: v2 = simple_call((type error), ('out of resources')) I was under the impression that that was a standard error, but then again that would have been for malloc(), not free(). I searched again and came up with is code in ll_thread.py: def allocate_ll_lock(): # track_allocation=False here; be careful to lltype.free() it. The # reason it is set to False is that we get it from all app-level # lock objects, as well as from the GIL, which exists at shutdown. ll_lock = lltype.malloc(TLOCKP.TO, flavor='raw', track_allocation=False) res = c_thread_lock_init(ll_lock) if rffi.cast(lltype.Signed, res) = 0: lltype.free(ll_lock, flavor='raw', track_allocation=False) raise error(out of resources) return ll_lock which looks very much like it (the link to the exit is a raise). So I think that it isn't my code that doesn't translate. :) Beats me then, why it would bite me. What is this error object? Some local exception class? I can look again in a half an hour: I had just restarted the translation after a removing some of my recent changes. But I'll bet it's what I see here above in allocate_ll_lock. The module ll_thread.py defines: class error(Exception): pass Thanks, Wim -- wlavrij...@lbl.gov--+1 (510) 486 6411--www.lavrijsen.net ___ pypy-dev mailing list pypy-dev@python.org http://mail.python.org/mailman/listinfo/pypy-dev