[Quipu-dev] quipu/quipu: Optimize flag handling

Back to archive index

scmno****@osdn***** scmno****@osdn*****
Sun Jun 3 03:43:44 JST 2018


changeset 7294e939ef48 in quipu/quipu
details: http://hg.osdn.jp/view/quipu/quipu?cmd=changeset;node=7294e939ef48
user: Agustina Arzille <avarz****@riseu*****>
date: Sat Jun 02 18:43:29 2018 +0000
description: Optimize flag handling

diffstat:

 array.cpp    |   6 +++---
 builtins.cpp |   4 ++--
 bvector.cpp  |  10 +++++-----
 compiler.cpp |  22 +++++++++++-----------
 defs.h       |   5 +++++
 floatp.cpp   |  12 ++++++------
 function.cpp |   8 ++++----
 function.h   |   4 ++--
 integer.cpp  |   2 +-
 interp.cpp   |   2 +-
 io.cpp       |   6 +++---
 memory.cpp   |   6 +++---
 misc.cpp     |   4 ++--
 str.cpp      |   6 +++---
 stream.cpp   |  32 ++++++++++++++++----------------
 stream.h     |  16 ++++++++--------
 symbol.cpp   |   4 ++--
 symbol.h     |   2 ++
 table.cpp    |   6 +++---
 thread.cpp   |   6 +++---
 tree.cpp     |   4 ++--
 21 files changed, 87 insertions(+), 80 deletions(-)

diffs (truncated from 752 to 300 lines):

