void unittest12() { bool overflow = false; assert(muls(2LL, 3LL, overflow) == 6); assert(!overflow); assert(muls(-200LL, 300LL, overflow) == -60000); assert(!overflow); assert(muls(1LL, INT64_MAX, overflow) == INT64_MAX); assert(!overflow); assert(muls(INT64_MIN, 1LL, overflow) == INT64_MIN); assert(!overflow); assert(muls(INT64_MAX, 2LL, overflow) == (INT64_MAX * 2)); assert(overflow); overflow = false; assert(muls(INT64_MIN, -1LL, overflow) == INT64_MIN); assert(overflow); assert(muls(0LL, 0LL, overflow) == 0); assert(overflow); // sticky }
void unittest11() { bool overflow = false; assert(muls(2, 3, overflow) == 6); assert(!overflow); assert(muls(-200, 300, overflow) == -60000); assert(!overflow); assert(muls(1, INT32_MAX, overflow) == INT32_MAX); assert(!overflow); assert(muls(INT32_MIN, 1, overflow) == INT32_MIN); assert(!overflow); assert(muls(INT32_MAX, 2, overflow) == (INT32_MAX * 2)); assert(overflow); overflow = false; assert(muls(INT32_MIN, -1, overflow) == INT32_MIN); assert(overflow); assert(muls(0, 0, overflow) == 0); assert(overflow); // sticky }
ll C(ll a, ll b) { return muls(b + 1, a) * pow_mod(muls(1, a - b), CONST_MOD - 2, CONST_MOD) % CONST_MOD; }
int ri_inter (void) { /* This is the shortest version of the interpreter, containing only those RASL operators which * are produced by the REFAL compiler. */ /* July, 27, 1985. D.T. */ /* Some macros have been expanded because the PC compiler can't handle too many macros. (its stack overflows.) * DT July 1 1986. */ /* Some other macros have been replaced by functions to reduce the size of object module. March 7 1987. DT. */ register short n; int error; char c, ins = 0; long mdig, bifnum; char *arg; /* short m;*/ error = 0; restart: while (error == 0) { ins = *p; # if MDEBUG if (dump_toggle) printf ("%lx: %d\n", p, ins); # endif switch (ins) { case ACT1: ASGN_CHARP (++p, arg); p += sizeof (char *); act1 (arg); curk ++; break; case BL: p++; bl; break; case BLR: p++; ri_blr (); break; case BR: p++; br; break; case CL: p++; cl; break; case SYM: c = (unsigned char) * ++p; p++; sym (c); break; case SYMR: c = (unsigned char) * ++p; p++; symr (c); break; case EMP: p++; emp; break; case EST: curk --; est; p = break0; break; case MULE: /* n = * ++p; ++p; mule ((int) n); */ ASGN_LONG (++p, mdig); p += sizeof (long); mule (mdig); break; case MULS: /*n = * ++p; muls (n); p++; break;*/ ASGN_LONG (++p, mdig); p += sizeof (long); muls (mdig); break; case PLEN: p++; plen; p++; break; case PLENS: p++; plens; break; case PLENP: p++; plenp; break; case PS: ++p; ps; break; case PSR: ++p; psr; break; case OEXP: n = (unsigned char) * ++p; ++p; oexp (n); break; case OEXPR: n = (unsigned char) * ++p; ++p; oexpr (n); break; case OVSYM: n = (unsigned char) * ++p; ovsym (n); ++p; break; case OVSYMR: n = (unsigned char) * ++p; ovsymr (n); p++; break; case TERM: p++; term; break; case TERMR: p++; termr; break; case RDY: n = (unsigned char) * ++p; ++p; rdy (n); break; case SETB: /* n = (unsigned char) * ++p; m = (unsigned char) * ++p; ++p; setb (n,m); break; */ { long l_n, l_m; ASGN_LONG (++p, l_n); p += sizeof (long); ASGN_LONG (p, l_m); p += sizeof (long); setb (l_n, l_m); } break; case LEN: p++; len; break; case LENS: c = (unsigned char) *++p; p++; lens (c); break; case LENP: ++p; lenp; break; case SYMS: n = (unsigned char) * ++p; p++; syms (n); break; case SYMSR: n = (unsigned char) * ++p; p++; symsr (n) break; case TEXT: n = (unsigned char) * ++p; p++; text (n); break; case NS: c = (unsigned char) * ++p; ++p; ns (c); break; case TPLE: /* n = * ++p; p++; tple (n); break; */ ASGN_LONG (++p, mdig); p += sizeof (long); tple (mdig); break; case TPLS: /* n = * ++p; p++; tpls (n); break; */ ASGN_LONG (++p, mdig); p += sizeof (long); tpls (mdig); break; case TRAN: ASGN_CHARP (++p, arg); p += sizeof (char *); tran (arg); break; case VSYM: p++; vsym; break; case VSYMR: ++p; vsymr; break; case OUTEST: curk --; out (2); est; p = break0; break; case ECOND: if (tel - te + nel + 100 >= size_table_element) { if (fp_debugInfo != NULL) ri_print_error_code(fp_debugInfo,13); ri_error (13); } ASGN_CHARP (++p, arg); b = st[sp].b1; b = st[sp].b1; act1 (arg); tel += (teoff = nel); est; p = break0; break; case POPVF: ++p; tel -= teoff; nel = teoff + 3; sp = stoff-1; teoff = st[sp].nel; stoff = (long) st[sp].b2; break; case PUSHVF: if (sp + 20 >= size_local_stack) { if (fp_debugInfo != NULL) ri_print_error_code(fp_debugInfo,14); ri_error (14); } ++p; b = tbel (2) -> prec; blr; pushst (b->prec,b,NULL,NULL); sp++; pushst (b,stoff,teoff, IMP_); b = b -> prec; stoff = sp + 1; break; case STLEN: ++p; sp = stoff; break; case CSYM: ASGN_CHARP (++p, arg); p += sizeof (char *); csym (arg); break; case CSYMR: ASGN_CHARP (++p, arg); p += sizeof (char *); csymr (arg); break; case NSYM: ASGN_LONG (++p, mdig); p += sizeof (long); nsym (mdig); break; case NSYMR: ASGN_LONG (++p, mdig); p += sizeof (long); nsymr (mdig); break; case NCS: ASGN_CHARP (++p, arg); p += sizeof (char *); ncs (arg); break; case NNS: ASGN_LONG (++p, mdig); p += sizeof (long); nns (mdig); break; /* builtin functions: R.N. - 20 Jul 85 */ case BUILT_IN: /* a call to a built in function no arguments. */ curk --; ASGN_LONG (p+1, bifnum); error = ri_bif (bifnum,NULL); p = break0; break; /* builtin functions with one argument: D.T. - July 27, 1985. */ case BUILT_IN1: /* a call to a function with one argument. */ /* Arguments are stored before function address. */ curk --; ASGN_CHARP(++p, arg); ASGN_LONG (p + (sizeof (char *)), bifnum); error = ri_bif (bifnum, arg); p = break0; break; default: ri_default (ins, &error); break; } } if (error != 0) { fprintf (stderr,"RASL instruction: %4d at address: %lx\n", *p, (unsigned long) p); if (fp_debugInfo != NULL) fprintf (fp_debugInfo,"RASL instruction: %4d at address: %lx\n", *p, (unsigned long) p); ri_error(4); } return 0; }
/* * L3_mdct_sub: * ------------ */ void L3_mdct_sub(shine_global_config *config) { /* note. we wish to access the array 'config->mdct_freq[2][2][576]' as * [2][2][32][18]. (32*18=576), */ long (*mdct_enc)[18]; int ch,gr,band,j,k; long mdct_in[36]; long bu,bd,*m; for(gr=0; gr<2; gr++) for(ch=config->wave.channels; ch--; ) { /* set up pointer to the part of config->mdct_freq we're using */ mdct_enc = (long (*)[18]) config->mdct_freq[gr][ch]; /* Compensate for inversion in the analysis filter * (every odd index of band AND k) */ for(band=1; band<=31; band+=2 ) for(k=1; k<=17; k+=2 ) config->l3_sb_sample[ch][gr+1][k][band] *= -1; /* Perform imdct of 18 previous subband samples + 18 current subband samples */ for(band=32; band--; ) { for(k=18; k--; ) { mdct_in[k] = config->l3_sb_sample[ch][ gr ][k][band]; mdct_in[k+18] = config->l3_sb_sample[ch][gr+1][k][band]; } /* Calculation of the MDCT * In the case of long blocks ( block_type 0,1,3 ) there are * 36 coefficients in the time domain and 18 in the frequency * domain. */ for(k=18; k--; ) { m = &mdct_enc[band][k]; for(j=36, *m=0; j--; ) *m += mul(mdct_in[j],config->mdct.cos_l[k][j]); } } /* Perform aliasing reduction butterfly */ for(band=31; band--; ) for(k=8; k--; ) { /* must left justify result of multiplication here because the centre * two values in each block are not touched. */ bu = muls(mdct_enc[band][17-k],config->mdct.cs[k]) + muls(mdct_enc[band+1][k],config->mdct.ca[k]); bd = muls(mdct_enc[band+1][k],config->mdct.cs[k]) - muls(mdct_enc[band][17-k],config->mdct.ca[k]); mdct_enc[band][17-k] = bu; mdct_enc[band+1][k] = bd; } } /* Save latest granule's subband samples to be used in the next mdct call */ for(ch=config->wave.channels ;ch--; ) for(j=18; j--; ) for(band=32; band--; ) config->l3_sb_sample[ch][0][j][band] = config->l3_sb_sample[ch][2][j][band]; }
V mul(ST s){O a,b;b=pop(s);if(b->t==TA){while(len(b->a)>1)mul(b->a);psh(s,dup(top(b->a)));dlo(b);R;};a=pop(s);if(a->t==TA)TE;if(a->t==TS){if(b->t!=TD)TE;psh(s,muls(a,b));}else psh(s,muld(a,b));dlo(a);dlo(b);} //mul