]> gitweb.factorcode.org Git - factor.git/commitdiff
VM: new method quotation_jit:nth
authorBjörn Lindqvist <bjourne@gmail.com>
Mon, 30 May 2016 17:32:03 +0000 (19:32 +0200)
committerBjörn Lindqvist <bjourne@gmail.com>
Tue, 31 May 2016 01:37:24 +0000 (03:37 +0200)
It's less tedious than writing array_nth(elements.untagged(), i + N) everywhere

vm/quotations.cpp
vm/quotations.hpp

index ef075ce18c9ca90e6eecd97f935e9b85cefc453b..7effb28c295c8493b8902e29cd8756447ee249c0 100644 (file)
@@ -37,51 +37,50 @@ includes stack shufflers, some fixnum arithmetic words, and words such as tag,
 slot and eq?. A primitive call is relatively expensive (two subroutine calls)
 so this results in a big speedup for relatively little effort. */
 
+inline cell quotation_jit::nth(cell index) {
+  return array_nth(elements.untagged(), index);
+}
+
 void quotation_jit::init_quotation(cell quot) {
   elements = untag<quotation>(quot)->array;
 }
 
 bool quotation_jit::fast_if_p(cell i, cell length) {
   return (i + 3) == length &&
-      TAG(array_nth(elements.untagged(), i + 1)) == QUOTATION_TYPE &&
-      array_nth(elements.untagged(), i + 2) == parent->special_objects[JIT_IF_WORD];
+      TAG(nth(i + 1)) == QUOTATION_TYPE &&
+      nth(i + 2) == parent->special_objects[JIT_IF_WORD];
 }
 
 bool quotation_jit::primitive_call_p(cell i, cell length) {
   cell jit_primitive_word = parent->special_objects[JIT_PRIMITIVE_WORD];
-  return (i + 2) <= length &&
-      array_nth(elements.untagged(), i + 1) == jit_primitive_word;
+  return (i + 2) <= length && nth(i + 1) == jit_primitive_word;
 }
 
 bool quotation_jit::fast_dip_p(cell i, cell length) {
   cell jit_dip_word = parent->special_objects[JIT_DIP_WORD];
-  return (i + 2) <= length &&
-      array_nth(elements.untagged(), i + 1) == jit_dip_word;
+  return (i + 2) <= length && nth(i + 1) == jit_dip_word;
 }
 
 bool quotation_jit::fast_2dip_p(cell i, cell length) {
   cell jit_2dip_word = parent->special_objects[JIT_2DIP_WORD];
-  return (i + 2) <= length &&
-      array_nth(elements.untagged(), i + 1) == jit_2dip_word;
+  return (i + 2) <= length && nth(i + 1) == jit_2dip_word;
 }
 
 bool quotation_jit::fast_3dip_p(cell i, cell length) {
   cell jit_3dip_word = parent->special_objects[JIT_3DIP_WORD];
-  return (i + 2) <= length &&
-      array_nth(elements.untagged(), i + 1) == jit_3dip_word;
+  return (i + 2) <= length && nth(i + 1) == jit_3dip_word;
 }
 
 bool quotation_jit::declare_p(cell i, cell length) {
   cell jit_declare_word = parent->special_objects[JIT_DECLARE_WORD];
-  return (i + 2) <= length &&
-      array_nth(elements.untagged(), i + 1) == jit_declare_word;
+  return (i + 2) <= length && nth(i + 1) == jit_declare_word;
 }
 
 bool quotation_jit::mega_lookup_p(cell i, cell length) {
   return (i + 4) <= length &&
-      TAG(array_nth(elements.untagged(), i + 1)) == FIXNUM_TYPE &&
-      TAG(array_nth(elements.untagged(), i + 2)) == ARRAY_TYPE &&
-      array_nth(elements.untagged(), i + 3) == parent->special_objects[MEGA_LOOKUP_WORD];
+      TAG(nth(i + 1)) == FIXNUM_TYPE &&
+      TAG(nth(i + 2)) == ARRAY_TYPE &&
+      nth(i + 3) == parent->special_objects[MEGA_LOOKUP_WORD];
 }
 
 /* Subprimitives should be flagged with whether they require a stack frame.
@@ -99,7 +98,7 @@ bool quotation_jit::special_subprimitive_p(cell obj) {
 bool quotation_jit::stack_frame_p() {
   cell length = array_capacity(elements.untagged());
   for (cell i = 0; i < length; i++) {
-    cell obj = array_nth(elements.untagged(), i);
+    cell obj = nth(i);
     cell tag = TAG(obj);
     if ((tag == WORD_TYPE && special_subprimitive_p(obj)) ||
         (tag == ARRAY_TYPE && mega_lookup_p(i, length)))
@@ -154,8 +153,7 @@ void quotation_jit::iterate_quotation() {
 
   for (cell i = 0; i < length; i++) {
     set_position(i);
-
-    data_root<object> obj(array_nth(elements.untagged(), i), parent);
+    data_root<object> obj(nth(i), parent);
 
     switch (obj.type()) {
       case WORD_TYPE:
@@ -202,11 +200,9 @@ void quotation_jit::iterate_quotation() {
         if (fast_if_p(i, length)) {
           emit_epilog(stack_frame);
           tail_call = true;
-
-          emit_quotation(array_nth(elements.untagged(), i));
-          emit_quotation(array_nth(elements.untagged(), i + 1));
+          emit_quotation(nth(i));
+          emit_quotation(nth(i + 1));
           emit(parent->special_objects[JIT_IF]);
-
           i += 2;
         } /* dip */
         else if (fast_dip_p(i, length)) {
@@ -230,9 +226,7 @@ void quotation_jit::iterate_quotation() {
         /* Method dispatch */
         if (mega_lookup_p(i, length)) {
           tail_call = true;
-          fixnum index = untag_fixnum(array_nth(elements.untagged(), i + 1));
-          emit_mega_cache_lookup(array_nth(elements.untagged(), i), index,
-                                 array_nth(elements.untagged(), i + 2));
+          emit_mega_cache_lookup(nth(i), untag_fixnum(nth(i + 1)), nth(i + 2));
           i += 3;
         } /* Non-optimizing compiler ignores declarations */
         else if (declare_p(i, length))
index 7177279dd6e19c69c3d69854802d5a3928d6846e..4f3f11c6a14f3ed3e552b4c7efbf1245ea037d8d 100644 (file)
@@ -4,6 +4,7 @@ struct quotation_jit : public jit {
   data_root<array> elements;
   bool compiling, relocate;
 
+  /* Allocates memory */
   quotation_jit(cell owner, bool compiling, bool relocate, factor_vm* vm)
       : jit(code_block_unoptimized, owner, vm),
         elements(false_object, vm),
@@ -11,6 +12,7 @@ struct quotation_jit : public jit {
         relocate(relocate) {}
   ;
 
+  cell nth(cell index);
   void init_quotation(cell quot);
   void emit_mega_cache_lookup(cell methods, fixnum index, cell cache);
   bool primitive_call_p(cell i, cell length);