diff -r 603f39f98a99 -r 7294e939ef48 array.cpp
--- a/array.cpp	Fri Jun 01 17:12:52 2018 -0300
+++ b/array.cpp	Sat Jun 02 18:43:29 2018 +0000
@@ -126,7 +126,7 @@
 object nput_a (interpreter *interp, object ax,
   object iv, object val)
 {
-  if (qp_unlikely (as_varobj(ax)->flags & FLAGS_CONST))
+  if (qp_unlikely (as_varobj(ax)->flagged_p (FLAGS_CONST)))
     interp->raise_const ("nput:array");
   else if (!int_p (iv))
     interp->raise2 ("type-error", "nput:array: index is not an integer");
@@ -193,7 +193,7 @@
 {
   array *ap = as_array (obj);
 
-  if (qp_unlikely (ap->flags & FLAGS_CONST))
+  if (qp_unlikely (ap->flagged_p (FLAGS_CONST)))
     interp->raise_const ("nreverse:array");
   else if (ap->len == 0)
     qp_return (obj);
@@ -226,7 +226,7 @@
 {
   array *ap = as_array (obj);
   
-  if (qp_unlikely (ap->flags & FLAGS_CONST))
+  if (qp_unlikely (ap->flagged_p (FLAGS_CONST)))
     interp->raise_const ("nsort:array");
   else if (ap->len <= 1)
     qp_return (obj);
diff -r 603f39f98a99 -r 7294e939ef48 builtins.cpp
--- a/builtins.cpp	Fri Jun 01 17:12:52 2018 -0300
+++ b/builtins.cpp	Sat Jun 02 18:43:29 2018 +0000
@@ -51,7 +51,7 @@
 object copy (interpreter *interp, object obj, bool deep)
 {
   if (immediate_p (obj) || (varobj_p (obj) &&
-      (as_varobj(obj)->flags & FLAGS_CONST)))
+      (as_varobj(obj)->flagged_p (FLAGS_CONST))))
     qp_return (obj);
 
   switch (itype (obj))
@@ -750,7 +750,7 @@
   else if (!int_p (argv[1]))
     interp->raise2 ("type-error", "%putd: second "
       "argument must be an integer");
-  else if (as_symbol(*argv)->flags & FLAGS_CONST)
+  else if (as_symbol(*argv)->flagged_p (FLAGS_CONST))
     interp->raise2 ("const-error", "%putd: cannot assign to a constant");
 
   uint32_t eflags = 0;
diff -r 603f39f98a99 -r 7294e939ef48 bvector.cpp
--- a/bvector.cpp	Fri Jun 01 17:12:52 2018 -0300
+++ b/bvector.cpp	Sat Jun 02 18:43:29 2018 +0000
@@ -34,7 +34,7 @@
 
       bvector *ret = (bvector *)alloch (nbytes +
         this->hsize + 1, this->rtype);
-      ret->flags = this->flags;
+      ret->full |= this->flags;
       ret->data = (unsigned char *)ret + this->hsize;
       ret->nbytes = nbytes;
       ret->data[nbytes] = '\0';
@@ -317,7 +317,7 @@
   bvector *bp = as_bvector (bvec);
   int idx, val;
 
-  if (qp_unlikely (bp->flags & FLAGS_CONST))
+  if (qp_unlikely (bp->flagged_p (FLAGS_CONST)))
     interp->raise_const ("nput:bvector");
   else if (!int_p (ix) || !int_p (byte) ||
       (val = (unsigned int)as_int (byte)) > 0xff)
@@ -396,7 +396,7 @@
 {
   bvector *bp = as_bvector (obj);
 
-  if (qp_unlikely (bp->flags & FLAGS_CONST))
+  if (qp_unlikely (bp->flagged_p (FLAGS_CONST)))
     interp->raise_const ("nreverse:bvector");
   else if (bp->nbytes == 0)
     qp_return (obj);
@@ -592,10 +592,10 @@
 do_init_bvector (interpreter *)
 {
   static const unsigned char empty_data[] = { 0 };
+  empty_bvector.full = FLAGS_CONST;
   empty_bvector.type = typecode::BVECTOR;
-  empty_bvector.flags = FLAGS_CONST;
+  empty_string.full = FLAGS_CONST;
   empty_string.type = typecode::STR;
-  empty_string.flags = FLAGS_CONST;
   empty_bvector.data = empty_string.data = (unsigned char *)empty_data;
   return (true);
 }
diff -r 603f39f98a99 -r 7294e939ef48 compiler.cpp
--- a/compiler.cpp	Fri Jun 01 17:12:52 2018 -0300
+++ b/compiler.cpp	Sat Jun 02 18:43:29 2018 +0000
@@ -596,7 +596,7 @@
   simplify_jmps (this->bytecode, fixup_lbl, large);
 
   // Finally, register the bytecode and return.
-  this->bytecode->flags |= FLAGS_CONST;
+  this->bytecode->full |= FLAGS_CONST;
   interp->alval = this->bytecode->as_obj ();
   gcregister (interp, this->bytecode);
   return (interp->alval);
@@ -764,7 +764,7 @@
 
   if (expr == NIL)
     return (expr);
-  else if (symbol_p (expr) && (as_varobj(expr)->flags & FLAGS_CONST))
+  else if (symbol_p (expr) && (as_symbol(expr)->flagged_p (FLAGS_CONST)))
     return (symval (expr));
 
   object head = xcar (expr), xt;
@@ -864,11 +864,11 @@
   if (loc < 0)
     {
       const varobj *vp = as_varobj (s);
-      if ((vp->flags & FLAGS_CONST) && *ixs == OPX_(LOADA))
+      if ((vp->flagged_p (FLAGS_CONST)) && *ixs == OPX_(LOADA))
         return (this->compile_atom (env, tail, symval (s), true));
       else
         // Dynamic access.
-        this->emit (ixs[(vp->flags & symbol::special_flag) ? 4 : 2], s);
+        this->emit (ixs[(vp->flagged_p (symbol::special_flag)) ? 4 : 2], s);
     }
   else if (depth < -this->inlet || (this->inlet &&
       depth == -this->inlet && index_of (s, xcar (env)) >= 0))
@@ -1737,7 +1737,7 @@
 static inline bool
 special_symbol_p (object obj)
 {
-  return ((as_varobj(obj)->flags & symbol::special_flag) != 0);
+  return (as_symbol(obj)->flagged_p (symbol::special_flag));
 }
 
 int bc_emitter::compile_let (object env, bool tail, object expr)
@@ -2565,7 +2565,7 @@
 
       if (!symbol_p (retval))
         raise_e (interp, "apply: expected a symbol, not", 0, retval);
-      else if ((as_symbol(retval)->flags & symbol::ctv_flag) ||
+      else if ((as_symbol(retval)->flagged_p (symbol::ctv_flag)) ||
           (interp->aux = symval (retval)) == UNBOUND)
         raise_e (interp, "apply: symbol", " is unbound",
           retval, "unbound-error");
@@ -2580,9 +2580,9 @@
       if (!symbol_p (retval))
         raise_e (interp, "setq requires a symbol as its argument, "
           "not ", 0, retval);
-      else if (as_varobj(retval)->flags & FLAGS_CONST)
+      else if (as_varobj(retval)->flagged_p (FLAGS_CONST))
         interp->raise2 ("const-error", "setq: cannot assign to a constant");
-      else if (!(as_varobj(retval)->flags & symbol::special_flag) ||
+      else if (!(as_symbol(retval)->flagged_p (symbol::special_flag)) ||
           !interp->update_dbind (retval, interp->stktop ()))
         symval(retval) = interp->stktop ();
       NEXT_OP;
@@ -2936,7 +2936,7 @@
   valref s2 (interp, sym);
 
   if (nksymbol_p (*s2) && (*s2 = lookup_alias (env, sym)) == sym &&
-      (as_symbol(*s2)->flags & symbol::alias_flag))
+      (as_symbol(*s2)->flagged_p (symbol::alias_flag)))
     *s2 = symval (*s2);
 
   qp_return (*s2);
@@ -2951,7 +2951,7 @@
     qp_return (expr);
   else if ((x = lookup_ctv (env, h)) == h)
     { // XXX: Rewrite once packages are working.
-      if (!(as_varobj(h)->flags & symbol::ctv_flag) ||
+      if (!(as_symbol(h)->flagged_p (symbol::ctv_flag)) ||
           !fct_p (interp->retval = symval (h)))
         qp_return (expr);
      
@@ -3010,7 +3010,7 @@
   switch (itype (expr))
     {
       case typecode::SYMBOL:
-        if (as_symbol(expr)->flags & (symbol::ctv_flag | symbol::alias_flag))
+        if (as_symbol(expr)->flagged_p (symbol::ctv_flag | symbol::alias_flag))
           break;
 
         interp->retval = symval (expr);
diff -r 603f39f98a99 -r 7294e939ef48 defs.h
--- a/defs.h	Fri Jun 01 17:12:52 2018 -0300
+++ b/defs.h	Sat Jun 02 18:43:29 2018 +0000
@@ -170,6 +170,11 @@
 #endif
     }
 
+  bool flagged_p (uint32_t __flg) const
+    {
+      return ((this->full & __flg) != 0);
+    }
+
   // Atomically manipulate the flags of a varobj.
   void set_flag (uint32_t __flg);
   void clr_flag (uint32_t __flg);
diff -r 603f39f98a99 -r 7294e939ef48 floatp.cpp
--- a/floatp.cpp	Fri Jun 01 17:12:52 2018 -0300
+++ b/floatp.cpp	Sat Jun 02 18:43:29 2018 +0000
@@ -183,7 +183,7 @@
     typecode::FLOAT, TYPE_SHIFT + 1);
 
   retp->val = val;
-  retp->flags |= FLAGS_CONST;
+  retp->full |= FLAGS_CONST;
 
   interp->alval = retp->as_obj ();
   gcregister (interp, retp);
@@ -211,10 +211,10 @@
       bigfloat tx, ty;   \
       limb_t data1[LNDBL_SIZE], data2[LNDBL_SIZE];   \
       \
+      tx.full = ty.full = 0;   \
       tx.type = ty.type = typecode::BIGFLOAT;   \
       tx.expo = dbltoui (fabs (d1), tx.data = data1, tx.len);   \
       ty.expo = dbltoui (fabs (d2), ty.data = data2, ty.len);   \
-      tx.flags = ty.flags = 0;   \
       \
       return (alt##_FF (interp,   \
         make_bigfloat (&tx, s1), make_bigfloat (&ty, s2)));   \
@@ -394,7 +394,7 @@
 
   retp->len = len;
   retp->data = (limb_t *)((char *)&retp[1] + bigfloat::data_offset);
-  retp->flags = FLAGS_CONST;
+  retp->full = FLAGS_CONST;
 
   return (retp);
 }
@@ -1226,7 +1226,7 @@
 static inline object
 int2flt (object i, fltval& out)
 {
-  out.flags = 0;
+  out.full = 0;
   out.type = typecode::FLOAT;
   out.val = as_int (i);
   return (out.as_obj ());
@@ -1236,10 +1236,10 @@
 bigint2flt (object i, bigfloat& out)
 {
   const bigint *lp = as_bigint (i);
+  out.full = 0;
   out.type = typecode::BIGFLOAT;
   out.data = lp->data;
   out.len = lp->len, out.expo = F_ABS (out.len);
-  out.flags = 0;
 #ifdef QP_ARCH_WIDE
   return (out.as_obj () | (i & SIGN_BIT));
 #else
@@ -1251,9 +1251,9 @@
 upgrade_float (double f, int sign,
   bigfloat& out, limb_t *datap)
 {
+  out.full = 0;
   out.type = typecode::BIGFLOAT;
   out.expo = dbltoui (fabs (f), out.data = datap, out.len);
-  out.flags = 0;
 
 #ifdef QP_ARCH_WIDE
   return (out.as_obj () | (sign ? SIGN_BIT : 0));
diff -r 603f39f98a99 -r 7294e939ef48 function.cpp
--- a/function.cpp	Fri Jun 01 17:12:52 2018 -0300
+++ b/function.cpp	Sat Jun 02 18:43:29 2018 +0000
@@ -17,7 +17,7 @@
   function *fp = (function *)alloch (sizeof (*fp), typecode::FCT);
   fp->bcode = fp->vals = NIL;
   fp->env = fp->name = NIL;
-  fp->flags = flags;
+  fp->full |= flags;
   interp->alval = fp->as_obj ();
   gcregister (interp, fp);
   return (interp->alval);
@@ -26,8 +26,8 @@
 void native_function::add_fct (interpreter *interp, const char *name,
   fn_type fct, uint32_t flag, native_function *outp)
 {
-  outp->flags = native_function::native_flag;
   outp->type = typecode::FCT;
+  outp->full |= native_function::native_flag;
   outp->fct = fct;
   outp->name = name;
 
@@ -44,10 +44,10 @@
 
 bool eq_xx (interpreter *interp, object x, object y)
 {
-  if ((as_varobj(x)->flags ^ as_varobj(y)->flags) &
+  if ((as_varobj(x)->full ^ as_varobj(y)->full) &
       native_function::native_flag)
     return (false);
-  else if (as_varobj(x)->flags & native_function::native_flag)
+  else if (as_varobj(x)->flagged_p (native_function::native_flag))
     return (as_native_fct(x)->fct == as_native_fct(y)->fct);
   else




More information about the Quipu-dev mailing list
Back to archive index