]> git.zerfleddert.de Git - proxmark3-svn/blame - common/parity.h
CHG: syntax suger
[proxmark3-svn] / common / parity.h
CommitLineData
2b1f4228 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// Generic CRC calculation code.
7//-----------------------------------------------------------------------------
8
9#ifndef __PARITY_H
10#define __PARITY_H
11
12#include <stdint.h>
13
14extern const uint8_t OddByteParity[256];
15
a531720a 16#define oddparity8(x) (OddByteParity[(x)])
2b1f4228 17
18
19extern const uint8_t EvenByteParity[256];
20
a531720a 21static inline bool /*__attribute__((always_inline))*/ evenparity8(const uint8_t x) {
22#if !defined __i386__ || !defined __GNUC__
23 return EvenByteParity[x];
24#else
25 uint8_t y;
26 __asm( "testb $255, %1\n"
27 "setpo %0\n" : "=r"(y) : "r"(x): );
28 return y;
29#endif
2b1f4228 30}
31
32
a531720a 33static inline uint8_t evenparity32(uint32_t x)
2b1f4228 34{
35 x ^= x >> 16;
36 x ^= x >> 8;
37 return EvenByteParity[x & 0xff];
38}
39
40
41#endif /* __PARITY_H */
Impressum, Datenschutz