]> git.zerfleddert.de Git - proxmark3-svn/blame - common/parity.h
Fix detection of AVX512 support for Apple clang compiler
[proxmark3-svn] / common / parity.h
CommitLineData
1f065e1d 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//-----------------------------------------------------------------------------
8
9// all functions defined in header file by purpose. Allows compiler optimizations.
10
11#ifndef __PARITY_H
12#define __PARITY_H
13
14#include <stdint.h>
15#include <stdbool.h>
16
17extern const uint8_t OddByteParity[256];
18
19
20static inline bool oddparity8(const uint8_t x) {
21 return OddByteParity[x];
22}
23
24
25static inline bool evenparity8(const uint8_t x) {
26 return !OddByteParity[x];
27}
28
29
30static inline bool evenparity32(uint32_t x)
31{
32#if !defined __GNUC__
33 x ^= x >> 16;
34 x ^= x >> 8;
35 return evenparity8(x);
36#else
37 return __builtin_parity(x);
38#endif
39}
40
41
42static inline bool oddparity32(uint32_t x)
43{
44#if !defined __GNUC__
45 x ^= x >> 16;
46 x ^= x >> 8;
47 return oddparity8(x);
48#else
49 return !__builtin_parity(x);
50#endif
51}
52
53#endif /* __PARITY_H */
Impressum, Datenschutz