Add Windows and Switch build support
This commit is contained in:
@@ -27,15 +27,32 @@
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <inttypes.h>
|
||||
#if defined(_MSC_VER)
|
||||
#include <intrin.h>
|
||||
#endif
|
||||
|
||||
/* set if CPU is big endian */
|
||||
#undef WORDS_BIGENDIAN
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#define likely(x) (x)
|
||||
#define unlikely(x) (x)
|
||||
#define force_inline __forceinline
|
||||
#define no_inline __declspec(noinline)
|
||||
#define __maybe_unused
|
||||
#ifndef __attribute__
|
||||
#define __attribute__(x)
|
||||
#endif
|
||||
#ifndef __attribute
|
||||
#define __attribute(x)
|
||||
#endif
|
||||
#else
|
||||
#define likely(x) __builtin_expect(!!(x), 1)
|
||||
#define unlikely(x) __builtin_expect(!!(x), 0)
|
||||
#define force_inline inline __attribute__((always_inline))
|
||||
#define no_inline __attribute__((noinline))
|
||||
#define __maybe_unused __attribute__((unused))
|
||||
#endif
|
||||
|
||||
#define xglue(x, y) x ## y
|
||||
#define glue(x, y) xglue(x, y)
|
||||
@@ -114,27 +131,69 @@ static inline int64_t min_int64(int64_t a, int64_t b)
|
||||
/* WARNING: undefined if a = 0 */
|
||||
static inline int clz32(unsigned int a)
|
||||
{
|
||||
#if defined(_MSC_VER)
|
||||
unsigned long r;
|
||||
_BitScanReverse(&r, a);
|
||||
return 31 - (int)r;
|
||||
#else
|
||||
return __builtin_clz(a);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* WARNING: undefined if a = 0 */
|
||||
static inline int clz64(uint64_t a)
|
||||
{
|
||||
#if defined(_MSC_VER)
|
||||
#if defined(_M_X64) || defined(_M_ARM64)
|
||||
unsigned long r;
|
||||
_BitScanReverse64(&r, a);
|
||||
return 63 - (int)r;
|
||||
#else
|
||||
uint32_t h = (uint32_t)(a >> 32);
|
||||
if (h != 0)
|
||||
return clz32(h);
|
||||
return 32 + clz32((uint32_t)a);
|
||||
#endif
|
||||
#else
|
||||
return __builtin_clzll(a);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* WARNING: undefined if a = 0 */
|
||||
static inline int ctz32(unsigned int a)
|
||||
{
|
||||
#if defined(_MSC_VER)
|
||||
unsigned long r;
|
||||
_BitScanForward(&r, a);
|
||||
return (int)r;
|
||||
#else
|
||||
return __builtin_ctz(a);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* WARNING: undefined if a = 0 */
|
||||
static inline int ctz64(uint64_t a)
|
||||
{
|
||||
#if defined(_MSC_VER)
|
||||
#if defined(_M_X64) || defined(_M_ARM64)
|
||||
unsigned long r;
|
||||
_BitScanForward64(&r, a);
|
||||
return (int)r;
|
||||
#else
|
||||
uint32_t l = (uint32_t)a;
|
||||
if (l != 0)
|
||||
return ctz32(l);
|
||||
return 32 + ctz32((uint32_t)(a >> 32));
|
||||
#endif
|
||||
#else
|
||||
return __builtin_ctzll(a);
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma pack(push, 1)
|
||||
#endif
|
||||
|
||||
struct __attribute__((packed)) packed_u64 {
|
||||
uint64_t v;
|
||||
};
|
||||
@@ -147,6 +206,10 @@ struct __attribute__((packed)) packed_u16 {
|
||||
uint16_t v;
|
||||
};
|
||||
|
||||
#if defined(_MSC_VER)
|
||||
#pragma pack(pop)
|
||||
#endif
|
||||
|
||||
static inline uint64_t get_u64(const uint8_t *tab)
|
||||
{
|
||||
return ((const struct packed_u64 *)tab)->v;
|
||||
|
||||
Reference in New Issue
Block a user