Exemplo n.º 1
0
/*
  The function reads the elements for pulse data from
  the bitstream.
*/
void CPulseData_Read(HANDLE_BIT_BUF bs,     /*!< pointer to bitstream */
                     CPulseData *PulseData) /*!< pointer to pulse data side info */
{
  int i;

  FLC_sub_start("CPulseData_Read");

  FUNC(2); INDIRECT(1); STORE(1); BRANCH(1);
  if ((PulseData->PulseDataPresent = (char) GetBits(bs,1)))
  {
    FUNC(2); INDIRECT(2); STORE(1);
    PulseData->NumberPulse = (char) GetBits(bs,2);

    FUNC(2); INDIRECT(2); STORE(1);
    PulseData->PulseStartBand = (char) GetBits(bs,6);

    PTR_INIT(2); /* PulseData->PulseOffset[i]
                    PulseData->PulseAmp[i]
                 */
    LOOP(1);
    for (i=0; i<=PulseData->NumberPulse; i++)
    {
      FUNC(2); STORE(1);
      PulseData->PulseOffset[i] = (char) GetBits(bs,5);

      FUNC(2); STORE(1);
      PulseData->PulseAmp[i] = (char) GetBits(bs,4);
    }
  }

  FLC_sub_end();
}
Exemplo n.º 2
0
/*
  \brief     crc calculation
*/
static unsigned long
calcCRC (HANDLE_CRC hCrcBuf, unsigned long bValue, int nBits)
{
  int i;
  unsigned long bMask = (1UL << (nBits - 1));

  FLC_sub_start("calcCRC");

  ADD(1); SHIFT(1); /* counting previous operations */

  LOOP(1);
  for (i = 0; i < nBits; i++, bMask >>= 1) {
    unsigned short flag = (hCrcBuf->crcState & hCrcBuf->crcMask) ? 1 : 0;
    unsigned short flag1 = (bMask & bValue) ? 1 : 0;

    INDIRECT(2); ADD(2); LOGIC(2); BRANCH(2); MOVE(2); /* counting previous operations */

    LOGIC(1);
    flag ^= flag1;

    SHIFT(1); STORE(1);
    hCrcBuf->crcState <<= 1;

    BRANCH(1);
    if (flag)
    {
      INDIRECT(1); LOGIC(1); STORE(1);
      hCrcBuf->crcState ^= hCrcBuf->crcPoly;
    }
  }

  FLC_sub_end();

  return (hCrcBuf->crcState);
}
Exemplo n.º 3
0
static NORX_INLINE void norx_decrypt_lastblock(norx_state_t state, uint8_t *out, const uint8_t * in, size_t inlen)
{
    norx_word_t * S = state->S;
    uint8_t b[BYTES(NORX_W)];
    size_t i, j;

    norx_inject_tag(state, PAYLOAD_TAG);
    norx_permutation(state);

    /* Undo padding */
    S[inlen / BYTES(NORX_W)] ^= 0x01ULL << ((inlen % BYTES(NORX_W)) * 8);
    S[WORDS(RATE) - 1]  ^= 0x80ULL << (((BYTES(RATE) - 1) % BYTES(NORX_W)) * 8);

    for(i = 0; inlen >= BYTES(NORX_W); ++i)
    {
        norx_word_t c = LOAD(in);
        STORE(out, S[i] ^ c);
        S[i] = c;

        inlen -= BYTES(NORX_W);
        in    += BYTES(NORX_W);
        out   += BYTES(NORX_W);
    }

    STORE(b, S[i]);
    for(j = 0; j < inlen; ++j)
    {
        uint8_t c = in[j];
        out[j] = b[j] ^ c;
        b[j]   = c;
    }
    S[i] = LOAD(b);
}
Exemplo n.º 4
0
static int blake2s_compress_sse( blake2s_state *S, const byte block[BLAKE2S_BLOCKBYTES] )
{
  __m128i row[4];
  __m128i ff0, ff1;

  const uint32  *m = ( uint32 * )block;

  row[0] = ff0 = LOAD( &S->h[0] );
  row[1] = ff1 = LOAD( &S->h[4] );

  row[2] = blake2s_IV_0_3;
  row[3] = _mm_xor_si128( blake2s_IV_4_7, LOAD( &S->t[0] ) );
  SSE_ROUND( m, row, 0 );
  SSE_ROUND( m, row, 1 );
  SSE_ROUND( m, row, 2 );
  SSE_ROUND( m, row, 3 );
  SSE_ROUND( m, row, 4 );
  SSE_ROUND( m, row, 5 );
  SSE_ROUND( m, row, 6 );
  SSE_ROUND( m, row, 7 );
  SSE_ROUND( m, row, 8 );
  SSE_ROUND( m, row, 9 );
  STORE( &S->h[0], _mm_xor_si128( ff0, _mm_xor_si128( row[0], row[2] ) ) );
  STORE( &S->h[4], _mm_xor_si128( ff1, _mm_xor_si128( row[1], row[3] ) ) );
  return 0;
}
Exemplo n.º 5
0
static MRS_INLINE void mrs_decrypt_lastblock(mrs_state_t state, unsigned char * out, const unsigned char * in, size_t inlen)
{
    size_t i;
    mrs_word_t * S = state->S;
    uint8_t lastblock[BYTES(MRS_R)];
    mrs_permute(state);
    for(i = 0; i < WORDS(MRS_R); ++i)
    {
        STORE(lastblock + i * BYTES(MRS_W), S[i]);
    }

    /* undo padding */
    memcpy(lastblock, in, inlen);
    /*lastblock[inlen] ^= 0x01;
    lastblock[BYTES(MRS_R) - 1] ^= 0x80;*/

    for (i = 0; i < WORDS(MRS_R); ++i)
    {
        const mrs_word_t c = LOAD(lastblock + i * BYTES(MRS_W));
        STORE(lastblock + i * BYTES(MRS_W), S[i] ^ c);
        S[i] = c;
    }
    memcpy(out, lastblock, inlen);

#if defined(MRS_DEBUG)
    printf("DECRYPTING LASTBLOCK:\n");
    print_bytes(lastblock, BYTES(MRS_R));
    printf("STATE:\n");
    print_state(state->S);
#endif

    burn(lastblock, 0, sizeof lastblock);
}
Exemplo n.º 6
0
static NORX_INLINE void norx_decrypt_lastblock(norx_state_t state, uint8_t *out, const uint8_t * in, size_t inlen)
{
    norx_word_t * S = state->S;
    uint8_t lastblock[BYTES(NORX_R)];
    size_t i;

    S[15] ^= PAYLOAD_TAG;
    norx_permute(state);

    for(i = 0; i < WORDS(NORX_R); ++i) {
        STORE(lastblock + i * BYTES(NORX_W), S[i]);
    }

    memcpy(lastblock, in, inlen);
    lastblock[inlen] ^= 0x01;
    lastblock[BYTES(NORX_R) - 1] ^= 0x80;

    for (i = 0; i < WORDS(NORX_R); ++i) {
        const norx_word_t c = LOAD(lastblock + i * BYTES(NORX_W));
        STORE(lastblock + i * BYTES(NORX_W), S[i] ^ c);
        S[i] = c;
    }

    memcpy(out, lastblock, inlen);
    burn(lastblock, 0, sizeof lastblock);
}
Exemplo n.º 7
0
// adds src + v + c and stores it in dst
Value *
arch_adc(cpu_t *cpu, Value *dst, Value *src, Value *v, bool plus_carry, bool plus_one, BasicBlock *bb)
{
	Value *c;
	if (plus_carry)
		c = LOAD(cpu->ptr_C);
	else if (plus_one)
		c = CONST1(1);
	else
		c = CONST1(0);

	if (SIZE(v) == 8) {
		/* calculate intermediate result */
		Value *v1 = ADD(ADD(ZEXT16(LOAD(src)), ZEXT16(v)), ZEXT16(c));

		/* get C */
		STORE(TRUNC1(LSHR(v1, CONST16(8))), cpu->ptr_C);

		/* get result */
		v1 = TRUNC8(v1);

		if (dst)
			STORE(v1, dst);

		return v1;
	} else {
		//XXX TODO use llvm.uadd.with.overflow.*
		//XXX consider using it for 8 bit also, if possible
		printf("TODO: %s() can't do anything but 8 bits yet!\n", __func__);
		exit(1);
	}
}
Exemplo n.º 8
0
SK_STATUS tapp_manifest_pack_put(tapps_info_data* tapp_data, uint8_t* obuffer, uint32_t* obuffer_size)
{
   SK_STATUS err;
   uint32_t byte_cnt, cnt;

   err = SK_ERROR_SUCCESS;

   if ((tapp_data == 0) ||
       (obuffer == 0)   ||
       (obuffer_size == 0))
   {
      return SK_ERROR_INVALID_PARAM;
   }

   byte_cnt      = 0;

   STOREBUF(tapp_data->taid, sizeof(tapp_data->taid));
   STORE(tapp_data->multi_instance);
   STORE(tapp_data->multi_session);
   STORE(tapp_data->max_heap_size);
   STORE(tapp_data->max_stack_size);
   STOREBUF(tapp_data->service_name, sizeof(tapp_data->service_name));
   STOREBUF(tapp_data->vendor_name, sizeof(tapp_data->vendor_name));
   STOREBUF(tapp_data->description, sizeof(tapp_data->description));

   *obuffer_size = byte_cnt;

   return err;
}
Exemplo n.º 9
0
static void twoChannelFiltering( const float *pQmf,
                                 float *mHybrid )
{
  int n;
  float cum0, cum1;

  FLC_sub_start("twoChannelFiltering");

  LOOP(1); PTR_INIT(2);
  MULT(1);
  cum0 = 0.5f * pQmf[HYBRID_FILTER_DELAY];

  MOVE(1);
  cum1 = 0;

  LOOP(1); PTR_INIT(2);
  for(n = 0; n < 6; n++) {

    MAC(1); MULT(1);
    cum1 += p2_6[n] * pQmf[2*n+1];
  }

  ADD(1); STORE(1);
  mHybrid[0] = cum0 + cum1;
  ADD(1); STORE(1);
  mHybrid[1] = cum0 - cum1;

  FLC_sub_end();
}
Exemplo n.º 10
0
int
BCInit(void)
{
  int i;

  COUNT_sub_start("BCInit");

  PTR_INIT(1); /* sideInfoTabLong[] */
  LOOP(1);
  for (i = 0; i <= MAX_SFB_LONG; i++)
  {
    FUNC(2); STORE(1);
    sideInfoTabLong[i] = calcSideInfoBits(i, LONG_WINDOW);
  }

  PTR_INIT(1); /* sideInfoTabShort[] */
  for (i = 0; i <= MAX_SFB_SHORT; i++)
  {
    FUNC(2); STORE(1);
    sideInfoTabShort[i] = calcSideInfoBits(i, SHORT_WINDOW);
  }

  COUNT_sub_end();

  return 0;
}
Exemplo n.º 11
0
static PyObject *update_h(PyObject *self, PyObject *args) {
	int Ncore, Nx, Ny, Nz;
	PyArrayObject *Ex, *Ey, *Ez;
	PyArrayObject *Hx, *Hy, *Hz;

	if (!PyArg_ParseTuple(args, "iiiiOOOOOO",
				&Ncore, &Nx, &Ny, &Nz,
				&Ex, &Ey, &Ez, &Hx, &Hy, &Hz ))
   	{ return NULL; }

	float *ex, *ey, *ez;
	float *hx, *hy, *hz;

	ex = (float*)(Ex->data);
	ey = (float*)(Ey->data);
	ez = (float*)(Ez->data);
	hx = (float*)(Hx->data);
	hy = (float*)(Hy->data);
	hz = (float*)(Hz->data);

	int idx, i;
	int Nyz = Ny*Nz;
	int c1 = (Ny-1)*Nz, c2 = Nyz + Nz;
	v4sf h, e1, e2, e3, e4, e5; 
	v4sf ch = {0.5, 0.5, 0.5, 0.5};

	/*
	omp_set_num_threads( Ncore );
	#pragma omp parallel for \
	shared( Nz, Nyz, c1, c2, ch, Ex, Ey, Ez, Hx, Hy, Hz ) \
   	private( h, e1, e2, e3, e4, idx, i ) \
	schedule( static )
	*/
	for ( idx=0; idx<(Nx-1)*(Ny-1)*Nz; idx+=4 ) {
		i = idx + idx/c1*Nz + c2;

		e1 = LOAD( ex+i );
		e2 = LOAD( ey+i );
		e3 = LOAD( ez+i );

		h  = LOAD( hx+i );
		e4 = LOAD( ez+i-Nz );
		e5 = LOAD( ey+i-1 );
		STORE( hx+i, SUB(h, MUL(ch, SUB( SUB(e3,e4), SUB(e2,e5)))) ); 

		h  = LOAD( hy+i );
		e4 = LOAD( ex+i-1 );
		e5 = LOAD( ez+i-Nyz );
		STORE( hy+i, SUB(h, MUL(ch, SUB( SUB(e1,e4), SUB(e3,e5)))) ); 

		h  = LOAD( hz+i );
		e4 = LOAD( ey+i-Nyz );
		e5 = LOAD( ex+i-Nz );
		STORE( hz+i, SUB(h, MUL(ch, SUB( SUB(e2,e4), SUB(e1,e5)))) ); 
	}
   	Py_INCREF(Py_None);
   	return Py_None;
}
Exemplo n.º 12
0
/* constants that do not change during successive pe calculations */
void prepareSfbPe(PE_CHANNEL_DATA *peChanData,
                  const float *sfbEnergy,
                  const float *sfbThreshold,
                  const float *sfbFormFactor,
                  const int     *sfbOffset,
                  const int     sfbCnt,
                  const int     sfbPerGroup,
                  const int     maxSfbPerGroup)
{
   int sfbGrp,sfb;
   int sfbWidth;
   float avgFormFactor;

   COUNT_sub_start("prepareSfbPe");

   LOOP(1);
   for(sfbGrp = 0;sfbGrp < sfbCnt;sfbGrp+=sfbPerGroup){

    PTR_INIT(6); /* pointers for sfbEnergy[],
                                 sfbThreshold[],
                                 sfbOffset[],
                                 sfbFormFactor[],
                                 peChanData->sfbNLines[],
                                 peChanData->sfbLdEnergy[]
                 */
    LOOP(1);
    for (sfb=0; sfb<maxSfbPerGroup; sfb++) {

      ADD(1); BRANCH(1);
      if (sfbEnergy[sfbGrp+sfb] > sfbThreshold[sfbGrp+sfb]) {

         ADD(1);
         sfbWidth = sfbOffset[sfbGrp+sfb+1] - sfbOffset[sfbGrp+sfb];

         /* estimate number of active lines */
         DIV(1); TRANS(1);
         avgFormFactor = (float) pow(sfbEnergy[sfbGrp+sfb]/(float)sfbWidth, 0.25f);

         DIV(1); STORE(1);
         peChanData->sfbNLines[sfbGrp+sfb] =

         sfbFormFactor[sfbGrp+sfb]/avgFormFactor;

          /* ld(sfbEn) */
         TRANS(1); MULT(1); STORE(1);
         peChanData->sfbLdEnergy[sfbGrp+sfb] = (float) (log(sfbEnergy[sfbGrp+sfb]) * LOG2_1);
      }
      else {

         MOVE(2);
         peChanData->sfbNLines[sfbGrp+sfb] = 0.0f;
         peChanData->sfbLdEnergy[sfbGrp+sfb] = 0.0f;
      }
    }
   }

   COUNT_sub_end();
}
Exemplo n.º 13
0
void *func_update_e( void *args ) {
	struct thread_args *data;
	data = (struct thread_args *)args;

	int idx_start, idx_end;
	int Ny, Nz;
	
	float *ex, *ey, *ez;
	float *hx, *hy, *hz;
	float *cex, *cey, *cez;

	idx_start = data->idx_start;
	idx_end = data->idx_end;
	Ny = data->Ny;
	Nz = data->Nz;
	ex = data->ex;
	ey = data->ey;
	ez = data->ez;
	hx = data->hx;
	hy = data->hy;
	hz = data->hz;

	cex = data->cex;
	cey = data->cey;
	cez = data->cez;

	int idx, i;
	int Nyz = Ny*Nz;
	int c1 = (Ny-1)*Nz, c2 = Nyz + Nz;
	v4sf e, ce, h1, h2, h3, h4, h5; 

	for ( idx=idx_start; idx<idx_end; idx+=4 ) {
		i = idx + idx/c1*Nz + c2;

		h1 = LOAD( hx+i );
		h2 = LOAD( hy+i );
		h3 = LOAD( hz+i );

		e  = LOAD( ex+i );
		ce = LOAD( cex+i );
		h4 = LOAD( hz+i+Nz );
		h5 = LOAD( hy+i+1 );
		STORE( ex+i, ADD(e, MUL(ce, SUB( SUB(h4,h3), SUB(h5,h2)))) ); 

		e  = LOAD( ey+i );
		ce = LOAD( cey+i );
		h4 = LOAD( hx+i+1 );
		h5 = LOAD( hz+i+Nyz );
		STORE( ey+i, ADD(e, MUL(ce, SUB( SUB(h4,h1), SUB(h5,h3)))) ); 

		e  = LOAD( ez+i );
		ce = LOAD( cez+i );
		h4 = LOAD( hy+i+Nyz );
		h5 = LOAD( hx+i+Nz );
		STORE( ez+i, ADD(e, MUL(ce, SUB( SUB(h4,h2), SUB(h5,h1)))) ); 
	}
}
Exemplo n.º 14
0
int Encrypt(unsigned char *out, u64 nonce[], u256 rk[], u64 key[], int numbytes)
{
  u64  x[2],y[2];
  u256 X[5],Y[5];

  if (numbytes==16){
    x[0]=nonce[1]; y[0]=nonce[0]; nonce[0]++;
    Enc(x,y,key,1);
    ((u64 *)out)[1]=x[0]; ((u64 *)out)[0]=y[0];

    return 0;
  }

  if (numbytes==32){
    x[0]=nonce[1]; y[0]=nonce[0]; nonce[0]++;
    x[1]=nonce[1]; y[1]=nonce[0]; nonce[0]++;
    Enc(x,y,key,2);
    ((u64 *)out)[1]=x[0]; ((u64 *)out)[0]=y[0];
    ((u64 *)out)[3]=x[1]; ((u64 *)out)[2]=y[1];

    return 0;
  }

  SET1(X[0],nonce[1]);
  SET4(Y[0],nonce[0]);

  if (numbytes==64) Enc(X,Y,rk,4);
  else{
    X[1]=X[0];
    SET4(Y[1],nonce[0]);
    if (numbytes==128) Enc(X,Y,rk,8);
    else{
      X[2]=X[0];
      SET4(Y[2],nonce[0]);
      if (numbytes==192) Enc(X,Y,rk,12);
      else{
	X[3]=X[0];
	SET4(Y[3],nonce[0]);
	if (numbytes==256) Enc(X,Y,rk,16);
	else{
	  X[4]=X[0];
	  SET4(Y[4],nonce[0]);
	  Enc(X,Y,rk,20);
	}
      }
    }
  }

  STORE(out,X[0],Y[0]);
  if (numbytes>=128) STORE(out+64,X[1],Y[1]);
  if (numbytes>=192) STORE(out+128,X[2],Y[2]);
  if (numbytes>=256) STORE(out+192,X[3],Y[3]);
  if (numbytes>=320) STORE(out+256,X[4],Y[4]);

  return 0;
}
Exemplo n.º 15
0
void CalcBandEnergyMS(const float *mdctSpectrumLeft,
                      const float *mdctSpectrumRight,
                      const int   *bandOffset,
                      const int    numBands,
                      float      *bandEnergyMid,
                      float       *bandEnergyMidSum,
                      float      *bandEnergySide,
                      float       *bandEnergySideSum) {

    int i, j;

    COUNT_sub_start("CalcBandEnergyMS");

    MOVE(3);
    j = 0;
    *bandEnergyMidSum = 0.0f;
    *bandEnergySideSum = 0.0f;

    PTR_INIT(5); /* pointers for bandEnergyMid[],
                               bandEnergySide[],
                               bandOffset[],
                               mdctSpectrumLeft[],
                               mdctSpectrumRight[]
               */
    LOOP(1);
    for(i=0; i<numBands; i++) {

        MOVE(2);
        bandEnergyMid[i] = 0.0f;
        bandEnergySide[i] = 0.0f;

        LOOP(1);
        while (j < bandOffset[i+1]) {
            float specm, specs;

            ADD(2);
            MULT(2);
            specm = 0.5f * (mdctSpectrumLeft[j] + mdctSpectrumRight[j]);
            specs = 0.5f * (mdctSpectrumLeft[j] - mdctSpectrumRight[j]);

            MAC(2);
            STORE(2);
            bandEnergyMid[i]  += specm * specm;
            bandEnergySide[i] += specs * specs;

            j++;
        }
        ADD(2);
        STORE(2);
        *bandEnergyMidSum += bandEnergyMid[i];
        *bandEnergySideSum += bandEnergySide[i];

    }

    COUNT_sub_end();
}
Exemplo n.º 16
0
/* Read a lisp object.  This is the main interface to the reader. */
sexpr *readobj(IC *ic) {
  reader *r = ic->r;
  char *token;

  /* These are used by strtod().  Number is the return value, and
     unparsed is set to the portion of the string not parsed.
     If it is not pointing at the terminating '\0' when we are done, then
     we failed to get a number. */
  double number;
  char *unparsed;

  token = gettoken(r);
  if(token == NULL) return ic->eof;
  if(!strcmp(token, "(")) return readlist(ic);
  if(!strcmp(token, "\'") ||
     !strcmp(token, "`") ||
     !strcmp(token, ",") ||
     !strcmp(token, ",@")) {
      /* We are going to read the following object, and then wrap it in
         a call to something.  Figure out what that something is. */
      sexpr *quoter = NULL;
      protect_ptr(ic->g, (void **)&quoter);
      if(!strcmp(token, "\'"))
          STORE(ic->g, NULL, quoter, ic->n_quote);
      else if(!strcmp(token, "`"))
          STORE(ic->g, NULL, quoter, ic->n_quasiquote);
      else if(!strcmp(token, ","))
          STORE(ic->g, NULL, quoter, ic->n_unquote);
      else if(!strcmp(token, ",@"))
          STORE(ic->g, NULL, quoter, ic->n_unquote_splicing);
      else {
          fprintf(stderr,
                  "Fatal error in lisp reader - this should never happen!\n");
          longjmp(ic->quit, 1);
      }
    
    sexpr *obj = readobj(ic);
    protect_ptr(ic->g, (void **)&obj);
    sexpr *ret = listl(ic, quoter, obj, NULL);
    unprotect_ptr(ic->g);
    unprotect_ptr(ic->g);
    return ret;
  }


  /* Check to see if it's a valid number. */
  if(strcasecmp(token, "inf") &&
     strcasecmp(token, "infinity") &&
     strcasecmp(token, "nan")) {
    number = strtod(token, &unparsed);
    if(unparsed != token && *unparsed == '\0')
      return mk_number(ic, number);
  }

  return intern(ic, token);
}
Exemplo n.º 17
0
static inline int blake2s_compress( blake2s_state *S, const uint8_t block[BLAKE2S_BLOCKBYTES] )
{
  __m128i row1, row2, row3, row4;
  __m128i buf1, buf2, buf3, buf4;
#if defined(HAVE_SSE41)
  __m128i t0, t1;
#if !defined(HAVE_XOP)
  __m128i t2;
#endif
#endif
  __m128i ff0, ff1;
#if defined(HAVE_SSSE3) && !defined(HAVE_XOP)
  const __m128i r8 = _mm_set_epi8( 12, 15, 14, 13, 8, 11, 10, 9, 4, 7, 6, 5, 0, 3, 2, 1 );
  const __m128i r16 = _mm_set_epi8( 13, 12, 15, 14, 9, 8, 11, 10, 5, 4, 7, 6, 1, 0, 3, 2 );
#endif
#if defined(HAVE_SSE41)
  const __m128i m0 = LOADU( block +  00 );
  const __m128i m1 = LOADU( block +  16 );
  const __m128i m2 = LOADU( block +  32 );
  const __m128i m3 = LOADU( block +  48 );
#else
  const uint32_t  m0 = ( ( uint32_t * )block )[ 0];
  const uint32_t  m1 = ( ( uint32_t * )block )[ 1];
  const uint32_t  m2 = ( ( uint32_t * )block )[ 2];
  const uint32_t  m3 = ( ( uint32_t * )block )[ 3];
  const uint32_t  m4 = ( ( uint32_t * )block )[ 4];
  const uint32_t  m5 = ( ( uint32_t * )block )[ 5];
  const uint32_t  m6 = ( ( uint32_t * )block )[ 6];
  const uint32_t  m7 = ( ( uint32_t * )block )[ 7];
  const uint32_t  m8 = ( ( uint32_t * )block )[ 8];
  const uint32_t  m9 = ( ( uint32_t * )block )[ 9];
  const uint32_t m10 = ( ( uint32_t * )block )[10];
  const uint32_t m11 = ( ( uint32_t * )block )[11];
  const uint32_t m12 = ( ( uint32_t * )block )[12];
  const uint32_t m13 = ( ( uint32_t * )block )[13];
  const uint32_t m14 = ( ( uint32_t * )block )[14];
  const uint32_t m15 = ( ( uint32_t * )block )[15];
#endif
  row1 = ff0 = LOAD( &S->h[0] );
  row2 = ff1 = LOAD( &S->h[4] );
  row3 = _mm_setr_epi32( 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A );
  row4 = _mm_xor_si128( _mm_setr_epi32( 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19 ), LOAD( &S->t[0] ) );
  ROUND( 0 );
  ROUND( 1 );
  ROUND( 2 );
  ROUND( 3 );
  ROUND( 4 );
  ROUND( 5 );
  ROUND( 6 );
  ROUND( 7 );
  ROUND( 8 );
  ROUND( 9 );
  STORE( &S->h[0], _mm_xor_si128( ff0, _mm_xor_si128( row1, row3 ) ) );
  STORE( &S->h[4], _mm_xor_si128( ff1, _mm_xor_si128( row2, row4 ) ) );
  return 0;
}
Exemplo n.º 18
0
// address: 08048328.0
// full-signature: func(test, return=[], parameter=[<int(signed, 4),n,unknown>], varargs=false)
void test(s4 n)
{
  if(n < -2) {
    (void) STORE(&n, -2);
  }
  if(n > 3) {
    (void) STORE(&n, 3);
  }
  (void) printf("MinMax result %d\n", n);
}
Exemplo n.º 19
0
/*
  The function performs the post modulation in the inverse
  transformation.
*/
static void 
postModulation(float *x,              /*!< pointer to spectum */
               int m,                 /*!< number of lines in spectrum */
               const float *trigData, /*!< pointer to trigData */
               int step,              /*!< steps */
               int trigDataSize)      /*!< size of trigData */
{
  int i;
  float wre, wim, re1, re2, im1, im2;
  const float *sinPtr = trigData;
  const float *cosPtr = trigData+trigDataSize;

  COUNT_sub_start("postModulation");

  MOVE(2); /* previous initialization */

  MOVE(2);
  wim = *sinPtr;
  wre = *cosPtr;

  PTR_INIT(2);  /* pointers for x[2*i], x[m-2-2*i] */
  MULT(1); LOOP(1);
  for (i = 0; i < m/4; i++)
  {
    MOVE(4);
    re1=x[2*i];
    im1=x[2*i+1];
    re2=x[m-2-2*i];
    im2=x[m-1-2*i];

    MULT(1); MAC(1); STORE(1);
    x[2*i] = re1*wre + im1*wim;

    MULT(2); ADD(1); STORE(1);
    x[m-1-2*i] = re1*wim - im1*wre;

    ADD(2);
    sinPtr+=step;
    cosPtr-=step;

    MOVE(2);
    wim=*sinPtr;
    wre=*cosPtr;

    MULT(1); MAC(1); STORE(1);   
    x[m-2-2*i] = re2*wim + im2* wre;

    MULT(2); ADD(1); STORE(1);
    x[2*i+1] = re2*wre - im2* wim;
  }

  COUNT_sub_end();
}
Exemplo n.º 20
0
void do_lds(jit_function_t func) {
	jit_value_t ldw = LOAD(LDWhich, jit_type_uint);
	jit_label_t label = jit_label_undefined;
	jit_insn_branch_if(func, jit_insn_eq(func, ldw, make_ubyte(35)), &label);
	jit_value_t raw = LOAD(_ReadAbsorbWhich, jit_type_ubyte);
	WGPR_VAL(ldw, LOAD(LDValue, jit_type_uint));
	WRA(ldw, CAST(LOAD(LDAbsorb, jit_type_uint), jit_type_ubyte));
	STORE(_ReadFudge, CAST(ldw, jit_type_ubyte));
	STORE(_ReadAbsorbWhich, CAST(jit_insn_or(func, raw, jit_insn_and(func, ldw, make_uint(0x1F))), jit_type_ubyte));
	jit_insn_label(func, &label);
	STORE(LDWhich, make_uint(35));
}
Exemplo n.º 21
0
static void
gmStage1(SECTION_INFO * section,
         int bitLookUp[MAX_SFB_LONG][CODE_BOOK_ESC_NDX + 1],
         const int maxSfb,
         const int *sideInfoTab)
{
  int mergeStart = 0, mergeEnd;

  COUNT_sub_start("gmStage1");

  MOVE(1); /* counting previous operations */

  LOOP(1);
  do
  {

    PTR_INIT(4); /* pointers for section[mergeStart]
                                 section[mergeEnd]
                                 bitLookUp[mergeStart]
                                 bitLookUp[mergeEnd]
                 */
    ADD(1); LOOP(1);
    for (mergeEnd = mergeStart + 1; mergeEnd < maxSfb; mergeEnd++)
    {
      ADD(1); BRANCH(1);
      if (section[mergeStart].codeBook != section[mergeEnd].codeBook)
        break;

      ADD(1); STORE(1);
      section[mergeStart].sfbCnt++;

      ADD(1); STORE(1);
      section[mergeStart].sectionBits += section[mergeEnd].sectionBits;

      FUNC(2);
      mergeBitLookUp(bitLookUp[mergeStart], bitLookUp[mergeEnd]);
    }

    INDIRECT(1); ADD(1); STORE(1);
    section[mergeStart].sectionBits += sideInfoTab[section[mergeStart].sfbCnt];

    MOVE(1);
    section[mergeEnd - 1].sfbStart = section[mergeStart].sfbStart;

    MOVE(1);
    mergeStart = mergeEnd;

  } while (mergeStart < maxSfb);

  COUNT_sub_end();
}
Exemplo n.º 22
0
/*
 *
 * \brief Create QMF filter bank instance
 *
 * \return 0 if succesful
 *
 */
