text
[RRG-proxmark3.git] / common / parity.h
blob3b829bdb4616de500fbc97b4ece1af4a4c7e2279
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];
18 static inline uint8_t oddparity8(const uint8_t x) {
19 return OddByteParity[x];
22 static inline uint8_t evenparity8(const uint8_t x) {
23 return !OddByteParity[x];
26 static inline uint8_t evenparity32(uint32_t x) {
27 #if !defined __GNUC__
28 x ^= x >> 16;
29 x ^= x >> 8;
30 return evenparity8(x);
31 #else
32 return (__builtin_parity(x) & 0xFF);
33 #endif
36 static inline uint8_t oddparity32(uint32_t x) {
37 #if !defined __GNUC__
38 x ^= x >> 16;
39 x ^= x >> 8;
40 return oddparity8(x);
41 #else
42 return !__builtin_parity(x);
43 #endif
46 #endif /* __PARITY_H */