Files
Viper_VRTE/atom.vp
T

42 lines
1.0 KiB
Plaintext

import t, c
define ATOMIC_RELAXED = 0
define ATOMIC_CONSUME = 1
define ATOMIC_ACQUIRE = 2
define ATOMIC_RELEASE = 3
define ATOMIC_ACQ_REL = 4
define ATOMIC_SEQ_CST = 5
def __atomic_test_and_set(ptr: uint64*, order: int) -> bool:
result: uint8 = 1
c.Asm(f"""mov al, 1
xchg byte ptr [{c.AsmInp(ptr, t.ASM_DESCR.REG_ANY)}], al
mov $0, al""",
out = [c.AsmOut(result, t.ASM_DESCR.OUTPUT_REG)],
op = [t.ASM_DESCR.CLOBBER_MEMORY, t.ASM_DESCR.CLOBBER_RAX])
return t.CBool(result)
def __atomic_clear(ptr: uint64*, order: int):
c.Asm(f"""mov byte ptr [{c.AsmInp(ptr, t.ASM_DESCR.REG_ANY)}], 0""",
inp = [c.AsmInp(ptr, t.ASM_DESCR.REG_ANY)],
op = [t.ASM_DESCR.CLOBBER_MEMORY])
def __atomic_thread_fence(order: int):
c.Asm("mfence", op=[t.ASM_DESCR.CLOBBER_MEMORY])
def __atomic_signal_fence(order: int):
pass
def __atomic_always_lock_free(size: sizet, ptr: rawptr) -> bool:
return True
def __atomic_is_lock_free(size: sizet, ptr: rawptr) -> bool:
return True