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
|
|
|
|
|
2017-01-25 00:35:11 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-12-15 09:34:55 +01:00
|
|
|
#include <stdint.h>
|
2017-07-14 15:51:12 +02:00
|
|
|
#include <stdbool.h>
|
2015-12-15 09:34:55 +01:00
|
|
|
|
|
|
|
extern const uint8_t OddByteParity[256];
|
|
|
|
|
2017-07-14 15:51:12 +02:00
|
|
|
|
2019-03-10 11:20:22 +01:00
|
|
|
static inline bool oddparity8(const uint8_t x) {
|
2019-03-09 19:19:50 +01:00
|
|
|
return OddByteParity[x];
|
2017-07-14 15:51:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-03-10 11:20:22 +01:00
|
|
|
static inline bool evenparity8(const uint8_t x) {
|
2019-03-09 19:19:50 +01:00
|
|
|
return !OddByteParity[x];
|
2016-01-16 23:05:21 +01:00
|
|
|
}
|
2015-12-15 09:34:55 +01:00
|
|
|
|
2017-07-14 15:51:12 +02:00
|
|
|
|
2019-03-10 11:20:22 +01:00
|
|
|
static inline bool 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
|
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
|
|
|
}
|
|
|
|
|
2017-07-14 15:51:12 +02:00
|
|
|
|
2019-03-10 11:20:22 +01:00
|
|
|
static inline bool 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
|
|
|
}
|
|
|
|
|
2017-01-25 00:35:11 +01:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
2015-12-15 09:34:55 +01:00
|
|
|
|
|
|
|
#endif /* __PARITY_H */
|