Skip to content

Commit

Permalink
kernel: replace NEW_WORD by NewWord
Browse files Browse the repository at this point in the history
Also move implementation of NewWord from .h into .c file; it is
not that performance critical, and this way, we don't have to include
HPC-GAP specific headers from `objfgelm.h`.
  • Loading branch information
fingolfin committed Oct 5, 2018
1 parent e10aef5 commit 94e61ab
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 48 deletions.
6 changes: 3 additions & 3 deletions src/collectors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ Obj WordVectorAndClear ( Obj type, Obj vv, Int num )
expm = (1UL << ebits) - 1;

/* construct a new object */
NEW_WORD( obj, type, num );
obj = NewWord(type, num);

/* clear <vv> */
ptr = DATA_WORD(obj);
Expand Down Expand Up @@ -655,7 +655,7 @@ Int Solution(
expm = (1UL << ebits) - 1;

/* use <g> as right argument for the collector */
NEW_WORD( g, SC_DEFAULT_TYPE(sc), 1 );
g = NewWord(SC_DEFAULT_TYPE(sc), 1);

/* start clearing <ww>, storing the result in <uu> */
ptr = (Int*)(ADDR_OBJ(ww)+1);
Expand Down Expand Up @@ -1471,7 +1471,7 @@ Obj ReducedPowerSmallInt (

/* return the trivial word if <pow> is zero */
if ( pow == 0 ) {
NEW_WORD( res, type, 0 );
res = NewWord(type, 0);
return res;
}

Expand Down
53 changes: 35 additions & 18 deletions src/objfgelm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
** the family. Any object of this type looks like:
**
** +------+-----+-------+-------+-----+-----------+
** | TYPE | len | g1/e1 | g2/e2 | ... | glen/elen |
** | TYPE | len | g1/e1 | g2/e2 | ... | glen/elen |
** +------+-----+-------+-------+-----+-----------+
**
** where <len> is a GAP integer object and <gi>/<ei> occupies 8, 16, or 32
Expand All @@ -29,16 +29,12 @@
** of accessing these entries directly you should use the following macros.
**
**
** The file "objects.h" defines the following macros:
** The file "objfgelm.h" defines the following functions and macros:
**
** NEW_WORD( <result>, <type>, <npairs> )
** creates a new objects of type <type> with room for <npairs>
** NewWord(( <type>, <npairs> )
** returns a new objects of type <type> with room for <npairs>
** generator/exponent pairs.
**
** RESIZE_WORD( <word>, <npairs> )
** resizes the <word> such that it will hold <npairs> generator/exponent
** pairs.
**
**
** BITS_WORD( <word> )
** returns the number of bits as C integers
Expand Down Expand Up @@ -86,6 +82,9 @@ extern "C" {
#include "plist.h"
#include "stringobj.h"

#ifdef HPCGAP
#include "hpc/guards.h"
#endif
}

// OverflowType<UIntN> is a type which is larger enough to detect
Expand All @@ -97,6 +96,23 @@ template<> struct OverflowType<UInt2> { typedef Int type; };
template<> struct OverflowType<UInt4> { typedef Int8 type; };


extern Obj NewWord(Obj type, UInt npairs)
{
Obj word;
#ifdef HPCGAP
ReadGuard(type);
#endif
word =
NewBag(T_DATOBJ, 2 * sizeof(Obj) + npairs * BITS_WORDTYPE(type) / 8L);
ADDR_OBJ(word)[1] = INTOBJ_INT(npairs);
SetTypeDatObj(word, type);
#ifdef HPCGAP
MakeBagReadOnly(word);
#endif
return word;
}


/****************************************************************************
**
*F FuncNBits_Equal( <self>, <l>, <r> )
Expand Down Expand Up @@ -418,7 +434,7 @@ Obj FuncNBits_HeadByNumber (
return l;

/* create a new word */
NEW_WORD( obj, PURETYPE_WORD(l), sl );
obj = NewWord(PURETYPE_WORD(l), sl);

/* copy the <l> part into the word */
po = DATA_WORD(obj);
Expand Down Expand Up @@ -589,7 +605,7 @@ Obj FuncNBits_AssocWord (

/* construct a new object */
num = LEN_LIST(data)/2;
NEW_WORD( obj, type, num );
obj = NewWord(type, num);

ptr = DATA_WORD(obj);
for ( i = 1; i <= num; i++, ptr++ ) {
Expand Down Expand Up @@ -658,7 +674,7 @@ Obj FuncNBits_ObjByVector (
}

/* construct a new object */
NEW_WORD( obj, type, num );
obj = NewWord(type, num);

ptr = DATA_WORD(obj);
for ( i = 1; i <= num; i++, ptr++, j++ ) {
Expand Down Expand Up @@ -727,7 +743,7 @@ Obj FuncNBits_Power (
/* if <pow> is zero return the identity */
pow = INT_INTOBJ(r);
if ( pow == 0 ) {
NEW_WORD( obj, PURETYPE_WORD(l), 0 );
obj = NewWord(PURETYPE_WORD(l), 0);
return obj;
}

Expand All @@ -737,7 +753,7 @@ Obj FuncNBits_Power (

/* if <pow> is minus one invert <l> */
if ( pow == -1 ) {
NEW_WORD( obj, PURETYPE_WORD(l), nl );
obj = NewWord(PURETYPE_WORD(l), nl);
pl = CONST_DATA_WORD(l);
pr = DATA_WORD(obj) + (nl-1);
sl = nl;
Expand Down Expand Up @@ -775,7 +791,7 @@ Obj FuncNBits_Power (
}

/* copy <l> into <obj> */
NEW_WORD( obj, PURETYPE_WORD(l), nl );
obj = NewWord(PURETYPE_WORD(l), nl);
pl = CONST_DATA_WORD(l);
pr = DATA_WORD(obj);
sl = nl;
Expand Down Expand Up @@ -806,7 +822,8 @@ Obj FuncNBits_Power (

/* create a new word */
apw = ( pow < 0 ) ? -pow : pow;
NEW_WORD( obj, PURETYPE_WORD(l), 2*(sl+1)+apw*(sr-sl-1)+(apw-1) );
obj = NewWord(PURETYPE_WORD(l),
2 * (sl + 1) + apw * (sr - sl - 1) + (apw - 1));

/* copy the beginning w * gj^x into <obj> */
pl = CONST_DATA_WORD(l);
Expand Down Expand Up @@ -863,7 +880,7 @@ Obj FuncNBits_Power (

/* create a new word */
apw = ( pow < 0 ) ? -pow : pow;
NEW_WORD( obj, PURETYPE_WORD(l), 2*sl+apw*(sr-sl+1) );
obj = NewWord(PURETYPE_WORD(l), 2 * sl + apw * (sr - sl + 1));

/* copy the beginning w * gj^x into <obj> */
pl = CONST_DATA_WORD(l);
Expand Down Expand Up @@ -978,7 +995,7 @@ Obj FuncNBits_Product (
return TRY_NEXT_METHOD;
}
}
NEW_WORD( obj, PURETYPE_WORD(l), nl+(nr-sr)-over );
obj = NewWord(PURETYPE_WORD(l), nl + (nr - sr) - over);

/* copy the <l> part into the word */
po = DATA_WORD(obj);
Expand Down Expand Up @@ -1065,7 +1082,7 @@ Obj FuncNBits_Quotient (
return TRY_NEXT_METHOD;
}
}
NEW_WORD( obj, PURETYPE_WORD(l), nl+nr-over );
obj = NewWord(PURETYPE_WORD(l), nl + nr - over);

/* copy the <l> part into the word */
po = DATA_WORD(obj);
Expand Down
31 changes: 4 additions & 27 deletions src/objfgelm.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@
#define GAP_OBJFGELM_H

#include "objects.h"
#include "plist.h"

#ifdef HPCGAP
#include "hpc/guards.h"
#endif

/****************************************************************************
**
Expand Down Expand Up @@ -121,30 +116,12 @@

/****************************************************************************
**
*F NEW_WORD( <word>, <type>, <npairs> )
*F NewWord( <type>, <npairs> )
**
** 'NEW_WORD' creates a new object which has the given <type> and room for
** <npairs> pairs of generator number/exponent. The new word is return in
** <word>.
** 'NewWord' returns a new object which has the given <type> and room for
** <npairs> pairs of generator number/exponent.
*/
static inline Obj NewWord(Obj type, UInt npairs) {
Obj word;
#ifdef HPCGAP
ReadGuard(type);
#endif
word = NewBag(T_DATOBJ,2*sizeof(Obj)+npairs*BITS_WORDTYPE(type)/8L);
ADDR_OBJ(word)[1] = INTOBJ_INT(npairs);
SetTypeDatObj(word, type);
#ifdef HPCGAP
MakeBagReadOnly( word );
#endif
return word;
}

#define NEW_WORD(word, type, npairs) \
do { \
(word) = NewWord((type), (npairs)); \
} while(0)
extern Obj NewWord(Obj type, UInt npairs);


/****************************************************************************
Expand Down

0 comments on commit 94e61ab

Please sign in to comment.