wingo pushed a commit to branch master
in repository guile.

commit 25a0fe8839358814c7c16e6ca8237b99b64cde0b
Author: Andy Wingo <wi...@pobox.com>
Date:   Thu Apr 12 17:10:35 2018 +0200

    logsub is intrinsic
    
    * libguile/intrinsics.h:
    * libguile/intrinsics.c (logsub): New intrinsic.
      (scm_bootstrap_intrinsics): Init new intrinsic.
    * libguile/vm-engine.c (logsub): Disable.
    * module/language/cps/reify-primitives.scm (compute-known-primitives):
      Add logsub.
    * module/system/vm/assembler.scm: Update logsub intrinsic assembler.
---
 libguile/intrinsics.c                    | 17 +++++++++++++++++
 libguile/intrinsics.h                    |  1 +
 libguile/vm-engine.c                     |  6 +-----
 module/language/cps/reify-primitives.scm |  1 +
 module/system/vm/assembler.scm           |  3 ++-
 5 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/libguile/intrinsics.c b/libguile/intrinsics.c
index a200995..e323691 100644
--- a/libguile/intrinsics.c
+++ b/libguile/intrinsics.c
@@ -80,6 +80,22 @@ scm_to_uint64_truncate (SCM x)
     return scm_to_uint64 (scm_logand (x, scm_from_uint64 ((scm_t_uint64) -1)));
 }
 
+static SCM
+logsub (SCM x, SCM y)
+{
+  if (SCM_I_INUMP (x) && SCM_I_INUMP (y))
+    {
+      scm_t_signed_bits a, b;
+
+      a = SCM_I_INUM (x);
+      b = SCM_I_INUM (y);
+
+      return SCM_I_MAKINUM (a & ~b);
+    }
+
+  return scm_logand (x, scm_lognot (y));
+}
+
 void
 scm_bootstrap_intrinsics (void)
 {
@@ -106,6 +122,7 @@ scm_bootstrap_intrinsics (void)
   scm_vm_intrinsics.scm_to_s64 = scm_to_int64;
   scm_vm_intrinsics.u64_to_scm = scm_from_uint64;
   scm_vm_intrinsics.s64_to_scm = scm_from_int64;
+  scm_vm_intrinsics.logsub = logsub;
 
   scm_c_register_extension ("libguile-" SCM_EFFECTIVE_VERSION,
                             "scm_init_intrinsics",
diff --git a/libguile/intrinsics.h b/libguile/intrinsics.h
index c935920..331e12a 100644
--- a/libguile/intrinsics.h
+++ b/libguile/intrinsics.h
@@ -57,6 +57,7 @@ typedef SCM (*scm_t_scm_from_s64_intrinsic) (scm_t_int64);
   M(s64_from_scm, scm_to_s64, "scm->s64", SCM_TO_S64) \
   M(scm_from_u64, u64_to_scm, "u64->scm", U64_TO_SCM) \
   M(scm_from_s64, s64_to_scm, "s64->scm", S64_TO_SCM) \
+  M(scm_from_scm_scm, logsub, "logsub", LOGSUB) \
   /* 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 e131503..dc61982 100644
--- a/libguile/vm-engine.c
+++ b/libguile/vm-engine.c
@@ -2564,11 +2564,7 @@ VM_NAME (scm_i_thread *thread, struct scm_vm *vp,
       NEXT (1);
     }
 
-  /* logsub dst:8 a:8 b:8
-   *
-   * Place the bitwise AND of A and the bitwise NOT of B into DST.
-   */
-  VM_DEFINE_OP (161, logsub, "logsub", OP1 (X8_S8_S8_S8) | OP_DST)
+  VM_DEFINE_OP (161, unused_161, NULL, NOP)
     {
       ARGS2 (x, y);
 
diff --git a/module/language/cps/reify-primitives.scm 
b/module/language/cps/reify-primitives.scm
index b9551e8..fb5858c 100644
--- a/module/language/cps/reify-primitives.scm
+++ b/module/language/cps/reify-primitives.scm
@@ -224,6 +224,7 @@
       logand
       logior
       logxor
+      logsub
       string-set!
       string->number
       string->symbol
diff --git a/module/system/vm/assembler.scm b/module/system/vm/assembler.scm
index fe3f910..6d97d60 100644
--- a/module/system/vm/assembler.scm
+++ b/module/system/vm/assembler.scm
@@ -195,6 +195,7 @@
             emit-logand
             emit-logior
             emit-logxor
+            emit-logsub
             emit-string-set!
             emit-string->number
             emit-string->symbol
@@ -255,7 +256,6 @@
             emit-uadd/immediate
             emit-usub/immediate
             emit-umul/immediate
-            emit-logsub
             emit-ulogand
             emit-ulogior
             emit-ulogxor
@@ -1321,6 +1321,7 @@ returned instead."
 (define-scm<-scm-scm-intrinsic logand)
 (define-scm<-scm-scm-intrinsic logior)
 (define-scm<-scm-scm-intrinsic logxor)
+(define-scm<-scm-scm-intrinsic logsub)
 (define-scm-u64-u64-intrinsic string-set!)
 (define-scm<-scm-intrinsic string->number)
 (define-scm<-scm-intrinsic string->symbol)

Reply via email to