]> gitweb.factorcode.org Git - factor.git/commitdiff
Machine code is now stored in a byte array instead of an array for add_code_block()
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 30 Apr 2009 09:34:35 +0000 (04:34 -0500)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Thu, 30 Apr 2009 09:34:35 +0000 (04:34 -0500)
basis/bootstrap/image/image.factor
basis/compiler/codegen/fixup/fixup.factor
basis/cpu/x86/bootstrap.factor
vm/code_block.c
vm/code_block.h
vm/code_heap.c
vm/jit.c
vm/jit.h
vm/quotations.c
vm/run.h

index 5bf3c30097bf2d59c91deeed373c22d19fd5f074..dde945e9afc5295587923c3c2484e1bb05e51a26 100644 (file)
@@ -111,7 +111,7 @@ SYMBOL: jit-define-offset
         jit-define-rc get
         jit-define-rt get
         jit-define-offset get 3array
-    ] { } make prefix ;
+    ] B{ } make prefix ;
 
 : jit-define ( quot name -- )
     [ make-jit ] dip set ;
@@ -135,7 +135,6 @@ SYMBOL: bootstrap-global
 SYMBOL: bootstrap-boot-quot
 
 ! JIT parameters
-SYMBOL: jit-code-format
 SYMBOL: jit-prolog
 SYMBOL: jit-primitive-word
 SYMBOL: jit-primitive
@@ -185,7 +184,6 @@ SYMBOL: undefined-quot
     H{
         { bootstrap-boot-quot 20 }
         { bootstrap-global 21 }
-        { jit-code-format 22 }
         { jit-prolog 23 }
         { jit-primitive-word 24 }
         { jit-primitive 25 }
@@ -538,7 +536,6 @@ M: quotation '
     \ mega-cache-miss \ mega-miss-word set
     [ undefined ] undefined-quot set
     {
-        jit-code-format
         jit-prolog
         jit-primitive-word
         jit-primitive
index 45d87b3270b78466d2c0fc9db8a3565767372d23..99f258d93c618faa0f143b9f575c59a23792b144 100755 (executable)
@@ -9,9 +9,7 @@ IN: compiler.codegen.fixup
 
 GENERIC: fixup* ( obj -- )
 
-: code-format ( -- n ) 22 getenv ;
-
-: compiled-offset ( -- n ) building get length code-format * ;
+: compiled-offset ( -- n ) building get length ;
 
 SYMBOL: relocation-table
 SYMBOL: label-table
@@ -91,4 +89,4 @@ SYMBOL: literal-table
         literal-table get >array
         relocation-table get >byte-array
         label-table get resolve-labels
-    ] { } make 4array ;
+    ] B{ } make 4array ;
index 4f9a94a58b36b1d322bcf8596e5ee2be538724de..f89839aa830561aafe265b807e0de1fe32e3311f 100644 (file)
@@ -8,8 +8,6 @@ IN: bootstrap.x86
 
 big-endian off
 
-1 jit-code-format set
-
 [
     ! Load word
     temp0 0 MOV rc-absolute-cell rt-immediate jit-rel
index 433129108364066ae7fdbf3c35fe826fcdf11499..1d428e4fcde441ed67ef1e13c4e4add7d93cdbe8 100644 (file)
@@ -396,7 +396,7 @@ void relocate_code_block(F_CODE_BLOCK *compiled)
 }
 
 /* Fixup labels. This is done at compile time, not image load time */
-void fixup_labels(F_ARRAY *labels, CELL code_format, F_CODE_BLOCK *compiled)
+void fixup_labels(F_ARRAY *labels, F_CODE_BLOCK *compiled)
 {
        CELL i;
        CELL size = array_capacity(labels);
@@ -413,31 +413,6 @@ void fixup_labels(F_ARRAY *labels, CELL code_format, F_CODE_BLOCK *compiled)
        }
 }
 
