summaryrefslogtreecommitdiffstats
path: root/itypes.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-01-25 07:06:05 -0800
committerKaz Kylheku <kaz@kylheku.com>2019-01-25 07:06:05 -0800
commit543f15cdc6b77f31639d87081b35aae3f1caf84a (patch)
tree71087ef24f5655e451a5de1aedaa6e368ab20421 /itypes.c
parent4b789435f8e4bb6ec9ea4bab3d0a109682adafa6 (diff)
downloadtxr-543f15cdc6b77f31639d87081b35aae3f1caf84a.tar.gz
txr-543f15cdc6b77f31639d87081b35aae3f1caf84a.tar.bz2
txr-543f15cdc6b77f31639d87081b35aae3f1caf84a.zip
itypes: take advantage of double_intptr_t.
If double_intptr_t is at least 64 bits wide (which is always going to be true) we can take advantage of it. * itypes.c (c_i64, c_u64): Provide implementations that use the new dbl_intptr_t and dbl_uintptr_t infrastructure. The fallback implementation that uses ash and logior is basically not used now. (num_64, unum_64): New functions for obtaining a Lisp value from a 64 bit number, abstracting whether this is done via the cnum or dbl_cnum route. * itypes.h (u64_t, i64_t): Define in terms of double_uintptr_t and double_intptr_t, if no other 64 bit type is available. (num_64, unum_64): Declared.
Diffstat (limited to 'itypes.c')
-rw-r--r--itypes.c48
1 files changed, 47 insertions, 1 deletions
diff --git a/itypes.c b/itypes.c
index 5c1e3e69..d9aa7aaa 100644
--- a/itypes.c
+++ b/itypes.c
@@ -98,7 +98,8 @@ u32_t c_u32(val n, val self)
#endif
#if HAVE_I64
-#if CHAR_BIT * SIZEOF_PTR == 64
+
+#if CHAR_BIT * SIZEOF_PTR >= 64
i64_t c_i64(val n, val self)
{
cnum v = c_num(n);
@@ -116,6 +117,24 @@ u64_t c_u64(val n, val self)
self, n, nao);
return v;
}
+#elif HAVE_DOUBLE_INTPTR_T && CHAR_BIT * SIZEOF_DOUBLE_INTPTR >= 64
+i64_t c_i64(val n, val self)
+{
+ dbl_cnum v = c_dbl_num(n);
+ if (v < (- (dbl_cnum) 0x7FFFFFFFFFFFFFFF - 1) || v > (dbl_cnum) 0x7FFFFFFFFFFFFFFF)
+ uw_throwf(error_s, lit("~a: value ~s is out of signed 64 bit range"),
+ self, n, nao);
+ return v;
+}
+
+u64_t c_u64(val n, val self)
+{
+ dbl_ucnum v = c_dbl_unum(n);
+ if (v > (dbl_ucnum) 0xFFFFFFFFFFFFFFFF)
+ uw_throwf(error_s, lit("~a: value ~s is out of unsigned 64 bit range"),
+ self, n, nao);
+ return v;
+}
#else
i64_t c_i64(val n, val self)
{
@@ -131,6 +150,33 @@ u64_t c_u64(val n, val self)
return convert(u64_t, c_u32(high32, self)) << 32 | c_u32(low32, self);
}
#endif
+
+val num_64(i64_t n)
+{
+#if CHAR_BIT * SIZEOF_PTR >= 64
+ return num(n);
+#elif HAVE_DOUBLE_INTPTR_T && CHAR_BIT * SIZEOF_DOUBLE_INTPTR >= 64
+ return normalize(bignum_dbl_ipt(n));
+#else
+ cnum hi32 = n >> 32;
+ ucnum lo32 = n & 0xFFFFFFFFU;
+ return logior(ash(num(hi32), num_fast(32)), unum(lo32));
+#endif
+}
+
+val unum_64(u64_t n)
+{
+#if CHAR_BIT * SIZEOF_PTR >= 64
+ return unum(n);
+#elif HAVE_DOUBLE_INTPTR_T && CHAR_BIT * SIZEOF_DOUBLE_INTPTR >= 64
+ return normalize(bignum_dbl_uipt(n));
+#else
+ ucnum hi32 = n >> 32;
+ ucnum lo32 = n & 0xFFFFFFFFU;
+ return logior(ash(unum(hi32), num_fast(32)), unum(lo32));
+#endif
+}
+
#endif
char c_char(val n, val self)