]> gitweb.factorcode.org Git - factor.git/commitdiff
compiler: add ##load-vector instruction to avoid wasting a temporary register on...
authorSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Sat, 1 May 2010 01:33:42 +0000 (21:33 -0400)
committerSlava Pestov <slava@slava-pestovs-macbook-pro.local>
Mon, 3 May 2010 21:34:28 +0000 (17:34 -0400)
14 files changed:
basis/compiler/cfg/instructions/instructions.factor
basis/compiler/cfg/representations/peephole/peephole.factor
basis/compiler/codegen/codegen.factor
basis/compiler/codegen/fixup/fixup.factor
basis/compiler/constants/constants.factor
basis/cpu/architecture/architecture.factor
basis/cpu/x86/32/32.factor
vm/code_blocks.cpp
vm/compaction.cpp
vm/image.cpp
vm/instruction_operands.cpp
vm/instruction_operands.hpp
vm/layouts.hpp
vm/slot_visitor.hpp

index 5286fd861b088255697e9de6cbc460d98d872016..e7a8338d91eeb290ffc49383eb2e562b5ee0a81b 100644 (file)
@@ -29,7 +29,7 @@ INSN: ##load-reference
 def: dst/tagged-rep
 literal: obj ;
 
-! These two are inserted by representation selection
+! These three are inserted by representation selection
 INSN: ##load-tagged
 def: dst/tagged-rep
 literal: val ;
@@ -38,6 +38,10 @@ INSN: ##load-double
 def: dst/double-rep
 literal: val ;
 
+INSN: ##load-vector
+def: dst
+literal: val rep ;
+
 ! Stack operations
 INSN: ##peek
 def: dst/tagged-rep
index 23e2e9c50c83091c9f437e0b7bfc32af767db652..4080e8077c1854035080aea9f1bb8691bc401918 100644 (file)
@@ -1,8 +1,8 @@
 ! Copyright (C) 2010 Slava Pestov.
 ! See http://factorcode.org/license.txt for BSD license.
-USING: accessors combinators combinators.short-circuit kernel
-layouts locals make math namespaces sequences cpu.architecture
-compiler.cfg.registers
+USING: accessors byte-arrays combinators
+combinators.short-circuit kernel layouts locals make math
+namespaces sequences cpu.architecture compiler.cfg.registers
 compiler.cfg.instructions
 compiler.cfg.representations.rewrite
 compiler.cfg.representations.selection ;
@@ -46,11 +46,18 @@ M: ##load-integer optimize-insn
 ! if the architecture supports it
 : convert-to-load-double? ( insn -- ? )
     {
-        [ drop load-double? ]
+        [ drop object-immediates? ]
         [ dst>> rep-of double-rep? ]
         [ obj>> float? ]
     } 1&& ;
 
+: convert-to-load-vector? ( insn -- ? )
+    {
+        [ drop object-immediates? ]
+        [ dst>> rep-of vector-rep? ]
+        [ obj>> byte-array? ]
+    } 1&& ;
+
 ! When a literal zeroes/ones vector is unboxed, we replace the ##load-reference
 ! with a ##zero-vector or ##fill-vector instruction since this is more efficient.
 : convert-to-zero-vector? ( insn -- ? )
@@ -65,25 +72,23 @@ M: ##load-integer optimize-insn
         [ obj>> B{ 255 255 255 255  255 255 255 255  255 255 255 255  255 255 255 255 } = ]
     } 1&& ;
 