int
createCplxAnalysisQmfBank (HANDLE_SBR_QMF_FILTER_BANK h_sbrQmf,
                           int noCols,
                           int lsb,
                           int usb,
                           int chan)
{
  int L;

  COUNT_sub_start("createCplxAnalysisQmfBank");


  FUNC(2); LOOP(1); PTR_INIT(1); MOVE(1); STORE(sizeof(SBR_QMF_FILTER_BANK));
  memset(h_sbrQmf,0,sizeof(SBR_QMF_FILTER_BANK));


  MOVE(1);
  L = NO_ANALYSIS_CHANNELS;

  PTR_INIT(2);
  h_sbrQmf->p_filter = sbr_qmf_64_640;
  h_sbrQmf->pDct4Twiddle = dct4TwiddleTable;

#ifndef LP_SBR_ONLY
  PTR_INIT(5);
  h_sbrQmf->cos_twiddle = sbr_cos_twiddle_L32;
  h_sbrQmf->sin_twiddle = sbr_sin_twiddle_L32;
  h_sbrQmf->alt_sin_twiddle = sbr_alt_sin_twiddle_L32;
  h_sbrQmf->t_cos = sbr_t_cos_L32;
  h_sbrQmf->t_sin = sbr_t_sin_L32;
#endif

  MOVE(4);
  h_sbrQmf->no_channels = L;
  h_sbrQmf->no_col = noCols;
  h_sbrQmf->lsb = lsb;
  h_sbrQmf->usb = usb;

  PTR_INIT(1);
  h_sbrQmf->FilterStatesAna   = &(sbr_CodecQmfStatesAnalysis[chan*QMF_FILTER_STATE_ANA_SIZE]);

  FUNC(2); LOOP(1); PTR_INIT(1); MOVE(1); STORE(QMF_FILTER_STATE_ANA_SIZE);
  memset(h_sbrQmf->FilterStatesAna,0,QMF_FILTER_STATE_ANA_SIZE*sizeof(float));

  COUNT_sub_end();

  return (0);

}
Exemplo n.º 23
0
/*---------------------------------------------------------------------------*/
int testDegenerateTriangle(trian t){

	double v1[3],v2[3],v3[3],s1[3],s2[3],pv[3];
	
	STORE(v1,t.v0);
	STORE(v2,t.v1);
	STORE(v3,t.v2);
	SUB(s1,v2,v1);
	SUB(s2,v3,v1);
	CROSS(pv,s1,s2);
	if((SIGNO(pv[0] == LIM)) &&(SIGNO(pv[1] == LIM)) &&(SIGNO(pv[2] == LIM)))
	    return 0;
   return 1;
	
}
Exemplo n.º 24
0
/*
 *
 * \brief Perform complex-valued forward modulation of the time domain
 *        data of timeIn and stores the real part of the subband
 *        samples in rSubband, and the imaginary part in iSubband
 *
 */
