aboutsummaryrefslogtreecommitdiff
path: root/system
diff options
context:
space:
mode:
authorJukka Jylänki <jujjyl@gmail.com>2014-04-07 18:28:07 +0300
committerJukka Jylänki <jujjyl@gmail.com>2014-04-07 18:28:07 +0300
commita04fd2a2c6110b5c7f65c1d993a582fb12e505e4 (patch)
treeb2d88be6aca5393486f8df1793fd35f49ce22918 /system
parenta7e6940d648044ccfd8b37d38a1f47977c5f84aa (diff)
Add JavaScript implementation of musl architecture-specific instructions.
Diffstat (limited to 'system')
-rw-r--r--system/lib/libc/musl/arch/js/atomic.h103
1 files changed, 103 insertions, 0 deletions
diff --git a/system/lib/libc/musl/arch/js/atomic.h b/system/lib/libc/musl/arch/js/atomic.h
new file mode 100644
index 00000000..07d5d4b6
--- /dev/null
+++ b/system/lib/libc/musl/arch/js/atomic.h
@@ -0,0 +1,103 @@
+#ifndef _INTERNAL_ATOMIC_H
+#define _INTERNAL_ATOMIC_H
+
+#include <stdint.h>
+
+static inline int a_ctz_l(unsigned long x)
+{
+ if (x == 0)
+ return 32;
+ int nTrailingZeros = 0;
+ while(!(x&1))
+ {
+ ++nTrailingZeros;
+ x >>= 1;
+ }
+ return nTrailingZeros;
+}
+
+static inline int a_ctz_64(uint64_t x)
+{
+ uint32_t lo = (uint32_t)x;
+ if (lo == 0)
+ return a_ctz_l((unsigned long)(x >> 32)) + 32;
+ else
+ return a_ctz_l((unsigned long)lo);
+}
+
+static inline void a_and_64(volatile uint64_t *p, uint64_t v)
+{
+ *p &= v;
+}
+
+static inline void a_or_64(volatile uint64_t *p, uint64_t v)
+{
+ *p |= v;
+}
+
+static inline void a_store_l(volatile void *p, long x)
+{
+ *(long*)p = x;
+}
+
+static inline void a_or_l(volatile void *p, long v)
+{
+ *(long*)p |= v;
+}
+
+static inline void *a_cas_p(volatile void *p, void *t, void *s)
+{
+ if (*(long*)p == t)
+ *(long*)p = s;
+ return t;
+}
+
+static inline long a_cas_l(volatile void *p, long t, long s)
+{
+ if (*(long*)p == t)
+ *(long*)p = s;
+ return t;
+}
+
+static inline int a_cas(volatile int *p, int t, int s)
+{
+ if (*p == t)
+ *p = s;
+ return t;
+}
+
+static inline void a_or(volatile void *p, int v)
+{
+ *(int*)p |= v;
+}
+
+static inline void a_and(volatile void *p, int v)
+{
+ *(int*)p &= v;
+}
+
+static inline void a_inc(volatile int *x)
+{
+ ++*x;
+}
+
+static inline void a_dec(volatile int *x)
+{
+ --*x;
+}
+
+static inline void a_store(volatile int *p, int x)
+{
+ *p = x;
+}
+
+static inline void a_spin()
+{
+}
+
+static inline void a_crash()
+{
+}
+
+
+#endif