mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-07 06:53:33 +00:00
Add xadd to chibicc
This commit is contained in:
parent
56eff8544f
commit
1216b6e7c7
2 changed files with 23 additions and 0 deletions
10
third_party/chibicc/as.c
vendored
10
third_party/chibicc/as.c
vendored
|
@ -2328,6 +2328,14 @@ static dontinline void OpBsu(struct As *a, struct Slice opname, int op) {
|
|||
OpBsuImpl(a, opname, op);
|
||||
}
|
||||
|
||||
static dontinline void OpXadd(struct As *a) {
|
||||
int reg, modrm, disp;
|
||||
reg = GetRegisterReg(a);
|
||||
ConsumeComma(a);
|
||||
modrm = ParseModrm(a, &disp);
|
||||
EmitRexOpModrm(a, 0x0FC0, reg, modrm, disp, 1);
|
||||
}
|
||||
|
||||
static dontinline int OpF6Impl(struct As *a, struct Slice s, int reg) {
|
||||
int modrm, imm, disp;
|
||||
modrm = ParseModrm(a, &disp);
|
||||
|
@ -3109,6 +3117,7 @@ static void OnUcomiss(struct As *a, struct Slice s) { OpSse(a, 0x0F2E); }
|
|||
static void OnUd2(struct As *a, struct Slice s) { EmitVarword(a, 0x0F0B); }
|
||||
static void OnUnpckhpd(struct As *a, struct Slice s) { OpSse(a, 0x660F15); }
|
||||
static void OnUnpcklpd(struct As *a, struct Slice s) { OpSse(a, 0x660F14); }
|
||||
static void OnXadd(struct As *a, struct Slice s) { OpXadd(a); }
|
||||
static void OnXor(struct As *a, struct Slice s) { OpAlu(a, s, 6); }
|
||||
static void OnXorpd(struct As *a, struct Slice s) { OpSse(a, 0x660F57); }
|
||||
static void OnXorps(struct As *a, struct Slice s) { OpSse(a, 0x0F57); }
|
||||
|
@ -3662,6 +3671,7 @@ static const struct Directive8 {
|
|||
{"unpckhpd", OnUnpckhpd}, //
|
||||
{"unpcklpd", OnUnpcklpd}, //
|
||||
{"wait", OnFwait}, //
|
||||
{"xadd", OnXadd}, //
|
||||
{"xchg", OnXchg}, //
|
||||
{"xor", OnXor}, //
|
||||
{"xorb", OnXor}, //
|
||||
|
|
13
third_party/chibicc/test/atomic_test.c
vendored
13
third_party/chibicc/test/atomic_test.c
vendored
|
@ -37,5 +37,18 @@ main() {
|
|||
ASSERT(4, x);
|
||||
ASSERT(4, lock);
|
||||
|
||||
// CAS success #3
|
||||
x = 4;
|
||||
ASSERT(1, __atomic_compare_exchange_n(&lock, &x, 31337, 0, __ATOMIC_SEQ_CST,
|
||||
__ATOMIC_SEQ_CST));
|
||||
ASSERT(4, x);
|
||||
ASSERT(31337, lock);
|
||||
|
||||
// xadd
|
||||
ASSERT(31337, __atomic_fetch_add(&lock, 31337, __ATOMIC_SEQ_CST));
|
||||
ASSERT(62674, lock);
|
||||
ASSERT(62674, __atomic_fetch_sub(&lock, 31337, __ATOMIC_SEQ_CST));
|
||||
ASSERT(31337, lock);
|
||||
|
||||
//
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue