Skip to content

Commit

Permalink
fix Linux builds errors, Windows not indicating as
Browse files Browse the repository at this point in the history
  • Loading branch information
TheTechsTech committed Nov 27, 2024
1 parent 8272fdb commit f69a583
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 25 deletions.
17 changes: 11 additions & 6 deletions include/catomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -2552,7 +2552,13 @@ static C89ATOMIC_INLINE double c89atomic_compare_and_swap_f64(volatile double* d
/* Spinlock */
typedef c89atomic_flag c89atomic_spinlock;

static C89ATOMIC_INLINE void c89atomic_spinlock_lock(volatile c89atomic_spinlock* pSpinlock)
#ifndef _STDATOMIC_H
make_atomic(c89atomic_flag, atomic_flag)
#endif

make_atomic(c89atomic_spinlock, atomic_spinlock)

static C89ATOMIC_INLINE void c89atomic_spinlock_lock(atomic_spinlock *pSpinlock)
{
for (;;) {
if (c89atomic_flag_test_and_set_explicit(pSpinlock, c89atomic_memory_order_acquire) == 0) {
Expand All @@ -2565,15 +2571,11 @@ static C89ATOMIC_INLINE void c89atomic_spinlock_lock(volatile c89atomic_spinlock
}
}

static C89ATOMIC_INLINE void c89atomic_spinlock_unlock(volatile c89atomic_spinlock* pSpinlock)
static C89ATOMIC_INLINE void c89atomic_spinlock_unlock(atomic_spinlock *pSpinlock)
{
c89atomic_flag_clear_explicit(pSpinlock, c89atomic_memory_order_release);
}

#ifndef _STDATOMIC_H
make_atomic(c89atomic_flag, atomic_flag)
#endif

#ifdef _WIN32
typedef volatile void *atomic_ptr_t;
static C89ATOMIC_INLINE c89atomic_bool c89atomic_cas_32(atomic_uint *a, c89atomic_uint32 *cmp, c89atomic_uint32 set) {
Expand Down Expand Up @@ -2641,6 +2643,9 @@ static C89ATOMIC_INLINE void c89atomic_spinlock_unlock(volatile c89atomic_spinlo
# define atomic_get(type, obj) (type)c89atomic_load_64((atomic_ullong *)obj)
#endif

#define atomic_lock(mutex) c89atomic_spinlock_lock((atomic_spinlock *)mutex)
#define atomic_unlock(mutex) c89atomic_spinlock_unlock((atomic_spinlock *)mutex)

#if !defined(_STDATOMIC_H)
/* reads an atomic_flag */
#define atomic_flag_load(ptr) c89atomic_flag_load_explicit((atomic_flag *)ptr, memory_order_seq_cst)
Expand Down
2 changes: 1 addition & 1 deletion include/raii.h
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ C_API args_t raii_args_ex(memory_t *scope, const char *desc, va_list);
* @param item index number
*/
C_API values_type raii_get_args(memory_t *scope, void_t params, int item);
C_API values_type get_args(void *params, int item);
C_API values_type get_args(args_t params, int item);
C_API values_type get_arg(void_t params);

/**
Expand Down
32 changes: 16 additions & 16 deletions include/swar.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
#include "exception.h"

// Cast char* to T using memcpy. memcpy is optimized away on x86
C_API RAII_INLINE uintptr_t cast(const char *src);
C_API RAII_INLINE uintptr_t cast8(const char *s, uint32_t len);
C_API uintptr_t cast(const char *src);
C_API uintptr_t cast8(const char *s, uint32_t len);

// Fill T with c's
C_API RAII_INLINE uintptr_t extend(char c);
Expand Down Expand Up @@ -64,7 +64,7 @@ C_API RAII_INLINE bool haszero(uint64_t x);
C_API RAII_INLINE bool hasbyte(uint64_t x, uint8_t c);

// Find char in binary string of 8 chars
C_API RAII_INLINE uint32_t memchr8(const char* s, uint8_t c);
C_API uint32_t memchr8(const char* s, uint8_t c);

// Find char in binary string of 8 chars
// * The string is known to contain the char
Expand All @@ -85,7 +85,7 @@ C_API int simd_strcmp(const char *s, const char *c);
//

// Find char in binary string
C_API RAII_INLINE string simd_memchr(const char *s, uint8_t c, uint32_t len);
C_API string simd_memchr(const char *s, uint8_t c, uint32_t len);

// Find char in binary string. Char c is known to be in s + len
C_API RAII_INLINE uint32_t memchrk(const char* s, uint32_t len, uint8_t c);
Expand All @@ -101,7 +101,7 @@ C_API RAII_INLINE uint32_t pmemchrk(const char* s, uint32_t len, uint8_t c);
//

// Find char, in reverse, in binary string
C_API RAII_INLINE string simd_memrchr(const char* s, uint8_t c, uint32_t len);
C_API string simd_memrchr(const char* s, uint8_t c, uint32_t len);

// Find char in binary string. Char c is known to be in s + len
C_API RAII_INLINE uint32_t memrchrk(const char* s, uint32_t len, uint8_t c);
Expand All @@ -116,39 +116,39 @@ C_API RAII_INLINE uint32_t pmemrchrk(const char* s, uint32_t len, uint8_t c);

// Parse uint64_t from string of up to 20 chars
// *** More than 20 char returns junk.
C_API RAII_INLINE uint64_t simd_atou(const char* s, uint32_t len);
C_API RAII_INLINE uint32_t atou8(const char *s, uint32_t len);
C_API uint64_t simd_atou(const char* s, uint32_t len);
C_API uint32_t atou8(const char *s, uint32_t len);

// Parse _signed_ int from string of up to 20 chars. No spaces
C_API RAII_INLINE int64_t simd_atoi(const char *s, uint32_t len);
C_API int64_t simd_atoi(const char *s, uint32_t len);

// Parse hex int from string of up to 16 chars
C_API RAII_INLINE uint64_t simd_htou(const char* s, uint32_t len);
C_API uint64_t simd_htou(const char* s, uint32_t len);

C_API RAII_INLINE uint32_t htou8(const char *s, uint32_t len);
C_API uint32_t htou8(const char *s, uint32_t len);

//// int to string

// *** p suffix means zero-padded

// Convert uint, of less than 100, to %02u, as int 16
C_API RAII_INLINE uint16_t utoa2p(uint64_t x);
C_API uint16_t utoa2p(uint64_t x);

// Convert uint, of less than 100, to %02u
C_API RAII_INLINE void utoa2p_ex(uint64_t x, char* s);
C_API void utoa2p_ex(uint64_t x, char* s);

// Convert uint to %0<N>u, N <= 20
C_API RAII_INLINE char* utoap(int N, uint64_t x, char* s);
C_API char* utoap(int N, uint64_t x, char* s);

// Convert signed int 64 to string. String buffer is at least 22 bytes.
// Returns length
// *** this feels inefficient :( ***
C_API RAII_INLINE uint32_t simd_itoa(int64_t x, char *buf);
C_API RAII_INLINE uint32_t itoa8(int32_t x, char *buf);
C_API uint32_t simd_itoa(int64_t x, char *buf);
C_API uint32_t itoa8(int32_t x, char *buf);

//// Double to string

// Parse double from string
// *** More than 20 char integer part returns junk.
// *** Too much decimal char will get lost to precision
C_API RAII_INLINE double simd_atod(const char *s, uint32_t len);
C_API double simd_atod(const char *s, uint32_t len);
2 changes: 1 addition & 1 deletion src/raii.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ RAII_INLINE string *raii_split(string_t s, string_t delim, int *count) {
return str_split_ex(raii_init(), s, delim, count);
}

RAII_INLINE string raii_concat(int num_args, ...) {
string raii_concat(int num_args, ...) {
va_list ap;
string data;

Expand Down
3 changes: 2 additions & 1 deletion src/swar.c
Original file line number Diff line number Diff line change
Expand Up @@ -564,11 +564,12 @@ RAII_INLINE double simd_atod(const char *s, uint32_t len) {

// Convert uint to %0<N>u, N <= 8
RAII_INLINE uint64_t _utoap(int N, uint64_t x, char *s) {
int i;
RAII_ASSERT(N <= 8);

uint64_t tmp = utoa2p(x % 100);

for (int i = 0; i < N - 2; i += 2) {
for (i = 0; i < N - 2; i += 2) {
x /= 100;
tmp <<= 16;
tmp |= utoa2p(x % 100);
Expand Down

0 comments on commit f69a583

Please sign in to comment.