Merge pull request #743 from XVilka/tinycc-support
Fix compilation with TinyCC
This commit is contained in:
commit
5caa83e020
2 changed files with 31 additions and 2 deletions
|
|
@ -3,7 +3,23 @@
|
|||
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifdef __TINYC__
|
||||
|
||||
static inline size_t atomic_load(const volatile size_t *p) {
|
||||
return *p;
|
||||
}
|
||||
|
||||
static inline uint32_t atomic_inc(volatile uint32_t *p) {
|
||||
*p += 1;
|
||||
return *p;
|
||||
}
|
||||
|
||||
static inline uint32_t atomic_dec(volatile uint32_t *p) {
|
||||
*p-= 1;
|
||||
return *p;
|
||||
}
|
||||
|
||||
#elif defined(_WIN32)
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,20 @@ static inline uint32_t bitmask_for_index(uint16_t id) {
|
|||
return (1u << (31 - id));
|
||||
}
|
||||
|
||||
#if defined _WIN32 && !defined __GNUC__
|
||||
#ifdef __TINYC__
|
||||
|
||||
// Algorithm taken from the Hacker's Delight book
|
||||
// See also https://graphics.stanford.edu/~seander/bithacks.html
|
||||
static inline uint32_t count_leading_zeros(uint32_t x) {
|
||||
int count = 0;
|
||||
if (x == 0) return 32;
|
||||
x = x - ((x >> 1) & 0x55555555);
|
||||
x = (x & 0x33333333) + ((x >> 2) & 0x33333333);
|
||||
count = (((x + (x >> 4)) & 0x0f0f0f0f) * 0x01010101) >> 24;
|
||||
return count;
|
||||
}
|
||||
|
||||
#elif defined _WIN32 && !defined __GNUC__
|
||||
|
||||
#include <intrin.h>
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue