unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
* wip-rtl native patch
@ 2012-08-09 18:59 Stefan Israelsson Tampe
  2013-01-21 13:21 ` Andy Wingo
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Israelsson Tampe @ 2012-08-09 18:59 UTC (permalink / raw)
  To: Andy Wingo; +Cc: guile-devel


[-- Attachment #1.1: Type: text/plain, Size: 1126 bytes --]

Hi,

DO you think that this will do as an initial patch to wip-rtl in order to
introduce the possibility to
execute native code or JIT:ed code. We reserve the first two indexes in the
ip text area to fit
a pointer to native code to be executed.

There is changes to two parts of the code
1.  module/system/vm/rtl.scm, we wrap the make-asm record constructor to
initiate the first
two slots to 0 and advance the index pointer.

2. We add code in libguile/cm-engine.c rtl function execution stubs to
include a check for 0 at the initial
two/one positions in ip. depending on architecture this will lead to a
nonzero value in the case native code should be executed. Currently the
code will abort if the head is nonzero but this will change of cause as we
introduce more code. When the head is zero the ip is incremented two steps
and the code executes as usual.

A cavet could be if writing compiled code out to disk is done lately when
native code have been compiled in. In this case we should clean the native
part (In the jit case). I did not find where the code that does this is
located so I left it open for now.

/Stefan

[-- Attachment #1.2: Type: text/html, Size: 1184 bytes --]

[-- Attachment #2: native-wip-rtl.diff --]
[-- Type: application/octet-stream, Size: 2845 bytes --]

diff --git a/libguile/vm-engine.c b/libguile/vm-engine.c
index 156b373..ffa32d2 100644
--- a/libguile/vm-engine.c
+++ b/libguile/vm-engine.c
@@ -990,6 +990,18 @@ RTL_VM_NAME (SCM vm, SCM program, SCM *argv, size_t nargs_)
    * after the end of the `call' instruction.  The word following that
    * is the RA.
    */
+
+#define CHECK_NATIVE(ip)                                \
+  if(*((scm_t_bits *) ip) == 0)                         \
+    {                                                   \
+      ip += 2;                                          \
+    }                                                   \
+  else                                                  \
+    {                                                   \
+      /* native code not implemented */                 \
+      abort();                                          \
+    }
+
   VM_DEFINE_OP (2, call, "call", OP3 (U8_U24, X8_U24, X8_R24))
     {
       scm_t_uint32 from, proc, n;
@@ -1018,6 +1030,10 @@ RTL_VM_NAME (SCM vm, SCM program, SCM *argv, size_t nargs_)
         goto apply;
 
       ip = SCM_RTL_PROGRAM_CODE (SCM_FRAME_PROGRAM (fp));
+
+      /* Check to se if native code is hooked in */
+      CHECK_NATIVE(ip)
+
       NEXT (0);
     }
 
@@ -1055,6 +1071,10 @@ RTL_VM_NAME (SCM vm, SCM program, SCM *argv, size_t nargs_)
         goto apply;
 
       ip = SCM_RTL_PROGRAM_CODE (SCM_FRAME_PROGRAM (fp));
+
+      /* Check to se if native code is hooked in */
+      CHECK_NATIVE(ip)
+
       NEXT (0);
     }
 
@@ -1083,6 +1103,10 @@ RTL_VM_NAME (SCM vm, SCM program, SCM *argv, size_t nargs_)
         goto apply;
 
       ip = SCM_RTL_PROGRAM_CODE (SCM_FRAME_PROGRAM (fp));
+
+      /* Check to se if native code is hooked in */
+      CHECK_NATIVE(ip)
+      
       NEXT (0);
     }
 
@@ -1318,6 +1342,10 @@ RTL_VM_NAME (SCM vm, SCM program, SCM *argv, size_t nargs_)
         goto apply;
 
       ip = SCM_RTL_PROGRAM_CODE (SCM_FRAME_PROGRAM (fp));
+
+      /* Check to se if native code is hooked in */
+      CHECK_NATIVE(ip)
+
       NEXT (0);
     }
 
diff --git a/module/system/vm/rtl.scm b/module/system/vm/rtl.scm
index 3832968..3c5b85e 100644
--- a/module/system/vm/rtl.scm
+++ b/module/system/vm/rtl.scm
@@ -74,7 +74,7 @@
 ;; We write constants using the target endianness, though.
 ;;
 (define-record-type <asm>
-  (make-asm cur idx start prev written
+  (make-asm- cur idx start prev written
             labels relocs
             word-size endianness
             constants inits
@@ -96,6 +96,13 @@
   (string-table asm-string-table set-asm-string-table!)
   (meta asm-meta set-asm-meta!))
 
+(define (make-asm . l)
+  (let ((asm (apply make-asm- l)))
+    (set-asm-idx! asm 2)
+    (u32-set! (asm-cur asm) 0 0)
+    (u32-set! (asm-cur asm) 0 1)
+    asm))
+
 (define-inlinable (fresh-block)
   (make-u32vector *block-size*))
 

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-01-21 19:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-08-09 18:59 wip-rtl native patch Stefan Israelsson Tampe
2013-01-21 13:21 ` Andy Wingo
2013-01-21 18:28   ` Stefan Israelsson Tampe
2013-01-21 19:06     ` Andy Wingo

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).