mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-08-20 13:23:25 -07:00
Refactor parity functions
- get rid of __asm function in crapto1.h, use gcc builtin function instead - make parity functions available in common directory
This commit is contained in:
parent
f513388ee0
commit
1f065e1dad
14 changed files with 127 additions and 90 deletions
53
common/parity.h
Normal file
53
common/parity.h
Normal file
|
@ -0,0 +1,53 @@
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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.
|
||||
//-----------------------------------------------------------------------------
|
||||
// Parity functions
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
// all functions defined in header file by purpose. Allows compiler optimizations.
|
||||
|
||||
#ifndef __PARITY_H
|
||||
#define __PARITY_H
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
extern const uint8_t OddByteParity[256];
|
||||
|
||||
|
||||
static inline bool oddparity8(const uint8_t x) {
|
||||
return OddByteParity[x];
|
||||
}
|
||||
|
||||
|
||||
static inline bool evenparity8(const uint8_t x) {
|
||||
return !OddByteParity[x];
|
||||
}
|
||||
|
||||
|
||||
static inline bool evenparity32(uint32_t x)
|
||||
{
|
||||
#if !defined __GNUC__
|
||||
x ^= x >> 16;
|
||||
x ^= x >> 8;
|
||||
return evenparity8(x);
|
||||
#else
|
||||
return __builtin_parity(x);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
static inline bool oddparity32(uint32_t x)
|
||||
{
|
||||
#if !defined __GNUC__
|
||||
x ^= x >> 16;
|
||||
x ^= x >> 8;
|
||||
return oddparity8(x);
|
||||
#else
|
||||
return !__builtin_parity(x);
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /* __PARITY_H */
|
Loading…
Add table
Add a link
Reference in a new issue