void SubByte(byte* Register, byte Operand) { byte Op1=*Register, Op2=-Operand; long Sum; Sum=Op1+Op2; *Register=(byte)Sum; SetFlags(*Register); if((Op1&0x08)^(Op2&0x08)^(Sum&0x08)) FlagH=0; else FlagH=1; if(Sum>(word)0xFF) FlagNC=!(FlagC=0); else FlagC=!(FlagNC=0); if(SignBit(Op1)==SignBit(Op2) && SignBit(Sum)!=SignBit(Op1)) FlagPO=!(FlagPE=1); else FlagPO=!(FlagPE=0); FlagN=0; TStates+=4; }
void SetFlags(byte Datum) { Flag3=(Datum&0x08)!=0; Flag5=(Datum&0x20)!=0; if(Datum==0) FlagZ=1; else FlagZ=0; FlagNZ=!FlagZ; FlagP=!SignBit(Datum); FlagM=!FlagP; FlagPE=Parity(Datum); FlagPO=!FlagPE; }
Integer cachelookup(const Real *para, double *base, void (*calc)(const Real *, Real *, const long *), const int *pnpara, const int *pnval) { const long one = 1; const Integer C_size = sizeof(Complex); const int npara = *pnpara, nval = *pnval; typedef struct node { struct node *next[2], *succ; int serial; Real para[2]; } Node; #define base_valid (int *)&base[0] #define base_last (Node ***)&base[1] #define base_first (Node **)&base[2] const int valid = *base_valid; Node **last = *base_last; Node **next = base_first; Node *node; if( last == NULL ) last = next; if( ltcache.cmpbits > 0 ) { dblint mask = -(1ULL << IDim(64 - ltcache.cmpbits)); #if KIND == 2 dblint (*cmp)(const Real *, const Real *, int, const dblint) = CmpPara; if( ltcache.cmpbits >= 64 ) { mask = -(1ULL << IDim(128 - ltcache.cmpbits)); cmp = CmpParaLo; } #else #define cmp CmpPara #endif while( (node = *next) && node->serial < valid ) { const dblint i = cmp(para, node->para, npara, mask); if( i == 0 ) { goto found; } next = &node->next[SignBit(i)]; } } node = *last; if( node == NULL ) { /* The "Real para[2]" bit in Node is effectively an extra Complex for alignment so that node can be reached with an integer index into base */ node = malloc(sizeof(Node) + npara*sizeof(Real) + nval*sizeof(Complex)); if( node == NULL ) { fputs("Out of memory for LoopTools cache.\n", stderr); exit(1); } node = (Node *)((char *)node + (PtrDiff(base, &node->para[npara]) & (sizeof(Complex) - 1))); node->succ = NULL; node->serial = valid; *last = node; } *next = node; *base_last = &node->succ; *base_valid = valid + 1; node->next[0] = NULL; node->next[1] = NULL; memcpy(node->para, para, npara*sizeof(Real)); calc(node->para, &node->para[npara], &one); found: return PtrDiff(&node->para[npara], base)/C_size; }