mirror of
https://github.com/lcbcFoo/ReonV.git
synced 2025-04-18 18:44:43 -04:00
Cleanup
This commit is contained in:
parent
4b3160f9a2
commit
91ecf18860
13 changed files with 0 additions and 3914 deletions
|
@ -1,875 +0,0 @@
|
|||
/* $Id: adpcm.c,v 1.7 2005/06/15 07:27:31 ael01 Exp $ */
|
||||
/*************************************************************************/
|
||||
/* */
|
||||
/* SNU-RT Benchmark Suite for Worst Case Timing Analysis */
|
||||
/* ===================================================== */
|
||||
/* Collected and Modified by S.-S. Lim */
|
||||
/* sslim@archi.snu.ac.kr */
|
||||
/* Real-Time Research Group */
|
||||
/* Seoul National University */
|
||||
/* */
|
||||
/* */
|
||||
/* < Features > - restrictions for our experimental environment */
|
||||
/* */
|
||||
/* 1. Completely structured. */
|
||||
/* - There are no unconditional jumps. */
|
||||
/* - There are no exit from loop bodies. */
|
||||
/* (There are no 'break' or 'return' in loop bodies) */
|
||||
/* 2. No 'switch' statements. */
|
||||
/* 3. No 'do..while' statements. */
|
||||
/* 4. Expressions are restricted. */
|
||||
/* - There are no multiple expressions joined by 'or', */
|
||||
/* 'and' operations. */
|
||||
/* 5. No library calls. */
|
||||
/* - All the functions needed are implemented in the */
|
||||
/* source file. */
|
||||
/* 6. Printouts removed (Jan G) */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/*************************************************************************/
|
||||
/* */
|
||||
/* FILE: adpcm.c */
|
||||
/* SOURCE : C Algorithms for Real-Time DSP by P. M. Embree */
|
||||
/* */
|
||||
/* DESCRIPTION : */
|
||||
/* */
|
||||
/* CCITT G.722 ADPCM (Adaptive Differential Pulse Code Modulation) */
|
||||
/* algorithm. */
|
||||
/* 16khz sample rate data is stored in the array test_data[SIZE]. */
|
||||
/* Results are stored in the array compressed[SIZE] and result[SIZE].*/
|
||||
/* Execution time is determined by the constant SIZE (default value */
|
||||
/* is 2000). */
|
||||
/* */
|
||||
/* REMARK : */
|
||||
/* */
|
||||
/* EXECUTION TIME : */
|
||||
/* */
|
||||
/* */
|
||||
/*************************************************************************/
|
||||
|
||||
/* To be able to run with printouts
|
||||
#include <stdio.h> */
|
||||
|
||||
/* common sampling rate for sound cards on IBM/PC */
|
||||
#define SAMPLE_RATE 11025
|
||||
|
||||
#define PI 3141
|
||||
#define SIZE 3
|
||||
#define IN_END 4
|
||||
|
||||
/* COMPLEX STRUCTURE */
|
||||
|
||||
typedef struct {
|
||||
int real, imag;
|
||||
} COMPLEX;
|
||||
|
||||
/* function prototypes for fft and filter functions */
|
||||
void fft(COMPLEX *,int);
|
||||
int fir_filter(int input,int *coef,int n,int *history);
|
||||
int iir_filter(int input,int *coef,int n,int *history);
|
||||
int gaussian(void);
|
||||
int my_abs(int n);
|
||||
|
||||
void setup_codec(int),key_down(),int_enable(),int_disable();
|
||||
int flags(int);
|
||||
|
||||
int getinput(void);
|
||||
void sendout(int),flush();
|
||||
|
||||
int encode(int,int);
|
||||
void decode(int);
|
||||
int filtez(int *bpl,int *dlt);
|
||||
void upzero(int dlt,int *dlti,int *bli);
|
||||
int filtep(int rlt1,int al1,int rlt2,int al2);
|
||||
int quantl(int el,int detl);
|
||||
/* int invqxl(int il,int detl,int *code_table,int mode); */
|
||||
int logscl(int il,int nbl);
|
||||
int scalel(int nbl,int shift_constant);
|
||||
int uppol2(int al1,int al2,int plt,int plt1,int plt2);
|
||||
int uppol1(int al1,int apl2,int plt,int plt1);
|
||||
/* int invqah(int ih,int deth); */
|
||||
int logsch(int ih,int nbh);
|
||||
void reset();
|
||||
int my_fabs(int n);
|
||||
int my_cos(int n);
|
||||
int my_sin(int n);
|
||||
|
||||
/* G722 C code */
|
||||
|
||||
/* variables for transimit quadrature mirror filter here */
|
||||
int tqmf[24];
|
||||
|
||||
/* QMF filter coefficients:
|
||||
scaled by a factor of 4 compared to G722 CCITT recommendation */
|
||||
int h[24] = {
|
||||
12, -44, -44, 212, 48, -624, 128, 1448,
|
||||
-840, -3220, 3804, 15504, 15504, 3804, -3220, -840,
|
||||
1448, 128, -624, 48, 212, -44, -44, 12
|
||||
};
|
||||
|
||||
int xl,xh;
|
||||
|
||||
/* variables for receive quadrature mirror filter here */
|
||||
int accumc[11],accumd[11];
|
||||
|
||||
/* outputs of decode() */
|
||||
int xout1,xout2;
|
||||
|
||||
int xs,xd;
|
||||
|
||||
/* variables for encoder (hi and lo) here */
|
||||
|
||||
int il,szl,spl,sl,el;
|
||||
|
||||
int qq4_code4_table[16] = {
|
||||
0, -20456, -12896, -8968, -6288, -4240, -2584, -1200,
|
||||
20456, 12896, 8968, 6288, 4240, 2584, 1200, 0
|
||||
};
|
||||
|
||||
int qq5_code5_table[32] = {
|
||||
-280, -280, -23352, -17560, -14120, -11664, -9752, -8184,
|
||||
-6864, -5712, -4696, -3784, -2960, -2208, -1520, -880,
|
||||
23352, 17560, 14120, 11664, 9752, 8184, 6864, 5712,
|
||||
4696, 3784, 2960, 2208, 1520, 880, 280, -280
|
||||
};
|
||||
|
||||
int qq6_code6_table[64] = {
|
||||
-136, -136, -136, -136, -24808, -21904, -19008, -16704,
|
||||
-14984, -13512, -12280, -11192, -10232, -9360, -8576, -7856,
|
||||
-7192, -6576, -6000, -5456, -4944, -4464, -4008, -3576,
|
||||
-3168, -2776, -2400, -2032, -1688, -1360, -1040, -728,
|
||||
24808, 21904, 19008, 16704, 14984, 13512, 12280, 11192,
|
||||
10232, 9360, 8576, 7856, 7192, 6576, 6000, 5456,
|
||||
4944, 4464, 4008, 3576, 3168, 2776, 2400, 2032,
|
||||
1688, 1360, 1040, 728, 432, 136, -432, -136
|
||||
};
|
||||
|
||||
int delay_bpl[6];
|
||||
|
||||
int delay_dltx[6];
|
||||
|
||||
int wl_code_table[16] = {
|
||||
-60, 3042, 1198, 538, 334, 172, 58, -30,
|
||||
3042, 1198, 538, 334, 172, 58, -30, -60
|
||||
};
|
||||
|
||||
int wl_table[8] = {
|
||||
-60, -30, 58, 172, 334, 538, 1198, 3042
|
||||
};
|
||||
|
||||
int ilb_table[32] = {
|
||||
2048, 2093, 2139, 2186, 2233, 2282, 2332, 2383,
|
||||
2435, 2489, 2543, 2599, 2656, 2714, 2774, 2834,
|
||||
2896, 2960, 3025, 3091, 3158, 3228, 3298, 3371,
|
||||
3444, 3520, 3597, 3676, 3756, 3838, 3922, 4008
|
||||
};
|
||||
|
||||
int nbl; /* delay line */
|
||||
int al1,al2;
|
||||
int plt,plt1,plt2;
|
||||
int rs;
|
||||
int dlt;
|
||||
int rlt,rlt1,rlt2;
|
||||
|
||||
/* decision levels - pre-multiplied by 8, 0 to indicate end */
|
||||
int decis_levl[30] = {
|
||||
280, 576, 880, 1200, 1520, 1864, 2208, 2584,
|
||||
2960, 3376, 3784, 4240, 4696, 5200, 5712, 6288,
|
||||
6864, 7520, 8184, 8968, 9752, 10712, 11664, 12896,
|
||||
14120, 15840, 17560, 20456, 23352, 32767
|
||||
};
|
||||
|
||||
int detl;
|
||||
|
||||
/* quantization table 31 long to make quantl look-up easier,
|
||||
last entry is for mil=30 case when wd is max */
|
||||
int quant26bt_pos[31] = {
|
||||
61, 60, 59, 58, 57, 56, 55, 54,
|
||||
53, 52, 51, 50, 49, 48, 47, 46,
|
||||
45, 44, 43, 42, 41, 40, 39, 38,
|
||||
37, 36, 35, 34, 33, 32, 32
|
||||
};
|
||||
|
||||
/* quantization table 31 long to make quantl look-up easier,
|
||||
last entry is for mil=30 case when wd is max */
|
||||
int quant26bt_neg[31] = {
|
||||
63, 62, 31, 30, 29, 28, 27, 26,
|
||||
25, 24, 23, 22, 21, 20, 19, 18,
|
||||
17, 16, 15, 14, 13, 12, 11, 10,
|
||||
9, 8, 7, 6, 5, 4, 4
|
||||
};
|
||||
|
||||
|
||||
int deth;
|
||||
int sh; /* this comes from adaptive predictor */
|
||||
int eh;
|
||||
|
||||
int qq2_code2_table[4] = {
|
||||
-7408, -1616, 7408, 1616
|
||||
};
|
||||
|
||||
int wh_code_table[4] = {
|
||||
798, -214, 798, -214
|
||||
};
|
||||
|
||||
|
||||
int dh,ih;
|
||||
int nbh,szh;
|
||||
int sph,ph,yh,rh;
|
||||
|
||||
int delay_dhx[6];
|
||||
|
||||
int delay_bph[6];
|
||||
|
||||
int ah1,ah2;
|
||||
int ph1,ph2;
|
||||
int rh1,rh2;
|
||||
|
||||
/* variables for decoder here */
|
||||
int ilr,yl,rl;
|
||||
int dec_deth,dec_detl,dec_dlt;
|
||||
|
||||
int dec_del_bpl[6];
|
||||
|
||||
int dec_del_dltx[6];
|
||||
|
||||
int dec_plt,dec_plt1,dec_plt2;
|
||||
int dec_szl,dec_spl,dec_sl;
|
||||
int dec_rlt1,dec_rlt2,dec_rlt;
|
||||
int dec_al1,dec_al2;
|
||||
int dl;
|
||||
int dec_nbl,dec_yh,dec_dh,dec_nbh;
|
||||
|
||||
/* variables used in filtez */
|
||||
int dec_del_bph[6];
|
||||
|
||||
int dec_del_dhx[6];
|
||||
|
||||
int dec_szh;
|
||||
/* variables used in filtep */
|
||||
int dec_rh1,dec_rh2;
|
||||
int dec_ah1,dec_ah2;
|
||||
int dec_ph,dec_sph;
|
||||
|
||||
int dec_sh,dec_rh;
|
||||
|
||||
int dec_ph1,dec_ph2;
|
||||
|
||||
/* G722 encode function two ints in, one 8 bit output */
|
||||
|
||||
/* put input samples in xin1 = first value, xin2 = second value */
|
||||
/* returns il and ih stored together */
|
||||
|
||||
/* MAX: 1 */
|
||||
int my_abs(int n)
|
||||
{
|
||||
int m;
|
||||
|
||||
if (n >= 0) m = n;
|
||||
else m = -n;
|
||||
return m;
|
||||
}
|
||||
|
||||
/* MAX: 1 */
|
||||
int my_fabs(int n)
|
||||
{
|
||||
int f;
|
||||
|
||||
if (n >= 0) f = n;
|
||||
else f = -n;
|
||||
return f;
|
||||
}
|
||||
|
||||
int my_sin(int rad)
|
||||
{
|
||||
int diff;
|
||||
int app=0;
|
||||
|
||||
int inc = 1;
|
||||
|
||||
/* MAX dependent on rad's value, say 50 */
|
||||
while (rad > 2*PI)
|
||||
rad -= 2*PI;
|
||||
/* MAX dependent on rad's value, say 50 */
|
||||
while (rad < -2*PI)
|
||||
rad += 2*PI;
|
||||
diff = rad;
|
||||
app = diff;
|
||||
diff = (diff * (-(rad*rad))) /
|
||||
((2 * inc) * (2 * inc + 1));
|
||||
app = app + diff;
|
||||
inc++;
|
||||
/* REALLY: while(my_fabs(diff) >= 0.00001) { */
|
||||
/* MAX: 1000 */
|
||||
while(my_fabs(diff) >= 1) {
|
||||
diff = (diff * (-(rad*rad))) /
|
||||
((2 * inc) * (2 * inc + 1));
|
||||
app = app + diff;
|
||||
inc++;
|
||||
}
|
||||
|
||||
return app;
|
||||
}
|
||||
|
||||
|
||||
int my_cos(int rad)
|
||||
{
|
||||
return (my_sin (PI / 2 - rad));
|
||||
}
|
||||
|
||||
|
||||
/* MAX: 1 */
|
||||
int encode(int xin1,int xin2)
|
||||
{
|
||||
int i;
|
||||
int *h_ptr,*tqmf_ptr,*tqmf_ptr1;
|
||||
long int xa,xb;
|
||||
int decis;
|
||||
|
||||
/* transmit quadrature mirror filters implemented here */
|
||||
h_ptr = h;
|
||||
tqmf_ptr = tqmf;
|
||||
xa = (long)(*tqmf_ptr++) * (*h_ptr++);
|
||||
xb = (long)(*tqmf_ptr++) * (*h_ptr++);
|
||||
/* main multiply accumulate loop for samples and coefficients */
|
||||
/* MAX: 10 */
|
||||
for(i = 0 ; i < 10 ; i++) {
|
||||
xa += (long)(*tqmf_ptr++) * (*h_ptr++);
|
||||
xb += (long)(*tqmf_ptr++) * (*h_ptr++);
|
||||
}
|
||||
/* final mult/accumulate */
|
||||
xa += (long)(*tqmf_ptr++) * (*h_ptr++);
|
||||
xb += (long)(*tqmf_ptr) * (*h_ptr++);
|
||||
|
||||
/* update delay line tqmf */
|
||||
tqmf_ptr1 = tqmf_ptr - 2;
|
||||
/* MAX: 22 */
|
||||
for(i = 0 ; i < 22 ; i++) *tqmf_ptr-- = *tqmf_ptr1--;
|
||||
*tqmf_ptr-- = xin1;
|
||||
*tqmf_ptr = xin2;
|
||||
|
||||
/* scale outputs */
|
||||
xl = (xa + xb) >> 15;
|
||||
xh = (xa - xb) >> 15;
|
||||
|
||||
/* end of quadrature mirror filter code */
|
||||
|
||||
/* starting with lower sub band encoder */
|
||||
|
||||
/* filtez - compute predictor output section - zero section */
|
||||
szl = filtez(delay_bpl,delay_dltx);
|
||||
|
||||
/* filtep - compute predictor output signal (pole section) */
|
||||
spl = filtep(rlt1,al1,rlt2,al2);
|
||||
|
||||
/* compute the predictor output value in the lower sub_band encoder */
|
||||
sl = szl + spl;
|
||||
el = xl - sl;
|
||||
|
||||
/* quantl: quantize the difference signal */
|
||||
il = quantl(el,detl);
|
||||
|
||||
/* invqxl: computes quantized difference signal */
|
||||
/* for invqbl, truncate by 2 lsbs, so mode = 3 */
|
||||
dlt = ((long)detl*qq4_code4_table[il >> 2]) >> 15;
|
||||
|
||||
/* logscl: updates logarithmic quant. scale factor in low sub band */
|
||||
nbl = logscl(il,nbl);
|
||||
|
||||
/* scalel: compute the quantizer scale factor in the lower sub band */
|
||||
/* calling parameters nbl and 8 (constant such that scalel can be scaleh) */
|
||||
detl = scalel(nbl,8);
|
||||
|
||||
/* parrec - simple addition to compute recontructed signal for adaptive pred */
|
||||
plt = dlt + szl;
|
||||
|
||||
/* upzero: update zero section predictor coefficients (sixth order)*/
|
||||
/* calling parameters: dlt, dlt1, dlt2, ..., dlt6 from dlt */
|
||||
/* bpli (linear_buffer in which all six values are delayed */
|
||||
/* return params: updated bpli, delayed dltx */
|
||||
upzero(dlt,delay_dltx,delay_bpl);
|
||||
|
||||
/* uppol2- update second predictor coefficient apl2 and delay it as al2 */
|
||||
/* calling parameters: al1, al2, plt, plt1, plt2 */
|
||||
al2 = uppol2(al1,al2,plt,plt1,plt2);
|
||||
|
||||
/* uppol1 :update first predictor coefficient apl1 and delay it as al1 */
|
||||
/* calling parameters: al1, apl2, plt, plt1 */
|
||||
al1 = uppol1(al1,al2,plt,plt1);
|
||||
|
||||
/* recons : compute recontructed signal for adaptive predictor */
|
||||
rlt = sl + dlt;
|
||||
|
||||
/* done with lower sub_band encoder; now implement delays for next time*/
|
||||
rlt2 = rlt1;
|
||||
rlt1 = rlt;
|
||||
plt2 = plt1;
|
||||
plt1 = plt;
|
||||
|
||||
/* high band encode */
|
||||
|
||||
szh = filtez(delay_bph,delay_dhx);
|
||||
|
||||
sph = filtep(rh1,ah1,rh2,ah2);
|
||||
|
||||
/* predic: sh = sph + szh */
|
||||
sh = sph + szh;
|
||||
/* subtra: eh = xh - sh */
|
||||
eh = xh - sh;
|
||||
|
||||
/* quanth - quantization of difference signal for higher sub-band */
|
||||
/* quanth: in-place for speed params: eh, deth (has init. value) */
|
||||
if(eh >= 0) {
|
||||
ih = 3; /* 2,3 are pos codes */
|
||||
}
|
||||
else {
|
||||
ih = 1; /* 0,1 are neg codes */
|
||||
}
|
||||
decis = (564L*(long)deth) >> 12L;
|
||||
if(my_abs(eh) > decis) ih--; /* mih = 2 case */
|
||||
|
||||
/* invqah: compute the quantized difference signal, higher sub-band*/
|
||||
dh = ((long)deth*qq2_code2_table[ih]) >> 15L ;
|
||||
|
||||
/* logsch: update logarithmic quantizer scale factor in hi sub-band*/
|
||||
nbh = logsch(ih,nbh);
|
||||
|
||||
/* note : scalel and scaleh use same code, different parameters */
|
||||
deth = scalel(nbh,10);
|
||||
|
||||
/* parrec - add pole predictor output to quantized diff. signal */
|
||||
ph = dh + szh;
|
||||
|
||||
/* upzero: update zero section predictor coefficients (sixth order) */
|
||||
/* calling parameters: dh, dhi, bphi */
|
||||
/* return params: updated bphi, delayed dhx */
|
||||
upzero(dh,delay_dhx,delay_bph);
|
||||
|
||||
/* uppol2: update second predictor coef aph2 and delay as ah2 */
|
||||
/* calling params: ah1, ah2, ph, ph1, ph2 */
|
||||
ah2 = uppol2(ah1,ah2,ph,ph1,ph2);
|
||||
|
||||
/* uppol1: update first predictor coef. aph2 and delay it as ah1 */
|
||||
ah1 = uppol1(ah1,ah2,ph,ph1);
|
||||
|
||||
/* recons for higher sub-band */
|
||||
yh = sh + dh;
|
||||
|
||||
/* done with higher sub-band encoder, now Delay for next time */
|
||||
rh2 = rh1;
|
||||
rh1 = yh;
|
||||
ph2 = ph1;
|
||||
ph1 = ph;
|
||||
|
||||
/* multiplex ih and il to get signals together */
|
||||
return(il | (ih << 6));
|
||||
}
|
||||
|
||||
/* decode function, result in xout1 and xout2 */
|
||||
|
||||
void decode(int input)
|
||||
{
|
||||
int i;
|
||||
long int xa1,xa2; /* qmf accumulators */
|
||||
int *h_ptr,*ac_ptr,*ac_ptr1,*ad_ptr,*ad_ptr1;
|
||||
|
||||
/* split transmitted word from input into ilr and ih */
|
||||
ilr = input & 0x3f;
|
||||
ih = input >> 6;
|
||||
|
||||
/* LOWER SUB_BAND DECODER */
|
||||
|
||||
/* filtez: compute predictor output for zero section */
|
||||
dec_szl = filtez(dec_del_bpl,dec_del_dltx);
|
||||
|
||||
/* filtep: compute predictor output signal for pole section */
|
||||
dec_spl = filtep(dec_rlt1,dec_al1,dec_rlt2,dec_al2);
|
||||
|
||||
dec_sl = dec_spl + dec_szl;
|
||||
|
||||
/* invqxl: compute quantized difference signal for adaptive predic */
|
||||
dec_dlt = ((long)dec_detl*qq4_code4_table[ilr >> 2]) >> 15;
|
||||
|
||||
/* invqxl: compute quantized difference signal for decoder output */
|
||||
dl = ((long)dec_detl*qq6_code6_table[il]) >> 15;
|
||||
|
||||
rl = dl + dec_sl;
|
||||
|
||||
/* logscl: quantizer scale factor adaptation in the lower sub-band */
|
||||
dec_nbl = logscl(ilr,dec_nbl);
|
||||
|
||||
/* scalel: computes quantizer scale factor in the lower sub band */
|
||||
dec_detl = scalel(dec_nbl,8);
|
||||
|
||||
/* parrec - add pole predictor output to quantized diff. signal */
|
||||
/* for partially reconstructed signal */
|
||||
dec_plt = dec_dlt + dec_szl;
|
||||
|
||||
/* upzero: update zero section predictor coefficients */
|
||||
upzero(dec_dlt,dec_del_dltx,dec_del_bpl);
|
||||
|
||||
/* uppol2: update second predictor coefficient apl2 and delay it as al2 */
|
||||
dec_al2 = uppol2(dec_al1,dec_al2,dec_plt,dec_plt1,dec_plt2);
|
||||
|
||||
/* uppol1: update first predictor coef. (pole setion) */
|
||||
dec_al1 = uppol1(dec_al1,dec_al2,dec_plt,dec_plt1);
|
||||
|
||||
/* recons : compute recontructed signal for adaptive predictor */
|
||||
dec_rlt = dec_sl + dec_dlt;
|
||||
|
||||
/* done with lower sub band decoder, implement delays for next time */
|
||||
dec_rlt2 = dec_rlt1;
|
||||
dec_rlt1 = dec_rlt;
|
||||
dec_plt2 = dec_plt1;
|
||||
dec_plt1 = dec_plt;
|
||||
|
||||
/* HIGH SUB-BAND DECODER */
|
||||
|
||||
/* filtez: compute predictor output for zero section */
|
||||
dec_szh = filtez(dec_del_bph,dec_del_dhx);
|
||||
|
||||
/* filtep: compute predictor output signal for pole section */
|
||||
dec_sph = filtep(dec_rh1,dec_ah1,dec_rh2,dec_ah2);
|
||||
|
||||
/* predic:compute the predictor output value in the higher sub_band decoder */
|
||||
dec_sh = dec_sph + dec_szh;
|
||||
|
||||
/* invqah: in-place compute the quantized difference signal */
|
||||
dec_dh = ((long)dec_deth*qq2_code2_table[ih]) >> 15L ;
|
||||
|
||||
/* logsch: update logarithmic quantizer scale factor in hi sub band */
|
||||
dec_nbh = logsch(ih,dec_nbh);
|
||||
|
||||
/* scalel: compute the quantizer scale factor in the higher sub band */
|
||||
dec_deth = scalel(dec_nbh,10);
|
||||
|
||||
/* parrec: compute partially recontructed signal */
|
||||
dec_ph = dec_dh + dec_szh;
|
||||
|
||||
/* upzero: update zero section predictor coefficients */
|
||||
upzero(dec_dh,dec_del_dhx,dec_del_bph);
|
||||
|
||||
/* uppol2: update second predictor coefficient aph2 and delay it as ah2 */
|
||||
dec_ah2 = uppol2(dec_ah1,dec_ah2,dec_ph,dec_ph1,dec_ph2);
|
||||
|
||||
/* uppol1: update first predictor coef. (pole setion) */
|
||||
dec_ah1 = uppol1(dec_ah1,dec_ah2,dec_ph,dec_ph1);
|
||||
|
||||
/* recons : compute recontructed signal for adaptive predictor */
|
||||
rh = dec_sh + dec_dh;
|
||||
|
||||
/* done with high band decode, implementing delays for next time here */
|
||||
dec_rh2 = dec_rh1;
|
||||
dec_rh1 = rh;
|
||||
dec_ph2 = dec_ph1;
|
||||
dec_ph1 = dec_ph;
|
||||
|
||||
/* end of higher sub_band decoder */
|
||||
|
||||
/* end with receive quadrature mirror filters */
|
||||
xd = rl - rh;
|
||||
xs = rl + rh;
|
||||
|
||||
/* receive quadrature mirror filters implemented here */
|
||||
h_ptr = h;
|
||||
ac_ptr = accumc;
|
||||
ad_ptr = accumd;
|
||||
xa1 = (long)xd * (*h_ptr++);
|
||||
xa2 = (long)xs * (*h_ptr++);
|
||||
/* main multiply accumulate loop for samples and coefficients */
|
||||
for(i = 0 ; i < 10 ; i++) {
|
||||
xa1 += (long)(*ac_ptr++) * (*h_ptr++);
|
||||
xa2 += (long)(*ad_ptr++) * (*h_ptr++);
|
||||
}
|
||||
/* final mult/accumulate */
|
||||
xa1 += (long)(*ac_ptr) * (*h_ptr++);
|
||||
xa2 += (long)(*ad_ptr) * (*h_ptr++);
|
||||
|
||||
/* scale by 2^14 */
|
||||
xout1 = xa1 >> 14;
|
||||
xout2 = xa2 >> 14;
|
||||
|
||||
/* update delay lines */
|
||||
ac_ptr1 = ac_ptr - 1;
|
||||
ad_ptr1 = ad_ptr - 1;
|
||||
for(i = 0 ; i < 10 ; i++) {
|
||||
*ac_ptr-- = *ac_ptr1--;
|
||||
*ad_ptr-- = *ad_ptr1--;
|
||||
}
|
||||
*ac_ptr = xd;
|
||||
*ad_ptr = xs;
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* clear all storage locations */
|
||||
|
||||
void reset()
|
||||
{
|
||||
int i;
|
||||
|
||||
detl = dec_detl = 32; /* reset to min scale factor */
|
||||
deth = dec_deth = 8;
|
||||
nbl = al1 = al2 = plt1 = plt2 = rlt1 = rlt2 = 0;
|
||||
nbh = ah1 = ah2 = ph1 = ph2 = rh1 = rh2 = 0;
|
||||
dec_nbl = dec_al1 = dec_al2 = dec_plt1 = dec_plt2 = dec_rlt1 = dec_rlt2 = 0;
|
||||
dec_nbh = dec_ah1 = dec_ah2 = dec_ph1 = dec_ph2 = dec_rh1 = dec_rh2 = 0;
|
||||
|
||||
for(i = 0 ; i < 6 ; i++) {
|
||||
delay_dltx[i] = 0;
|
||||
delay_dhx[i] = 0;
|
||||
dec_del_dltx[i] = 0;
|
||||
dec_del_dhx[i] = 0;
|
||||
}
|
||||
|
||||
for(i = 0 ; i < 6 ; i++) {
|
||||
delay_bpl[i] = 0;
|
||||
delay_bph[i] = 0;
|
||||
dec_del_bpl[i] = 0;
|
||||
dec_del_bph[i] = 0;
|
||||
}
|
||||
|
||||
for(i = 0 ; i < 23 ; i++) tqmf[i] = 0;
|
||||
|
||||
for(i = 0 ; i < 11 ; i++) {
|
||||
accumc[i] = 0;
|
||||
accumd[i] = 0;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* filtez - compute predictor output signal (zero section) */
|
||||
/* input: bpl1-6 and dlt1-6, output: szl */
|
||||
|
||||
int filtez(int *bpl,int *dlt)
|
||||
{
|
||||
int i;
|
||||
long int zl;
|
||||
zl = (long)(*bpl++) * (*dlt++);
|
||||
/* MAX: 6 */
|
||||
for(i = 1 ; i < 6 ; i++)
|
||||
zl += (long)(*bpl++) * (*dlt++);
|
||||
|
||||
return((int)(zl >> 14)); /* x2 here */
|
||||
}
|
||||
|
||||
/* filtep - compute predictor output signal (pole section) */
|
||||
/* input rlt1-2 and al1-2, output spl */
|
||||
|
||||
int filtep(int rlt1,int al1,int rlt2,int al2)
|
||||
{
|
||||
long int pl,pl2;
|
||||
pl = 2*rlt1;
|
||||
pl = (long)al1*pl;
|
||||
pl2 = 2*rlt2;
|
||||
pl += (long)al2*pl2;
|
||||
return((int)(pl >> 15));
|
||||
}
|
||||
|
||||
/* quantl - quantize the difference signal in the lower sub-band */
|
||||
int quantl(int el,int detl)
|
||||
{
|
||||
int ril,mil;
|
||||
long int wd,decis;
|
||||
|
||||
/* abs of difference signal */
|
||||
wd = my_abs(el);
|
||||
/* determine mil based on decision levels and detl gain */
|
||||
/* MAX: 30 */
|
||||
for(mil = 0 ; mil < 30 ; mil++) {
|
||||
decis = (decis_levl[mil]*(long)detl) >> 15L;
|
||||
if(wd <= decis) break;
|
||||
}
|
||||
/* if mil=30 then wd is less than all decision levels */
|
||||
if(el >= 0) ril = quant26bt_pos[mil];
|
||||
else ril = quant26bt_neg[mil];
|
||||
return(ril);
|
||||
}
|
||||
|
||||
/* invqxl is either invqbl or invqal depending on parameters passed */
|
||||
/* returns dlt, code table is pre-multiplied by 8 */
|
||||
|
||||
/* int invqxl(int il,int detl,int *code_table,int mode) */
|
||||
/* { */
|
||||
/* long int dlt; */
|
||||
/* dlt = (long)detl*code_table[il >> (mode-1)]; */
|
||||
/* return((int)(dlt >> 15)); */
|
||||
/* } */
|
||||
|
||||
/* logscl - update log quantizer scale factor in lower sub-band */
|
||||
/* note that nbl is passed and returned */
|
||||
|
||||
int logscl(int il,int nbl)
|
||||
{
|
||||
long int wd;
|
||||
wd = ((long)nbl * 127L) >> 7L; /* leak factor 127/128 */
|
||||
nbl = (int)wd + wl_code_table[il >> 2];
|
||||
if(nbl < 0) nbl = 0;
|
||||
if(nbl > 18432) nbl = 18432;
|
||||
return(nbl);
|
||||
}
|
||||
|
||||
/* scalel: compute quantizer scale factor in lower or upper sub-band*/
|
||||
|
||||
int scalel(int nbl,int shift_constant)
|
||||
{
|
||||
int wd1,wd2,wd3;
|
||||
wd1 = (nbl >> 6) & 31;
|
||||
wd2 = nbl >> 11;
|
||||
wd3 = ilb_table[wd1] >> (shift_constant + 1 - wd2);
|
||||
return(wd3 << 3);
|
||||
}
|
||||
|
||||
/* upzero - inputs: dlt, dlti[0-5], bli[0-5], outputs: updated bli[0-5] */
|
||||
/* also implements delay of bli and update of dlti from dlt */
|
||||
|
||||
void upzero(int dlt,int *dlti,int *bli)
|
||||
{
|
||||
int i,wd2,wd3;
|
||||
/*if dlt is zero, then no sum into bli */
|
||||
if(dlt == 0) {
|
||||
for(i = 0 ; i < 6 ; i++) {
|
||||
bli[i] = (int)((255L*bli[i]) >> 8L); /* leak factor of 255/256 */
|
||||
}
|
||||
}
|
||||
else {
|
||||
for(i = 0 ; i < 6 ; i++) {
|
||||
if((long)dlt*dlti[i] >= 0) wd2 = 128; else wd2 = -128;
|
||||
wd3 = (int)((255L*bli[i]) >> 8L); /* leak factor of 255/256 */
|
||||
bli[i] = wd2 + wd3;
|
||||
}
|
||||
}
|
||||
/* implement delay line for dlt */
|
||||
dlti[5] = dlti[4];
|
||||
dlti[4] = dlti[3];
|
||||
dlti[3] = dlti[2];
|
||||
dlti[1] = dlti[0];
|
||||
dlti[0] = dlt;
|
||||
return;
|
||||
}
|
||||
|
||||
/* uppol2 - update second predictor coefficient (pole section) */
|
||||
/* inputs: al1, al2, plt, plt1, plt2. outputs: apl2 */
|
||||
|
||||
int uppol2(int al1,int al2,int plt,int plt1,int plt2)
|
||||
{
|
||||
long int wd2,wd4;
|
||||
int apl2;
|
||||
wd2 = 4L*(long)al1;
|
||||
if((long)plt*plt1 >= 0L) wd2 = -wd2; /* check same sign */
|
||||
wd2 = wd2 >> 7; /* gain of 1/128 */
|
||||
if((long)plt*plt2 >= 0L) {
|
||||
wd4 = wd2 + 128; /* same sign case */
|
||||
}
|
||||
else {
|
||||
wd4 = wd2 - 128;
|
||||
}
|
||||
apl2 = wd4 + (127L*(long)al2 >> 7L); /* leak factor of 127/128 */
|
||||
|
||||
/* apl2 is limited to +-.75 */
|
||||
if(apl2 > 12288) apl2 = 12288;
|
||||
if(apl2 < -12288) apl2 = -12288;
|
||||
return(apl2);
|
||||
}
|
||||
|
||||
/* uppol1 - update first predictor coefficient (pole section) */
|
||||
/* inputs: al1, apl2, plt, plt1. outputs: apl1 */
|
||||
|
||||
int uppol1(int al1,int apl2,int plt,int plt1)
|
||||
{
|
||||
long int wd2;
|
||||
int wd3,apl1;
|
||||
wd2 = ((long)al1*255L) >> 8L; /* leak factor of 255/256 */
|
||||
if((long)plt*plt1 >= 0L) {
|
||||
apl1 = (int)wd2 + 192; /* same sign case */
|
||||
}
|
||||
else {
|
||||
apl1 = (int)wd2 - 192;
|
||||
}
|
||||
/* note: wd3= .9375-.75 is always positive */
|
||||
wd3 = 15360 - apl2; /* limit value */
|
||||
if(apl1 > wd3) apl1 = wd3;
|
||||
if(apl1 < -wd3) apl1 = -wd3;
|
||||
return(apl1);
|
||||
}
|
||||
|
||||
/* INVQAH: inverse adaptive quantizer for the higher sub-band */
|
||||
/* returns dh, code table is pre-multiplied by 8 */
|
||||
|
||||
/* int invqah(int ih,int deth) */
|
||||
/* { */
|
||||
/* long int rdh; */
|
||||
/* rdh = ((long)deth*qq2_code2_table[ih]) >> 15L ; */
|
||||
/* return((int)(rdh )); */
|
||||
/* } */
|
||||
|
||||
/* logsch - update log quantizer scale factor in higher sub-band */
|
||||
/* note that nbh is passed and returned */
|
||||
|
||||
int logsch(int ih,int nbh)
|
||||
{
|
||||
int wd;
|
||||
wd = ((long)nbh * 127L) >> 7L; /* leak factor 127/128 */
|
||||
nbh = wd + wh_code_table[ih];
|
||||
if(nbh < 0) nbh = 0;
|
||||
if(nbh > 22528) nbh = 22528;
|
||||
return(nbh);
|
||||
}
|
||||
|
||||
|
||||
#ifndef Seoul_Mate
|
||||
int main()
|
||||
{
|
||||
int i,j,f/*,answer*/;
|
||||
static int test_data[SIZE*2],compressed[SIZE],result[SIZE*2];
|
||||
|
||||
/* reset, initialize required memory */
|
||||
reset();
|
||||
|
||||
/* read in amplitude and frequency for test data */
|
||||
/* scanf("%d",&j);
|
||||
scanf("%d",&f); */
|
||||
j = 10; f = 2000; /* körs men, används inte */
|
||||
|
||||
/* 16 KHz sample rate */
|
||||
/* XXmain_0, MAX: 2 */
|
||||
/* Since the number of times we loop in my_sin depends on the argument we
|
||||
add the fact: xxmain_0:[]: */
|
||||
for(i = 0 ; i < SIZE ; i++) {
|
||||
test_data[i] = (int)j*my_cos(f*PI*i);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* MAX: 2 */
|
||||
|
||||
/*******Antar att test_data[0] = 10 och test_data[1]=-6 från ovan, *******
|
||||
och att anropet i forloopen blir encode(test_data[0],test_data[0]);
|
||||
och encode(test_data[1],test_data[1]), eftersom att den annars går
|
||||
*******över array gränsen *******/
|
||||
|
||||
|
||||
for(i = 0 ; i < IN_END ; i += 2)
|
||||
compressed[i/2] = encode(test_data[i],test_data[i+1]);
|
||||
/* MAX: 2 */
|
||||
for(i = 0 ; i < IN_END ; i += 2) {
|
||||
decode(compressed[i/2]);
|
||||
result[i] = xout1;
|
||||
result[i+1] = xout2;
|
||||
}
|
||||
/*
|
||||
for( ; j < 32767 ; j++) {
|
||||
i=IN_END-1;
|
||||
printf("\n%4d %4d %4d %4d %4d",j,compressed[i/2] >> 6,compressed[i/2] & 63,result[i],result[i-1]);
|
||||
}
|
||||
*/
|
||||
/* print ih, il */
|
||||
/*
|
||||
for(i = 0 ; i < IN_END/2 ; i++) printf("\n%4d %2d %2d",
|
||||
i,compressed[i] >> 6,compressed[i] & 63);
|
||||
*/
|
||||
|
||||
return result[i]+result[i+1];
|
||||
}
|
||||
#endif
|
|
@ -1,113 +0,0 @@
|
|||
/*************************************************************************/
|
||||
/* */
|
||||
/* SNU-RT Benchmark Suite for Worst Case Timing Analysis */
|
||||
/* ===================================================== */
|
||||
/* Collected and Modified by S.-S. Lim */
|
||||
/* sslim@archi.snu.ac.kr */
|
||||
/* Real-Time Research Group */
|
||||
/* Seoul National University */
|
||||
/* */
|
||||
/* */
|
||||
/* < Features > - restrictions for our experimental environment */
|
||||
/* */
|
||||
/* 1. Completely structured. */
|
||||
/* - There are no unconditional jumps. */
|
||||
/* - There are no exit from loop bodies. */
|
||||
/* (There are no 'break' or 'return' in loop bodies) */
|
||||
/* 2. No 'switch' statements. */
|
||||
/* 3. No 'do..while' statements. */
|
||||
/* 4. Expressions are restricted. */
|
||||
/* - There are no multiple expressions joined by 'or', */
|
||||
/* 'and' operations. */
|
||||
/* 5. No library calls. */
|
||||
/* - All the functions needed are implemented in the */
|
||||
/* source file. */
|
||||
/* */
|
||||
/* */
|
||||
/*************************************************************************/
|
||||
/* */
|
||||
/* FILE: bs.c */
|
||||
/* SOURCE : Public Domain Code */
|
||||
/* */
|
||||
/* DESCRIPTION : */
|
||||
/* */
|
||||
/* Binary search for the array of 15 integer elements. */
|
||||
/* */
|
||||
/* REMARK : */
|
||||
/* */
|
||||
/* EXECUTION TIME : */
|
||||
/* */
|
||||
/* */
|
||||
/*************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
struct DATA {
|
||||
int key;
|
||||
int value;
|
||||
} ;
|
||||
|
||||
#ifdef DEBUG
|
||||
int cnt1;
|
||||
#endif
|
||||
|
||||
struct DATA data[15] = { {1, 100},
|
||||
{5,200},
|
||||
{6, 300},
|
||||
{7, 700},
|
||||
{8, 900},
|
||||
{9, 250},
|
||||
{10, 400},
|
||||
{11, 600},
|
||||
{12, 800},
|
||||
{13, 1500},
|
||||
{14, 1200},
|
||||
{15, 110},
|
||||
{16, 140},
|
||||
{17, 133},
|
||||
{18, 10} };
|
||||
|
||||
main()
|
||||
{
|
||||
binary_search(8);
|
||||
}
|
||||
|
||||
binary_search(x)
|
||||
{
|
||||
int fvalue, mid, up, low ;
|
||||
|
||||
low = 0;
|
||||
up = 14;
|
||||
fvalue = -1 /* all data are positive */ ;
|
||||
while (low <= up) {
|
||||
mid = (low + up) >> 1;
|
||||
if ( data[mid].key == x ) { /* found */
|
||||
up = low - 1;
|
||||
fvalue = data[mid].value;
|
||||
#ifdef DEBUG
|
||||
printf("FOUND!!\n");
|
||||
#endif
|
||||
}
|
||||
else /* not found */
|
||||
if ( data[mid].key > x ) {
|
||||
up = mid - 1;
|
||||
#ifdef DEBUG
|
||||
printf("MID-1\n");
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
low = mid + 1;
|
||||
#ifdef DEBUG
|
||||
printf("MID+1\n");
|
||||
#endif
|
||||
}
|
||||
#ifdef DEBUG
|
||||
cnt1++;
|
||||
#endif
|
||||
}
|
||||
#ifdef DEBUG
|
||||
printf("Loop Count : %d\n", cnt1);
|
||||
#endif
|
||||
return fvalue;
|
||||
}
|
|
@ -1,127 +0,0 @@
|
|||
/* bsort100.c */
|
||||
|
||||
/* All output disabled for wcsim */
|
||||
#define WCSIM 1
|
||||
|
||||
/* A read from this address will result in an known value of 1 */
|
||||
#define KNOWN_VALUE (int)(*((char *)0x80200001))
|
||||
|
||||
/* A read from this address will result in an unknown value */
|
||||
#define UNKNOWN_VALUE (int)(*((char *)0x80200003))
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/times.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define WORSTCASE 1
|
||||
#define FALSE 0
|
||||
#define TRUE 1
|
||||
#define NUMELEMS 100
|
||||
#define MAXDIM (NUMELEMS+1)
|
||||
|
||||
/* BUBBLESORT BENCHMARK PROGRAM:
|
||||
* This program tests the basic loop constructs, integer comparisons,
|
||||
* and simple array handling of compilers by sorting 10 arrays of
|
||||
* randomly generated integers.
|
||||
*/
|
||||
|
||||
int Array[MAXDIM], Seed;
|
||||
int factor;
|
||||
|
||||
main()
|
||||
{
|
||||
long StartTime, StopTime;
|
||||
float TotalTime;
|
||||
|
||||
#ifndef WCSIM
|
||||
printf("\n *** BUBBLE SORT BENCHMARK TEST ***\n\n");
|
||||
printf("RESULTS OF TEST:\n\n");
|
||||
#endif
|
||||
Initialize(Array);
|
||||
/* StartTime = ttime (); */
|
||||
BubbleSort(Array);
|
||||
/* StopTime = ttime(); */
|
||||
/* TotalTime = (StopTime - StartTime) / 1000.0; */
|
||||
#ifndef WCSIM
|
||||
printf(" - Number of elements sorted is %d\n", NUMELEMS);
|
||||
printf(" - Total time sorting is %3.3f seconds\n\n", TotalTime);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int ttime()
|
||||
/*
|
||||
* This function returns in milliseconds the amount of compiler time
|
||||
* used prior to it being called.
|
||||
*/
|
||||
{
|
||||
struct tms buffer;
|
||||
int utime;
|
||||
|
||||
/* times(&buffer); not implemented */
|
||||
utime = (buffer.tms_utime / 60.0) * 1000.0;
|
||||
return(utime);
|
||||
}
|
||||
|
||||
|
||||
Initialize(Array)
|
||||
int Array[];
|
||||
/*
|
||||
* Initializes given array with randomly generated integers.
|
||||
*/
|
||||
{
|
||||
int Index, fact;
|
||||
|
||||
#ifdef WORSTCASE
|
||||
factor = -1;
|
||||
#else
|
||||
factor = 1;
|
||||
#endif
|
||||
|
||||
fact = factor;
|
||||
for (Index = 1; Index <= NUMELEMS; Index ++)
|
||||
Array[Index] = Index*fact * KNOWN_VALUE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
BubbleSort(Array)
|
||||
int Array[];
|
||||
/*
|
||||
* Sorts an array of integers of size NUMELEMS in ascending order.
|
||||
*/
|
||||
{
|
||||
int Sorted = FALSE;
|
||||
int Temp, LastIndex, Index, i;
|
||||
|
||||
for (i = 1;
|
||||
i <= NUMELEMS-1; /* apsim_loop 1 0 */
|
||||
i++)
|
||||
{
|
||||
Sorted = TRUE;
|
||||
for (Index = 1;
|
||||
Index <= NUMELEMS-1; /* apsim_loop 10 1 */
|
||||
Index ++) {
|
||||
if (Index > NUMELEMS-i)
|
||||
break;
|
||||
if (Array[Index] > Array[Index + 1])
|
||||
{
|
||||
Temp = Array[Index];
|
||||
Array[Index] = Array[Index+1];
|
||||
Array[Index+1] = Temp;
|
||||
Sorted = FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
if (Sorted)
|
||||
break;
|
||||
}
|
||||
|
||||
#ifndef WCSIM
|
||||
if (Sorted || i == 1)
|
||||
fprintf(stderr, "array was successfully sorted in %d passes\n", i-1);
|
||||
else
|
||||
fprintf(stderr, "array was unsuccessfully sorted in %d passes\n", i-1);
|
||||
#endif
|
||||
}
|
|
@ -1,521 +0,0 @@
|
|||
/* MDH WCET BENCHMARK SUITE. File version $Id: compress.c,v 1.7 2005/12/21 09:37:18 jgn Exp $ */
|
||||
|
||||
/*
|
||||
* Compress - data compression program
|
||||
*
|
||||
* Adopted from SPEC95 for WCET-calculation by Thomas Lundqvist, 1997-11-28.
|
||||
* Only compression is done on a buffer (small one) containing
|
||||
* totally random data. This should come closer to a worst case
|
||||
* compared to the original SPEC95-version.
|
||||
*
|
||||
* All unused code removed by Jakob Engblom, february 2000. Cleaned
|
||||
* up for IAR compilation.
|
||||
*
|
||||
* Removed the prototype declaration of "code_int getcode();" that is
|
||||
* niether defined nor used. Christer Sandberg
|
||||
*
|
||||
* Changes:
|
||||
* JG 2005/12/20: Changed declaration of maxmaxcode to avoid warning
|
||||
* JG 2012/09/28: Comment within comment removed
|
||||
*/
|
||||
|
||||
/* #define DO_TRACING */
|
||||
|
||||
#ifdef DO_TRACING /* ON PC */
|
||||
|
||||
#include <stdio.h>
|
||||
#define TRACE(x) trace((x))
|
||||
#undef TEST /* finished testing! */
|
||||
|
||||
/*
|
||||
void trace(char *s)
|
||||
{
|
||||
printf("%s\n",s);
|
||||
}
|
||||
*/
|
||||
|
||||
#else /* ON TARGET */
|
||||
|
||||
#define TRACE(x)
|
||||
#undef TEST
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#define BUFFERSIZE 50
|
||||
#define IN_COUNT BUFFERSIZE
|
||||
|
||||
#define HSIZE 257 /* 95% occupancy */
|
||||
#define BITS 16
|
||||
#define INIT_BITS 9 /* initial number of bits/code */
|
||||
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
#define min(a,b) ((a>b) ? b : a)
|
||||
|
||||
/*
|
||||
* Set USERMEM to the maximum amount of physical user memory available
|
||||
* in bytes. USERMEM is used to determine the maximum BITS that can be used
|
||||
* for compression.
|
||||
*
|
||||
* SACREDMEM is the amount of physical memory saved for others; compress
|
||||
* will hog the rest.
|
||||
*/
|
||||
/* For SPEC95 use, SACREDMEM automatically set to 0.
|
||||
Jeff Reilly, 1/15/95 */
|
||||
|
||||
#define SACREDMEM 0
|
||||
|
||||
/* For SPEC95 use, USERMEM automatically set to 450000.
|
||||
Jeff Reilly, 1/15/95 */
|
||||
# define USERMEM 450000 /* default user memory */
|
||||
|
||||
#ifdef interdata /* (Perkin-Elmer) */
|
||||
#define SIGNED_COMPARE_SLOW /* signed compare is slower than unsigned */
|
||||
#endif
|
||||
|
||||
/* For SPEC95 use, PBITS and BITS automatically set to 16.
|
||||
Jeff Reilyy, 1/15/95 */
|
||||
#define PBITS 16
|
||||
#define BITS 16
|
||||
#define HSIZE 257 /* 95% occupancy was 69001 */
|
||||
|
||||
|
||||
/*
|
||||
* a code_int must be able to hold 2**BITS values of type int, and also -1
|
||||
*/
|
||||
#if BITS > 15
|
||||
typedef long int code_int;
|
||||
#else
|
||||
typedef int code_int;
|
||||
#endif
|
||||
|
||||
#ifdef SIGNED_COMPARE_SLOW
|
||||
typedef unsigned long int count_int;
|
||||
typedef unsigned short int count_short;
|
||||
#else
|
||||
typedef long int count_int;
|
||||
#endif
|
||||
|
||||
typedef unsigned char char_type;
|
||||
|
||||
/* Defines for third byte of header */
|
||||
#define BIT_MASK 0x1f
|
||||
#define BLOCK_MASK 0x80
|
||||
/* Masks 0x40 and 0x20 are free. I think 0x20 should mean that there is
|
||||
a fourth header byte (for expansion).
|
||||
*/
|
||||
|
||||
/* Global variables */
|
||||
int n_bits; /* number of bits/code */
|
||||
int maxbits = BITS; /* user settable max # bits/code */
|
||||
code_int maxcode; /* maximum code, given n_bits */
|
||||
#if BITS > 15
|
||||
code_int maxmaxcode = 1L << BITS; /* should NEVER generate this code */
|
||||
#else
|
||||
code_int maxmaxcode = 1 << BITS; /* should NEVER generate this code */
|
||||
#endif
|
||||
|
||||
# define MAXCODE(n_bits) ((1 << (n_bits)) - 1)
|
||||
|
||||
|
||||
#define htabof(i) htab[i]
|
||||
#define codetabof(i) codetab[i]
|
||||
|
||||
code_int hsize = HSIZE; /* for dynamic table sizing */
|
||||
count_int fsize;
|
||||
|
||||
/*
|
||||
* To save much memory, we overlay the table used by compress() with those
|
||||
* used by decompress(). The tab_prefix table is the same size and type
|
||||
* as the codetab. The tab_suffix table needs 2**BITS characters. We
|
||||
* get this from the beginning of htab. The output stack uses the rest
|
||||
* of htab, and contains characters. There is plenty of room for any
|
||||
* possible stack (stack used to be 8000 characters).
|
||||
*/
|
||||
|
||||
#define tab_prefixof(i) codetabof(i)
|
||||
#define tab_suffixof(i) ((char_type *)(htab))[i]
|
||||
#define de_stack ((char_type *)&tab_suffixof(1<<BITS))
|
||||
|
||||
code_int free_ent = 0; /* first unused entry */
|
||||
int exit_stat = 0;
|
||||
|
||||
int nomagic = 1; /* Use a 3-byte magic number header, unless old file */
|
||||
int zcat_flg = 0; /* Write output on stdout, suppress messages */
|
||||
int quiet = 1; /* don't tell me about compression */
|
||||
|
||||
/*
|
||||
* block compression parameters -- after all codes are used up,
|
||||
* and compression rate changes, start over.
|
||||
*/
|
||||
int block_compress = BLOCK_MASK;
|
||||
int clear_flg = 0;
|
||||
long int ratio = 0;
|
||||
#define CHECK_GAP 10000 /* ratio check interval */
|
||||
count_int checkpoint = CHECK_GAP;
|
||||
/*
|
||||
* the next two codes should not be changed lightly, as they must not
|
||||
* lie within the contiguous general code space.
|
||||
*/
|
||||
#define FIRST 257 /* first free entry */
|
||||
#define CLEAR 256 /* table clear output code */
|
||||
|
||||
int force = 0;
|
||||
char ofname [100];
|
||||
int InCnt;
|
||||
int apsim_InCnt;
|
||||
unsigned char *InBuff;
|
||||
unsigned char *OutBuff;
|
||||
|
||||
char orig_text_buffer[BUFFERSIZE];
|
||||
char comp_text_buffer[BUFFERSIZE+5];
|
||||
|
||||
count_int htab [HSIZE];
|
||||
unsigned short codetab [HSIZE];
|
||||
char buf[BITS];
|
||||
|
||||
|
||||
|
||||
/*---------------------------------------------------- */
|
||||
/*----------------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------*/
|
||||
/*----------------------------------------------------------------------*/
|
||||
|
||||
|
||||
/*----------------------------------------- Prototypes */
|
||||
void initbuffer(void);
|
||||
void compress(void);
|
||||
void cl_hash(count_int hsize); /* reset code table */
|
||||
unsigned int getbyte(void);
|
||||
void putbyte( char c );
|
||||
void cl_block (void);
|
||||
void output( code_int code );
|
||||
void writebytes( char *buf, int n );
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int count = IN_COUNT;
|
||||
|
||||
initbuffer();
|
||||
|
||||
/*if(maxbits < INIT_BITS) maxbits = INIT_BITS;*/
|
||||
/* With our setting, maxbits = 16,
|
||||
INIT_BITS = 9 */
|
||||
/*if (maxbits > BITS) maxbits = BITS;*/
|
||||
maxbits = BITS;
|
||||
maxmaxcode = 1 << maxbits;
|
||||
|
||||
InCnt = count;
|
||||
apsim_InCnt = IN_COUNT + 3;
|
||||
InBuff = (unsigned char *)orig_text_buffer;
|
||||
OutBuff = (unsigned char *)comp_text_buffer;
|
||||
|
||||
compress();
|
||||
|
||||
return (0);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
void initbuffer(void)
|
||||
{
|
||||
int seed = 1;
|
||||
int i;
|
||||
int tabort;
|
||||
|
||||
for (i = 0 ; i < BUFFERSIZE ; i++) {
|
||||
/* Generates random integers between 0 and 8095 */
|
||||
tabort = i;
|
||||
seed = ((seed * 133) + 81) % 8095;
|
||||
|
||||
orig_text_buffer[i] = seed % 256;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int offset;
|
||||
long int in_count = 1; /* length of input */
|
||||
long int bytes_out; /* length of compressed output */
|
||||
long int out_count = 0; /* # of codes output (for debugging) */
|
||||
|
||||
|
||||
void compress(void)
|
||||
{
|
||||
register long fcode;
|
||||
register code_int i = 0;
|
||||
register int c;
|
||||
register code_int ent;
|
||||
register int disp;
|
||||
register code_int hsize_reg;
|
||||
register int hshift;
|
||||
|
||||
|
||||
offset = 0;
|
||||
bytes_out = 3; /* includes 3-byte header mojo */
|
||||
out_count = 0;
|
||||
clear_flg = 0;
|
||||
ratio = 0;
|
||||
in_count = 1;
|
||||
checkpoint = CHECK_GAP;
|
||||
maxcode = MAXCODE(n_bits = INIT_BITS);
|
||||
free_ent = ((block_compress) ? (FIRST) : (256) );
|
||||
|
||||
ent = getbyte ();
|
||||
|
||||
hshift = 0;
|
||||
for ( fcode = (long) hsize; fcode < 65536L; fcode *= 2L )
|
||||
{
|
||||
hshift++;
|
||||
}
|
||||
|
||||
hshift = 8 - hshift; /* set hash code range bound */
|
||||
|
||||
hsize_reg = hsize;
|
||||
cl_hash( (count_int) hsize_reg); /* clear hash table */
|
||||
|
||||
|
||||
while ( InCnt > 0 ) /* apsim_loop 11 0 */
|
||||
{
|
||||
int apsim_bound111 = 0;
|
||||
|
||||
c = getbyte(); /* decrements InCnt */
|
||||
|
||||
in_count++;
|
||||
fcode = (long) (((long) c << maxbits) + ent);
|
||||
i = ((c << hshift) ^ ent); /* xor hashing */
|
||||
|
||||
if ( htabof (i) == fcode ) {
|
||||
ent = codetabof (i);
|
||||
continue;
|
||||
} else if ( (long)htabof (i) < 0 ) { /* empty slot */
|
||||
goto nomatch;
|
||||
}
|
||||
|
||||
|
||||
disp = hsize_reg - i; /* secondary hash (after G. Knott) */
|
||||
if ( i == 0 ) {
|
||||
disp = 1;
|
||||
}
|
||||
|
||||
probe:
|
||||
|
||||
if ( (i -= disp) < 0 ) { /* apsim_loop 111 11 */
|
||||
i += hsize_reg;
|
||||
}
|
||||
|
||||
if ( htabof (i) == fcode ) {
|
||||
ent = codetabof (i);
|
||||
continue;
|
||||
}
|
||||
|
||||
if ( (long)htabof (i) > 0 && (++apsim_bound111 < in_count) )
|
||||
goto probe;
|
||||
nomatch:
|
||||
|
||||
out_count++;
|
||||
ent = c;
|
||||
if ( free_ent < maxmaxcode ) {
|
||||
codetabof (i) = free_ent++; /* apsim_unknown codetab */
|
||||
htabof (i) = fcode; /* apsim_unknown htab */
|
||||
} else if ( ((count_int)in_count >= checkpoint) && (block_compress) ) {
|
||||
cl_block ();
|
||||
}
|
||||
|
||||
}
|
||||
if(bytes_out > in_count) { /* exit(2) if no savings */
|
||||
exit_stat = 2;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void cl_block (void) /* table clear for block compress */
|
||||
{
|
||||
register long int rat;
|
||||
|
||||
checkpoint = in_count + CHECK_GAP;
|
||||
|
||||
if(in_count > 0x007fffff) { /* shift will overflow */
|
||||
|
||||
rat = bytes_out >> 8;
|
||||
if(rat == 0) { /* Don't divide by zero */
|
||||
rat = 0x7fffffff;
|
||||
} else {
|
||||
rat = in_count / rat;
|
||||
}
|
||||
} else {
|
||||
rat = (in_count << 8) / bytes_out; /* 8 fractional bits */
|
||||
}
|
||||
if ( rat > ratio ) {
|
||||
ratio = rat;
|
||||
} else {
|
||||
ratio = 0;
|
||||
cl_hash ( (count_int) hsize );
|
||||
|
||||
|
||||
free_ent = FIRST;
|
||||
clear_flg = 1;
|
||||
output ( (code_int) CLEAR );
|
||||
}
|
||||
}
|
||||
|
||||
void cl_hash(count_int hsize) /* reset code table */
|
||||
{
|
||||
register count_int *htab_p = htab+hsize;
|
||||
register long i;
|
||||
register long m1 = -1;
|
||||
|
||||
i = hsize - 16;
|
||||
do { /* might use Sys V memset(3) here */
|
||||
|
||||
*(htab_p-16) = m1;
|
||||
*(htab_p-15) = m1;
|
||||
*(htab_p-14) = m1;
|
||||
*(htab_p-13) = m1;
|
||||
*(htab_p-12) = m1;
|
||||
*(htab_p-11) = m1;
|
||||
*(htab_p-10) = m1;
|
||||
*(htab_p-9) = m1;
|
||||
*(htab_p-8) = m1;
|
||||
*(htab_p-7) = m1;
|
||||
*(htab_p-6) = m1;
|
||||
*(htab_p-5) = m1;
|
||||
*(htab_p-4) = m1;
|
||||
*(htab_p-3) = m1;
|
||||
*(htab_p-2) = m1;
|
||||
*(htab_p-1) = m1;
|
||||
htab_p -= 16;
|
||||
} while ((i -= 16) >= 0);
|
||||
for ( i += 16; i > 0; i-- ) {
|
||||
*--htab_p = m1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
unsigned int getbyte(void)
|
||||
{
|
||||
if( InCnt > 0 && (apsim_InCnt-- > 0)) {
|
||||
InCnt--;
|
||||
return( (unsigned int)*InBuff++ );
|
||||
} else {
|
||||
return( -1 );
|
||||
}
|
||||
}
|
||||
|
||||
void putbyte( char c )
|
||||
{
|
||||
*OutBuff++ = c; /* apsim_unknown comp_text_buffer */
|
||||
}
|
||||
|
||||
|
||||
void writebytes( char *buf, int n )
|
||||
{
|
||||
int i;
|
||||
for( i=0; (i<n) && /*apsim*/ (i < BITS) ; i++ ) {
|
||||
*OutBuff++ = buf[i]; /* apsim_unknown comp_text_buffer */
|
||||
}
|
||||
}
|
||||
|
||||
/* apsim_rel 111 < 112 */
|
||||
|
||||
char_type lmask[9] = {0xff, 0xfe, 0xfc, 0xf8, 0xf0, 0xe0, 0xc0, 0x80, 0x00};
|
||||
char_type rmask[9] = {0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff};
|
||||
|
||||
void output( code_int code )
|
||||
{
|
||||
/*
|
||||
* On the VAX, it is important to have the register declarations
|
||||
* in exactly the order given, or the asm will break.
|
||||
*/
|
||||
register int r_off = offset, bits= n_bits;
|
||||
register char * bp = buf;
|
||||
|
||||
if ( code >= 0 ) {
|
||||
/*
|
||||
* byte/bit numbering on the VAX is simulated by the following code
|
||||
*/
|
||||
/*
|
||||
* Get to the first byte.
|
||||
*/
|
||||
bp += (r_off >> 3);
|
||||
r_off &= 7;
|
||||
/*
|
||||
* Since code is always >= 8 bits, only need to mask the first
|
||||
* hunk on the left.
|
||||
*/
|
||||
*bp = ((*bp & rmask[r_off]) | (code << r_off)) & lmask[r_off]; /* apsim_unknown buf */
|
||||
bp++;
|
||||
bits -= (8 - r_off);
|
||||
code >>= 8 - r_off;
|
||||
/* Get any 8 bit parts in the middle (<=1 for up to 16 bits). */
|
||||
if ( bits >= 8 ) {
|
||||
|
||||
*bp++ = code; /* apsim_unknown buf */
|
||||
code >>= 8;
|
||||
bits -= 8;
|
||||
}
|
||||
|
||||
/* Last bits. */
|
||||
if(bits) {
|
||||
*bp = code; /* apsim_unknown buf */
|
||||
}
|
||||
|
||||
offset += n_bits;
|
||||
if ( offset == (n_bits << 3) ) {
|
||||
bp = buf;
|
||||
bits = n_bits;
|
||||
bytes_out += bits;
|
||||
do {
|
||||
putbyte(*bp++);
|
||||
} while(( --bits) && ((bp - buf < BITS)));
|
||||
offset = 0;
|
||||
}
|
||||
/*
|
||||
* If the next entry is going to be too big for the code size,
|
||||
* then increase it, if possible.
|
||||
*/
|
||||
if ( free_ent > maxcode || ((clear_flg > 0))) {
|
||||
/*
|
||||
* Write the whole buffer, because the input side won't
|
||||
* discover the size increase until after it has read it.
|
||||
*/
|
||||
if ( offset > 0 ) {
|
||||
writebytes( buf, n_bits );
|
||||
bytes_out += n_bits;
|
||||
}
|
||||
offset = 0;
|
||||
if ( clear_flg ) {
|
||||
maxcode = MAXCODE (n_bits = INIT_BITS);
|
||||
clear_flg = 0;
|
||||
} else {
|
||||
n_bits++;
|
||||
if ( n_bits == maxbits )
|
||||
{
|
||||
maxcode = maxmaxcode;
|
||||
}
|
||||
else
|
||||
{
|
||||
maxcode = MAXCODE(n_bits);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/*
|
||||
* At EOF, write the rest of the buffer.
|
||||
*/
|
||||
if ( offset > 0 )
|
||||
{
|
||||
writebytes( buf, ((offset + 7) / 8) );
|
||||
}
|
||||
bytes_out += (offset + 7) / 8;
|
||||
offset = 0;
|
||||
}
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
/* $Id: fibcall.c,v 1.2 2005/04/04 11:34:58 csg Exp $ */
|
||||
|
||||
/*************************************************************************/
|
||||
/* */
|
||||
/* SNU-RT Benchmark Suite for Worst Case Timing Analysis */
|
||||
/* ===================================================== */
|
||||
/* Collected and Modified by S.-S. Lim */
|
||||
/* sslim@archi.snu.ac.kr */
|
||||
/* Real-Time Research Group */
|
||||
/* Seoul National University */
|
||||
/* */
|
||||
/* */
|
||||
/* < Features > - restrictions for our experimental environment */
|
||||
/* */
|
||||
/* 1. Completely structured. */
|
||||
/* - There are no unconditional jumps. */
|
||||
/* - There are no exit from loop bodies. */
|
||||
/* (There are no 'break' or 'return' in loop bodies) */
|
||||
/* 2. No 'switch' statements. */
|
||||
/* 3. No 'do..while' statements. */
|
||||
/* 4. Expressions are restricted. */
|
||||
/* - There are no multiple expressions joined by 'or', */
|
||||
/* 'and' operations. */
|
||||
/* 5. No library calls. */
|
||||
/* - All the functions needed are implemented in the */
|
||||
/* source file. */
|
||||
/* */
|
||||
/* */
|
||||
/*************************************************************************/
|
||||
/* */
|
||||
/* FILE: fibcall.c */
|
||||
/* SOURCE : Public Domain Code */
|
||||
/* */
|
||||
/* DESCRIPTION : */
|
||||
/* */
|
||||
/* Summing the Fibonacci series. */
|
||||
/* */
|
||||
/* REMARK : */
|
||||
/* */
|
||||
/* EXECUTION TIME : */
|
||||
/* */
|
||||
/* */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef TEST
|
||||
#include "../mini_printf.h"
|
||||
#else
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
int fib(int n)
|
||||
{
|
||||
int i, Fnew, Fold, temp,ans;
|
||||
|
||||
Fnew = 1; Fold = 0;
|
||||
for ( i = 2;
|
||||
i <= 30 && i <= n; /* apsim_loop 1 0 */
|
||||
i++ )
|
||||
{
|
||||
temp = Fnew;
|
||||
Fnew = Fnew + Fold;
|
||||
Fold = temp;
|
||||
}
|
||||
ans = Fnew;
|
||||
return ans;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
int a;
|
||||
|
||||
a = 30;
|
||||
a = fib(a);
|
||||
printf("%d\n", a);
|
||||
return a;
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,89 +0,0 @@
|
|||
/* $Id: insertsort.c,v 1.2 2005/04/04 11:34:58 csg Exp $ */
|
||||
|
||||
/*************************************************************************/
|
||||
/* */
|
||||
/* SNU-RT Benchmark Suite for Worst Case Timing Analysis */
|
||||
/* ===================================================== */
|
||||
/* Collected and Modified by S.-S. Lim */
|
||||
/* sslim@archi.snu.ac.kr */
|
||||
/* Real-Time Research Group */
|
||||
/* Seoul National University */
|
||||
/* */
|
||||
/* */
|
||||
/* < Features > - restrictions for our experimental environment */
|
||||
/* */
|
||||
/* 1. Completely structured. */
|
||||
/* - There are no unconditional jumps. */
|
||||
/* - There are no exit from loop bodies. */
|
||||
/* (There are no 'break' or 'return' in loop bodies) */
|
||||
/* 2. No 'switch' statements. */
|
||||
/* 3. No 'do..while' statements. */
|
||||
/* 4. Expressions are restricted. */
|
||||
/* - There are no multiple expressions joined by 'or', */
|
||||
/* 'and' operations. */
|
||||
/* 5. No library calls. */
|
||||
/* - All the functions needed are implemented in the */
|
||||
/* source file. */
|
||||
/* */
|
||||
/* */
|
||||
/*************************************************************************/
|
||||
/* */
|
||||
/* FILE: insertsort.c */
|
||||
/* SOURCE : Public Domain Code */
|
||||
/* */
|
||||
/* DESCRIPTION : */
|
||||
/* */
|
||||
/* Insertion sort for 10 integer numbers. */
|
||||
/* The integer array a[] is initialized in main function. */
|
||||
/* */
|
||||
/* REMARK : */
|
||||
/* */
|
||||
/* EXECUTION TIME : */
|
||||
/* */
|
||||
/* */
|
||||
/*************************************************************************/
|
||||
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
int cnt1, cnt2;
|
||||
#endif
|
||||
|
||||
unsigned int a[11];
|
||||
|
||||
int main()
|
||||
{
|
||||
int i,j, temp;
|
||||
|
||||
a[0] = 0; /* assume all data is positive */
|
||||
a[1] = 11; a[2]=10;a[3]=9; a[4]=8; a[5]=7; a[6]=6; a[7]=5;
|
||||
a[8] =4; a[9]=3; a[10]=2;
|
||||
i = 2;
|
||||
while(i <= 10){
|
||||
#ifdef DEBUG
|
||||
cnt1++;
|
||||
#endif
|
||||
j = i;
|
||||
#ifdef DEBUG
|
||||
cnt2=0;
|
||||
#endif
|
||||
while (a[j] < a[j-1])
|
||||
{
|
||||
#ifdef DEBUG
|
||||
cnt2++;
|
||||
#endif
|
||||
temp = a[j];
|
||||
a[j] = a[j-1];
|
||||
a[j-1] = temp;
|
||||
j--;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
printf("Inner Loop Counts: %d\n", cnt2);
|
||||
#endif
|
||||
i++;
|
||||
}
|
||||
#ifdef DEBUG
|
||||
printf("Outer Loop : %d , Inner Loop : %d\n", cnt1, cnt2);
|
||||
#endif
|
||||
return 1;
|
||||
}
|
|
@ -1,162 +0,0 @@
|
|||
/* $Id: matmult.c,v 1.2 2005/04/04 11:34:58 csg Exp $ */
|
||||
|
||||
/* matmult.c */
|
||||
/* was mm.c! */
|
||||
|
||||
|
||||
/*----------------------------------------------------------------------*
|
||||
* To make this program compile under our assumed embedded environment,
|
||||
* we had to make several changes:
|
||||
* - Declare all functions in ANSI style, not K&R.
|
||||
* this includes adding return types in all cases!
|
||||
* - Declare function prototypes
|
||||
* - Disable all output
|
||||
* - Disable all UNIX-style includes
|
||||
*
|
||||
* This is a program that was developed from mm.c to matmult.c by
|
||||
* Thomas Lundqvist at Chalmers.
|
||||
*----------------------------------------------------------------------*/
|
||||
#define UPPSALAWCET 1
|
||||
|
||||
|
||||
/* ***UPPSALA WCET***:
|
||||
disable stupid UNIX includes */
|
||||
#ifndef UPPSALAWCET
|
||||
#include <sys/types.h>
|
||||
#include <sys/times.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* MATRIX MULTIPLICATION BENCHMARK PROGRAM:
|
||||
* This program multiplies 2 square matrices resulting in a 3rd
|
||||
* matrix. It tests a compiler's speed in handling multidimensional
|
||||
* arrays and simple arithmetic.
|
||||
*/
|
||||
|
||||
#define UPPERLIMIT 20
|
||||
|
||||
typedef int matrix [UPPERLIMIT][UPPERLIMIT];
|
||||
|
||||
int Seed;
|
||||
matrix ArrayA, ArrayB, ResultArray;
|
||||
|
||||
#ifdef UPPSALAWCET
|
||||
/* Our picky compiler wants prototypes! */
|
||||
void Multiply(matrix A, matrix B, matrix Res);
|
||||
void InitSeed(void);
|
||||
void Test(matrix A, matrix B, matrix Res);
|
||||
void Initialize(matrix Array);
|
||||
int RandomInteger(void);
|
||||
#endif
|
||||
|
||||
void main()
|
||||
{
|
||||
InitSeed();
|
||||
/* ***UPPSALA WCET***:
|
||||
no printing please! */
|
||||
#ifndef UPPSALAWCET
|
||||
printf("\n *** MATRIX MULTIPLICATION BENCHMARK TEST ***\n\n");
|
||||
printf("RESULTS OF THE TEST:\n");
|
||||
#endif
|
||||
Test(ArrayA, ArrayB, ResultArray);
|
||||
}
|
||||
|
||||
|
||||
void InitSeed(void)
|
||||
/*
|
||||
* Initializes the seed used in the random number generator.
|
||||
*/
|
||||
{
|
||||
/* ***UPPSALA WCET***:
|
||||
changed Thomas Ls code to something simpler.
|
||||
Seed = KNOWN_VALUE - 1; */
|
||||
Seed = 0;
|
||||
}
|
||||
|
||||
|
||||
void Test(matrix A, matrix B, matrix Res)
|
||||
/*
|
||||
* Runs a multiplication test on an array. Calculates and prints the
|
||||
* time it takes to multiply the matrices.
|
||||
*/
|
||||
{
|
||||
#ifndef UPPSALAWCET
|
||||
long StartTime, StopTime;
|
||||
float TotalTime;
|
||||
#endif
|
||||
|
||||
Initialize(A);
|
||||
Initialize(B);
|
||||
|
||||
/* ***UPPSALA WCET***: don't print or time */
|
||||
#ifndef UPPSALAWCET
|
||||
StartTime = ttime ();
|
||||
#endif
|
||||
|
||||
Multiply(A, B, Res);
|
||||
|
||||
/* ***UPPSALA WCET***: don't print or time */
|
||||
#ifndef UPPSALAWCET
|
||||
StopTime = ttime();
|
||||
TotalTime = (StopTime - StartTime) / 1000.0;
|
||||
printf(" - Size of array is %d\n", UPPERLIMIT);
|
||||
printf(" - Total multiplication time is %3.3f seconds\n\n", TotalTime);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void Initialize(matrix Array)
|
||||
/*
|
||||
* Intializes the given array with random integers.
|
||||
*/
|
||||
{
|
||||
int OuterIndex, InnerIndex;
|
||||
|
||||
for (OuterIndex = 0; OuterIndex < UPPERLIMIT; OuterIndex++)
|
||||
for (InnerIndex = 0; InnerIndex < UPPERLIMIT; InnerIndex++)
|
||||
Array[OuterIndex][InnerIndex] = RandomInteger();
|
||||
}
|
||||
|
||||
|
||||
int RandomInteger(void)
|
||||
/*
|
||||
* Generates random integers between 0 and 8095
|
||||
*/
|
||||
{
|
||||
Seed = ((Seed * 133) + 81) % 8095;
|
||||
return (Seed);
|
||||
}
|
||||
|
||||
|
||||
#ifndef UPPSALAWCET
|
||||
int ttime()
|
||||
/*
|
||||
* This function returns in milliseconds the amount of compiler time
|
||||
* used prior to it being called.
|
||||
*/
|
||||
{
|
||||
struct tms buffer;
|
||||
int utime;
|
||||
|
||||
/* times(&buffer); times not implemented */
|
||||
utime = (buffer.tms_utime / 60.0) * 1000.0;
|
||||
return (utime);
|
||||
}
|
||||
#endif
|
||||
|
||||
void Multiply(matrix A, matrix B, matrix Res)
|
||||
/*
|
||||
* Multiplies arrays A and B and stores the result in ResultArray.
|
||||
*/
|
||||
{
|
||||
register int Outer, Inner, Index;
|
||||
|
||||
for (Outer = 0; Outer < UPPERLIMIT; Outer++)
|
||||
for (Inner = 0; Inner < UPPERLIMIT; Inner++)
|
||||
{
|
||||
Res [Outer][Inner] = 0;
|
||||
for (Index = 0; Index < UPPERLIMIT; Index++)
|
||||
Res[Outer][Inner] +=
|
||||
A[Outer][Index] * B[Index][Inner];
|
||||
}
|
||||
}
|
|
@ -1,238 +0,0 @@
|
|||
/* MDH WCET BENCHMARK SUITE. */
|
||||
|
||||
/* 2012/10/03, Jan Gustafsson <jan.gustafsson@mdh.se>
|
||||
* Changes:
|
||||
* - init of "is" fixed (added a lot of brackets)
|
||||
* - warning: array subscript is of type 'char': fixed in three places
|
||||
*/
|
||||
|
||||
|
||||
/* #include <math.h> -- no include files in Uppsala tests, plz */
|
||||
|
||||
/* All output disabled for wcsim */
|
||||
|
||||
/* A read from this address will result in an known value of 1 */
|
||||
/* #define KNOWN_VALUE (int)(*((char *)0x80200001)) Changed JG/Ebbe */
|
||||
#define KNOWN_VALUE 1
|
||||
|
||||
/* A read from this address will result in an unknown value */
|
||||
#define UNKNOWN_VALUE (int)(*((char *)0x80200003))
|
||||
|
||||
|
||||
#define WORSTCASE 1
|
||||
|
||||
typedef struct IMMENSE { unsigned long l, r; } immense;
|
||||
typedef struct GREAT { unsigned long l, c, r; } great;
|
||||
|
||||
unsigned long bit[33];
|
||||
|
||||
static immense icd;
|
||||
static char ipc1[57]={0,57,49,41,33,25,17,9,1,58,50,
|
||||
42,34,26,18,10,2,59,51,43,35,27,19,11,3,60,
|
||||
52,44,36,63,55,47,39,31,23,15,7,62,54,46,38,
|
||||
30,22,14,6,61,53,45,37,29,21,13,5,28,20,12,4};
|
||||
static char ipc2[49]={0,14,17,11,24,1,5,3,28,15,6,21,
|
||||
10,23,19,12,4,26,8,16,7,27,20,13,2,41,52,31,
|
||||
37,47,55,30,40,51,45,33,48,44,49,39,56,34,
|
||||
53,46,42,50,36,29,32};
|
||||
|
||||
void des(immense inp, immense key, int * newkey, int isw, immense * out);
|
||||
unsigned long getbit(immense source, int bitno, int nbits);
|
||||
void ks(/*immense key, */int n, great * kn);
|
||||
void cyfun(unsigned long ir, great k, unsigned long * iout);
|
||||
|
||||
void des(immense inp, immense key, int * newkey, int isw, immense * out) {
|
||||
|
||||
static char ip[65] =
|
||||
{0,58,50,42,34,26,18,10,2,60,52,44,36,
|
||||
28,20,12,4,62,54,46,38,30,22,14,6,64,56,48,40,
|
||||
32,24,16,8,57,49,41,33,25,17,9,1,59,51,43,35,
|
||||
27,19,11,3,61,53,45,37,29,21,13,5,63,55,47,39,
|
||||
31,23,15,7};
|
||||
static char ipm[65]=
|
||||
{0,40,8,48,16,56,24,64,32,39,7,47,15,
|
||||
55,23,63,31,38,6,46,14,54,22,62,30,37,5,45,13,
|
||||
53,21,61,29,36,4,44,12,52,20,60,28,35,3,43,11,
|
||||
51,19,59,27,34,2,42,10,50,18,58,26,33,1,41,9,
|
||||
49,17,57,25};
|
||||
static great kns[17];
|
||||
#ifdef WORSTCASE
|
||||
static int initflag=1;
|
||||
#else
|
||||
static int initflag=0;
|
||||
#endif
|
||||
int ii,i,j,k;
|
||||
unsigned long ic,shifter,getbit();
|
||||
immense itmp;
|
||||
great pg;
|
||||
|
||||
if (initflag) {
|
||||
initflag=0;
|
||||
bit[1]=shifter=1L;
|
||||
for(j=2;j<=32;j++) bit[j] = (shifter <<= 1);
|
||||
}
|
||||
if (*newkey) {
|
||||
*newkey=0;
|
||||
icd.r=icd.l=0L;
|
||||
for (j=28,k=56;j>=1;j--,k--) {
|
||||
icd.r = (icd.r <<= 1) | getbit(key,ipc1[j],32);
|
||||
icd.l = (icd.l <<= 1) | getbit(key,ipc1[k],32);
|
||||
}
|
||||
|
||||
for(i=1;i<=16;i++) {pg = kns[i]; ks(/* key,*/ i, &pg); kns[i] = pg;}
|
||||
}
|
||||
itmp.r=itmp.l=0L;
|
||||
for (j=32,k=64;j>=1;j--,k--) {
|
||||
itmp.r = (itmp.r <<= 1) | getbit(inp,ip[j],32);
|
||||
itmp.l = (itmp.l <<= 1) | getbit(inp,ip[k],32);
|
||||
}
|
||||
for (i=1;i<=16;i++) {
|
||||
ii = (isw == 1 ? 17-i : i);
|
||||
cyfun(itmp.l, kns[ii], &ic);
|
||||
ic ^= itmp.r;
|
||||
itmp.r=itmp.l;
|
||||
itmp.l=ic;
|
||||
}
|
||||
ic=itmp.r;
|
||||
itmp.r=itmp.l;
|
||||
itmp.l=ic;
|
||||
(*out).r=(*out).l=0L;
|
||||
for (j=32,k=64; j >= 1; j--, k--) {
|
||||
(*out).r = ((*out).r <<= 1) | getbit(itmp,ipm[j],32);
|
||||
(*out).l = ((*out).l <<= 1) | getbit(itmp,ipm[k],32);
|
||||
}
|
||||
}
|
||||
unsigned long getbit(immense source, int bitno, int nbits) {
|
||||
if (bitno <= nbits)
|
||||
return bit[bitno] & source.r ? 1L : 0L;
|
||||
else
|
||||
return bit[bitno-nbits] & source.l ? 1L : 0L;
|
||||
}
|
||||
|
||||
void ks(/*immense key, */int n, great * kn) {
|
||||
int i,j,k,l;
|
||||
|
||||
if (n == 1 || n == 2 || n == 9 || n == 16) {
|
||||
icd.r = (icd.r | ((icd.r & 1L) << 28)) >> 1;
|
||||
icd.l = (icd.l | ((icd.l & 1L) << 28)) >> 1;
|
||||
}
|
||||
else
|
||||
for (i=1;i<=2;i++) {
|
||||
icd.r = (icd.r | ((icd.r & 1L) << 28)) >> 1;
|
||||
icd.l = (icd.l | ((icd.l & 1L) << 28)) >> 1;
|
||||
}
|
||||
(*kn).r=(*kn).c=(*kn).l=0;
|
||||
for (j=16,k=32,l=48; j>=1; j--,k--,l--) {
|
||||
(*kn).r=((*kn).r <<= 1) | (unsigned short)
|
||||
getbit(icd,ipc2[j],28);
|
||||
(*kn).c=((*kn).c <<= 1) | (unsigned short)
|
||||
getbit(icd,ipc2[k],28);
|
||||
(*kn).l=((*kn).l <<= 1) | (unsigned short)
|
||||
getbit(icd,ipc2[l],28);
|
||||
}
|
||||
}
|
||||
|
||||
void cyfun(unsigned long ir, great k, unsigned long * iout) {
|
||||
static int iet[49]={0,32,1,2,3,4,5,4,5,6,7,8,9,8,9,
|
||||
10,11,12,13,12,13,14,15,16,17,16,17,18,19,
|
||||
20,21,20,21,22,23,24,25,24,25,26,27,28,29,
|
||||
28,29,30,31,32,1};
|
||||
static int ipp[33]={0,16,7,20,21,29,12,28,17,1,15,
|
||||
23,26,5,18,31,10,2,8,24,14,32,27,3,9,19,13,
|
||||
30,6,22,11,4,25};
|
||||
static char is[16][4][9]={
|
||||
{{0,14,15,10,7,2,12,4,13},{0,0,3,13,13,14,10,13,1},
|
||||
{0,4,0,13,10,4,9,1,7},{0,15,13,1,3,11,4,6, 2}},
|
||||
{{0,4,1,0,13,12,1,11,2},{0,15,13,7,8,11,15,0,15},
|
||||
{0,1,14,6,6,2,14,4,11},{0,12,8,10,15,8,3,11,1}},
|
||||
{{0,13,8,9,14,4,10,2,8},{0,7,4,0,11,2,4,11,13},
|
||||
{0,14,7,4,9,1,15,11,4},{0,8,10,13,0,12,2,13,14}},
|
||||
{{0,1,14,14,3,1,15,14,4},{0,4,7,9,5,12,2,7,8},
|
||||
{0,8,11,9,0,11,5,13,1},{0,2,1,0,6,7,12,8,7}},
|
||||
{{0,2,6,6,0,7,9,15,6},{0,14,15,3,6,4,7,4,10},
|
||||
{0,13,10,8,12,10,2,12,9},{0,4,3,6,10,1,9,1,4}},
|
||||
{{0,15,11,3,6,10,2,0,15},{0,2,2,4,15,7,12,9,3},
|
||||
{0,6,4,15,11,13,8,3,12},{0,9,15,9,1,14,5,4,10}},
|
||||
{{0,11,3,15,9,11,6,8,11},{0,13,8,6,0,13,9,1,7},
|
||||
{0,2,13,3,7,7,12,7,14},{0,1,4,8,13,2,15,10,8}},
|
||||
{{0,8,4,5,10,6,8,13,1},{0,1,14,10,3,1,5,10,4},
|
||||
{0,11,1,0,13,8,3,14,2},{0,7,2,7,8,13,10,7,13}},
|
||||
{{0,3,9,1,1,8,0,3,10},{0,10,12,2,4,5,6,14,12},
|
||||
{0,15,5,11,15,15,7,10,0},{0,5,11,4,9,6,11,9,15}},
|
||||
{{0,10,7,13,2,5,13,12,9},{0,6,0,8,7,0,1,3,5},
|
||||
{0,12,8,1,1,9,0,15,6},{0,11,6,15,4,15,14,5,12}},
|
||||
{{0,6,2,12,8,3,3,9,3},{0,12,1,5,2,15,13,5,6},
|
||||
{0,9,12,2,3,12,4,6,10},{0,3,7,14,5,0,1,0,9}},
|
||||
{{0,12,13,7,5,15,4,7,14},{0,11,10,14,12,10,14,12,11},
|
||||
{0,7,6,12,14,5,10,8,13},{0,14,12,3,11,9,7,15,0}},
|
||||
{{0,5,12,11,11,13,14,5,5},{0,9,6,12,1,3,0,2,0},
|
||||
{0,3,9,5,5,6,1,0,15},{0,10,0,11,12,10,6,14,3}},
|
||||
{{0,9,0,4,12,0,7,10,0},{0,5,9,11,10,9,11,15,14},
|
||||
{0,10,3,10,2,3,13,5,3},{0,0,5,5,7,4,0,2,5}},
|
||||
{{0,0,5,2,4,14,5,6,12},{0,3,11,15,14,8,3,8,9},
|
||||
{0,5,2,14,8,0,11,9,5},{0,6,14,2,2,5,8,3,6}},
|
||||
{{0,7,10,8,15,9,11,1,7},{0,8,5,1,9,6,8,6,2},
|
||||
{0,0,15,7,4,14,6,2,8},{0,13,9,12,14,3,13,12,11}}};
|
||||
static char ibin[16]={0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15};
|
||||
great ie;
|
||||
unsigned long itmp,ietmp1,ietmp2;
|
||||
char iec[9];
|
||||
int jj,irow,icol,iss,j,l,m;
|
||||
unsigned long *p;
|
||||
|
||||
p = bit;
|
||||
ie.r=ie.c=ie.l=0;
|
||||
for (j=16,l=32,m=48;j>=1;j--,l--,m--) {
|
||||
ie.r = (ie.r <<=1) | (p[iet[j]] & ir ? 1 : 0);
|
||||
ie.c = (ie.c <<=1) | (p[iet[l]] & ir ? 1 : 0);
|
||||
ie.l = (ie.l <<=1) | (p[iet[m]] & ir ? 1 : 0);
|
||||
}
|
||||
ie.r ^= k.r;
|
||||
ie.c ^= k.c;
|
||||
ie.l ^= k.l;
|
||||
ietmp1=((unsigned long) ie.c << 16)+(unsigned long) ie.r;
|
||||
ietmp2=((unsigned long) ie.l << 8)+((unsigned long) ie.c >> 8);
|
||||
for (j=1,m=5;j<=4;j++,m++) {
|
||||
iec[j]=ietmp1 & 0x3fL;
|
||||
iec[m]=ietmp2 & 0x3fL;
|
||||
ietmp1 >>= 6;
|
||||
ietmp2 >>= 6;
|
||||
}
|
||||
itmp=0L;
|
||||
for (jj=8;jj>=1;jj--) {
|
||||
j =iec[jj];
|
||||
irow=((j & 0x1) << 1)+((j & 0x20) >> 5);
|
||||
icol=((j & 0x2) << 2)+(j & 0x4)
|
||||
+((j & 0x8) >> 2)+((j & 0x10) >> 4);
|
||||
iss=is[icol][irow][jj];
|
||||
itmp = (itmp <<= 4) | ibin[iss];
|
||||
}
|
||||
*iout=0L;
|
||||
p = bit;
|
||||
for (j=32;j>=1;j--)
|
||||
*iout = (*iout <<= 1) | (p[ipp[j]] & itmp ? 1 : 0);
|
||||
}
|
||||
#ifdef WORSTCASE
|
||||
int value = 1;
|
||||
#else
|
||||
int value = 0;
|
||||
#endif
|
||||
|
||||
int main(void)
|
||||
{
|
||||
immense inp, key, out;
|
||||
int newkey, isw;
|
||||
|
||||
inp.l = KNOWN_VALUE * 35;
|
||||
inp.r = KNOWN_VALUE * 26;
|
||||
key.l = KNOWN_VALUE * 2;
|
||||
key.r = KNOWN_VALUE * 16;
|
||||
|
||||
newkey = value;
|
||||
isw = value;
|
||||
|
||||
des(inp, key, &newkey, isw, &out);
|
||||
/* printf("%u %u\n", out.l, out.r);*/
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,46 +0,0 @@
|
|||
/* MDH WCET BENCHMARK SUITE. */
|
||||
|
||||
/* Changes:
|
||||
* JG 2005/12/08: Prototypes added, and changed exit to return in main.
|
||||
*/
|
||||
|
||||
typedef unsigned char bool;
|
||||
typedef unsigned int uint;
|
||||
|
||||
bool divides (uint n, uint m);
|
||||
bool even (uint n);
|
||||
bool prime (uint n);
|
||||
void swap (uint* a, uint* b);
|
||||
|
||||
bool divides (uint n, uint m) {
|
||||
return (m % n == 0);
|
||||
}
|
||||
|
||||
bool even (uint n) {
|
||||
return (divides (2, n));
|
||||
}
|
||||
|
||||
bool prime (uint n) {
|
||||
uint i;
|
||||
if (even (n))
|
||||
return (n == 2);
|
||||
for (i = 3; i * i <= n; i += 2) {
|
||||
if (divides (i, n)) /* ai: loop here min 0 max 357 end; */
|
||||
return 0;
|
||||
}
|
||||
return (n > 1);
|
||||
}
|
||||
|
||||
void swap (uint* a, uint* b) {
|
||||
uint tmp = *a;
|
||||
*a = *b;
|
||||
*b = tmp;
|
||||
}
|
||||
|
||||
int main () {
|
||||
uint x = 21649;
|
||||
uint y = 513239;
|
||||
swap (&x, &y);
|
||||
return (!(prime(x) && prime(y)));
|
||||
}
|
||||
|
|
@ -1,118 +0,0 @@
|
|||
/*************************************************************************/
|
||||
/* */
|
||||
/* SNU-RT Benchmark Suite for Worst Case Timing Analysis */
|
||||
/* ===================================================== */
|
||||
/* Collected and Modified by S.-S. Lim */
|
||||
/* sslim@archi.snu.ac.kr */
|
||||
/* Real-Time Research Group */
|
||||
/* Seoul National University */
|
||||
/* */
|
||||
/* */
|
||||
/* < Features > - restrictions for our experimental environment */
|
||||
/* */
|
||||
/* 1. Completely structured. */
|
||||
/* - There are no unconditional jumps. */
|
||||
/* - There are no exit from loop bodies. */
|
||||
/* (There are no 'break' or 'return' in loop bodies) */
|
||||
/* 2. No 'switch' statements. */
|
||||
/* 3. No 'do..while' statements. */
|
||||
/* 4. Expressions are restricted. */
|
||||
/* - There are no multiple expressions joined by 'or', */
|
||||
/* 'and' operations. */
|
||||
/* 5. No library calls. */
|
||||
/* - All the functions needed are implemented in the */
|
||||
/* source file. */
|
||||
/* */
|
||||
/* */
|
||||
/*************************************************************************/
|
||||
/* */
|
||||
/* FILE: qsort-exam.c */
|
||||
/* SOURCE : Numerical Recipes in C - The Second Edition */
|
||||
/* */
|
||||
/* DESCRIPTION : */
|
||||
/* */
|
||||
/* Non-recursive version of quick sort algorithm. */
|
||||
/* This example sorts 20 floating point numbers, arr[]. */
|
||||
/* */
|
||||
/* REMARK : */
|
||||
/* */
|
||||
/* EXECUTION TIME : */
|
||||
/* */
|
||||
/* */
|
||||
/*************************************************************************/
|
||||
|
||||
|
||||
#define SWAP(a,b) temp=(a);(a)=(b);(b)=temp;
|
||||
#define M 7
|
||||
#define NSTACK 50
|
||||
|
||||
float arr[20] = {
|
||||
5, 4, 10.3, 1.1, 5.7, 100, 231, 111, 49.5, 99,
|
||||
10, 150, 222.22, 101, 77, 44, 35, 20.54, 99.99, 88.88
|
||||
};
|
||||
|
||||
int istack[100];
|
||||
|
||||
void sort(unsigned long n)
|
||||
{
|
||||
unsigned long i,ir=n,j,k,l=1;
|
||||
int jstack=0;
|
||||
int flag;
|
||||
float a,temp;
|
||||
|
||||
flag = 0;
|
||||
for (;;) {
|
||||
if (ir-l < M) {
|
||||
for (j=l+1;j<=ir;j++) {
|
||||
a=arr[j];
|
||||
for (i=j-1;i>=l;i--) {
|
||||
if (arr[i] <= a) break;
|
||||
arr[i+1]=arr[i];
|
||||
}
|
||||
arr[i+1]=a;
|
||||
}
|
||||
if (jstack == 0) break;
|
||||
ir=istack[jstack--];
|
||||
l=istack[jstack--];
|
||||
} else {
|
||||
k=(l+ir) >> 1;
|
||||
SWAP(arr[k],arr[l+1])
|
||||
if (arr[l] > arr[ir]) {
|
||||
SWAP(arr[l],arr[ir])
|
||||
}
|
||||
if (arr[l+1] > arr[ir]) {
|
||||
SWAP(arr[l+1],arr[ir])
|
||||
}
|
||||
if (arr[l] > arr[l+1]) {
|
||||
SWAP(arr[l],arr[l+1])
|
||||
}
|
||||
i=l+1;
|
||||
j=ir;
|
||||
a=arr[l+1];
|
||||
for (;;) {
|
||||
i++; while (arr[i] < a) i++;
|
||||
j--; while (arr[j] > a) j--;
|
||||
if (j < i) break;
|
||||
SWAP(arr[i],arr[j]);
|
||||
}
|
||||
arr[l+1]=arr[j];
|
||||
arr[j]=a;
|
||||
jstack += 2;
|
||||
|
||||
if (ir-i+1 >= j-l) {
|
||||
istack[jstack]=ir;
|
||||
istack[jstack-1]=i;
|
||||
ir=j-1;
|
||||
} else {
|
||||
istack[jstack]=j-1;
|
||||
istack[jstack-1]=l;
|
||||
l=i;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
main()
|
||||
{
|
||||
sort(20);
|
||||
}
|
|
@ -1,111 +0,0 @@
|
|||
/*************************************************************************/
|
||||
/* */
|
||||
/* SNU-RT Benchmark Suite for Worst Case Timing Analysis */
|
||||
/* ===================================================== */
|
||||
/* Collected and Modified by S.-S. Lim */
|
||||
/* sslim@archi.snu.ac.kr */
|
||||
/* Real-Time Research Group */
|
||||
/* Seoul National University */
|
||||
/* */
|
||||
/* */
|
||||
/* < Features > - restrictions for our experimental environment */
|
||||
/* */
|
||||
/* 1. Completely structured. */
|
||||
/* - There are no unconditional jumps. */
|
||||
/* - There are no exit from loop bodies. */
|
||||
/* (There are no 'break' or 'return' in loop bodies) */
|
||||
/* 2. No 'switch' statements. */
|
||||
/* 3. No 'do..while' statements. */
|
||||
/* 4. Expressions are restricted. */
|
||||
/* - There are no multiple expressions joined by 'or', */
|
||||
/* 'and' operations. */
|
||||
/* 5. No library calls. */
|
||||
/* - All the functions needed are implemented in the */
|
||||
/* source file. */
|
||||
/* */
|
||||
/* */
|
||||
/*************************************************************************/
|
||||
/* */
|
||||
/* FILE: select.c */
|
||||
/* SOURCE : Numerical Recipes in C - The Second Edition */
|
||||
/* */
|
||||
/* DESCRIPTION : */
|
||||
/* */
|
||||
/* A function to select the Nth largest number in the floating poi- */
|
||||
/* nt array arr[]. */
|
||||
/* The parameters to function select are k and n. Then the function */
|
||||
/* selects k-th largest number out of n original numbers. */
|
||||
/* */
|
||||
/* REMARK : */
|
||||
/* */
|
||||
/* EXECUTION TIME : */
|
||||
/* */
|
||||
/* */
|
||||
/*************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#define SWAP(a,b) temp=(a);(a)=(b);(b)=temp;
|
||||
|
||||
float arr[20] = {
|
||||
5, 4, 10.3, 1.1, 5.7, 100, 231, 111, 49.5, 99,
|
||||
10, 150, 222.22, 101, 77, 44, 35, 20.54, 99.99, 888.88
|
||||
};
|
||||
|
||||
|
||||
float select(unsigned long k, unsigned long n)
|
||||
{
|
||||
unsigned long i,ir,j,l,mid;
|
||||
float a,temp;
|
||||
int flag, flag2;
|
||||
|
||||
l=1;
|
||||
ir=n;
|
||||
flag = flag2 = 0;
|
||||
while (!flag) {
|
||||
if (ir <= l+1) {
|
||||
if (ir == l+1)
|
||||
if (arr[ir] < arr[l]) {
|
||||
SWAP(arr[l],arr[ir])
|
||||
}
|
||||
flag = 1;
|
||||
} else if (!flag) {
|
||||
mid=(l+ir) >> 1;
|
||||
SWAP(arr[mid],arr[l+1])
|
||||
if (arr[l+1] > arr[ir]) {
|
||||
SWAP(arr[l+1],arr[ir])
|
||||
}
|
||||
if (arr[l] > arr[ir]) {
|
||||
SWAP(arr[l],arr[ir])
|
||||
}
|
||||
if (arr[l+1]> arr[l]) {
|
||||
SWAP(arr[l+1],arr[l])
|
||||
}
|
||||
i=l+1;
|
||||
j=ir;
|
||||
a=arr[l];
|
||||
while (!flag2) {
|
||||
i++;
|
||||
while (arr[i] < a) i++;
|
||||
j--;
|
||||
while (arr[j] > a) j--;
|
||||
if (j < i) flag2 = 1;
|
||||
if (!flag2) SWAP(arr[i],arr[j]);
|
||||
|
||||
}
|
||||
arr[l]=arr[j];
|
||||
arr[j]=a;
|
||||
if (j >= k) ir=j-1;
|
||||
if (j <= k) l=i;
|
||||
}
|
||||
|
||||
}
|
||||
return arr[k];
|
||||
}
|
||||
|
||||
main()
|
||||
{
|
||||
select(10, 20);
|
||||
}
|
File diff suppressed because it is too large
Load diff
|
@ -1,160 +0,0 @@
|
|||
/* MDH WCET BENCHMARK SUITE. File version $Id: ud.c,v 1.4 2005/11/11 10:32:53 ael01 Exp $ */
|
||||
|
||||
|
||||
/*************************************************************************/
|
||||
/* */
|
||||
/* SNU-RT Benchmark Suite for Worst Case Timing Analysis */
|
||||
/* ===================================================== */
|
||||
/* Collected and Modified by S.-S. Lim */
|
||||
/* sslim@archi.snu.ac.kr */
|
||||
/* Real-Time Research Group */
|
||||
/* Seoul National University */
|
||||
/* */
|
||||
/* */
|
||||
/* < Features > - restrictions for our experimental environment */
|
||||
/* */
|
||||
/* 1. Completely structured. */
|
||||
/* - There are no unconditional jumps. */
|
||||
/* - There are no exit from loop bodies. */
|
||||
/* (There are no 'break' or 'return' in loop bodies) */
|
||||
/* 2. No 'switch' statements. */
|
||||
/* 3. No 'do..while' statements. */
|
||||
/* 4. Expressions are restricted. */
|
||||
/* - There are no multiple expressions joined by 'or', */
|
||||
/* 'and' operations. */
|
||||
/* 5. No library calls. */
|
||||
/* - All the functions needed are implemented in the */
|
||||
/* source file. */
|
||||
/* */
|
||||
/* */
|
||||
/*************************************************************************/
|
||||
/* */
|
||||
/* FILE: ludcmp.c */
|
||||
/* SOURCE : Turbo C Programming for Engineering */
|
||||
/* */
|
||||
/* DESCRIPTION : */
|
||||
/* */
|
||||
/* Simultaneous linear equations by LU decomposition. */
|
||||
/* The arrays a[][] and b[] are input and the array x[] is output */
|
||||
/* row vector. */
|
||||
/* The variable n is the number of equations. */
|
||||
/* The input arrays are initialized in function main. */
|
||||
/* */
|
||||
/* */
|
||||
/* REMARK : */
|
||||
/* */
|
||||
/* EXECUTION TIME : */
|
||||
/* */
|
||||
/* */
|
||||
/*************************************************************************/
|
||||
|
||||
/*************************************************************************
|
||||
* This file:
|
||||
*
|
||||
* - Name changed to "ud.c"
|
||||
* - Modified for use with Uppsala/Paderborn tool
|
||||
* : doubles changed to int
|
||||
* : some tests removed
|
||||
* - Program is much more linear, all loops will run to end
|
||||
* - Purpose: test the effect of conditional flows
|
||||
*
|
||||
*************************************************************************/
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
** Benchmark Suite for Real-Time Applications, by Sung-Soo Lim
|
||||
**
|
||||
** III-4. ludcmp.c : Simultaneous Linear Equations by LU Decomposition
|
||||
** (from the book C Programming for EEs by Hyun Soon Ahn)
|
||||
*/
|
||||
|
||||
|
||||
|
||||
long int a[50][50], b[50], x[50];
|
||||
|
||||
int ludcmp(int nmax, int n);
|
||||
|
||||
|
||||
/* static double fabs(double n) */
|
||||
/* { */
|
||||
/* double f; */
|
||||
|
||||
/* if (n >= 0) f = n; */
|
||||
/* else f = -n; */
|
||||
/* return f; */
|
||||
/* } */
|
||||
|
||||
void main()
|
||||
{
|
||||
int i, j, nmax = 50, n = 5, chkerr;
|
||||
long int /* eps, */ w;
|
||||
|
||||
/* eps = 1.0e-6; */
|
||||
|
||||
/* Init loop */
|
||||
for(i = 0; i <= n; i++)
|
||||
{
|
||||
w = 0.0; /* data to fill in cells */
|
||||
for(j = 0; j <= n; j++)
|
||||
{
|
||||
a[i][j] = (i + 1) + (j + 1);
|
||||
if(i == j) /* only once per loop pass */
|
||||
a[i][j] *= 2.0;
|
||||
w += a[i][j];
|
||||
}
|
||||
b[i] = w;
|
||||
}
|
||||
|
||||
/* chkerr = ludcmp(nmax, n, eps); */
|
||||
chkerr = ludcmp(nmax,n);
|
||||
}
|
||||
|
||||
int ludcmp(int nmax, int n)
|
||||
{
|
||||
int i, j, k;
|
||||
long w, y[100];
|
||||
|
||||
/* if(n > 99 || eps <= 0.0) return(999); */
|
||||
for(i = 0; i < n; i++)
|
||||
{
|
||||
/* if(fabs(a[i][i]) <= eps) return(1); */
|
||||
for(j = i+1; j <= n; j++) /* triangular loop vs. i */
|
||||
{
|
||||
w = a[j][i];
|
||||
if(i != 0) /* sub-loop is conditional, done
|
||||
all iterations except first of the
|
||||
OUTER loop */
|
||||
for(k = 0; k < i; k++)
|
||||
w -= a[j][k] * a[k][i];
|
||||
a[j][i] = w / a[i][i];
|
||||
}
|
||||
for(j = i+1; j <= n; j++) /* triangular loop vs. i */
|
||||
{
|
||||
w = a[i+1][j];
|
||||
for(k = 0; k <= i; k++) /* triangular loop vs. i */
|
||||
w -= a[i+1][k] * a[k][j];
|
||||
a[i+1][j] = w;
|
||||
}
|
||||
}
|
||||
y[0] = b[0];
|
||||
for(i = 1; i <= n; i++) /* iterates n times */
|
||||
{
|
||||
w = b[i];
|
||||
for(j = 0; j < i; j++) /* triangular sub loop */
|
||||
w -= a[i][j] * y[j];
|
||||
y[i] = w;
|
||||
}
|
||||
x[n] = y[n] / a[n][n];
|
||||
for(i = n-1; i >= 0; i--) /* iterates n times */
|
||||
{
|
||||
w = y[i];
|
||||
for(j = i+1; j <= n; j++) /* triangular sub loop */
|
||||
w -= a[i][j] * x[j];
|
||||
x[i] = w / a[i][i] ;
|
||||
}
|
||||
return(0);
|
||||
}
|
Loading…
Add table
Reference in a new issue