Author: leo
Date: Thu Feb  9 06:30:21 2006
New Revision: 11484

Added:
   trunk/src/pic_jit.c   (contents, props changed)
Modified:
   trunk/config/gen/makefiles/root.in
   trunk/include/parrot/pic.h
   trunk/src/pic.c
Log:
PIC/JIT - add new file src/pic_jit.c

* all the sannity checks, if a Sub is JITtable and the actual JIT
  codegen call is here / will be here


Modified: trunk/config/gen/makefiles/root.in
==============================================================================
--- trunk/config/gen/makefiles/root.in  (original)
+++ trunk/config/gen/makefiles/root.in  Thu Feb  9 06:30:21 2006
@@ -427,6 +427,7 @@ INTERP_O_FILES = \
        $(SRC_DIR)/utils$(O) \
        $(SRC_DIR)/vtables$(O) \
        $(SRC_DIR)/pic$(O) \
+       $(SRC_DIR)/pic_jit$(O) \
        $(SRC_DIR)/mmd$(O) \
        $(SRC_DIR)/builtin$(O) \
        $(SRC_DIR)/extend$(O) \
@@ -1026,6 +1027,8 @@ $(SRC_DIR)/memory$(O) : $(GENERAL_H_FILE
 
 $(SRC_DIR)/pic$(O) : $(GENERAL_H_FILES)
 
+$(SRC_DIR)/pic_jit$(O) : $(GENERAL_H_FILES)
+
 $(SRC_DIR)/mmd$(O) : $(GENERAL_H_FILES) $(SRC_DIR)/mmd.str
 
 $(SRC_DIR)/builtin$(O) : $(GENERAL_H_FILES) $(SRC_DIR)/builtin.str

Modified: trunk/include/parrot/pic.h
==============================================================================
--- trunk/include/parrot/pic.h  (original)
+++ trunk/include/parrot/pic.h  Thu Feb  9 06:30:21 2006
@@ -80,6 +80,11 @@ void * parrot_pic_opcode(Interp *, INTVA
 typedef int (*arg_pass_f)(Interp *, PMC *sig,
         char *src_base, void **src_pc, char *dest_base, void **dest_pc);
 
+int parrot_pic_is_save_to_jit(Interp *, PMC *sub,
+       PMC *sig_args, PMC *sig_results);
+
+funcptr_t  parrot_pic_JIT_sub(Interp *, PMC *sub);
+
 #endif /* PARROT_PIC_H_GUARD */
 
 /*

Modified: trunk/src/pic.c
==============================================================================
--- trunk/src/pic.c     (original)
+++ trunk/src/pic.c     Thu Feb  9 06:30:21 2006
@@ -480,53 +480,14 @@ is_pic_param(Interp *interpreter, void *
     return 1;
 }
 
-#if PIC_TEST
-/*
- * just for testing the whole scheme ...
-
-
-.sub main :main
-    .local int i
-    i = 32
-    i = __pic_test(i, 10)
-    print i
-    print "\n"
-.end
-.sub __pic_test
-    .param int i
-    .param int j
-    $I0 = i + j
-    .return ($I0)
-.end
-... prints 42, if PIC_TEST is 1, because the C function is called
-    with -C and -S runcores.
-*/
-
-static opcode_t *
-pic_test_func(Interp *interpreter, INTVAL *sig_bits, void **args)
-{
-    opcode_t *pc;
-    INTVAL *result, i, j;
-
-    result = (INTVAL*) args[0];
-    i = (INTVAL) args[1];
-    j = (INTVAL) args[2];
-    *result = i + j;
-    pc = args[3];
-    return pc;
-}
-#endif
 
 static int
 is_pic_func(Interp *interpreter, void **pc, Parrot_MIC *mic, int core_type)
 {
-    PMC *sub, *sig;
+    PMC *sub, *sig_args, *sig_results;
     char *base;
     parrot_context_t *ctx;
     opcode_t *op, n;
-#if PIC_TEST
-    STRING *name;
-#endif
     
     /*
      * if we have these opcodes
@@ -548,9 +509,9 @@ is_pic_func(Interp *interpreter, void **
 
     base = (char*)interpreter->ctx.bp.regs_i;
     ctx = CONTEXT(interpreter->ctx);
-    sig = (PMC*)(pc[1]);
-    ASSERT_SIG_PMC(sig);
-    n = SIG_ELEMS(sig);
+    sig_args = (PMC*)(pc[1]);
+    ASSERT_SIG_PMC(sig_args);
+    n = SIG_ELEMS(sig_args);
     interpreter->current_args = (opcode_t*)pc + ctx->pred_offset;
     pc += 2 + n;
     op = (opcode_t*)pc + ctx->pred_offset;
@@ -566,42 +527,15 @@ is_pic_func(Interp *interpreter, void **
     if (*op != PARROT_OP_get_results_pc)
         return 0;
     do_prederef(pc, interpreter, core_type);
-    ctx->current_results = (opcode_t*)pc + ctx->pred_offset;
-#if PIC_TEST
-    name = VTABLE_get_string(interpreter, sub);
-    if (memcmp((char*) name->strstart, "__pic_test", 10) == 0) {
-#if 0
-        mic->lru.f.real_function = (funcptr_t) pic_test_func;
-        mic->m.sig = sig;
-        return 1;
-#else
-#if HAS_JIT
-        /*
-         * create JIT code - just a test
-         */
-        Parrot_jit_info_t *jit_info;
-        opcode_t *base, *start, *end;
-        
-        base = interpreter->code->base.data;
-        start = base + PMC_sub(sub)->start_offs;
-        end   = base + PMC_sub(sub)->end_offs;
-        /* TODO pass Sub */
+    sig_results = (PMC*)(pc[1]);
+    ASSERT_SIG_PMC(sig_results);
 
-        jit_info = parrot_build_asm(interpreter, start, end, NULL,
-            JIT_CODE_SUB_REGS_ONLY_REC);
-        if (!jit_info)
-            return 0;
-        
-        mic->lru.f.real_function = (funcptr_t) jit_info->arena.start;
-        mic->m.sig = sig;
-        return 1;
-#else
+    ctx->current_results = (opcode_t*)pc + ctx->pred_offset;
+    if (!parrot_pic_is_save_to_jit(interpreter, sub, sig_args, sig_results))
         return 0;
-#endif
-#endif
-    }
-#endif
-    return 0;
+    mic->lru.f.real_function = parrot_pic_JIT_sub(interpreter, sub);
+    mic->m.sig = sig_args;
+    return 1;
 }
 
 void

Added: trunk/src/pic_jit.c
==============================================================================
--- (empty file)
+++ trunk/src/pic_jit.c Thu Feb  9 06:30:21 2006
@@ -0,0 +1,167 @@
+/*
+Copyright: 2006 The Perl Foundation.  All Rights Reserved.
+$Id:$
+
+=head1 NAME
+
+src/pic_jit.c - Polymorphic Inline Cache to JIT compilation
+
+=head1 DESCRIPTION
+
+Some statically known and simple subroutines are replace by
+their JITted variants, if
+
+  - JIT is supported and can JIT subroutines
+  - arguments passing is simple
+  - the code is fully JITtable
+  - and more such checks
+
+=head2 Functions
+
+=over 4
+
+=cut
+
+*/
+
+#include "parrot/parrot.h"
+#include "parrot/oplib/ops.h"
+#include <assert.h>
+#ifdef HAVE_COMPUTED_GOTO
+#  include "parrot/oplib/core_ops_cgp.h"
+#endif
+
+#if HAS_JIT
+#include "parrot/exec.h"
+#include "parrot/jit.h"
+
+#if PIC_TEST
+/*
+ * just for testing the whole scheme ...
+
+
+.sub main :main
+    .local int i
+    i = 32
+    i = __pic_test(i, 10)
+    print i
+    print "\n"
+.end
+.sub __pic_test
+    .param int i
+    .param int j
+    $I0 = i + j
+    .return ($I0)
+.end
+... prints 42, if PIC_TEST is 1, because the C function is called
+    with -C and -S runcores.
+*/
+
+static opcode_t *
+pic_test_func(Interp *interpreter, INTVAL *sig_bits, void **args)
+{
+    opcode_t *pc;
+    INTVAL *result, i, j;
+
+    result = (INTVAL*) args[0];
+    i = (INTVAL) args[1];
+    j = (INTVAL) args[2];
+    *result = i + j;
+    pc = args[3];
+    return pc;
+}
+#endif
+
+int
+parrot_pic_is_save_to_jit(Interp *interpreter, PMC *sub,
+       PMC *sig_args, PMC *sig_results)
+{
+    STRING *name;
+
+    name = VTABLE_get_string(interpreter, sub);
+    /* XXX test code */
+    if (memcmp((char*) name->strstart, "__pic_test", 10) != 0)
+       return 0;
+    return 1;
+}
+
+funcptr_t 
+parrot_pic_JIT_sub(Interp *interpreter, PMC *sub) {
+#if PIC_TEST
+    UNUSED(interpreter);
+    UNUSED(sub);
+    return (funcptr_t) pic_test_func;
+#else
+    /*
+     * create JIT code - just a test
+     */
+    Parrot_jit_info_t *jit_info;
+    opcode_t *base, *start, *end;
+
+    base = interpreter->code->base.data;
+    start = base + PMC_sub(sub)->start_offs;
+    end   = base + PMC_sub(sub)->end_offs;
+    /* TODO pass Sub */
+
+    jit_info = parrot_build_asm(interpreter, start, end, NULL,
+            JIT_CODE_SUB_REGS_ONLY_REC);
+    if (!jit_info)
+        return NULLfunc;
+    return (funcptr_t) jit_info->arena.start;
+#endif
+}
+
+
+
+
+
+
+
+
+
+#else
+
+int
+parrot_pic_is_save_to_jit(Interp *interpreter, PMC *sub,
+       PMC *sig_args, PMC *sig_results)
+{
+    return 0;
+}
+
+funcptr_t 
+parrot_pic_JIT_sub(Interp *interpreter, PMC *sub) {
+    UNUSED(interpreter);
+    UNUSED(sub);
+
+    return NULLfunc;
+}
+
+#endif     /* HAS_JIT */
+   
+
+/*
+
+=back
+
+=head1 AUTHOR
+
+Leopold Toetsch
+
+=head1 SEE ALSO
+
+F<src/pic.c>, F<src/jit.c>, F<ops/core_ops_cgp.c>,
+F<include/parrot/pic.h>, F<ops/pic.ops>
+
+=cut
+
+*/
+
+/*
+ * Local variables:
+ * c-indentation-style: bsd
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ *
+ * vim: expandtab shiftwidth=4:
+*/

Reply via email to