summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2018-04-10 19:39:50 +0200
committerAndy Wingo <wingo@pobox.com>2018-04-10 19:39:50 +0200
commitb9f7621e132873f9aa2dc198e1f428f959ce93ab (patch)
tree46b98a841514ea9db591ed4aaefc42455d9f2e7c
parent59f1f5a6a70ee2077a40686aa9a10e3ba045a07f (diff)
Add scm->f64 intrinsic
* libguile/vm-engine.c (call-f64<-scm): New intrinsic kind. (scm->f64): Disable instruction. * libguile/intrinsics.h (SCM_FOR_ALL_VM_INTRINSICS): * libguile/intrinsics.c (scm_bootstrap_intrinsics): * module/language/cps/reify-primitives.scm (compute-known-primitives): * module/system/vm/assembler.scm (define-f64<-scm-intrinsic): Add scm->f64.
-rw-r--r--libguile/intrinsics.c1
-rw-r--r--libguile/intrinsics.h2
-rw-r--r--libguile/vm-engine.c26
-rw-r--r--module/language/cps/reify-primitives.scm1
-rw-r--r--module/system/vm/assembler.scm6
5 files changed, 27 insertions, 9 deletions
diff --git a/libguile/intrinsics.c b/libguile/intrinsics.c
index 8bb99472e..0814b0d22 100644
--- a/libguile/intrinsics.c
+++ b/libguile/intrinsics.c
@@ -91,6 +91,7 @@ scm_bootstrap_intrinsics (void)
scm_vm_intrinsics.string_to_symbol = scm_string_to_symbol;
scm_vm_intrinsics.symbol_to_keyword = scm_symbol_to_keyword;
scm_vm_intrinsics.class_of = scm_class_of;
+ scm_vm_intrinsics.scm_to_f64 = scm_to_double;
scm_c_register_extension ("libguile-" SCM_EFFECTIVE_VERSION,
"scm_init_intrinsics",
diff --git a/libguile/intrinsics.h b/libguile/intrinsics.h
index a70669a92..b14bb4761 100644
--- a/libguile/intrinsics.h
+++ b/libguile/intrinsics.h
@@ -27,6 +27,7 @@ typedef SCM (*scm_t_scm_from_scm_scm_intrinsic) (SCM, SCM);
typedef SCM (*scm_t_scm_from_scm_uimm_intrinsic) (SCM, scm_t_uint8);
typedef void (*scm_t_scm_u64_u64_intrinsic) (SCM, scm_t_uint64, scm_t_uint64);
typedef SCM (*scm_t_scm_from_scm_intrinsic) (SCM);
+typedef double (*scm_t_f64_from_scm_intrinsic) (SCM);
#define SCM_FOR_ALL_VM_INTRINSICS(M) \
M(scm_from_scm_scm, add, "add", ADD) \
@@ -46,6 +47,7 @@ typedef SCM (*scm_t_scm_from_scm_intrinsic) (SCM);
M(scm_from_scm, string_to_symbol, "string->symbol", STRING_TO_SYMBOL) \
M(scm_from_scm, symbol_to_keyword, "symbol->keyword", SYMBOL_TO_KEYWORD) \
M(scm_from_scm, class_of, "class-of", CLASS_OF) \
+ M(f64_from_scm, scm_to_f64, "scm->f64", SCM_TO_F64) \
/* Add new intrinsics here; also update scm_bootstrap_intrinsics. */
enum scm_vm_intrinsic
diff --git a/libguile/vm-engine.c b/libguile/vm-engine.c
index 691be9a3a..b936cdc6f 100644
--- a/libguile/vm-engine.c
+++ b/libguile/vm-engine.c
@@ -1563,7 +1563,23 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
NEXT (2);
}
- VM_DEFINE_OP (55, unused_55, NULL, NOP)
+ VM_DEFINE_OP (55, call_f64_from_scm, "call-f64<-scm", OP2 (X8_S12_S12, C32) | OP_DST)
+ {
+ scm_t_uint8 dst, src;
+ double res;
+ scm_t_f64_from_scm_intrinsic intrinsic;
+
+ UNPACK_12_12 (op, dst, src);
+ intrinsic = intrinsics[ip[1]];
+
+ SYNC_IP ();
+ res = intrinsic (SP_REF (src));
+ CACHE_SP ();
+ SP_SET_F64 (dst, res);
+
+ NEXT (2);
+ }
+
VM_DEFINE_OP (56, unused_56, NULL, NOP)
{
vm_error_bad_instruction (op);
@@ -2219,13 +2235,7 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
abort (); /* never reached */
}
- /* scm->f64 dst:12 src:12
- *
- * Unpack a raw double-precision floating-point value from SRC and
- * place it in DST. Note that SRC can be any value on which
- * scm_to_double can operate.
- */
- VM_DEFINE_OP (136, scm_to_f64, "scm->f64", OP1 (X8_S12_S12) | OP_DST)
+ VM_DEFINE_OP (136, unused_136, NULL, NOP)
{
scm_t_uint16 dst, src;
UNPACK_12_12 (op, dst, src);
diff --git a/module/language/cps/reify-primitives.scm b/module/language/cps/reify-primitives.scm
index 6f09024af..add6271c9 100644
--- a/module/language/cps/reify-primitives.scm
+++ b/module/language/cps/reify-primitives.scm
@@ -217,6 +217,7 @@
string->symbol
symbol->keyword
class-of
+ scm->f64
u64->s64
s64->u64
cache-current-module!
diff --git a/module/system/vm/assembler.scm b/module/system/vm/assembler.scm
index f1c2db220..0c43ce6e7 100644
--- a/module/system/vm/assembler.scm
+++ b/module/system/vm/assembler.scm
@@ -200,6 +200,7 @@
emit-string->symbol
emit-symbol->keyword
emit-class-of
+ emit-scm->f64
emit-call
emit-call-label
@@ -261,7 +262,6 @@
emit-srsh/immediate
emit-ulsh/immediate
emit-make-array
- emit-scm->f64
emit-load-f64
emit-f64->scm
emit-scm->u64
@@ -1294,6 +1294,9 @@ returned instead."
(define-syntax-rule (define-scm<-scm-intrinsic name)
(define-macro-assembler (name asm dst src)
(emit-call-scm<-scm asm dst src (intrinsic-name->index 'name))))
+(define-syntax-rule (define-f64<-scm-intrinsic name)
+ (define-macro-assembler (name asm dst src)
+ (emit-call-f64<-scm asm dst src (intrinsic-name->index 'name))))
(define-scm<-scm-scm-intrinsic add)
(define-scm<-scm-uimm-intrinsic add/immediate)
@@ -1312,6 +1315,7 @@ returned instead."
(define-scm<-scm-intrinsic string->symbol)
(define-scm<-scm-intrinsic symbol->keyword)
(define-scm<-scm-intrinsic class-of)
+(define-f64<-scm-intrinsic scm->f64)
(define-macro-assembler (begin-program asm label properties)
(emit-label asm label)