按根目录 新规范 迁移 R1/R2/R3/R4/R6/R7/R8/R9:指针 T* 后缀、内建类型短别名、c.Addr/c.Deref 单目化、c.Asm 改 __asm__、t.CDefine 改 define 软关键字、t.CEnum 改 enum。R4 对内建 cast 多参实参保留 c.Deref 原写法(单目化会致 TPC 类型退化)。验证:includes 52/52 编译通过,TransPyV 自举产物顺序回归 77/77 全通过。
42 lines
1.0 KiB
Plaintext
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 = [asmout(result, ASM_DESCR.OUTPUT_REG)],
|
|
op = [ASM_DESCR.CLOBBER_MEMORY, ASM_DESCR.CLOBBER_RAX])
|
|
return bool(result)
|
|
|
|
|
|
def __atomic_clear(ptr: uint64*, order: int):
|
|
__asm__(f"""mov byte ptr [{c.AsmInp(ptr, t.ASM_DESCR.REG_ANY)}], 0""",
|
|
inp = [asminp(ptr, ASM_DESCR.REG_ANY)],
|
|
op = [ASM_DESCR.CLOBBER_MEMORY])
|
|
|
|
|
|
def __atomic_thread_fence(order: int):
|
|
__asm__("mfence", op=[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
|