Skip to content

Commit

Permalink
kernel: change static inline to EXPORT_INLINE
Browse files Browse the repository at this point in the history
... which is #defined to `inline` in `system.h` by default, unless it is
already defined differently. And we do define it differently in one place,
namely in debug.c, where we set it to `extern inline`.

This ensures all these functions have external linkage, and are emitted at
least once as an actual function (even if all calls to them are inlined). They
thus can be referenced from clients of libgap, which so far had to manually
write wrappers for any of our static inline functions.

It also prevents the compiler from emitting multiple instances of the same
function, which can confuse lldb when debugging (as a result, I was no longer
able to use functions like TNAM_OBJ, IS_INTOBJ etc. in lldb, which made
debugging MUCH harder than it used to be; the immediate cause for this was
that we now also compile some code as C++, which resulted in two slightly
different versions of these functions to be emitted, namely one with the
original name, and one with a C++ mangled name).

Finally, we can get rid of the `debug_func_pointers` array in debug.c, whose
maintenance was a bit of a nuisance.
  • Loading branch information
fingolfin committed Jan 7, 2019
1 parent c3dba02 commit 7a18e51
Show file tree
Hide file tree
Showing 39 changed files with 410 additions and 724 deletions.
38 changes: 19 additions & 19 deletions src/ariths.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ extern ArithMethod1 ZeroFuncs[LAST_REAL_TNUM + 1];
**
** 'ZERO' returns the zero of the object <op>.
*/
static inline Obj ZERO(Obj op)
EXPORT_INLINE Obj ZERO(Obj op)
{
UInt tnum = TNUM_OBJ(op);
return (*ZeroFuncs[tnum])(op);
Expand All @@ -86,7 +86,7 @@ extern ArithMethod1 ZeroMutFuncs[LAST_REAL_TNUM + 1];
**
** 'ZERO_MUT' returns the mutable zero of the object <op>.
*/
static inline Obj ZERO_MUT(Obj op)
EXPORT_INLINE Obj ZERO_MUT(Obj op)
{
UInt tnum = TNUM_OBJ(op);
return (*ZeroMutFuncs[tnum])(op);
Expand All @@ -106,7 +106,7 @@ extern ArithMethod1 AInvFuncs[LAST_REAL_TNUM + 1];
**
** 'AINV' returns the additive inverse of the object <op>.
*/
static inline Obj AINV(Obj op)
EXPORT_INLINE Obj AINV(Obj op)
{
UInt tnum = TNUM_OBJ(op);
return (*AInvFuncs[tnum])(op);
Expand All @@ -126,7 +126,7 @@ extern ArithMethod1 AInvMutFuncs[LAST_REAL_TNUM + 1];
**
** 'AINV_MUT' returns the mutable additive inverse of the object <op>.
*/
static inline Obj AINV_MUT(Obj op)
EXPORT_INLINE Obj AINV_MUT(Obj op)
{
UInt tnum = TNUM_OBJ(op);
return (*AInvMutFuncs[tnum])(op);
Expand Down Expand Up @@ -170,7 +170,7 @@ extern ArithMethod1 OneFuncs[LAST_REAL_TNUM + 1];
**
** 'ONE' returns the one of the object <op>.
*/
static inline Obj ONE(Obj op)
EXPORT_INLINE Obj ONE(Obj op)
{
UInt tnum = TNUM_OBJ(op);
return (*OneFuncs[tnum])(op);
Expand All @@ -191,7 +191,7 @@ extern ArithMethod1 OneMutFuncs[LAST_REAL_TNUM + 1];
** 'ONE_MUT' returns the one of the object <op> with the same
** mutability level as <op>.
*/
static inline Obj ONE_MUT(Obj op)
EXPORT_INLINE Obj ONE_MUT(Obj op)
{
UInt tnum = TNUM_OBJ(op);
return (*OneMutFuncs[tnum])(op);
Expand All @@ -211,7 +211,7 @@ extern ArithMethod1 InvFuncs[LAST_REAL_TNUM + 1];
**
** 'INV' returns the multiplicative inverse of the object <op>.
*/
static inline Obj INV(Obj op)
EXPORT_INLINE Obj INV(Obj op)
{
UInt tnum = TNUM_OBJ(op);
return (*InvFuncs[tnum])(op);
Expand All @@ -231,7 +231,7 @@ extern ArithMethod1 InvMutFuncs[LAST_REAL_TNUM + 1];
**
** 'INV_MUT' returns the multiplicative inverse of the object <op>.
*/
static inline Obj INV_MUT(Obj op)
EXPORT_INLINE Obj INV_MUT(Obj op)
{
UInt tnum = TNUM_OBJ(op);
return (*InvMutFuncs[tnum])(op);
Expand All @@ -258,7 +258,7 @@ extern CompaMethod EqFuncs[LAST_REAL_TNUM + 1][LAST_REAL_TNUM + 1];
** 'EQ' returns a nonzero value if the object <opL> is equal to the object
** <opR>, and zero otherwise.
*/
static inline Int EQ(Obj opL, Obj opR)
EXPORT_INLINE Int EQ(Obj opL, Obj opR)
{
if (opL == opR)
return 1;
Expand Down Expand Up @@ -286,7 +286,7 @@ extern CompaMethod LtFuncs[LAST_REAL_TNUM + 1][LAST_REAL_TNUM + 1];
** 'LT' returns a nonzero value if the object <opL> is less than the object
** <opR>, and zero otherwise.
*/
static inline Int LT(Obj opL, Obj opR)
EXPORT_INLINE Int LT(Obj opL, Obj opR)
{
if (opL == opR)
return 0;
Expand Down Expand Up @@ -314,7 +314,7 @@ extern CompaMethod InFuncs[LAST_REAL_TNUM + 1][LAST_REAL_TNUM + 1];
** 'IN' returns a nonzero value if the object <opL> is a member of the
** object <opR>, and zero otherwise.
*/
static inline Int IN(Obj opL, Obj opR)
EXPORT_INLINE Int IN(Obj opL, Obj opR)
{
UInt tnumL = TNUM_OBJ(opL);
UInt tnumR = TNUM_OBJ(opR);
Expand Down Expand Up @@ -346,7 +346,7 @@ extern ArithMethod2 SumFuncs[LAST_REAL_TNUM + 1][LAST_REAL_TNUM + 1];
** || ! SUM_INTOBJS( <res>, <opL>, <opR> ) )
** <res> = SUM( <opL>, <opR> );
*/
static inline Obj SUM(Obj opL, Obj opR)
EXPORT_INLINE Obj SUM(Obj opL, Obj opR)
{
UInt tnumL = TNUM_OBJ(opL);
UInt tnumR = TNUM_OBJ(opR);
Expand Down Expand Up @@ -404,7 +404,7 @@ extern ArithMethod2 DiffFuncs[LAST_REAL_TNUM + 1][LAST_REAL_TNUM + 1];
** || ! DIFF_INTOBJS( <res>, <opL>, <opR> ) )
** <res> = DIFF( <opL>, <opR> );
*/
static inline Obj DIFF(Obj opL, Obj opR)
EXPORT_INLINE Obj DIFF(Obj opL, Obj opR)
{
UInt tnumL = TNUM_OBJ(opL);
UInt tnumR = TNUM_OBJ(opR);
Expand Down Expand Up @@ -459,7 +459,7 @@ extern ArithMethod2 ProdFuncs[LAST_REAL_TNUM + 1][LAST_REAL_TNUM + 1];
** || ! PROD_INTOBJS( <res>, <opL>, <opR> ) )
** <res> = PROD( <opL>, <opR> );
*/
static inline Obj PROD(Obj opL, Obj opR)
EXPORT_INLINE Obj PROD(Obj opL, Obj opR)
{
UInt tnumL = TNUM_OBJ(opL);
UInt tnumR = TNUM_OBJ(opR);
Expand Down Expand Up @@ -508,7 +508,7 @@ extern ArithMethod2 QuoFuncs[LAST_REAL_TNUM + 1][LAST_REAL_TNUM + 1];
**
** 'QUO' returns the quotient of the object <opL> by the object <opR>.
*/
static inline Obj QUO(Obj opL, Obj opR)
EXPORT_INLINE Obj QUO(Obj opL, Obj opR)
{
UInt tnumL = TNUM_OBJ(opL);
UInt tnumR = TNUM_OBJ(opR);
Expand All @@ -529,7 +529,7 @@ extern ArithMethod2 LQuoFuncs[LAST_REAL_TNUM + 1][LAST_REAL_TNUM + 1];
**
** 'LQUO' returns the left quotient of the object <opL> by the object <opR>.
*/
static inline Obj LQUO(Obj opL, Obj opR)
EXPORT_INLINE Obj LQUO(Obj opL, Obj opR)
{
UInt tnumL = TNUM_OBJ(opL);
UInt tnumR = TNUM_OBJ(opR);
Expand All @@ -550,7 +550,7 @@ extern ArithMethod2 PowFuncs[LAST_REAL_TNUM + 1][LAST_REAL_TNUM + 1];
**
** 'POW' returns the power of the object <opL> by the object <opL>.
*/
static inline Obj POW(Obj opL, Obj opR)
EXPORT_INLINE Obj POW(Obj opL, Obj opR)
{
UInt tnumL = TNUM_OBJ(opL);
UInt tnumR = TNUM_OBJ(opR);
Expand All @@ -571,7 +571,7 @@ extern ArithMethod2 CommFuncs[LAST_REAL_TNUM + 1][LAST_REAL_TNUM + 1];
**
** 'COMM' returns the commutator of the two objects <opL> and <opR>.
*/
static inline Obj COMM(Obj opL, Obj opR)
EXPORT_INLINE Obj COMM(Obj opL, Obj opR)
{
UInt tnumL = TNUM_OBJ(opL);
UInt tnumR = TNUM_OBJ(opR);
Expand All @@ -592,7 +592,7 @@ extern ArithMethod2 ModFuncs[LAST_REAL_TNUM + 1][LAST_REAL_TNUM + 1];
**
** 'MOD' returns the remainder of the object <opL> by the object <opR>.
*/
static inline Obj MOD(Obj opL, Obj opR)
EXPORT_INLINE Obj MOD(Obj opL, Obj opR)
{
UInt tnumL = TNUM_OBJ(opL);
UInt tnumR = TNUM_OBJ(opR);
Expand Down
36 changes: 18 additions & 18 deletions src/blister.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
**
*F IS_BLIST_REP( <list> ) . . . . . check if <list> is in boolean list rep
*/
static inline Int IS_BLIST_REP(Obj list)
EXPORT_INLINE Int IS_BLIST_REP(Obj list)
{
return T_BLIST <= TNUM_OBJ(list) &&
TNUM_OBJ(list) <= T_BLIST_SSORT + IMMUTABLE;
Expand All @@ -42,7 +42,7 @@ static inline Int IS_BLIST_REP(Obj list)
** <plen> elements must at least have.
**
*/
static inline Int SIZE_PLEN_BLIST(Int plen)
EXPORT_INLINE Int SIZE_PLEN_BLIST(Int plen)
{
GAP_ASSERT(plen >= 0);
return sizeof(Obj) + (plen + BIPEB - 1) / BIPEB * sizeof(UInt);
Expand All @@ -56,7 +56,7 @@ static inline Int SIZE_PLEN_BLIST(Int plen)
** integer.
**
*/
static inline Int LEN_BLIST(Obj list)
EXPORT_INLINE Int LEN_BLIST(Obj list)
{
GAP_ASSERT(IS_BLIST_REP(list));
return INT_INTOBJ(CONST_ADDR_OBJ(list)[0]);
Expand All @@ -68,7 +68,7 @@ static inline Int LEN_BLIST(Obj list)
*F NUMBER_BLOCKS_BLIST(<list>) . . . . . . . . number of UInt blocks in list
**
*/
static inline Int NUMBER_BLOCKS_BLIST(Obj blist)
EXPORT_INLINE Int NUMBER_BLOCKS_BLIST(Obj blist)
{
GAP_ASSERT(IS_BLIST_REP(blist));
return (LEN_BLIST(blist) + BIPEB - 1) / BIPEB;
Expand All @@ -83,7 +83,7 @@ static inline Int NUMBER_BLOCKS_BLIST(Obj blist)
** <len>, which must be a positive C integer.
**
*/
static inline void SET_LEN_BLIST(Obj list, Int len)
EXPORT_INLINE void SET_LEN_BLIST(Obj list, Int len)
{
GAP_ASSERT(IS_BLIST_REP(list));
GAP_ASSERT(len >= 0);
Expand All @@ -98,12 +98,12 @@ static inline void SET_LEN_BLIST(Obj list, Int len)
** returns a pointer to the start of the data of the Boolean list
**
*/
static inline UInt * BLOCKS_BLIST(Obj list)
EXPORT_INLINE UInt * BLOCKS_BLIST(Obj list)
{
return ((UInt *)(ADDR_OBJ(list) + 1));
}

static inline const UInt * CONST_BLOCKS_BLIST(Obj list)
EXPORT_INLINE const UInt * CONST_BLOCKS_BLIST(Obj list)
{
return ((const UInt *)(CONST_ADDR_OBJ(list) + 1));
}
Expand All @@ -116,12 +116,12 @@ static inline const UInt * CONST_BLOCKS_BLIST(Obj list)
** <pos>-th element of the boolean list <list>. <pos> must be a positive
** integer less than or equal to the length of <list>.
*/
static inline UInt * BLOCK_ELM_BLIST_PTR(Obj list, UInt pos)
EXPORT_INLINE UInt * BLOCK_ELM_BLIST_PTR(Obj list, UInt pos)
{
return BLOCKS_BLIST(list) + ((pos)-1) / BIPEB;
}

static inline const UInt * CONST_BLOCK_ELM_BLIST_PTR(Obj list, UInt pos)
EXPORT_INLINE const UInt * CONST_BLOCK_ELM_BLIST_PTR(Obj list, UInt pos)
{
return CONST_BLOCKS_BLIST(list) + ((pos)-1) / BIPEB;
}
Expand All @@ -134,7 +134,7 @@ static inline const UInt * CONST_BLOCK_ELM_BLIST_PTR(Obj list, UInt pos)
** '(<pos>-1) % BIPEB',
** useful for accessing the <pos>-th element of a blist.
*/
static inline UInt MASK_POS_BLIST(UInt pos)
EXPORT_INLINE UInt MASK_POS_BLIST(UInt pos)
{
return ((UInt)1) << (pos - 1) % BIPEB;
}
Expand All @@ -147,7 +147,7 @@ static inline UInt MASK_POS_BLIST(UInt pos)
** boolean list <list> is 1, and otherwise 0. <pos> must be a positive
** integer less than or equal to the length of <list>.
*/
static inline Int TEST_BIT_BLIST(Obj list, UInt pos)
EXPORT_INLINE Int TEST_BIT_BLIST(Obj list, UInt pos)
{
return *CONST_BLOCK_ELM_BLIST_PTR(list, pos) & MASK_POS_BLIST(pos);
}
Expand All @@ -160,7 +160,7 @@ static inline Int TEST_BIT_BLIST(Obj list, UInt pos)
** either 'true' or 'false'. <pos> must be a positive integer less than or
** equal to the length of <list>.
*/
static inline Obj ELM_BLIST(Obj list, UInt pos)
EXPORT_INLINE Obj ELM_BLIST(Obj list, UInt pos)
{
return TEST_BIT_BLIST(list, pos) ? True : False;
}
Expand All @@ -174,12 +174,12 @@ static inline Obj ELM_BLIST(Obj list, UInt pos)
** to 1 resp. 0. <pos> must be a positive integer less than or equal to
** the length of <list>.
*/
static inline void SET_BIT_BLIST(Obj list, UInt pos)
EXPORT_INLINE void SET_BIT_BLIST(Obj list, UInt pos)
{
*BLOCK_ELM_BLIST_PTR(list, pos) |= MASK_POS_BLIST(pos);
}

static inline void CLEAR_BIT_BLIST(Obj list, UInt pos)
EXPORT_INLINE void CLEAR_BIT_BLIST(Obj list, UInt pos)
{
*BLOCK_ELM_BLIST_PTR(list, pos) &= ~MASK_POS_BLIST(pos);
}
Expand Down Expand Up @@ -222,7 +222,7 @@ static inline void CLEAR_BIT_BLIST(Obj list, UInt pos)
**
*/

static inline UInt COUNT_TRUES_BLOCK( UInt block ) {
EXPORT_INLINE UInt COUNT_TRUES_BLOCK( UInt block ) {
#if USE_POPCNT && defined(HAVE___BUILTIN_POPCOUNTL)
return __builtin_popcountl(block);
#else
Expand Down Expand Up @@ -268,7 +268,7 @@ static inline UInt COUNT_TRUES_BLOCK( UInt block ) {
*T monitor this situation periodically.
*/

static inline UInt COUNT_TRUES_BLOCKS(const UInt * ptr, UInt nblocks)
EXPORT_INLINE UInt COUNT_TRUES_BLOCKS(const UInt * ptr, UInt nblocks)
{
UInt n = 0;
while (nblocks >= 4) {
Expand Down Expand Up @@ -345,7 +345,7 @@ extern void ConvBlist (
*/

/* constructs a mask that selects bits <from> to <to> inclusive of a UInt */
static inline UInt MaskForCopyBits(UInt from, UInt to)
EXPORT_INLINE UInt MaskForCopyBits(UInt from, UInt to)
{
return ((to == BIPEB - 1) ? 0 : (1L << (to + 1))) - (1L << from);
}
Expand All @@ -356,7 +356,7 @@ static inline UInt MaskForCopyBits(UInt from, UInt to)
single word (so endbits + shift must be < BIPEB and frombits +
shift must be non-negative */

static inline void
EXPORT_INLINE void
CopyInWord(UInt * to, UInt startbit, UInt endbit, UInt from, Int shift)
{
UInt m = MaskForCopyBits(startbit + shift, endbit + shift);
Expand Down
Loading

0 comments on commit 7a18e51

Please sign in to comment.