refactory parity files a bit

This commit is contained in:
iceman1001 2022-01-09 13:34:54 +01:00
commit 0942ce7a68
8 changed files with 30 additions and 76 deletions

View file

@ -23,20 +23,42 @@
#include "common.h"
extern const uint8_t g_OddByteParity[256];
static const uint8_t g_odd_byte_parity[256] = {
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0,
1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0, 1, 0, 0, 1
};
//extern const uint8_t OddByteParity[256];
#define ODD_PARITY8(x) { g_odd_byte_parity[x] }
#define EVEN_PARITY8(x) { !g_odd_byte_parity[x] }
static inline uint8_t oddparity8(const uint8_t x) {
return g_OddByteParity[x];
return g_odd_byte_parity[x];
}
static inline uint8_t evenparity8(const uint8_t x) {
return !g_OddByteParity[x];
return !g_odd_byte_parity[x];
}
static inline uint8_t evenparity16(uint16_t x) {
#if !defined __GNUC__
x ^= x >> 8;
return evenparity8(x);
return EVEN_PARITY8(x) ;
#else
return (__builtin_parity(x) & 0xFF);
#endif
@ -45,7 +67,7 @@ static inline uint8_t evenparity16(uint16_t x) {
static inline uint8_t oddparity16(uint16_t x) {
#if !defined __GNUC__
x ^= x >> 8;
return oddparity8(x);
return ODD_PARITY8(x);
#else
return !__builtin_parity(x);
#endif
@ -55,7 +77,7 @@ static inline uint8_t evenparity32(uint32_t x) {
#if !defined __GNUC__
x ^= x >> 16;
x ^= x >> 8;
return evenparity8(x);
return EVEN_PARITY8(x);
#else
return (__builtin_parity(x) & 0xFF);
#endif
@ -65,7 +87,7 @@ static inline uint8_t oddparity32(uint32_t x) {
#if !defined __GNUC__
x ^= x >> 16;
x ^= x >> 8;
return oddparity8(x);
return ODD_PARITY8(x);
#else
return !__builtin_parity(x);
#endif