2015-12-15 09:34:55 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// This code is licensed to you under the terms of the GNU GPL, version 2 or,
|
|
|
|
// at your option, any later version. See the LICENSE.txt file for the text of
|
|
|
|
// the license.
|
|
|
|
//-----------------------------------------------------------------------------
|
2017-07-14 15:51:12 +02:00
|
|
|
// Parity functions
|
2015-12-15 09:34:55 +01:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2019-03-09 08:59:13 +01:00
|
|
|
// all functions defined in header file by purpose. Allows compiler optimizations.
|
2017-07-14 15:51:12 +02:00
|
|
|
|
2015-12-15 09:34:55 +01:00
|
|
|
#ifndef __PARITY_H
|
|
|
|
#define __PARITY_H
|
|
|
|
|
2019-08-08 16:57:33 +02:00
|
|
|
#include "common.h"
|
2015-12-15 09:34:55 +01:00
|
|
|
|
2021-08-21 17:53:54 +02:00
|
|
|
extern const uint8_t g_OddByteParity[256];
|
2015-12-15 09:34:55 +01:00
|
|
|
|
2021-02-23 23:00:29 +01:00
|
|
|
static inline uint8_t oddparity8(const uint8_t x) {
|
2021-08-21 17:53:54 +02:00
|
|
|
return g_OddByteParity[x];
|
2017-07-14 15:51:12 +02:00
|
|
|
}
|
|
|
|
|
2021-02-23 23:00:29 +01:00
|
|
|
static inline uint8_t evenparity8(const uint8_t x) {
|
2021-08-21 17:53:54 +02:00
|
|
|
return !g_OddByteParity[x];
|
2016-01-16 23:05:21 +01:00
|
|
|
}
|
2015-12-15 09:34:55 +01:00
|
|
|
|
2021-07-14 15:01:01 +02:00
|
|
|
static inline uint8_t evenparity16(uint16_t x) {
|
|
|
|
#if !defined __GNUC__
|
|
|
|
x ^= x >> 8;
|
|
|
|
return evenparity8(x);
|
|
|
|
#else
|
|
|
|
return (__builtin_parity(x) & 0xFF);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uint8_t oddparity16(uint16_t x) {
|
|
|
|
#if !defined __GNUC__
|
|
|
|
x ^= x >> 8;
|
|
|
|
return oddparity8(x);
|
|
|
|
#else
|
|
|
|
return !__builtin_parity(x);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2021-02-23 23:00:29 +01:00
|
|
|
static inline uint8_t evenparity32(uint32_t x) {
|
2017-07-14 15:51:12 +02:00
|
|
|
#if !defined __GNUC__
|
2019-03-09 19:19:50 +01:00
|
|
|
x ^= x >> 16;
|
|
|
|
x ^= x >> 8;
|
|
|
|
return evenparity8(x);
|
2017-07-14 15:51:12 +02:00
|
|
|
#else
|
2021-04-17 13:16:39 +02:00
|
|
|
return (__builtin_parity(x) & 0xFF);
|
2017-07-14 15:51:12 +02:00
|
|
|
#endif
|
2015-12-15 09:34:55 +01:00
|
|
|
}
|
|
|
|
|
2021-02-23 23:00:29 +01:00
|
|
|
static inline uint8_t oddparity32(uint32_t x) {
|
2017-07-14 15:51:12 +02:00
|
|
|
#if !defined __GNUC__
|
2019-03-09 19:19:50 +01:00
|
|
|
x ^= x >> 16;
|
|
|
|
x ^= x >> 8;
|
|
|
|
return oddparity8(x);
|
2017-07-14 15:51:12 +02:00
|
|
|
#else
|
2019-03-09 19:19:50 +01:00
|
|
|
return !__builtin_parity(x);
|
2017-07-14 15:51:12 +02:00
|
|
|
#endif
|
2015-12-15 09:34:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __PARITY_H */
|