Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/code.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@

GAP_STATIC_ASSERT(sizeof(StatHeader) == 8, "StatHeader has wrong size");

#ifdef HPCGAP
struct CodeModuleState {
Bag StackStat;
Int CountStat;
#endif
DECL_MODULE_STATE Bag StackStat;
DECL_MODULE_STATE Int CountStat;

Bag StackExpr;
Int CountExpr;
DECL_MODULE_STATE Bag StackExpr;
DECL_MODULE_STATE Int CountExpr;
#ifdef HPCGAP
};

static ModuleStateOffset CodeStateOffset = -1;
Expand All @@ -60,6 +63,9 @@ extern inline struct CodeModuleState * CShelper(void)
}

#define CS(x) (CShelper()->x)
#else
#define CS(x) (x)
#endif


/****************************************************************************
Expand Down Expand Up @@ -3250,8 +3256,10 @@ static StructInitInfo module = {
.preSave = PreSave,
.postRestore = PostRestore,

#ifdef HPCGAP
.moduleStateSize = sizeof(struct CodeModuleState),
.moduleStateOffsetPtr = &CodeStateOffset,
#endif
.initModuleState = InitModuleState,
};

Expand Down
114 changes: 65 additions & 49 deletions src/collectors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,19 @@ extern "C" {
*F * * * * * * * * * * * * * module specific state * * * * * * * * * * * * *
*/

#ifdef HPCGAP
struct CollectorsState_ {
Obj SC_NW_STACK;
Obj SC_LW_STACK;
Obj SC_PW_STACK;
Obj SC_EW_STACK;
Obj SC_GE_STACK;
Obj SC_CW_VECTOR;
Obj SC_CW2_VECTOR;
UInt SC_MAX_STACK_SIZE;
#endif

DECL_MODULE_STATE Obj SC_NW_STACK;
DECL_MODULE_STATE Obj SC_LW_STACK;
DECL_MODULE_STATE Obj SC_PW_STACK;
DECL_MODULE_STATE Obj SC_EW_STACK;
DECL_MODULE_STATE Obj SC_GE_STACK;
DECL_MODULE_STATE Obj SC_CW_VECTOR;
DECL_MODULE_STATE Obj SC_CW2_VECTOR;
DECL_MODULE_STATE UInt SC_MAX_STACK_SIZE;
#ifdef HPCGAP
};

static ModuleStateOffset CollectorsStateOffset = -1;
Expand All @@ -64,6 +68,17 @@ extern inline struct CollectorsState_ * CollectorsState(void)
return (struct CollectorsState_ *)StateSlotsAtOffset(CollectorsStateOffset);
}

#define SC_NW_STACK (CollectorsState()->SC_NW_STACK)
#define SC_LW_STACK (CollectorsState()->SC_LW_STACK)
#define SC_PW_STACK (CollectorsState()->SC_PW_STACK)
#define SC_EW_STACK (CollectorsState()->SC_EW_STACK)
#define SC_GE_STACK (CollectorsState()->SC_GE_STACK)
#define SC_CW_VECTOR (CollectorsState()->SC_CW_VECTOR)
#define SC_CW2_VECTOR (CollectorsState()->SC_CW2_VECTOR)
#define SC_MAX_STACK_SIZE (CollectorsState()->SC_MAX_STACK_SIZE)

#endif


/****************************************************************************
**
Expand All @@ -84,7 +99,7 @@ extern inline struct CollectorsState_ * CollectorsState(void)
*/
#define SC_PUSH_WORD( word, exp ) \
if ( ++sp == max ) { \
CollectorsState()->SC_MAX_STACK_SIZE *= 2; \
SC_MAX_STACK_SIZE *= 2; \
return -1; \
} \
*++nw = DATA_WORD(word); \
Expand All @@ -95,7 +110,7 @@ extern inline struct CollectorsState_ * CollectorsState(void)

#define SC_PUSH_GEN( gen, exp ) \
if ( ++sp == max ) { \
CollectorsState()->SC_MAX_STACK_SIZE *= 2; \
SC_MAX_STACK_SIZE *= 2; \
return -1; \
} \
*++nw = DATA_WORD(gen); \
Expand Down Expand Up @@ -385,22 +400,22 @@ static Int SingleCollectWord(Obj sc, Obj vv, Obj w)
exps = (UInt)1 << (ebits-1);

