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

* Re: wip-rtl native patch
  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
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Wingo @ 2013-01-21 13:21 UTC (permalink / raw)
  To: Stefan Israelsson Tampe; +Cc: guile-devel

On Thu 09 Aug 2012 20:59, Stefan Israelsson Tampe <stefan.itampe@gmail.com> writes:

> 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.

I would rather use a different tc7 and the existing fallback `apply'
loop.  Note that this does not preclude JIT compilation: we can change
the tc7 of an object at runtime.

Cheers,

Andy
-- 
http://wingolog.org/



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

* Re: wip-rtl native patch
  2013-01-21 13:21 ` Andy Wingo
@ 2013-01-21 18:28   ` Stefan Israelsson Tampe
  2013-01-21 19:06     ` Andy Wingo
  0 siblings, 1 reply; 4+ messages in thread
From: Stefan Israelsson Tampe @ 2013-01-21 18:28 UTC (permalink / raw)
  To: Andy Wingo; +Cc: guile-devel

[-- Attachment #1: Type: text/plain, Size: 1377 bytes --]

Hi,

As I understood my reason for doing this was that many closures point to
the same code fragment
and If we compile one of those closures the others will not benefit. So
therefore I stored the native
code at the beginning of the rtl code fragment and used this mechanism. I
have not gotten this nailed
though because I'm unsure how to treat this data correctly w.r.t. GC.
Currently I just keep a reference
to the native code to prevent garbage collection if I'm not miss-remember.
But perhaps I'm missing
something in this argument I would be glad to be wrong in this case :-). Of
cause if we compile the
module directly to native code this will be a non issue and I completely
agree with your approach.

Cheers!
Stefan


On Mon, Jan 21, 2013 at 2:21 PM, Andy Wingo <wingo@pobox.com> wrote:

> On Thu 09 Aug 2012 20:59, Stefan Israelsson Tampe <stefan.itampe@gmail.com>
> writes:
>
> > 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.
>
> I would rather use a different tc7 and the existing fallback `apply'
> loop.  Note that this does not preclude JIT compilation: we can change
> the tc7 of an object at runtime.
>
> Cheers,
>
> Andy
> --
> http://wingolog.org/
>

[-- Attachment #2: Type: text/html, Size: 2125 bytes --]

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

* Re: wip-rtl native patch
  2013-01-21 18:28   ` Stefan Israelsson Tampe
@ 2013-01-21 19:06     ` Andy Wingo
  0 siblings, 0 replies; 4+ messages in thread
From: Andy Wingo @ 2013-01-21 19:06 UTC (permalink / raw)
  To: Stefan Israelsson Tampe; +Cc: guile-devel

On Mon 21 Jan 2013 19:28, Stefan Israelsson Tampe <stefan.itampe@gmail.com> writes:

> As I understood my reason for doing this was that many closures point to
> the same code fragment

Ah, I see.  Yes indeed this may make sense.  I'll keep it in mind.

Andy
-- 
http://wingolog.org/



^ permalink raw reply	[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).