-/* Write a sequence of integers to memory, with 'format' bytes per integer */
-void deposit_integers(CELL here, F_ARRAY *array, CELL format)
-{
-       CELL count = array_capacity(array);
-       CELL i;
-
-       for(i = 0; i < count; i++)
-       {
-               F_FIXNUM value = to_fixnum(array_nth(array,i));
-               if(format == 1)
-                       bput(here + i,value);
-               else if(format == sizeof(unsigned int))
-                       *(unsigned int *)(here + format * i) = value;
-               else if(format == sizeof(CELL))
-                       *(CELL *)(here + format * i) = value;
-               else
-                       critical_error("Bad format in deposit_integers()",format);
-       }
-}
-
-CELL compiled_code_format(void)
-{
-       return untag_fixnum_fast(userenv[JIT_CODE_FORMAT]);
-}
-
 /* Might GC */
 F_CODE_BLOCK *allot_code_block(CELL size)
 {
@@ -469,7 +444,7 @@ F_CODE_BLOCK *allot_code_block(CELL size)
 /* Might GC */
 F_CODE_BLOCK *add_code_block(
        CELL type,
-       F_ARRAY *code,
+       F_BYTE_ARRAY *code,
        F_ARRAY *labels,
        CELL relocation,
        CELL literals)
@@ -477,11 +452,10 @@ F_CODE_BLOCK *add_code_block(
 #ifdef FACTOR_DEBUG
        type_check(ARRAY_TYPE,literals);
        type_check(BYTE_ARRAY_TYPE,relocation);
-       assert(untag_header(code->header) == ARRAY_TYPE);
+       assert(untag_header(code->header) == BYTE_ARRAY_TYPE);
 #endif
 
-       CELL code_format = compiled_code_format();
-       CELL code_length = align8(array_capacity(code) * code_format);
+       CELL code_length = align8(array_capacity(code));
 
        REGISTER_ROOT(literals);
        REGISTER_ROOT(relocation);
@@ -506,16 +480,11 @@ F_CODE_BLOCK *add_code_block(
        compiled->literals = literals;
        compiled->relocation = relocation;
 
-#ifdef FACTOR_DEBUG
-       type_check(ARRAY_TYPE,compiled->literals);
-       type_check(BYTE_ARRAY_TYPE,compiled->relocation);
-#endif
-
        /* code */
-       deposit_integers((CELL)(compiled + 1),code,code_format);
+       memcpy(compiled + 1,code + 1,code_length);
 
        /* fixup labels */
-       if(labels) fixup_labels(labels,code_format,compiled);
+       if(labels) fixup_labels(labels,compiled);
 
        /* next time we do a minor GC, we have to scan the code heap for
        literals */
index b8201c44a18b330ed4fd4cf6f2a10aaa52c05d34..385f414f88bf2b59f72a33a422818ba066822186 100644 (file)
@@ -79,8 +79,6 @@ void mark_object_code_block(CELL scan);
 
 void relocate_code_block(F_CODE_BLOCK *relocating);
 
-CELL compiled_code_format(void);
-
 INLINE bool stack_traces_p(void)
 {
        return userenv[STACK_TRACES_ENV] != F;
@@ -88,7 +86,7 @@ INLINE bool stack_traces_p(void)
 
 F_CODE_BLOCK *add_code_block(
        CELL type,
-       F_ARRAY *code,
+       F_BYTE_ARRAY *code,
        F_ARRAY *labels,
        CELL relocation,
        CELL literals);
index 0ae3d6b3fab57c44664dc28c21bda25fe7236325..6ba98dfa779a9c51e52f2c3d0d1e0a7c47b39363 100755 (executable)
@@ -93,7 +93,7 @@ void primitive_modify_code_heap(void)
                        CELL literals = array_nth(compiled_code,0);
                        CELL relocation = array_nth(compiled_code,1);
                        F_ARRAY *labels = untag_array(array_nth(compiled_code,2));
-                       F_ARRAY *code = untag_array(array_nth(compiled_code,3));
+                       F_BYTE_ARRAY *code = untag_byte_array(array_nth(compiled_code,3));
 
                        REGISTER_UNTAGGED(alist);
                        REGISTER_UNTAGGED(word);
index 8421b79468b804d8f2d620c35a044e5ff9c8e831..8145d18b368acb2dcb0f1387790a2e4b73c78f3d 100644 (file)
--- a/vm/jit.c
+++ b/vm/jit.c
@@ -13,9 +13,8 @@ void jit_init(F_JIT *jit, CELL jit_type, CELL owner)
        REGISTER_ROOT(jit->owner);
 
        jit->type = jit_type;
-       jit->code_format = compiled_code_format();
 
-       jit->code = make_growable_array();
+       jit->code = make_growable_byte_array();
        REGISTER_ROOT(jit->code.array);
        jit->relocation = make_growable_byte_array();
        REGISTER_ROOT(jit->relocation.array);
@@ -29,7 +28,7 @@ void jit_init(F_JIT *jit, CELL jit_type, CELL owner)
 /* Allocates memory */
 F_CODE_BLOCK *jit_make_code_block(F_JIT *jit)
 {
-       growable_array_trim(&jit->code);
+       growable_byte_array_trim(&jit->code);
        growable_byte_array_trim(&jit->relocation);
        growable_array_trim(&jit->literals);
 
@@ -66,9 +65,9 @@ static F_REL rel_to_emit(F_JIT *jit, CELL template, bool *rel_p)
        else
        {
                *rel_p = true;
-               return (to_fixnum(rel_type) << 28)
-                       | (to_fixnum(rel_class) << 24)
-                       | ((jit->code.count + to_fixnum(offset)) * jit->code_format);
+               return (untag_fixnum_fast(rel_type) << 28)
+                       | (untag_fixnum_fast(rel_class) << 24)
+                       | ((jit->code.count + untag_fixnum_fast(offset)));
        }
 }
 
@@ -79,7 +78,8 @@ void jit_emit(F_JIT *jit, CELL template)
        bool rel_p;
        F_REL rel = rel_to_emit(jit,template,&rel_p);
        if(rel_p) growable_byte_array_append(&jit->relocation,&rel,sizeof(F_REL));
-       growable_array_append(&jit->code,code_to_emit(template));
+       F_BYTE_ARRAY *code = code_to_emit(template);
+       growable_byte_array_append(&jit->code,code + 1,array_capacity(code));
        UNREGISTER_ROOT(template);
 }
 
index 0e27f2a7ab3f29f934dda8bdc65a826e789e175d..2085c8c8bde69128922f39ffe57b49ef37b37b47 100644 (file)
--- a/vm/jit.h
+++ b/vm/jit.h
@@ -1,8 +1,7 @@
 typedef struct {
        CELL type;
        CELL owner;
-       CELL code_format;
-       F_GROWABLE_ARRAY code;
+       F_GROWABLE_BYTE_ARRAY code;
        F_GROWABLE_BYTE_ARRAY relocation;
        F_GROWABLE_ARRAY literals;
 } F_JIT;
@@ -11,7 +10,7 @@ void jit_init(F_JIT *jit, CELL jit_type, CELL owner);
 F_CODE_BLOCK *jit_make_code_block(F_JIT *jit);
 void jit_dispose(F_JIT *jit);
 
-INLINE F_ARRAY *code_to_emit(CELL template)
+INLINE F_BYTE_ARRAY *code_to_emit(CELL template)
 {
        return untag_object(array_nth(untag_object(template),0));
 }
index 0e24297ac19abba1f7570c2c44f5da67c3ac7fde..d358a2c571c6236ae4c64883822e25e1f23753ab 100755 (executable)
@@ -310,7 +310,7 @@ worse than the duplication itself (eg, putting all state in some global
 struct.) */
 #define COUNT(name,scan) \
        { \
-               CELL size = array_capacity(code_to_emit(name)) * code_format; \
+               CELL size = array_capacity(code_to_emit(name)); \
                if(offset == 0) return scan - 1; \
                if(offset < size) return scan + 1; \
                offset -= size; \
@@ -324,8 +324,6 @@ struct.) */
 
 F_FIXNUM quot_code_offset_to_scan(CELL quot, F_FIXNUM offset)
 {
-       CELL code_format = compiled_code_format();
-
        CELL array = untag_quotation(quot)->array;
 
        bool stack_frame = jit_stack_frame_p(untag_object(array));
index e3e7aacf6f15326fc3424526a39514a3ecae853a..d32a91e67afdc15ac5721e9b7d7a8672b077c6c2 100755 (executable)
--- a/vm/run.h
+++ b/vm/run.h
@@ -33,8 +33,7 @@ typedef enum {
        GLOBAL_ENV,               /* global namespace */
 
        /* Quotation compilation in quotations.c */
-       JIT_CODE_FORMAT     = 22,
-       JIT_PROLOG,
+       JIT_PROLOG          = 23,
        JIT_PRIMITIVE_WORD,
        JIT_PRIMITIVE,
        JIT_WORD_JUMP,