-: (convert-to-load-double) ( insn -- dst val )
-    [ dst>> ] [ obj>> ] bi ; inline
-
-: (convert-to-zero/fill-vector) ( insn -- dst rep )
-    dst>> dup rep-of ; inline
-
 M: ##load-reference optimize-insn
     {
         {
             [ dup convert-to-load-double? ]
-            [ (convert-to-load-double) ##load-double here ]
+            [ [ dst>> ] [ obj>> ] bi ##load-double here ]
         }
         {
             [ dup convert-to-zero-vector? ]
-            [ (convert-to-zero/fill-vector) ##zero-vector here ]
+            [ dst>> dup rep-of ##zero-vector here ]
         }
         {
             [ dup convert-to-fill-vector? ]
-            [ (convert-to-zero/fill-vector) ##fill-vector here ]
+            [ dst>> dup rep-of ##fill-vector here ]
+        }
+        {
+            [ dup convert-to-load-vector? ]
+            [ [ dst>> ] [ obj>> ] [ dst>> rep-of ] tri ##load-vector here ]
         }
         [ call-next-method ]
     } cond ;
index 2d0cfa82893e0c6ddf3c603a41c4d677c241c13b..3d0a6ee8aff1ecffc3c47e249a013765cd64265b 100755 (executable)
@@ -78,6 +78,7 @@ CODEGEN: ##load-integer %load-immediate
 CODEGEN: ##load-tagged %load-immediate
 CODEGEN: ##load-reference %load-reference
 CODEGEN: ##load-double %load-double
+CODEGEN: ##load-vector %load-vector
 CODEGEN: ##peek %peek
 CODEGEN: ##replace %replace
 CODEGEN: ##inc-d %inc-d
index fa8dfc21492a496ff151cdf614f69e54ed8a36f9..ebc9c7b4762bdb26c6e7b98d0878f5b2bd60c79c 100644 (file)
@@ -76,6 +76,9 @@ MEMO: cached-string>symbol ( symbol -- obj ) string>symbol ;
 : rel-float ( literal class -- )
     [ add-literal ] dip rt-float rel-fixup ;
 
+: rel-byte-array ( literal class -- )
+    [ add-literal ] dip rt-byte-array rel-fixup ;
+
 : rel-this ( class -- )
     rt-this rel-fixup ;
 
index 2fdf81452102efadde11ccef11bdf8f1883f3b02..ca9dc5136dbe8ddf2d6feaa5dbd70469166bc681 100644 (file)
@@ -68,6 +68,7 @@ CONSTANT: rt-cards-offset 10
 CONSTANT: rt-decks-offset 11
 CONSTANT: rt-exception-handler 12
 CONSTANT: rt-float 13
+CONSTANT: rt-byte-array 14
 
 : rc-absolute? ( n -- ? )
     ${
index 09745dea6b2c5a0de6f0096e7c5dfe8ef0047df8..1418ab90b6952524ee3aaf34483197ce1d0e5b8f 100644 (file)
@@ -225,6 +225,7 @@ HOOK: complex-addressing? cpu ( -- ? )
 HOOK: %load-immediate cpu ( reg val -- )
 HOOK: %load-reference cpu ( reg obj -- )
 HOOK: %load-double cpu ( reg val -- )
+HOOK: %load-vector cpu ( reg val rep -- )
 
 HOOK: %peek cpu ( vreg loc -- )
 HOOK: %replace cpu ( vreg loc -- )
@@ -500,10 +501,11 @@ M: reg-class param-reg param-regs nth ;
 
 M: stack-params param-reg 2drop ;
 
-! Does this architecture support %load-double?
-HOOK: load-double? cpu ( -- ? )
+! Does this architecture support %load-double, %load-vector and
+! objects in %compare-imm?
+HOOK: object-immediates? cpu ( -- ? )
 
-M: object load-double? f ;
+M: object object-immediates? f ;
 
 ! Can this value be an immediate operand for %add-imm, %sub-imm,
 ! or %mul-imm?
index 79ff4b1e35b9707415e1ca68f38aaff5e6abd78f..4df4fbd6026f2d7b7588cd39d6404c8465513c22 100755 (executable)
@@ -27,11 +27,14 @@ M: x86.32 temp-reg ECX ;
 M: x86.32 immediate-comparand? ( n -- ? )
     [ call-next-method ] [ word? ] bi or ;
 
-M: x86.32 load-double? ( -- ? ) t ;
+M: x86.32 object-immediates? ( -- ? ) t ;
 
 M: x86.32 %load-double ( dst val -- )
     [ 0 [] MOVSD ] dip rc-absolute rel-float ;
 
+M:: x86.32 %load-vector ( dst val rep -- )
+    dst 0 [] rep copy-memory* val rc-absolute rel-byte-array ;
+
 M: x86.32 %mov-vm-ptr ( reg -- )
     0 MOV 0 rc-absolute-cell rel-vm ;
 
index 2e7b8d4f0970fddf003590005e8c761524bda3e9..351ce5a95e9627e0d27b4f5ac3fb43fc0835e197 100755 (executable)
@@ -231,7 +231,7 @@ void factor_vm::store_external_address(instruction_operand op)
                break;
 #endif
        default:
-               critical_error("Bad rel type",op.rel_type());
+               critical_error("Bad rel type in store_external_address()",op.rel_type());
                break;
        }
 }
@@ -268,6 +268,9 @@ struct initial_code_block_visitor {
                case RT_FLOAT:
                        op.store_float(next_literal());
                        break;
+               case RT_BYTE_ARRAY:
+                       op.store_byte_array(next_literal());
+                       break;
                case RT_ENTRY_POINT:
                        op.store_value(parent->compute_entry_point_address(next_literal()));
                        break;
index 34398e3d88ccfbefd786d8a4f8c9acb9c7987872..f596c3040f5f11fd0601bdb9ae4d5794dd4dc810 100644 (file)
@@ -114,6 +114,9 @@ struct code_block_compaction_relocation_visitor {
                case RT_FLOAT:
                        op.store_float(slot_forwarder.visit_pointer(op.load_float(old_offset)));
                        break;
+               case RT_BYTE_ARRAY:
+                       op.store_byte_array(slot_forwarder.visit_pointer(op.load_byte_array(old_offset)));
+                       break;
                case RT_ENTRY_POINT:
                case RT_ENTRY_POINT_PIC:
                case RT_ENTRY_POINT_PIC_TAIL:
index 4dfdc4242eac3957ed85ef0ebd1b0f1e40bf642e..b64d8289477d32f3ee85e80d0eb25951e12777a8 100755 (executable)
@@ -188,6 +188,9 @@ struct code_block_fixup_relocation_visitor {
                case RT_FLOAT:
                        op.store_float(data_visitor.visit_pointer(op.load_float(old_offset)));
                        break;
+               case RT_BYTE_ARRAY:
+                       op.store_byte_array(data_visitor.visit_pointer(op.load_byte_array(old_offset)));
+                       break;
                case RT_ENTRY_POINT:
                case RT_ENTRY_POINT_PIC:
                case RT_ENTRY_POINT_PIC_TAIL:
index af7d363aefa82f5beeb9db1cf3035a22dfa762d9..65a2f93b2d6d62af9f63ca303fa23a6386d5ab35 100644 (file)
@@ -72,6 +72,16 @@ cell instruction_operand::load_float(cell pointer)
        return (cell)load_value(pointer) - boxed_float_offset;
 }
 
+cell instruction_operand::load_byte_array()
+{
+       return (cell)load_value() - byte_array_offset;
+}
+
+cell instruction_operand::load_byte_array(cell pointer)
+{
+       return (cell)load_value(pointer) - byte_array_offset;
+}
+
 code_block *instruction_operand::load_code_block(cell relative_to)
 {
        return ((code_block *)load_value(relative_to) - 1);
@@ -150,6 +160,11 @@ void instruction_operand::store_float(cell value)
        store_value((fixnum)value + boxed_float_offset);
 }
 
+void instruction_operand::store_byte_array(cell value)
+{
+       store_value((fixnum)value + byte_array_offset);
+}
+
 void instruction_operand::store_code_block(code_block *compiled)
 {
        store_value((cell)compiled->entry_point());
index 5c120c2ec770934e617aabfa78c5291a89a593dd..7adb517f186ef0b4b8f9065d4dd6eddd4dfa0bdc 100644 (file)
@@ -32,6 +32,8 @@ enum relocation_type {
        RT_EXCEPTION_HANDLER,
        /* pointer to a float's payload */
        RT_FLOAT,
+       /* pointer to a byte array's payload */
+       RT_BYTE_ARRAY,
 
 };
 
@@ -116,9 +118,10 @@ struct relocation_entry {
                case RT_DECKS_OFFSET:
                case RT_EXCEPTION_HANDLER:
                case RT_FLOAT:
+               case RT_BYTE_ARRAY:
                        return 0;
                default:
-                       critical_error("Bad rel type",rel_type());
+                       critical_error("Bad rel type in number_of_parameters()",rel_type());
                        return -1; /* Can't happen */
                }
        }
@@ -158,6 +161,8 @@ struct instruction_operand {
        fixnum load_value();
        cell load_float(cell relative_to);
        cell load_float();
+       cell load_byte_array(cell relative_to);
+       cell load_byte_array();
        code_block *load_code_block(cell relative_to);
        code_block *load_code_block();
 
@@ -165,6 +170,7 @@ struct instruction_operand {
        void store_value_masked(fixnum value, cell mask, cell shift);
        void store_value(fixnum value);
        void store_float(cell value);
+       void store_byte_array(cell value);
        void store_code_block(code_block *compiled);
 };
 
index 5275c796128d06758688d36810dac2079208b5bb..35f04e7cc518a2703b7e94db84a44b55cdf0808a 100644 (file)
@@ -178,6 +178,8 @@ struct bignum : public object {
        cell *data() const { return (cell *)(this + 1); }
 };
 
+const cell byte_array_offset = 16 - BYTE_ARRAY_TYPE;
+
 struct byte_array : public object {
        static const cell type_number = BYTE_ARRAY_TYPE;
        static const cell element_size = 1;
index cb2db1c7050b96356ece36f154189dab00144763..d0507da93f81b0ea5872cd251ff9b2d28e6c4854 100644 (file)
@@ -200,6 +200,9 @@ struct literal_references_visitor {
                case RT_FLOAT:
                        op.store_float(visitor->visit_pointer(op.load_float()));
                        break;
+               case RT_BYTE_ARRAY:
+                       op.store_byte_array(visitor->visit_pointer(op.load_byte_array()));
+                       break;
                default:
                        break;
                }