Release v4.9237 - Ice Coffee :coffee:
[RRG-proxmark3.git] / common / parity.h
bloba768f51fb02403a47e1a6fafc0735d05f8cc3dd1
1 //-----------------------------------------------------------------------------
2 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
3 // at your option, any later version. See the LICENSE.txt file for the text of
4 // the license.
5 //-----------------------------------------------------------------------------
6 // Parity functions
7 //-----------------------------------------------------------------------------
9 // all functions defined in header file by purpose. Allows compiler optimizations.
11 #ifndef __PARITY_H
12 #define __PARITY_H
14 #include "common.h"
16 extern const uint8_t OddByteParity[256];
19 static inline bool oddparity8(const uint8_t x) {
20 return OddByteParity[x];
24 static inline bool evenparity8(const uint8_t x) {
25 return !OddByteParity[x];
29 static inline bool evenparity32(uint32_t x) {
30 #if !defined __GNUC__
31 x ^= x >> 16;
32 x ^= x >> 8;
33 return evenparity8(x);
34 #else
35 return __builtin_parity(x);
36 #endif
40 static inline bool oddparity32(uint32_t x) {
41 #if !defined __GNUC__
42 x ^= x >> 16;
43 x ^= x >> 8;
44 return oddparity8(x);
45 #else
46 return !__builtin_parity(x);
47 #endif
50 #endif /* __PARITY_H */