CMSIS-DSP: Biquad improvement

Improvement to formatting script.
pull/19/head
Christophe Favergeon 5 years ago
parent 212e9cb805
commit af027f97c5

@ -175,6 +175,112 @@
#if defined(ARM_MATH_MVEI) && !defined(ARM_MATH_AUTOVECTORIZE)
#include "arm_helium_utils.h"
static void arm_biquad_cas_df1_32x64_q31_scalar(const arm_biquad_cas_df1_32x64_ins_q31 * S,
const q31_t * pSrc,
q31_t * pDst,
uint32_t blockSize)
{
const q31_t *pIn = pSrc; /* input pointer initialization */
q31_t *pOut = pDst; /* output pointer initialization */
q63_t *pState = S->pState; /* state pointer initialization */
const q31_t *pCoeffs = S->pCoeffs; /* coeff pointer initialization */
q63_t acc; /* accumulator */
q31_t Xn1, Xn2; /* Input Filter state variables */
q63_t Yn1, Yn2; /* Output Filter state variables */
q31_t b0, b1, b2, a1, a2; /* Filter coefficients */
q31_t Xn; /* temporary input */
int32_t shift = (int32_t) S->postShift + 1; /* Shift to be applied to the output */
uint32_t sample, stage = S->numStages; /* loop counters */
q31_t acc_l, acc_h; /* temporary output */
uint32_t uShift = ((uint32_t) S->postShift + 1U);
uint32_t lShift = 32U - uShift; /* Shift to be applied to the output */
do
{
/* Reading the coefficients */
b0 = *pCoeffs++;
b1 = *pCoeffs++;
b2 = *pCoeffs++;
a1 = *pCoeffs++;
a2 = *pCoeffs++;
/* Reading the state values */
Xn1 = (q31_t) (pState[0]);
Xn2 = (q31_t) (pState[1]);
Yn1 = pState[2];
Yn2 = pState[3];
/* Initialize blkCnt with number of samples */
sample = blockSize;
while (sample > 0U)
{
/* Read the input */
Xn = *pIn++;
/* acc = b0 * x[n] + b1 * x[n-1] + b2 * x[n-2] + a1 * y[n-1] + a2 * y[n-2] */
/* acc = b0 * x[n] */
acc = (q63_t) Xn * b0;
/* acc += b1 * x[n-1] */
acc += (q63_t) Xn1 * b1;
/* acc += b[2] * x[n-2] */
acc += (q63_t) Xn2 * b2;
/* acc += a1 * y[n-1] */
acc += mult32x64(Yn1, a1);
/* acc += a2 * y[n-2] */
acc += mult32x64(Yn2, a2);
/* Every time after the output is computed state should be updated. */
/* The states should be updated as: */
/* Xn2 = Xn1 */
/* Xn1 = Xn */
/* Yn2 = Yn1 */
/* Yn1 = acc */
Xn2 = Xn1;
Xn1 = Xn;
Yn2 = Yn1;
/* The result is converted to 1.63, Yn1 variable is reused */
Yn1 = acc << shift;
/* Calc lower part of acc */
acc_l = acc & 0xffffffff;
/* Calc upper part of acc */
acc_h = (acc >> 32) & 0xffffffff;
/* Apply shift for lower part of acc and upper part of acc */
acc_h = (uint32_t) acc_l >> lShift | acc_h << uShift;
/* Store the output in the destination buffer in 1.31 format. */
*pOut++ = acc_h;
/* Yn1 = acc << shift; */
/* Store the output in the destination buffer in 1.31 format. */
/* *pOut++ = (q31_t) (acc >> (32 - shift)); */
/* decrement loop counter */
sample--;
}
/* The first stage output is given as input to the second stage. */
pIn = pDst;
/* Reset to destination buffer working pointer */
pOut = pDst;
/* Store the updated state variables back into the pState array */
*pState++ = (q63_t) Xn1;
*pState++ = (q63_t) Xn2;
*pState++ = Yn1;
*pState++ = Yn2;
} while (--stage);
}
void arm_biquad_cas_df1_32x64_q31(
const arm_biquad_cas_df1_32x64_ins_q31 * S,
const q31_t * pSrc,
@ -193,6 +299,12 @@ void arm_biquad_cas_df1_32x64_q31(
q31x4_t vecCoef, vecIn;
q63_t acc;
if (blockSize <= 3)
{
arm_biquad_cas_df1_32x64_q31_scalar(S,pSrc,pDst,blockSize);
}
else
{
do
{
uint32_t i;
@ -406,6 +518,7 @@ void arm_biquad_cas_df1_32x64_q31(
}
while (--stage);
}
}
#else
void arm_biquad_cas_df1_32x64_q31(
const arm_biquad_cas_df1_32x64_ins_q31 * S,

@ -11,6 +11,13 @@
#define ABS_32x64_ERROR_Q31 ((q31_t)25)
void checkInnerTail(q31_t *b)
{
ASSERT_TRUE(b[0] == 0);
ASSERT_TRUE(b[1] == 0);
ASSERT_TRUE(b[2] == 0);
ASSERT_TRUE(b[3] == 0);
}
void BIQUADQ31::test_biquad_cascade_df1()
{
@ -112,7 +119,7 @@
the state management of the fir is working.)
*/
#if 0
arm_biquad_cas_df1_32x64_q31(&this->S32x64,inputp,outp,blockSize);
outp += blockSize;
@ -120,7 +127,27 @@
arm_biquad_cas_df1_32x64_q31(&this->S32x64,inputp,outp,blockSize);
outp += blockSize;
#else
int delta=1;
int k;
for(k=0;k + delta <2*blockSize ; k+=delta)
{
arm_biquad_cas_df1_32x64_q31(&this->S32x64,inputp,outp,delta);
outp += delta;
checkInnerTail(outp);
inputp += delta;
}
if (k < 2*blockSize)
{
delta = 2*blockSize - k;
arm_biquad_cas_df1_32x64_q31(&this->S32x64,inputp,outp,delta);
outp += delta;
checkInnerTail(outp);
inputp += delta;
}
#endif
ASSERT_EMPTY_TAIL(output);

@ -9,7 +9,6 @@ import os.path
refCoreName=""
runidCMD = "runid = ?"
# Command to get last runid
lastID="""SELECT runid FROM RUN ORDER BY runid DESC LIMIT 1
@ -62,8 +61,7 @@ parser.add_argument('-ratio', action='store_true', help="Compute ratios for regr
parser.add_argument('-ref', nargs='?',type = str, default="M55", help="Reference COREDEF for ratio in db")
parser.add_argument('-clampval', nargs='?',type = float, default=8.0, help="Clamp for ratio")
parser.add_argument('-clamp', action='store_true', help="Clamp enabled for ratio")
parser.add_argument('-keep', nargs='?',type = str, help="Core to keep for ratio")
parser.add_argument('-disprunid', action='store_true', help="Include runid in html")
parser.add_argument('-cores', nargs='?',type = str, help="Cores to keep")
# For runid or runid range
parser.add_argument('others', nargs=argparse.REMAINDER,help="Run ID")
@ -72,36 +70,66 @@ args = parser.parse_args()
c = sqlite3.connect(args.b)
if args.others:
coreidSQL="select distinct coreid from CORE where coredef==?"
def getCoreID(corename):
r=c.execute(coreidSQL,(corename,))
t=r.fetchone()
if t is None:
print("Unrecognized reference core \"%s\"" % corename)
quit()
return(t[0])
def parseSelector(o,field="runid"):
vals=[]
runidCMD=[]
runidHeader=[]
# parameters are not allowed in VIEWs
runidVIEWcmd=[]
for t in args.others:
for t in o:
if re.search(r'-',t):
bounds=[int(x) for x in t.split("-")]
vals += bounds
runidHeader += ["%d <= runid <= %d" % tuple(bounds)]
runidCMD += ["(runid >= ? AND runid <= ?)"]
runidVIEWcmd += ["(runid >= %d AND runid <= %d) " % tuple(bounds)]
runidCMD += ["(%s >= ? AND %s <= ?)" % (field,field)]
x=(field,bounds[0],field,bounds[1])
runidVIEWcmd += ["(%s >= %d AND %s <= %d)" % x]
else:
theid=int(t)
runidHeader += ["runid == %d" % theid]
runidCMD += ["runid == ?"]
runidVIEWcmd += ["runid == %d" % theid]
runidCMD += ["%s == ?" % field]
runidVIEWcmd += ["%s == %d" % (field,theid)]
vals.append(theid)
runidval = tuple(vals)
runidHeader = "(" + "".join(joinit(runidHeader," OR ")) + ")"
runidCMD = "(" + "".join(joinit(runidCMD," OR ")) + ")"
runidVIEWcmd = "(" + "".join(joinit(runidVIEWcmd," OR ")) + ")"
return(runidval,runidCMD,runidVIEWcmd)
if args.others:
runidval,runidCMD,runidVIEWcmd = parseSelector(args.others)
else:
theid=getLastRunID()
print("Last run ID = %d\n" % theid)
runidval=(theid,)
runidHeader="%d" % theid
runidCMD = "runid = ?"
runidVIEWcmd="(runid = %d)" % theid
# None means all
coreidval = []
coreidCMD = []
keepCoreIds=None
if args.cores:
cores=args.cores.split(",")
coreids = [str(getCoreID(x.strip())) for x in cores]
keepCoreIds = coreids.copy()
if args.ref:
coreids.append(str(getCoreID(args.ref.strip())))
#print(coreids)
coreidval,coreidCMD, coreidVIEWcmd = parseSelector(coreids,field="coreid")
runidval += coreidval
runidCMD += " AND %s" % coreidCMD
runidVIEWcmd += " AND %s" % coreidVIEWcmd
# We extract data only from data tables
# Those tables below are used for descriptions
@ -703,28 +731,16 @@ referenceCoreID = None
coreidSQL="select distinct coreid from CORE where coredef==?"
def getCoreID(corename):
r=c.execute(coreidSQL,(corename,))
t=r.fetchone()
if t is None:
print("Unrecognized reference core")
quit()
return(t[0])
refCore="""CREATE TEMP VIEW if not exists refCore AS
select * from %s where (coreid = %s) and (typeid = %s)
and %s
and compilerid = %s"""
allOtherCores="""CREATE TEMP VIEW if not exists otherCore AS
select * from %s where (coreid != %s) and (typeid = %s)
and %s
and compilerid = %s"""
otherCore="""CREATE TEMP VIEW if not exists otherCore AS
select * from %s where (coreid = %s) and (typeid = %s)
select * from %s where (typeid = %s)
and %s
and compilerid = %s"""
@ -838,11 +854,10 @@ def computeRatio(benchName,viewParams,refMkViewCmd,otherMkViewCmd,byd):
def computeRatioTable(benchName,referenceCore,typeID,compiler):
viewParams = (benchName,referenceCore,typeID,runidVIEWcmd,compiler)
refMkViewCmd = refCore % viewParams
otherMkViewCmd = allOtherCores % viewParams
if args.keep:
keepCoreID = getCoreID(args.keep)
otherParams = (benchName,keepCoreID,typeID,runidVIEWcmd,compiler)
otherParams = (benchName,typeID,runidVIEWcmd,compiler)
otherMkViewCmd = otherCore % otherParams
#print(refMkViewCmd)
#print(otherMkViewCmd)
return(computeRatio(benchName,viewParams,refMkViewCmd,otherMkViewCmd,False))
@ -851,6 +866,8 @@ def computeRatioTableForCore(benchName,referenceCore,otherCoreID,compiler):
refMkViewCmd = refCoreAllTypes % viewParams
otherParams = (benchName,otherCoreID,runidVIEWcmd,compiler)
otherMkViewCmd = otherCoreAllTypes % otherParams
#print(refMkViewCmd)
#print(otherMkViewCmd)
return(computeRatio(benchName,viewParams,refMkViewCmd,otherMkViewCmd,True))
def formatPerfRatio(s):
@ -945,9 +962,10 @@ def addReportFor(document,benchName):
if args.byd:
allCores=getAllExistingCores(benchName)
if args.ratio:
allCores.remove(referenceCoreID)
if args.keep:
allCores=[getCoreID(args.keep)]
if keepCoreIds:
allCores=keepCoreIds
if ("%d" % referenceCoreID) in allCores:
allCores.remove("%d" % referenceCoreID)
for aCoreID in allCores:
nbElems = getNbElemsInBenchAndCoreCmd(benchName,aCoreID)
if nbElems > 0:
@ -1106,9 +1124,6 @@ def createDoc(document,sections,benchtables):
try:
benchtables=getBenchTables()
if args.disprunid:
document = Document(runidHeader)
else:
document = Document(None)
if args.ratio:

Loading…
Cancel
Save