You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
683 B
C

/*
11 years ago
* Copyright 2004, Phil Karn, KA9Q
* May be used under the terms of the GNU Affero General Public License (LGPL)
11 years ago
*/
#ifdef __x86_64__
#define __i386__
#endif
/* Determine parity of argument: 1 = odd, 0 = even */
#ifdef __i386__
static inline uint32_t parityb(uint8_t x){
__asm__ __volatile__ ("test %1,%1;setpo %0" : "=q" (x) : "q" (x));
11 years ago
return x;
}
#else
void partab_init();
static inline uint32_t parityb(uint8_t x){
extern uint8_t Partab[256];
extern uint32_t P_init;
11 years ago
if(!P_init){
partab_init();
}
return Partab[x];
}
#endif
static inline uint32_t parity(int x){
11 years ago
/* Fold down to one byte */
x ^= (x >> 16);
x ^= (x >> 8);
return parityb(x);
}