Skip to content

Commit 46cedfd

Browse files
committed
kernel: change pcp collector to use their own stacks
... instead of using the stack objects in the pcp collector objects provided by the polycyclic package. This will make it possible to remove the latter in a future version of polycyclic, thus reducing the size of these objects considerably.
1 parent 7a9c9b8 commit 46cedfd

File tree

2 files changed

+50
-6
lines changed

2 files changed

+50
-6
lines changed

src/objcftl.c

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,28 @@
1919

2020
#include "ariths.h"
2121
#include "error.h"
22+
#include "gapstate.h"
2223
#include "gvars.h"
2324
#include "integer.h"
2425
#include "modules.h"
2526
#include "plist.h"
2627

2728

29+
static ModuleStateOffset CFTLStateOffset = -1;
30+
31+
struct CFTLModuleState {
32+
Obj WORD_STACK;
33+
Obj WORD_EXPONENT_STACK;
34+
Obj SYLLABLE_STACK;
35+
Obj EXPONENT_STACK;
36+
};
37+
38+
extern inline struct CFTLModuleState *CFTLState(void)
39+
{
40+
return (struct CFTLModuleState *)StateSlotsAtOffset(CFTLStateOffset);
41+
}
42+
43+
2844
#define IS_INT_ZERO( n ) ((n) == INTOBJ_INT(0))
2945

3046
#define GET_COMMUTE( g ) INT_INTOBJ(ELM_PLIST(commute,(g)))
@@ -87,14 +103,14 @@ Obj CollectPolycyc (
87103
Obj ipow = ADDR_OBJ(pcp)[ PC_INVERSEPOWERS ];
88104
Obj exp = ADDR_OBJ(pcp)[ PC_EXPONENTS ];
89105

90-
Obj wst = ADDR_OBJ(pcp)[ PC_WORD_STACK ];
91-
Obj west = ADDR_OBJ(pcp)[ PC_WORD_EXPONENT_STACK ];
92-
Obj sst = ADDR_OBJ(pcp)[ PC_SYLLABLE_STACK ];
93-
Obj est = ADDR_OBJ(pcp)[ PC_EXPONENT_STACK ];
106+
Obj wst = CFTLState()->WORD_STACK;
107+
Obj west = CFTLState()->WORD_EXPONENT_STACK;
108+
Obj sst = CFTLState()->SYLLABLE_STACK;
109+
Obj est = CFTLState()->EXPONENT_STACK;
94110

95111
Obj conj=0, iconj=0; /*QQ initialize to please compiler */
96112

97-
Int st, bottom = INT_INTOBJ( ADDR_OBJ(pcp)[ PC_STACK_POINTER ] );
113+
Int st, bottom = 0;
98114

99115
Int g, syl, h, hh;
100116

@@ -296,7 +312,6 @@ Obj CollectPolycyc (
296312
}
297313
}
298314

299-
ADDR_OBJ(pcp)[ PC_STACK_POINTER ] = INTOBJ_INT( bottom );
300315
return (Obj)0;
301316
}
302317

@@ -394,6 +409,13 @@ static Int InitLibrary (
394409
return 0;
395410
}
396411

412+
static void InitModuleState(ModuleStateOffset offset)
413+
{
414+
CFTLState()->WORD_STACK = NEW_PLIST( T_PLIST, 4096 );
415+
CFTLState()->WORD_EXPONENT_STACK = NEW_PLIST( T_PLIST, 4096 );
416+
CFTLState()->SYLLABLE_STACK = NEW_PLIST( T_PLIST, 4096 );
417+
CFTLState()->EXPONENT_STACK = NEW_PLIST( T_PLIST, 4096 );
418+
}
397419

398420
/****************************************************************************
399421
**
@@ -411,5 +433,6 @@ static StructInitInfo module = {
411433

412434
StructInitInfo * InitInfoPcc ( void )
413435
{
436+
CFTLStateOffset = RegisterModuleState(sizeof(struct CFTLModuleState), InitModuleState, 0);
414437
return &module;
415438
}

src/objcftl.h

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,35 @@
2727
#define PC_DEEP_THOUGHT_BOUND 13
2828
#define PC_ORDERS 14
2929

30+
// TODO: the following stack related positions are not
31+
// used anymore by CollectPolycyc, and will not be used
32+
// anymore in future releases of the polycyclic package.
33+
// We should phase them out for GAP 4.10.
3034
#define PC_WORD_STACK 15
3135
#define PC_STACK_SIZE 16
3236
#define PC_WORD_EXPONENT_STACK 17
3337
#define PC_SYLLABLE_STACK 18
3438
#define PC_EXPONENT_STACK 19
3539
#define PC_STACK_POINTER 20
40+
// TODO: end obsolete
41+
3642
#define PC_DEFAULT_TYPE 21
3743

44+
/* the following are defined in polycyclic:
45+
46+
#define PC_PCP_ELEMENTS_FAMILY 22
47+
#define PC_PCP_ELEMENTS_TYPE 23
48+
49+
#define PC_COMMUTATORS 24
50+
#define PC_INVERSECOMMUTATORS 25
51+
#define PC_COMMUTATORSINVERSE 26
52+
#define PC_INVERSECOMMUTATORSINVERSE 27
53+
54+
#define PC_NILPOTENT_COMMUTE 28
55+
#define PC_WEIGHTS 29
56+
#define PC_ABELIAN_START 30
57+
*/
58+
3859
/****************************************************************************
3960
**
4061
*F * * * * * * * * * * * * * initialize module * * * * * * * * * * * * * * *

0 commit comments

Comments
 (0)