/* $Id: pnetOps.h,v 1.2 2011/03/14 20:36:04 strauman Exp $ */ #ifndef PNET_OPS_H #define PNET_OPS_H #include #include #include #if defined(__GNUC__) && ( defined(__SSE__) || defined(__ALTIVEC__) ) #define USE_VEC #endif #if defined(__GNUC__) #define inline __inline__ #endif #ifdef __cplusplus extern "C" { #endif #ifdef USE_VEC /* gcc can vectorize simple operations on 16-byte 'vectors' * w/o having to use special CPU-specific inline functions. */ typedef union { epicsUInt32 v __attribute__(( vector_size(16) )); epicsUInt32 u[4]; } PnetPatt; #ifdef __SSE__ typedef float PnetVFlt __attribute__(( vector_size(16) )); #endif #else /* If vectors are unavailable then we can only directly * operate on 64-bit quantities. The compiler breaks this * up into smaller (32-bit) operations if the machine's * word size is smaller. */ typedef union { uint64_t a[2]; epicsUInt32 u[4]; } PnetPatt; #endif #ifdef USE_VEC /* Can use straight C operators :-) */ #define OP2(c,a,b,op) do { (c).v = (a).v op (b).v; } while (0) #define OP1(c,a, op) do { (c).v = (a).v op ; } while (0) #define PO1(c,a, op) do { (c).v = op (a).v ; } while (0) static inline int p_eq(PnetPatt a, PnetPatt b) { #ifdef __ALTIVEC__ return vec_all_eq((vector unsigned int)a.v, (vector unsigned int)b.v); #elif defined(__SSE__) return __builtin_ia32_movmskps((PnetVFlt)__builtin_ia32_cmpeqps((PnetVFlt)a.v, (PnetVFlt)b.v)); #else #error "Unknown/unsupported vector engine!" #endif } #else /* Operate on 64-bit entities */ #define OP2(c,a,b,op) do { \ (c).a[0] = (a).a[0] op (b).a[0]; \ (c).a[1] = (a).a[1] op (b).a[1]; \ } while (0) #define OP1(c,a, op) do { \ (c).a[0] = (a).a[0] op ; \ (c).a[1] = (a).a[1] op ; \ } while (0) #define PO1(c,a, op) do { \ (c).a[0] = op (a).a[0] ; \ (c).a[1] = op (a).a[1] ; \ } while (0) static inline int p_eq(PnetPatt a, PnetPatt b) { return a.a[0] == b.a[0] && a.a[1] == b.a[1]; } #endif /* inclusive OR */ static inline PnetPatt p_or(PnetPatt a, PnetPatt b) { PnetPatt c; OP2(c,a,b,|); return c; } /* exclusive OR */ static inline PnetPatt p_xor(PnetPatt a, PnetPatt b) { PnetPatt c; OP2(c,a,b,^); return c; } /* AND */ static inline PnetPatt p_and(PnetPatt a, PnetPatt b) { PnetPatt c; OP2(c,a,b,&); return c; } /* (bitwise) NOT */ static inline PnetPatt p_not(PnetPatt a) { PnetPatt c; PO1(c,a,~); return c; } /* extract dword */ static inline epicsUInt32 p_ext(PnetPatt a, int i) { return a.u[i]; } /* insert dword */ static inline void p_ins(PnetPatt *a, int i, epicsUInt32 v) { a->u[i] = v; } /* build pattern */ static inline PnetPatt p_cons(epicsUInt32 m0, epicsUInt32 m1, epicsUInt32 m2, epicsUInt32 m3) { PnetPatt c; c.u[0] = m0; c.u[1] = m1; c.u[2] = m2; c.u[3] = m3; return c; } /* sprintf/fprintf for pattern. * * 'fun': function pointer. Either 'fprintf' or 'sprintf'. * 'arg': file/buffer argument to fprintf/sprintf. Of type * FILE * or char *, respectively. Must match chosen * 'fun'. * 'fmt': Format to use for one 32-bit word in pattern. * 'sep': String to print between 32-bit words. * 'pat': PnetPattern to print. * * RETURNS: Number of chars generated. * * NOTES: * - If either 'fun' or 'arg' is NULL then fprintf/stdout are used. * - Defaults for fmt/sep (when NULL) are "%08X" and "", respectively. */ int p_print(void *fun, void *arg, const char *fmt, const char *sep, PnetPatt pat); #ifdef __cplusplus } #endif #endif