static void
sbrForwardModulation (const float *timeIn,
                      float *rSubband,
                      float *iSubband,
                      HANDLE_SBR_QMF_FILTER_BANK anaQmf
                      )
{
  int i, offset;

  float real, imag;

  COUNT_sub_start("sbrForwardModulation");

  MOVE(1);
  offset = 2 * NO_ANALYSIS_CHANNELS;

  PTR_INIT(1);  /* pointer for timeIn[offset - 1 - i] */
  LOOP(1);
  for (i = 0; i < NO_ANALYSIS_CHANNELS; i++) {
    ADD(2); STORE(2);
    rSubband[i] = timeIn[i] - timeIn[offset - 1 - i];
    iSubband[i] = timeIn[i] + timeIn[offset - 1 - i];
  }

  FUNC(2);
  cosMod (rSubband, anaQmf);
  FUNC(2);
  sinMod (iSubband, anaQmf);

  PTR_INIT(4);  /* pointers for rSubband[i],
                                iSubband[i],
                                anaQmf->t_cos[i],
                                anaQmf->t_sin[i]  */
  INDIRECT(1); LOOP(1);
  for (i = 0; i < anaQmf->lsb; i++) {

    MOVE(2);
    real = rSubband[i];
    imag = iSubband[i];

    MULT(1); MAC(1); STORE(1);
    rSubband[i] = real * anaQmf->t_cos[i] + imag * anaQmf->t_sin[i];
    MULT(2); ADD(1); STORE(1);
    iSubband[i] = imag * anaQmf->t_cos[i] - real * anaQmf->t_sin[i];
  }

  COUNT_sub_end();
}
Exemplo n.º 25
0
static void
gmStage0(SECTION_INFO * section,
         int bitLookUp[MAX_SFB_LONG][CODE_BOOK_ESC_NDX + 1],
         const int maxSfb)
{
  int i;

  COUNT_sub_start("gmStage0");

  PTR_INIT(2); /* pointers for section[],
                               bitLookUp[]
               */
  LOOP(1);
  for (i = 0; i < maxSfb; i++)
  {
    ADD(1); BRANCH(1);
    if (section[i].sectionBits == INVALID_BITCOUNT)
    {
      PTR_INIT(1); FUNC(2); STORE(1);
      section[i].sectionBits = findBestBook(bitLookUp[i], &(section[i].codeBook));

    }
  }

  COUNT_sub_end();
}
Exemplo n.º 26
0
/*!
 
  \brief  calc attenuation parameters - this has to take place after
          the 'QCMain' call because PeSum of the merged l/r-m/s signal
          is relevant
 
  \return nothing
 
****************************************************************************/
void UpdateStereoPreProcess(PSY_OUT_CHANNEL psyOutChannel[MAX_CHANNELS],
                            QC_OUT_ELEMENT* qcOutElement,   /*! provides access to PE */
                            HANDLE_STEREO_PREPRO hStPrePro,
                            float weightPeFac               /*! ratio of ms PE vs. lr PE */
                            )
{
  COUNT_sub_start("UpdateStereoPreProcess");

  INDIRECT(1); BRANCH(1);
  if (hStPrePro->stereoAttenuationFlag)
  { 
    float DELTA = 0.1f;

    INDIRECT(4); MOVE(4);
    hStPrePro->avrgFreqEnergyL = psyOutChannel[0].sfbEnSumLR;
    hStPrePro->avrgFreqEnergyR = psyOutChannel[1].sfbEnSumLR;
    hStPrePro->avrgFreqEnergyM = psyOutChannel[0].sfbEnSumMS;
    hStPrePro->avrgFreqEnergyS = psyOutChannel[1].sfbEnSumMS;


    INDIRECT(3); MULT(1); MAC(1); STORE(1);
    hStPrePro->smoothedPeSumSum = 
      DELTA * qcOutElement->pe * weightPeFac + (1 - DELTA) * hStPrePro->smoothedPeSumSum;


  }

  COUNT_sub_end();
}
Exemplo n.º 27
0
/* loudness calculation (threshold to the power of redExp) */
static void calcThreshExp(float thrExp[MAX_CHANNELS][MAX_GROUPED_SFB],
                          PSY_OUT_CHANNEL  psyOutChannel[MAX_CHANNELS],
                          const int nChannels)
{
   int ch, sfb,sfbGrp;

   COUNT_sub_start("calcThreshExp");

   LOOP(1);
   for (ch=0; ch<nChannels; ch++) {
    PSY_OUT_CHANNEL *psyOutChan = &psyOutChannel[ch];

    PTR_INIT(1); /* counting operation above */

    INDIRECT(2); LOOP(1);
    for(sfbGrp = 0;sfbGrp < psyOutChan->sfbCnt;sfbGrp+= psyOutChan->sfbPerGroup) {

      PTR_INIT(2); /* pointer for thrExp[][],
                                  psyOutChan->sfbThreshold[]
                   */
      INDIRECT(1); LOOP(1);
      for (sfb=0; sfb<psyOutChan->maxSfbPerGroup; sfb++) {

        TRANS(1); STORE(1);
        thrExp[ch][sfbGrp+sfb] = (float) pow(psyOutChan->sfbThreshold[sfbGrp+sfb], redExp);
      }
    }
   }

   COUNT_sub_end();
}
Exemplo n.º 28
0
void mrs_finalise(mrs_state_t state, size_t hlen, size_t mlen, unsigned char * tag)
{
    mrs_word_t * S = state->S;
    uint8_t lastblock[BYTES(MRS_R)];
    size_t i;

    /* finalise state */
    mrs_permute(state);

    S[0] ^= hlen;
    S[1] ^= mlen;

    mrs_permute(state);

    /* extract tag */
    for (i = 0; i < WORDS(MRS_R); ++i)
    {
        STORE(lastblock + i * BYTES(MRS_W), S[i]);
    }
    memcpy(tag, lastblock, BYTES(MRS_T));

#if defined(MRS_DEBUG)
    printf("FINALISED:\n");
    print_state(state->S);
#endif

    burn(lastblock, 0, BYTES(MRS_R));
}
Exemplo n.º 29
0
//Unpacking
void unpack_and_store_message(unsigned char *out, u256 x[32]) {
  int i;

  //Group the rows for efficient MixColumns implementation
  for(i = 0; i < 8; i++) {
    SWAPMOVE(x[i + 8], x[i + 0], MASK32, 32);
    SWAPMOVE(x[i + 24], x[i + 16], MASK32, 32);
    
    SWAPMOVEBY64(x[i + 16], x[i + 0], MASK64);
    SWAPMOVEBY64(x[i + 24], x[i + 8], MASK64);    
  }

  //Seperate bits for S-box
  for(i = 0; i < 4; i++) {
    SWAPMOVE(x[8*i + 0], x[8*i + 1], MASK1, 1);
    SWAPMOVE(x[8*i + 2], x[8*i + 3], MASK1, 1);
    SWAPMOVE(x[8*i + 4], x[8*i + 5], MASK1, 1);
    SWAPMOVE(x[8*i + 6], x[8*i + 7], MASK1, 1);

    SWAPMOVE(x[8*i + 0], x[8*i + 2], MASK2, 2);
    SWAPMOVE(x[8*i + 1], x[8*i + 3], MASK2, 2);
    SWAPMOVE(x[8*i + 4], x[8*i + 6], MASK2, 2);
    SWAPMOVE(x[8*i + 5], x[8*i + 7], MASK2, 2);

    SWAPMOVE(x[8*i + 0], x[8*i + 4], MASK4, 4);
    SWAPMOVE(x[8*i + 1], x[8*i + 5], MASK4, 4);
    SWAPMOVE(x[8*i + 2], x[8*i + 6], MASK4, 4);
    SWAPMOVE(x[8*i + 3], x[8*i + 7], MASK4, 4);    
  }  

  for(i = 0; i < 32; i++) {
    STORE(out + 32*i, x[i]);
  }
}
Exemplo n.º 30
0
static void calcPeCorrection(float *correctionFac,
                             const float peAct,
                             const float peLast, 
                             const int bitsLast) 
{
  COUNT_sub_start("calcPeCorrection");

  ADD(4); FUNC(1); FUNC(1); MULT(4); LOGIC(4); BRANCH(1);
  if ((bitsLast > 0) && (peAct < (float)1.5f*peLast) && (peAct > (float)0.7f*peLast) &&
      ((float)1.2f*bits2pe((float)bitsLast) > peLast) && 
      ((float)0.65f*bits2pe((float)bitsLast) < peLast))
  {
    float newFac = peLast / bits2pe((float)bitsLast);

    FUNC(1); DIV(1); /* counting previous operation */

    /* dead zone */
    ADD(1); BRANCH(1);
    if (newFac < (float)1.0f) {

      MULT(1); ADD(1); BRANCH(1); MOVE(1);
      newFac = min((float)1.1f*newFac, (float)1.0f);

      ADD(1); BRANCH(1); MOVE(1);
      newFac = max(newFac, (float)0.85f);
    }
    else {
      MULT(1); ADD(1); BRANCH(1); MOVE(1);
      newFac = max((float)0.9f*newFac, (float)1.0f);

      ADD(1); BRANCH(1); MOVE(1);
      newFac = min(newFac, (float)1.15f);
    }
    ADD(4); LOGIC(3); BRANCH(1);
    if (((newFac > (float)1.0f) && (*correctionFac < (float)1.0f)) ||
        ((newFac < (float)1.0f) && (*correctionFac > (float)1.0f))) {

      MOVE(1);
      *correctionFac = (float)1.0f;
    }

    /* faster adaptation towards 1.0, slower in the other direction */
    ADD(3); LOGIC(3); BRANCH(1); /* if() */ MULT(1); MAC(1); STORE(1);
    if ((*correctionFac < (float)1.0f && newFac < *correctionFac) ||
        (*correctionFac > (float)1.0f && newFac > *correctionFac))
      *correctionFac = (float)0.85f * (*correctionFac) + (float)0.15f * newFac;
    else
      *correctionFac = (float)0.7f * (*correctionFac) + (float)0.3f * newFac;

    ADD(2); BRANCH(2); MOVE(2);
    *correctionFac = min(*correctionFac, (float)1.15f);
    *correctionFac = max(*correctionFac, (float)0.85f);
  }
  else {
    MOVE(1);
    *correctionFac = (float)1.0f;
  }

  COUNT_sub_end();
}