swar-c99.h 1.61 KB
#ifndef SWAR_C99_COMMON_HEADER_FILE
#define SWAR_C99_COMMON_HEADER_FILE

#ifdef SWAR_USE_UNSIGNED_TYPES
  typedef unsigned int su32x1b __attribute__((subword(1)));
  typedef unsigned int su16x2b __attribute__((subword(2)));
  typedef unsigned int su10x3b __attribute__((subword(3)));
  typedef unsigned int su8x4b  __attribute__((subword(4)));
  typedef unsigned int su4x8b  __attribute__((subword(8)));
  typedef unsigned int su2x16b __attribute__((subword(16)));
#endif /* SWAR_USE_UNSIGNED_TYPES */

#ifdef SWAR_USE_SIGNED_TYPES
  typedef signed int ss32x1b __attribute__((subword(1)));
  typedef signed int ss16x2b __attribute__((subword(2)));
  typedef signed int ss10x3b __attribute__((subword(3)));
  typedef signed int ss8x4b  __attribute__((subword(4)));
  typedef signed int ss4x8b  __attribute__((subword(8)));
  typedef signed int ss2x16b __attribute__((subword(16)));
#endif /* SWAR_USE_SIGNED_TYPES */

// -----------------------------------------------------------------------------
// SWAR - macros
//#define SWAR_SET_ELM(tp,svar,index,value)
      //svar = (svar ) |
      //((value & ((1<<sizeofswar(tp))-1))<<(index*sizeofswar(tp)))

void SWAR_SET_ELM(void *swar, int idx, int val, int bitsz)
{
  *((unsigned int *)swar) = ( (*((unsigned int *)swar)) & ~(((1<<bitsz)-1)<<(bitsz*idx))) | ((val & ((1<<bitsz)-1))<<(bitsz*idx));
}

//#define SWAR_GET_ELM(tp,svar,index)
int SWAR_GET_ELM(void *swar, int idx, int bitsz)
{
  return ((*((unsigned int *)swar) >> (bitsz*idx)) & ((1<<bitsz)-1));
}


//#define SWAR_SET_ARR_ELM(tp,arry,index,value)

//#define SWAR_GET_ARR_ELM(tp,arry,index)


#endif /* SWAR_C99_COMMON_HEADER_FILE */