update env.c to use ck api

main
phani 5 years ago
parent cfa458c5b9
commit a72e702c77

@ -1,5 +1,6 @@
/* https://github.com/gwsystems/silverfish/blob/master/runtime/libc/libc_backing.c */
#include <runtime.h>
#include <ck_pr.h>
extern i32 inner_syscall_handler(i32 n, i32 a, i32 b, i32 c, i32 d, i32 e, i32 f);
@ -33,7 +34,7 @@ INLINE void
env_a_and_64(i32 p_off, u64 v)
{
uint64_t *p = worker_thread_get_memory_ptr_void(p_off, sizeof(uint64_t));
*p &= v;
ck_pr_and_64(p, v);
}
INLINE void
@ -41,37 +42,37 @@ env_a_or_64(i32 p_off, i64 v)
{
assert(sizeof(i64) == sizeof(uint64_t));
uint64_t *p = worker_thread_get_memory_ptr_void(p_off, sizeof(i64));
*p |= v;
ck_pr_or_64(p, v);
}
i32
env_a_cas(i32 p_off, i32 t, i32 s)
{
assert(sizeof(i32) == sizeof(volatile int));
volatile int *p = worker_thread_get_memory_ptr_void(p_off, sizeof(i32));
int *p = worker_thread_get_memory_ptr_void(p_off, sizeof(i32));
return __sync_val_compare_and_swap(p, t, s);
return ck_pr_cas_int(p, t, s);
}
void
env_a_or(i32 p_off, i32 v)
{
assert(sizeof(i32) == sizeof(volatile int));
volatile int *p = worker_thread_get_memory_ptr_void(p_off, sizeof(i32));
//__asm__("lock ; or %1, %0" : "=m"(*p) : "r"(v) : "memory");
*p |= v;
int *p = worker_thread_get_memory_ptr_void(p_off, sizeof(i32));
ck_pr_or_int(p, v);
}
i32
env_a_swap(i32 x_off, i32 v)
{
assert(sizeof(i32) == sizeof(volatile int));
volatile int *x = worker_thread_get_memory_ptr_void(x_off, sizeof(i32));
int *x = worker_thread_get_memory_ptr_void(x_off, sizeof(i32));
//__asm__("xchg %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory");
int t = *x;
*x = v;
v = t;
int p;
do {
p = ck_pr_load_int(x);
} while (!ck_pr_cas_int(x, p, v));
v = p;
return v;
}
@ -80,39 +81,32 @@ i32
env_a_fetch_add(i32 x_off, i32 v)
{
assert(sizeof(i32) == sizeof(volatile int));
volatile int *x = worker_thread_get_memory_ptr_void(x_off, sizeof(i32));
//__asm__("lock ; xadd %0, %1" : "=r"(v), "=m"(*x) : "0"(v) : "memory");
return __sync_fetch_and_add(x, v);
int *x = worker_thread_get_memory_ptr_void(x_off, sizeof(i32));
return ck_pr_faa_int(x, v);
}
void
env_a_inc(i32 x_off)
{
assert(sizeof(i32) == sizeof(volatile int));
volatile int *x = worker_thread_get_memory_ptr_void(x_off, sizeof(i32));
(*x)++;
//__asm__("lock ; incl %0" : "=m"(*x) : "m"(*x) : "memory");
int *x = worker_thread_get_memory_ptr_void(x_off, sizeof(i32));
ck_pr_inc_int(x);
}
void
env_a_dec(i32 x_off)
{
assert(sizeof(i32) == sizeof(volatile int));
volatile int *x = worker_thread_get_memory_ptr_void(x_off, sizeof(i32));
(*x)--;
//__asm__("lock ; decl %0" : "=m"(*x) : "m"(*x) : "memory");
int *x = worker_thread_get_memory_ptr_void(x_off, sizeof(i32));
ck_pr_dec_int(x);
}
void
env_a_store(i32 p_off, i32 x)
{
assert(sizeof(i32) == sizeof(volatile int));
volatile int *p = worker_thread_get_memory_ptr_void(p_off, sizeof(i32));
*p = x;
//__asm__ __volatile__("mov %1, %0 ; lock ; orl $0,(%%esp)" : "=m"(*p) : "r"(x) : "memory");
int *p = worker_thread_get_memory_ptr_void(p_off, sizeof(i32));
ck_pr_store_int(p, x);
}
int
@ -124,8 +118,7 @@ env_a_ctz_32(i32 x)
void
env_do_spin(i32 i)
{
printf("nope! not happening: %d\n", i);
assert(0);
ck_pr_stall();
}
void
@ -138,7 +131,7 @@ env_do_crash(i32 i)
void
env_do_barrier(i32 x)
{
__sync_synchronize();
ck_pr_barrier();
}
// Floating point routines

Loading…
Cancel
Save