// <nw> contains the stack of words to insert
vnw = CollectorsState()->SC_NW_STACK;
vnw = SC_NW_STACK;

// <lw> contains the word end of the word in <nw>
vlw = CollectorsState()->SC_LW_STACK;
vlw = SC_LW_STACK;

// <pw> contains the position of the word in <nw> to look at
vpw = CollectorsState()->SC_PW_STACK;
vpw = SC_PW_STACK;

// <ew> contains the unprocessed exponents at position <pw>
vew = CollectorsState()->SC_EW_STACK;
vew = SC_EW_STACK;

// <ge> contains the global exponent of the word
vge = CollectorsState()->SC_GE_STACK;
vge = SC_GE_STACK;

// get the maximal stack size
max = CollectorsState()->SC_MAX_STACK_SIZE;
max = SC_MAX_STACK_SIZE;

// ensure that the stacks are large enough
const UInt desiredStackSize = sizeof(Obj) * (max + 2);
Expand Down Expand Up @@ -893,22 +908,22 @@ static Int CombiCollectWord(Obj sc, Obj vv, Obj w)
exps = (UInt)1 << (ebits-1);

// <nw> contains the stack of words to insert
vnw = CollectorsState()->SC_NW_STACK;
vnw = SC_NW_STACK;

// <lw> contains the word end of the word in <nw>
vlw = CollectorsState()->SC_LW_STACK;
vlw = SC_LW_STACK;

// <pw> contains the position of the word in <nw> to look at
vpw = CollectorsState()->SC_PW_STACK;
vpw = SC_PW_STACK;

// <ew> contains the unprocessed exponents at position <pw>
vew = CollectorsState()->SC_EW_STACK;
vew = SC_EW_STACK;

// <ge> contains the global exponent of the word
vge = CollectorsState()->SC_GE_STACK;
vge = SC_GE_STACK;

// get the maximal stack size
max = CollectorsState()->SC_MAX_STACK_SIZE;
max = SC_MAX_STACK_SIZE;

// ensure that the stacks are large enough
const UInt desiredStackSize = sizeof(Obj) * (max + 2);
Expand Down Expand Up @@ -1267,7 +1282,7 @@ static Obj ReducedComm(FinPowConjCol * fc, Obj sc, Obj w, Obj u)
Obj vc2; // collect vector

// use 'cwVector' to collect word <u>*<w> to
vcw = CollectorsState()->SC_CW_VECTOR;
vcw = SC_CW_VECTOR;
num = SC_NUMBER_RWS_GENERATORS(sc);

// check that it has the correct length, unpack <u> into it
Expand All @@ -1283,7 +1298,7 @@ static Obj ReducedComm(FinPowConjCol * fc, Obj sc, Obj w, Obj u)
}

// use 'cw2Vector' to collect word <w>*<u> to
vc2 = CollectorsState()->SC_CW2_VECTOR;
vc2 = SC_CW2_VECTOR;

// check that it has the correct length, unpack <w> into it
if ( fc->vectorWord( vc2, w, num ) == -1 ) {
Expand Down Expand Up @@ -1325,7 +1340,7 @@ static Obj ReducedForm(FinPowConjCol * fc, Obj sc, Obj w)
Obj type; // type of the return objue

// use 'cwVector' to collect word <w> to
vcw = CollectorsState()->SC_CW_VECTOR;
vcw = SC_CW_VECTOR;
num = SC_NUMBER_RWS_GENERATORS(sc);

// check that it has the correct length
Expand Down Expand Up @@ -1358,7 +1373,7 @@ static Obj ReducedLeftQuotient(FinPowConjCol * fc, Obj sc, Obj w, Obj u)
Obj vc2; // collect vector

// use 'cwVector' to collect word <w> to
vcw = CollectorsState()->SC_CW_VECTOR;
vcw = SC_CW_VECTOR;
num = SC_NUMBER_RWS_GENERATORS(sc);

// check that it has the correct length, unpack <w> into it
Expand All @@ -1368,7 +1383,7 @@ static Obj ReducedLeftQuotient(FinPowConjCol * fc, Obj sc, Obj w, Obj u)
}

