Skip to content

Commit

Permalink
Fix some additional cases where the old SIZEOF_VOIDP was being used t…
Browse files Browse the repository at this point in the history
…o detect the bitness of a given architecture.
  • Loading branch information
insertinterestingnamehere committed Sep 19, 2024
1 parent eca8a60 commit 4b2d32b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 21 deletions.
3 changes: 0 additions & 3 deletions include/qthread/common.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,6 @@
#define BITFIELD_ORDER_FORWARD
#endif

/* The size of `void*', as computed by sizeof. */
#undef SIZEOF_VOIDP

/* builtin cas supported */
#undef QTHREAD_ATOMIC_CAS

Expand Down
4 changes: 2 additions & 2 deletions include/qthread/qthread.h
Original file line number Diff line number Diff line change
Expand Up @@ -1344,11 +1344,11 @@ static QINLINE aligned_t qthread_cas_xx(aligned_t *addr,

static QINLINE void *
qthread_cas_ptr_(void **addr, void *oldval, void *newval) { /*{{{*/
#if (SIZEOF_VOIDP == 4)
#if (QTHREAD_BITS == 32)
return (void *)(uintptr_t)qthread_cas32(
(uint32_t *)addr, (uint32_t)(uintptr_t)oldval, (uint32_t)(uintptr_t)newval);

#elif (SIZEOF_VOIDP == 8)
#elif (QTHREAD_BITS == 64)
return (void *)(uintptr_t)qthread_cas64(
(uint64_t *)addr, (uint64_t)(uintptr_t)oldval, (uint64_t)(uintptr_t)newval);

Expand Down
32 changes: 16 additions & 16 deletions src/ds/dictionary/hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ uint64_t API_FUNC qt_hash64(uint64_t key) { /*{{{*/
uint8_t b[sizeof(uint64_t)];
} k = {key};

#if (SIZEOF_VOIDP == 8) /* i.e. a 64-bit machine */
#if (QTHREAD_BITS == 64)
uint64_t a, b, c;

a = b = 0x9e3779b97f4a7c13LL; // the golden ratio
Expand Down Expand Up @@ -72,37 +72,37 @@ uint64_t API_FUNC qt_hash64(uint64_t key) { /*{{{*/
c = c ^ (b >> 22u);
return c;

#else /* i.e. a 32-bit machine */
#else
uint32_t a, b, c;

a = b = 0x9e3779b9; // golden ratio
c = 0xdeadbeef + sizeof(uint64_t);

b += k.b[7] << 24;
b += k.b[6] << 16;
b += k.b[5] << 8;
b += k.b[7] << 24u;
b += k.b[6] << 16u;
b += k.b[5] << 8u;
b += k.b[4];
a += k.b[3] << 24;
a += k.b[2] << 16;
a += k.b[1] << 8;
a += k.b[3] << 24u;
a += k.b[2] << 16u;
a += k.b[1] << 8u;
a += k.b[0];

c ^= b;
c -= rot(b, 14);
c -= rot(b, 14u);
a ^= c;
a -= rot(c, 11);
a -= rot(c, 11u);
b ^= a;
b -= rot(a, 25);
b -= rot(a, 25u);
c ^= b;
c -= rot(b, 16);
c -= rot(b, 16u);
a ^= c;
a -= rot(c, 4);
a -= rot(c, 4u);
b ^= a;
b -= rot(a, 14);
b -= rot(a, 14u);
c ^= b;
c -= rot(b, 24);
c -= rot(b, 24u);
return ((uint64_t)c + (((uint64_t)b) << 32));
#endif /* if (SIZEOF_VOIDP == 8) */
#endif /* if (QTHREAD_BITS == 64) */
} /*}}}*/

#if (QTHREAD_BITS == 32)
Expand Down

0 comments on commit 4b2d32b

Please sign in to comment.