From 4a443c8b48bef9f85e82c3283a1794d97513799f Mon Sep 17 00:00:00 2001 From: Max Horn Date: Fri, 8 Sep 2017 10:33:00 +0200 Subject: [PATCH] update src/cyclotom.c --- src/cyclotom.c | 223 ++++++++++++++++++++++++++----------------------- 1 file changed, 120 insertions(+), 103 deletions(-) diff --git a/src/cyclotom.c b/src/cyclotom.c index 3f6868a3860..42c1e1e6dd1 100644 --- a/src/cyclotom.c +++ b/src/cyclotom.c @@ -128,12 +128,29 @@ static inline UInt SIZE_CYC(Obj cyc) return SIZE_OBJ(cyc) / (sizeof(Obj)+sizeof(UInt4)); } -#define COEFS_CYC(cyc) (ADDR_OBJ(cyc)) -#define EXPOS_CYC(cyc,len) ((UInt4*)(ADDR_OBJ(cyc)+(len))) +static inline Obj * COEFS_CYC(Obj cyc) +{ + return ADDR_OBJ(cyc); +} + +static inline const Obj * CONST_COEFS_CYC(Obj cyc) +{ + return CONST_ADDR_OBJ(cyc); +} + +static inline UInt4 * EXPOS_CYC(Obj cyc, UInt len) +{ + return (UInt4 *)(ADDR_OBJ(cyc)+(len)); +} + +static inline const UInt4 * CONST_EXPOS_CYC(Obj cyc, UInt len) +{ + return (const UInt4 *)(CONST_ADDR_OBJ(cyc)+(len)); +} static inline Obj NOF_CYC(Obj cyc) { - return COEFS_CYC(cyc)[0]; + return CONST_COEFS_CYC(cyc)[0]; } static inline void SET_NOF_CYC(Obj cyc, Obj val) @@ -225,8 +242,8 @@ void PrintCyc ( { UInt n; /* order of the field */ UInt len; /* number of terms */ - Obj * cfs; /* pointer to the coefficients */ - UInt4 * exs; /* pointer to the exponents */ + const Obj * cfs; /* pointer to the coefficients */ + const UInt4 * exs; /* pointer to the exponents */ UInt i; /* loop variable */ n = INT_INTOBJ( NOF_CYC(cyc) ); @@ -234,8 +251,8 @@ void PrintCyc ( Pr("%>",0L,0L); for ( i = 1; i < len; i++ ) { /* get pointers, they can change during Pr */ - cfs = COEFS_CYC(cyc); - exs = EXPOS_CYC(cyc,len); + cfs = CONST_COEFS_CYC(cyc); + exs = CONST_EXPOS_CYC(cyc,len); if ( cfs[i]==INTOBJ_INT(1) && exs[i]==0 ) Pr("1",0L,0L); else if ( cfs[i]==INTOBJ_INT(1) && exs[i]==1 && i==1 ) @@ -291,10 +308,10 @@ Int EqCyc ( Obj opR ) { UInt len; /* number of terms */ - Obj * cfl; /* ptr to coeffs of left operand */ - UInt4 * exl; /* ptr to expnts of left operand */ - Obj * cfr; /* ptr to coeffs of right operand */ - UInt4 * exr; /* ptr to expnts of right operand */ + const Obj * cfl; /* ptr to coeffs of left operand */ + const UInt4 * exl; /* ptr to expnts of left operand */ + const Obj * cfr; /* ptr to coeffs of right operand */ + const UInt4 * exr; /* ptr to expnts of right operand */ UInt i; /* loop variable */ /* compare the order of both fields */ @@ -307,10 +324,10 @@ Int EqCyc ( /* compare the cyclotomics termwise */ len = SIZE_CYC(opL); - cfl = COEFS_CYC(opL); - cfr = COEFS_CYC(opR); - exl = EXPOS_CYC(opL,len); - exr = EXPOS_CYC(opR,len); + cfl = CONST_COEFS_CYC(opL); + cfr = CONST_COEFS_CYC(opR); + exl = CONST_EXPOS_CYC(opL,len); + exr = CONST_EXPOS_CYC(opR,len); for ( i = 1; i < len; i++ ) { if ( exl[i] != exr[i] ) return 0L; @@ -347,11 +364,11 @@ Int LtCyc ( Obj opR ) { UInt lel; /* nr of terms of left operand */ - Obj * cfl; /* ptr to coeffs of left operand */ - UInt4 * exl; /* ptr to expnts of left operand */ + const Obj * cfl; /* ptr to coeffs of left operand */ + const UInt4 * exl; /* ptr to expnts of left operand */ UInt ler; /* nr of terms of right operand */ - Obj * cfr; /* ptr to coeffs of right operand */ - UInt4 * exr; /* ptr to expnts of right operand */ + const Obj * cfr; /* ptr to coeffs of right operand */ + const UInt4 * exr; /* ptr to expnts of right operand */ UInt i; /* loop variable */ /* compare the order of both fields */ @@ -365,10 +382,10 @@ Int LtCyc ( /* compare the cyclotomics termwise */ lel = SIZE_CYC(opL); ler = SIZE_CYC(opR); - cfl = COEFS_CYC(opL); - cfr = COEFS_CYC(opR); - exl = EXPOS_CYC(opL,lel); - exr = EXPOS_CYC(opR,ler); + cfl = CONST_COEFS_CYC(opL); + cfr = CONST_COEFS_CYC(opR); + exl = CONST_EXPOS_CYC(opL,lel); + exr = CONST_EXPOS_CYC(opR,ler); for ( i = 1; i < lel && i < ler; i++ ) { if ( exl[i] != exr[i] ) if ( exl[i] < exr[i] ) @@ -875,8 +892,8 @@ Obj SumCyc ( UInt n; /* order of smallest superfield */ UInt ml, mr; /* cofactors into the superfield */ UInt len; /* number of terms */ - Obj * cfs; /* pointer to the coefficients */ - UInt4 * exs; /* pointer to the exponents */ + const Obj * cfs; /* pointer to the coefficients */ + const UInt4 * exs; /* pointer to the exponents */ Obj * res; /* pointer to the result */ Obj sum; /* sum of two coefficients */ UInt i; /* loop variable */ @@ -900,8 +917,8 @@ Obj SumCyc ( } else { len = SIZE_CYC(opL); - cfs = COEFS_CYC(opL); - exs = EXPOS_CYC(opL,len); + cfs = CONST_COEFS_CYC(opL); + exs = CONST_EXPOS_CYC(opL,len); res = BASE_PTR_PLIST(STATE(ResultCyc)); if ( ml == 1 ) { for ( i = 1; i < len; i++ ) @@ -924,16 +941,16 @@ Obj SumCyc ( } else { len = SIZE_CYC(opR); - cfs = COEFS_CYC(opR); - exs = EXPOS_CYC(opR,len); + cfs = CONST_COEFS_CYC(opR); + exs = CONST_EXPOS_CYC(opR,len); res = BASE_PTR_PLIST(STATE(ResultCyc)); for ( i = 1; i < len; i++ ) { if ( ! ARE_INTOBJS( res[exs[i]*mr], cfs[i] ) || ! SUM_INTOBJS( sum, res[exs[i]*mr], cfs[i] ) ) { CHANGED_BAG( STATE(ResultCyc) ); sum = SUM( res[exs[i]*mr], cfs[i] ); - cfs = COEFS_CYC(opR); - exs = EXPOS_CYC(opR,len); + cfs = CONST_COEFS_CYC(opR); + exs = CONST_EXPOS_CYC(opR,len); res = BASE_PTR_PLIST(STATE(ResultCyc)); } res[exs[i]*mr] = sum; @@ -971,8 +988,8 @@ Obj AInvCyc ( { Obj res; /* inverse, result */ UInt len; /* number of terms */ - Obj * cfs; /* ptr to coeffs of left operand */ - UInt4 * exs; /* ptr to expnts of left operand */ + const Obj * cfs; /* ptr to coeffs of left operand */ + const UInt4 * exs; /* ptr to expnts of left operand */ Obj * cfp; /* ptr to coeffs of product */ UInt4 * exp; /* ptr to expnts of product */ UInt i; /* loop variable */ @@ -982,18 +999,18 @@ Obj AInvCyc ( res = NewBag( T_CYC, SIZE_CYC(op) * (sizeof(Obj)+sizeof(UInt4)) ); SET_NOF_CYC(res, NOF_CYC(op)); len = SIZE_CYC(op); - cfs = COEFS_CYC(op); + cfs = CONST_COEFS_CYC(op); + exs = CONST_EXPOS_CYC(op,len); cfp = COEFS_CYC(res); - exs = EXPOS_CYC(op,len); exp = EXPOS_CYC(res,len); for ( i = 1; i < len; i++ ) { if ( ! IS_INTOBJ( cfs[i] ) || cfs[i] == INTOBJ_INT(-(1L< is a cyclotomic integer and 'false' otherwise*/ @@ -1722,8 +1739,8 @@ Obj FuncCOEFFS_CYC ( Obj list; /* list of coefficients, result */ UInt n; /* order of field */ UInt len; /* number of terms */ - Obj * cfs; /* pointer to the coefficients */ - UInt4 * exs; /* pointer to the exponents */ + const Obj * cfs; /* pointer to the coefficients */ + const UInt4 * exs; /* pointer to the exponents */ UInt i; /* loop variable */ /* do full operation */ @@ -1756,8 +1773,8 @@ Obj FuncCOEFFS_CYC ( list = NEW_PLIST( T_PLIST, n ); SET_LEN_PLIST( list, n ); len = SIZE_CYC(cyc); - cfs = COEFS_CYC(cyc); - exs = EXPOS_CYC(cyc,len); + cfs = CONST_COEFS_CYC(cyc); + exs = CONST_EXPOS_CYC(cyc,len); for ( i = 1; i <= n; i++ ) SET_ELM_PLIST( list, i, INTOBJ_INT(0) ); for ( i = 1; i < len; i++ ) @@ -1799,8 +1816,8 @@ Obj FuncGALOIS_CYC ( Int o; /* galois automorphism */ UInt gcd, s, t; /* gcd of n and ord, temporaries */ UInt len; /* number of terms */ - Obj * cfs; /* pointer to the coefficients */ - UInt4 * exs; /* pointer to the exponents */ + const Obj * cfs; /* pointer to the coefficients */ + const UInt4 * exs; /* pointer to the exponents */ Obj * res; /* pointer to the result */ UInt i; /* loop variable */ UInt tnumord, tnumcyc; @@ -1865,15 +1882,15 @@ Obj FuncGALOIS_CYC ( else if ( n % 2 == 0 && o == n/2 ) { gal = INTOBJ_INT(0); len = SIZE_CYC(cyc); - cfs = COEFS_CYC(cyc); - exs = EXPOS_CYC(cyc,len); + cfs = CONST_COEFS_CYC(cyc); + exs = CONST_EXPOS_CYC(cyc,len); for ( i = 1; i < len; i++ ) { if ( exs[i] % 2 == 1 ) { if ( ! ARE_INTOBJS( gal, cfs[i] ) || ! DIFF_INTOBJS( sum, gal, cfs[i] ) ) { sum = DIFF( gal, cfs[i] ); - cfs = COEFS_CYC(cyc); - exs = EXPOS_CYC(cyc,len); + cfs = CONST_COEFS_CYC(cyc); + exs = CONST_EXPOS_CYC(cyc,len); } gal = sum; } @@ -1881,8 +1898,8 @@ Obj FuncGALOIS_CYC ( if ( ! ARE_INTOBJS( gal, cfs[i] ) || ! SUM_INTOBJS( sum, gal, cfs[i] ) ) { sum = SUM( gal, cfs[i] ); - cfs = COEFS_CYC(cyc); - exs = EXPOS_CYC(cyc,len); + cfs = CONST_COEFS_CYC(cyc); + exs = CONST_EXPOS_CYC(cyc,len); } gal = sum; } @@ -1894,8 +1911,8 @@ Obj FuncGALOIS_CYC ( /* permute the coefficients */ len = SIZE_CYC(cyc); - cfs = COEFS_CYC(cyc); - exs = EXPOS_CYC(cyc,len); + cfs = CONST_COEFS_CYC(cyc); + exs = CONST_EXPOS_CYC(cyc,len); res = BASE_PTR_PLIST(STATE(ResultCyc)); for ( i = 1; i < len; i++ ) { res[(UInt8)exs[i]*(UInt8)o%(UInt8)n] = cfs[i]; @@ -1918,16 +1935,16 @@ Obj FuncGALOIS_CYC ( /* multiple roots may be mapped to the same root, add the coeffs */ len = SIZE_CYC(cyc); - cfs = COEFS_CYC(cyc); - exs = EXPOS_CYC(cyc,len); + cfs = CONST_COEFS_CYC(cyc); + exs = CONST_EXPOS_CYC(cyc,len); res = BASE_PTR_PLIST(STATE(ResultCyc)); for ( i = 1; i < len; i++ ) { if ( ! ARE_INTOBJS( res[(UInt8)exs[i]*(UInt8)o%(UInt8)n], cfs[i] ) || ! SUM_INTOBJS( sum, res[(UInt8)exs[i]*(UInt8)o%(UInt8)n], cfs[i] ) ) { CHANGED_BAG( STATE(ResultCyc) ); sum = SUM( res[(UInt8)exs[i]*(UInt8)o%(UInt8)n], cfs[i] ); - cfs = COEFS_CYC(cyc); - exs = EXPOS_CYC(cyc,len); + cfs = CONST_COEFS_CYC(cyc); + exs = CONST_EXPOS_CYC(cyc,len); res = BASE_PTR_PLIST(STATE(ResultCyc)); } res[exs[i]*o%n] = sum; @@ -2032,13 +2049,13 @@ void MarkCycSubBags( Obj cyc ) void SaveCyc ( Obj cyc ) { UInt len, i; - Obj *coefs; - UInt4 *expos; + const Obj *coefs; + const UInt4 *expos; len = SIZE_CYC(cyc); - coefs = COEFS_CYC(cyc); + coefs = CONST_COEFS_CYC(cyc); for (i = 0; i < len; i++) SaveSubObj(*coefs++); - expos = EXPOS_CYC(cyc,len); + expos = CONST_EXPOS_CYC(cyc,len); expos++; /*Skip past the XXX */ for (i = 1; i < len; i++) SaveUInt4(*expos++);