| 1 |
""" |
| 2 |
Support for 'long long' on 32-bits: this is done by casting all floats |
| 3 |
to long longs, and using long longs systematically. |
| 4 |
|
| 5 |
On 64-bit platforms, we use float directly to avoid the cost of |
| 6 |
converting them back and forth. |
| 7 |
""" |
| 8 |
|
| 9 |
import sys |
| 10 |
from rpython.rtyper.lltypesystem import lltype, rffi |
| 11 |
from rpython.rlib import rarithmetic, longlong2float |
| 12 |
from rpython.rlib.objectmodel import compute_hash |
| 13 |
|
| 14 |
|
| 15 |
if sys.maxint > 2147483647: |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
is_64_bit = True |
| 21 |
supports_longlong = False |
| 22 |
r_float_storage = float |
| 23 |
FLOATSTORAGE = lltype.Float |
| 24 |
|
| 25 |
getfloatstorage = lambda x: x |
| 26 |
getrealfloat = lambda x: x |
| 27 |
gethash = compute_hash |
| 28 |
gethash_fast = longlong2float.float2longlong |
| 29 |
extract_bits = longlong2float.float2longlong |
| 30 |
is_longlong = lambda TYPE: False |
| 31 |
|
| 32 |
|
| 33 |
else: |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
is_64_bit = False |
| 38 |
supports_longlong = True |
| 39 |
r_float_storage = rarithmetic.r_longlong |
| 40 |
FLOATSTORAGE = lltype.SignedLongLong |
| 41 |
|
| 42 |
getfloatstorage = longlong2float.float2longlong |
| 43 |
getrealfloat = longlong2float.longlong2float |
| 44 |
gethash = lambda xll: rarithmetic.intmask(xll - (xll >> 32)) |
| 45 |
gethash_fast = gethash |
| 46 |
extract_bits = lambda x: x |
| 47 |
is_longlong = lambda TYPE: (TYPE is lltype.SignedLongLong or |
| 48 |
TYPE is lltype.UnsignedLongLong) |
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
ZEROF = getfloatstorage(0.0) |
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
def int2singlefloat(x): |
| 57 |
x = rffi.r_uint(x) |
| 58 |
return longlong2float.uint2singlefloat(x) |
| 59 |
|
| 60 |
def singlefloat2int(x): |
| 61 |
x = longlong2float.singlefloat2uint(x) |
| 62 |
return rffi.cast(lltype.Signed, x) |