// use 'cw2Vector' to collect word <u> to
vc2 = CollectorsState()->SC_CW2_VECTOR;
vc2 = SC_CW2_VECTOR;

// check that it has the correct length, unpack <u> into it
if ( fc->vectorWord( vc2, u, num ) == -1 ) {
Expand Down Expand Up @@ -1402,7 +1417,7 @@ static Obj ReducedProduct(FinPowConjCol * fc, Obj sc, Obj w, Obj u)
Obj vcw; // collect vector

// use 'cwVector' to collect word <w> to
vcw = CollectorsState()->SC_CW_VECTOR;
vcw = SC_CW_VECTOR;
num = SC_NUMBER_RWS_GENERATORS(sc);

// check that it has the correct length, unpack <w> into it
Expand Down Expand Up @@ -1441,8 +1456,8 @@ static Obj ReducedPowerSmallInt(FinPowConjCol * fc, Obj sc, Obj w, Obj vpow)
pow = INT_INTOBJ(vpow);

// use 'cwVector' and 'cw2Vector to collect words to
vcw = CollectorsState()->SC_CW_VECTOR;
vc2 = CollectorsState()->SC_CW2_VECTOR;
vcw = SC_CW_VECTOR;
vc2 = SC_CW2_VECTOR;
num = SC_NUMBER_RWS_GENERATORS(sc);
type = SC_DEFAULT_TYPE(sc);

Expand Down Expand Up @@ -1528,8 +1543,8 @@ static Obj ReducedQuotient(FinPowConjCol * fc, Obj sc, Obj w, Obj u)
Obj vc2; // collect vector

// use 'cwVector' to collect word <w> to
vcw = CollectorsState()->SC_CW_VECTOR;
vc2 = CollectorsState()->SC_CW2_VECTOR;
vcw = SC_CW_VECTOR;
vc2 = SC_CW2_VECTOR;
num = SC_NUMBER_RWS_GENERATORS(sc);
type = SC_DEFAULT_TYPE(sc);

Expand Down Expand Up @@ -1647,8 +1662,7 @@ static Obj FuncFinPowConjCol_ReducedQuotient ( Obj self, Obj sc, Obj w, Obj u )
*/
static Obj FuncSET_SCOBJ_MAX_STACK_SIZE(Obj self, Obj size)
{
CollectorsState()->SC_MAX_STACK_SIZE =
GetPositiveSmallInt(SELF_NAME, size);
SC_MAX_STACK_SIZE = GetPositiveSmallInt(SELF_NAME, size);
return 0;
}

Expand Down Expand Up @@ -1739,25 +1753,25 @@ static Int InitLibrary (
static Int InitModuleState(void)
{
// register global bags with the garbage collector
InitGlobalBag( &CollectorsState()->SC_NW_STACK, "SC_NW_STACK" );
InitGlobalBag( &CollectorsState()->SC_LW_STACK, "SC_LW_STACK" );
InitGlobalBag( &CollectorsState()->SC_PW_STACK, "SC_PW_STACK" );
InitGlobalBag( &CollectorsState()->SC_EW_STACK, "SC_EW_STACK" );
InitGlobalBag( &CollectorsState()->SC_GE_STACK, "SC_GE_STACK" );
InitGlobalBag( &CollectorsState()->SC_CW_VECTOR, "SC_CW_VECTOR" );
InitGlobalBag( &CollectorsState()->SC_CW2_VECTOR, "SC_CW2_VECTOR" );
InitGlobalBag(&SC_NW_STACK, "SC_NW_STACK");
InitGlobalBag(&SC_LW_STACK, "SC_LW_STACK");
InitGlobalBag(&SC_PW_STACK, "SC_PW_STACK");
InitGlobalBag(&SC_EW_STACK, "SC_EW_STACK");
InitGlobalBag(&SC_GE_STACK, "SC_GE_STACK");
InitGlobalBag(&SC_CW_VECTOR, "SC_CW_VECTOR");
InitGlobalBag(&SC_CW2_VECTOR, "SC_CW2_VECTOR");

const UInt maxStackSize = 256;
const UInt desiredStackSize = sizeof(Obj) * (maxStackSize + 2);
CollectorsState()->SC_NW_STACK = NewKernelBuffer(desiredStackSize);
CollectorsState()->SC_LW_STACK = NewKernelBuffer(desiredStackSize);
CollectorsState()->SC_PW_STACK = NewKernelBuffer(desiredStackSize);
CollectorsState()->SC_EW_STACK = NewKernelBuffer(desiredStackSize);
CollectorsState()->SC_GE_STACK = NewKernelBuffer(desiredStackSize);
SC_NW_STACK = NewKernelBuffer(desiredStackSize);
SC_LW_STACK = NewKernelBuffer(desiredStackSize);
SC_PW_STACK = NewKernelBuffer(desiredStackSize);
SC_EW_STACK = NewKernelBuffer(desiredStackSize);
SC_GE_STACK = NewKernelBuffer(desiredStackSize);

CollectorsState()->SC_CW_VECTOR = NEW_STRING(0);
CollectorsState()->SC_CW2_VECTOR = NEW_STRING(0);
CollectorsState()->SC_MAX_STACK_SIZE = maxStackSize;
SC_CW_VECTOR = NEW_STRING(0);
SC_CW2_VECTOR = NEW_STRING(0);
SC_MAX_STACK_SIZE = maxStackSize;

return 0;
}
Expand All @@ -1779,8 +1793,10 @@ static StructInitInfo module = {
/* preSave = */ 0,
/* postSave = */ 0,
/* postRestore = */ 0,
#ifdef HPCGAP
/* moduleStateSize = */ sizeof(CollectorsState_),
/* moduleStateOffsetPtr = */ &CollectorsStateOffset,
#endif
/* initModuleState = */ InitModuleState,
/* destroyModuleState = */ 0,
};
Expand Down
20 changes: 12 additions & 8 deletions src/cyclotom.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,11 @@ static inline void SET_NOF_CYC(Obj cyc, Obj val)

// #define XXX_CYC(cyc,len) (EXPOS_CYC(cyc,len)[0])


#ifdef HPCGAP
static ModuleStateOffset CycStateOffset = -1;

struct CycModuleState {
#endif

/****************************************************************************
**
Expand All @@ -158,7 +159,7 @@ struct CycModuleState {
** It is created in 'InitCyc' with room for up to 1000 coefficients and is
** resized when need arises.
*/
Obj ResultCyc;
DECL_MODULE_STATE Obj ResultCyc;

/****************************************************************************
**
Expand All @@ -178,9 +179,10 @@ Obj ResultCyc;
** is called to compute $e_n^i$ and can then do this easier by just putting
** 1 at the <i>th place in 'ResultCyc' and then calling 'Cyclotomic'.
*/
Obj LastECyc;
UInt LastNCyc;
DECL_MODULE_STATE Obj LastECyc;
DECL_MODULE_STATE UInt LastNCyc;

#ifdef HPCGAP
}; // end of struct CycModuleState

extern inline struct CycModuleState *CycState(void)
Expand All @@ -189,10 +191,10 @@ extern inline struct CycModuleState *CycState(void)
}

// For convenience and readability
#define ResultCyc CycState()->ResultCyc
#define LastECyc CycState()->LastECyc
#define LastNCyc CycState()->LastNCyc

#define ResultCyc (CycState()->ResultCyc)
#define LastECyc (CycState()->LastECyc)
#define LastNCyc (CycState()->LastNCyc)
#endif

static void GrowResultCyc(UInt size)
{
Expand Down Expand Up @@ -2201,8 +2203,10 @@ static StructInitInfo module = {
.initKernel = InitKernel,
.initLibrary = InitLibrary,

#ifdef HPCGAP
.moduleStateSize = sizeof(struct CycModuleState),
.moduleStateOffsetPtr = &CycStateOffset,
#endif
.initModuleState = InitModuleState,
};

Expand Down
Loading