Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend coverage of aarch64 lifter, including SIMD #1546

Open
wants to merge 175 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
175 commits
Select commit Hold shift + click to select a range
7278902
Add some bitvector functions and assert-msg macro
DukMastaaa Feb 4, 2022
86ed4d4
Add immediate decoding and logical immediate insns
DukMastaaa Feb 4, 2022
51ad92c
Add barrier instructions via the special primitive
DukMastaaa Feb 4, 2022
cf95551
add MADD, MSUB, SDIV, UDIV and conditional select
DukMastaaa Feb 4, 2022
d2199a8
Fix zeros and ones bitvector constructors
DukMastaaa Feb 4, 2022
98b94c7
organise instructions into categories
DukMastaaa Feb 8, 2022
7abc695
move ADRP to integer arithmetic category
DukMastaaa Feb 8, 2022
5d42b6d
remove private access from arm-bits functions
DukMastaaa Feb 8, 2022
7d6df06
Added stur instructions and fixed bug in `condition-holds` macro
Thomas-Malcolm Feb 8, 2022
3286a9d
Bug fixes for STUR insns
Thomas-Malcolm Feb 8, 2022
6bb8453
Merge pull request #2 from UQ-PAC/stur-instructions
Thomas-Malcolm Feb 8, 2022
42b9e44
condense repeated definitions into macros
DukMastaaa Feb 9, 2022
e565ccb
Merge branch 'implement-missing-aarch64-insns' of https://github.com/…
DukMastaaa Feb 9, 2022
be91fcd
implement TBZ and TBNZ
DukMastaaa Feb 9, 2022
2e379ca
separated into files
DukMastaaa Feb 9, 2022
2fb075f
Merge pull request #3 from UQ-PAC/insn-cleanup
Thomas-Malcolm Feb 9, 2022
522bb94
rename aarch64 files and make aarch64-helper
DukMastaaa Feb 9, 2022
6d133e5
add some processor state instructions
DukMastaaa Mar 28, 2022
e3a7da8
fix typo in pstate instructions
DukMastaaa Apr 4, 2022
f4fb588
implement rotate-left
DukMastaaa Apr 4, 2022
7bd7dbb
add missing documentation and rename for clarity
DukMastaaa Apr 4, 2022
85f8648
Merge branch 'master' into implement-missing-aarch64-insns
DukMastaaa Apr 5, 2022
0231a76
apply upstream changes from #1454
DukMastaaa Apr 11, 2022
cc4027d
Merge branch 'implement-missing-aarch64-insns' of https://github.com/…
DukMastaaa Apr 11, 2022
28dc108
implement CAS and friends for X registers
DukMastaaa Apr 11, 2022
469d134
correct CAS mnemonic and code
DukMastaaa Apr 11, 2022
381d627
fix typos in CAS instruction code
DukMastaaa Apr 12, 2022
0ff0df2
Merge branch 'BinaryAnalysisPlatform:master' into implement-missing-a…
DukMastaaa Apr 12, 2022
fa75ba9
Merge branch 'implement-missing-aarch64-insns' of https://github.com/…
DukMastaaa Apr 12, 2022
ed080e3
fix CFINV, RMIF, SETF8 and SETF16 using #1461
DukMastaaa Apr 12, 2022
d8b71af
Added instructions ANDS, ASRV, BIC to aarch64-logical.lisp
kaitlyn-lake Apr 12, 2022
7947937
Merge branch 'implement-missing-aarch64-insns' of https://github.com/…
kaitlyn-lake Apr 12, 2022
108f4c7
use clz instead of loop for highest-set-bit
DukMastaaa Apr 12, 2022
20bec8d
miscellaneous changes to helper functions
DukMastaaa Apr 12, 2022
647a9e4
update barrier code to use symbol-concat (#1452)
DukMastaaa Apr 12, 2022
dbaf536
fix CAS and friends for X registers
DukMastaaa Apr 12, 2022
d0016c4
generalise CAS to W or X registers
DukMastaaa Apr 12, 2022
1dd5ed4
generalise CAS and friends to 8-bit and 16-bit
DukMastaaa Apr 12, 2022
e5be8cb
rename CAS parameter names
DukMastaaa Apr 12, 2022
ca14999
fixes the cast-signed Primus Lisp primitive
ivg Apr 12, 2022
a25ceb2
Merge remote-tracking branch 'UQ-PAC/implement-missing-aarch64-insns'…
ivg Apr 12, 2022
05efc67
fixes the arithmetic modulus in Primus Lisp primitives
ivg Apr 12, 2022
9ce1406
adds arbitrary-precision loopless clz and popcount in Primus Lisp
ivg Apr 12, 2022
ce83a22
Merge branch 'arbitrary-precision-clz' into tests-1458
ivg Apr 12, 2022
84ab310
Merge branch 'fixes-bitvector-arithmetic' into tests-1458
ivg Apr 12, 2022
4e5cd71
uses clz instead of clz64 and properly casts the operand
ivg Apr 12, 2022
6011aa7
Merge remote-tracking branch 'upstream/master' into tests-1458
ivg Apr 12, 2022
73cee18
Merge pull request #4 from ivg/tests-1458
DukMastaaa Apr 20, 2022
c642d9b
use fixed cast-signed primitive from #1462
DukMastaaa Apr 20, 2022
c5a8a64
fix bitmask decoding of W registers
DukMastaaa Apr 20, 2022
cfb9336
Merge branch 'implement-missing-aarch64-insns' of https://github.com/…
kaitlyn-lake Apr 22, 2022
d6301c9
Created helper set-nzcv-after-logic-op to arm-bits, implemented REV i…
kaitlyn-lake Apr 25, 2022
63c61c0
Implemented REV instructionin logical.lisp. Created reverse-byte-orde…
kaitlyn-lake May 3, 2022
1de8205
Added documentation to reverse-byte-order and REV functions, there ma…
kaitlyn-lake May 10, 2022
642d53b
fix and finish non-vector REV instructions
DukMastaaa May 23, 2022
af6fef5
Added INSvi32gpr + INSvi32lane + helpers. Added pseudocode for LD2T
kaitlyn-lake Jun 14, 2022
1fb0669
test commit for github auth
DukMastaaa Jun 20, 2022
3e1a6d2
Merge branch 'implement-missing-aarch64-insns' of https://github.com/…
DukMastaaa Jun 20, 2022
4a2e594
undo git test commit
DukMastaaa Jun 20, 2022
c8dce71
implement ADDS, add set argument to add_with_carry
ailrst Jun 24, 2022
a9710d1
$Merge branch 'implement-missing-aarch64-insns' of https://github.com…
ailrst Jun 24, 2022
8295b19
Implemented LDPWi, LDRBBpost, LDRBBpre, LDRBBrow. Added better vector…
kaitlyn-lake Jun 27, 2022
01f0d4d
Merge branch 'implement-missing-aarch64-insns' of https://github.com/…
kaitlyn-lake Jun 27, 2022
054c68e
add ADR, del redundant alias CMP
ailrst Jun 27, 2022
e14f28d
Merge pull request #5 from UQ-PAC/implement-missing-aarch64-insns
DukMastaaa Jun 27, 2022
a01ba04
Merge branch 'master' of https://github.com/BinaryAnalysisPlatform/ba…
DukMastaaa Jun 27, 2022
e48fd0f
Merge branch 'BinaryAnalysisPlatform-master'
DukMastaaa Jun 27, 2022
8e9f878
Fix improper usage of intrinsic primitive
DukMastaaa Jun 28, 2022
4bf7769
Add STUR(D|Q)i
ailrst Jun 28, 2022
aad5267
add STPQi STPWi, fix STPXi
ailrst Jun 28, 2022
453493c
add STRBBpost and STRBBroX
ailrst Jun 28, 2022
ee61345
Implemented multiple gpr & vector register load instructions
kaitlyn-lake Jun 29, 2022
eb4e523
Implement CASPX and helpers for W and X pairs
DukMastaaa Jun 29, 2022
08e9bd4
Generalise CASP over W and X registers
DukMastaaa Jun 29, 2022
b163841
Implement CASP family with acquire and release
DukMastaaa Jun 29, 2022
7a6db18
Merge pull request #7 from UQ-PAC/implement-CASP-instructions
DukMastaaa Jun 29, 2022
ee0ccf8
implement STR*post STR*roX
ailrst Jun 29, 2022
1ffed99
implement STRHHui
ailrst Jun 29, 2022
3080c0e
add STR*ui
ailrst Jun 30, 2022
b5a567c
Add STUR(D|Q)i
ailrst Jun 28, 2022
c353e32
add STPQi STPWi, fix STPXi
ailrst Jun 28, 2022
f54a253
add STRBBpost and STRBBroX
ailrst Jun 28, 2022
1a16368
implement STR*post STR*roX
ailrst Jun 29, 2022
2e7f74e
implement STRHHui
ailrst Jun 29, 2022
52c5a9c
add STR*ui
ailrst Jun 30, 2022
b919f0f
Merge branch 'implement-SIMD-store-insns' of github.com:UQ-PAC/bap in…
ailrst Jun 30, 2022
a10c1de
generalise STP for reg sizes
ailrst Jun 30, 2022
dc13820
generalise STR and add STR.roW
ailrst Jul 1, 2022
6c818f8
fix STP 2nd reg ofset
ailrst Jul 1, 2022
4f3d4b0
fix STRHHui offset
ailrst Jul 1, 2022
4d13d29
Merge pull request #9 from UQ-PAC/implement-SIMD-store-insns
DukMastaaa Jul 4, 2022
b14b391
Cleaned up aarch64-data-movement.lisp, added helper for getting vecto…
kaitlyn-lake Jul 5, 2022
7dc8bc4
Removed debugging code
kaitlyn-lake Jul 5, 2022
5675ca0
change tabs to spaces
DukMastaaa Jul 6, 2022
c9fd8f2
Merge branch 'aarch64-pull-request-2' into implement-LD-insns
DukMastaaa Jul 6, 2022
bada81b
Merge pull request #11 from UQ-PAC/implement-LD-insns
DukMastaaa Jul 6, 2022
bf06e7d
Fix LD2, represent memory accesses in order
DukMastaaa Jul 7, 2022
692c010
Merge branch 'implement-LD-insns' of https://github.com/UQ-PAC/bap in…
DukMastaaa Jul 7, 2022
e0fdc80
implement movi
ailrst Jul 7, 2022
7ca9132
fix 8bns
ailrst Jul 7, 2022
6ba5af1
Completely implemented LDR imm, mem-read helper from ISA psuedocode, …
kaitlyn-lake Jul 7, 2022
256674e
Merge pull request #12 from UQ-PAC/implement-MOVI
ailrst Jul 8, 2022
46c82b3
SUBS
ailrst Jul 4, 2022
25bbb56
add LSL,LSR,ROR
ailrst Jul 4, 2022
88901f4
fix SUB
ailrst Jul 4, 2022
6e32781
add UMADDL
ailrst Jul 4, 2022
94a1a8c
add pre variant of STR and STRB
ailrst Jul 7, 2022
5d08c2a
Merge pull request #13 from UQ-PAC/implement-LD-insns
DukMastaaa Jul 8, 2022
fe6c45a
fix LDRBBpre
ailrst Jul 8, 2022
f7f2c1d
add UMULH
ailrst Jul 8, 2022
b8755e1
add LDR pre+post variants
ailrst Jul 8, 2022
ba8ade0
add missing LDP,LDRH,LDR variants
ailrst Jul 8, 2022
40c9893
Merge pull request #14 from UQ-PAC/fix-init-empty-bin-missing
ailrst Jul 8, 2022
98c3ac4
Use extract and concat approach for REVn*r insns
DukMastaaa Jul 11, 2022
e6de3da
Merge branch 'aarch64-pull-request-2' of https://github.com/UQ-PAC/ba…
DukMastaaa Jul 11, 2022
d767f7a
add BRK
ailrst Jul 11, 2022
45522d2
implement vector addition instructions
DukMastaaa Jul 12, 2022
f19cf45
remove double LSL/LSR implementation
ailrst Jul 12, 2022
2446001
add generic vector-binop function, SUB and MUL
DukMastaaa Jul 12, 2022
d23ed69
make bitvec-to-symbol total
ailrst Jul 12, 2022
acd3bf4
implement EXTR
ailrst Jul 12, 2022
8b2a6f1
add EXTv
ailrst Jul 12, 2022
403499a
implement AND, EOR, NOT, ORR, ORN (vector)
DukMastaaa Jul 12, 2022
2076553
Merge pull request #16 from UQ-PAC/add-arithmetic-logical-vector-cntlm
DukMastaaa Jul 12, 2022
474f916
Merge pull request #15 from UQ-PAC/add-missing-misc
ailrst Jul 12, 2022
93d759d
Merged Adriel's changes to LD2, added more missing LD instruction ver…
kaitlyn-lake Jul 12, 2022
e9fc8a5
temporary commit
kaitlyn-lake Jul 12, 2022
060a467
fix lognot
ailrst Jul 13, 2022
eb41ed2
add SMADDL
ailrst Jul 13, 2022
3a9e416
fix lognot Merge pull request #17 from UQ-PAC/add-missing-empty-bin
ailrst Jul 13, 2022
04785ef
tabs to spaces
DukMastaaa Jul 15, 2022
d314a24
use full stop for simd macros instead of asterisk
DukMastaaa Jul 15, 2022
9d9b2ab
implement nth-reg-in-group primitive for LD2
DukMastaaa Jul 15, 2022
e4eee76
Improved ptimitive, but it does not compile
kaitlyn-lake Jul 15, 2022
f585317
Replaced replace-bit-range rd high low elem with replace-bit-range rd…
kaitlyn-lake Jul 15, 2022
c5b93ea
Merge branch 'aarch64-pull-request-2' into implement-LD-insns
DukMastaaa Jul 15, 2022
5a7342c
Merge pull request #18 from UQ-PAC/implement-LD-insns
DukMastaaa Jul 15, 2022
0038b07
Implemented all LD (multiple structres), LD (single structures), LD.R…
kaitlyn-lake Jul 20, 2022
9e4c2a6
fix lognot
ailrst Jul 13, 2022
4a64053
add SMADDL
ailrst Jul 13, 2022
e5dac86
add LDURHH,LDURSB,LDURSH,LDURSW
ailrst Jul 13, 2022
a6e5d61
redo brk
ailrst Jul 13, 2022
a4247fa
add UMSUBL
ailrst Jul 13, 2022
ec0fa99
add SMSUBL
ailrst Jul 13, 2022
6bf46bd
add RBIT
ailrst Jul 13, 2022
5ff9426
make RBIT bil better
ailrst Jul 20, 2022
4ca0f1c
Merge branch 'aarch64-pull-request-2' into add-missing-empty-bin
ailrst Jul 20, 2022
1cb9933
Merge pull request #19 from UQ-PAC/add-missing-empty-bin
ailrst Jul 20, 2022
7d8e630
Merge pull request #20 from UQ-PAC/implement-LD-insns
DukMastaaa Jul 20, 2022
721917a
extract simd instructions into package
DukMastaaa Jul 23, 2022
1f5d65a
limit comment length
DukMastaaa Jul 25, 2022
5dd6371
Separate simd data movement instructions
DukMastaaa Jul 27, 2022
698d7eb
remove simd folder which doesn't get read by bap
DukMastaaa Jul 27, 2022
96dc059
finish STUR.i instructions
DukMastaaa Jul 27, 2022
a324ed4
move reverse-bits and helper to bits.lisp
DukMastaaa Jul 27, 2022
40841c3
add comment to bitvec-to-symbol
DukMastaaa Jul 27, 2022
e5cf036
use nth-reg-in-group in CASPord* except concat
DukMastaaa Jul 28, 2022
328914e
Fix bug in REVnWr implementation
DukMastaaa Jul 29, 2022
3a007ab
fix comment length and LLVM code for BIC
DukMastaaa Jul 29, 2022
92c68b0
Implemented all SIMD load instructions
kaitlyn-lake Aug 1, 2022
82a4262
Merged aarch64-pull-request-2 to implement-LD-insns
kaitlyn-lake Aug 1, 2022
cdaf4fc
Fixed intrinsic usage in LDNP
kaitlyn-lake Aug 2, 2022
be36805
Minor comment changes
kaitlyn-lake Aug 2, 2022
3250199
Merge branch 'master' into aarch64-pull-request-2
DukMastaaa Aug 3, 2022
a1f0852
add ADC instruction & setup repo
andrewj-brown Aug 12, 2022
feb8dc1
fix flag behaviour with adc/adcs
andrewj-brown Aug 12, 2022
3b7b928
switch macros
andrewj-brown Aug 12, 2022
666d9b5
add sbc and sbcs
andrewj-brown Aug 12, 2022
851d126
switch SBCS to clear-base as SUBS, use "-" with SBC
andrewj-brown Aug 12, 2022
d1a25f3
fix brackets
andrewj-brown Aug 12, 2022
7ede5a8
switch off clear-base
andrewj-brown Aug 12, 2022
4091cfd
fixes
andrewj-brown Aug 12, 2022
e8d35c9
add SUBSWrx and finish SBC, SBCS, ADC, ADCS
andrewj-brown Aug 19, 2022
abb7f40
added CLZXr and CLZWr
andrewj-brown Sep 9, 2022
acfdc10
Merge arithmetic-pr into aarch64-pull-request-2
andrewj-brown Nov 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 88 additions & 3 deletions plugins/arm/semantics/aarch64-arithmetic.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,104 @@
(defun ADDWrs (rd rn rm off) (ADD*r* setw shift-encoded rd rn rm off))
(defun ADDXrs (rd rn rm off) (ADD*r* set$ shift-encoded rd rn rm off))


; ADCS: add with carry, setting flags
(defun ADCSXr (rd rn rm)
(add-with-carry set$ rd CF rm rn))
(defun ADCSWr (rd rn rm)
(add-with-carry setw rd CF rm rn))

; ADC: add with carry, no flags
(defun ADCXr (rd rn rm)
(set$ rd (+ CF rm rn)))
(defun ADCWr (rd rn rm)
(setw rd (+ CF rm rn)))

; adds immediate
(defun ADDSXri (rd rn imm off)
(add-with-carry set$ rd rn (lshift imm off) 0))

(defun ADDSWri (rd rn imm off)
(add-with-carry setw rd rn (lshift imm off) 0))

; adds shifted
(defun ADDSXrs (rd rn rm shift)
(add-with-carry set$ rd rn (shift-encoded rm shift) 0))

(defun ADDSWrs (rd rn rm shift)
(add-with-carry set$ rd rn (shift-encoded rm shift) 0))

; add extended
(defun ADDXrx (rd rn rm shift)
(set$ rd (+ rn (extended rm shift))))

(defun ADDWrx (rd rn rm shift)
(setw rd (+ rn (extended rm shift))))

; add extend SXRX|UXTX
(defun ADDXrx64 (rd rn rm shift)
(set$ rd (+ rn (extended rm shift))))

; endTODO


(defun ADRP (dst imm)
(set$ dst (+
(logand (get-program-counter) (lshift -1 12))
(cast-signed (word) (lshift imm 12)))))

(defmacro SUB*r* (set shift-function rd rn imm-or-rm off)
"Implements SUB*ri and SUB*rs by specifying the shift function."
(set rd (- rn (shift-function imm-or-rm off))))
(set rd (cast-low (word-width rd) (- rn (shift-function imm-or-rm off)))))

;; see ADD*ri vs ADD*rs
(defun SUBWri (rd rn rm off) (SUB*r* setw lshift rd rn rm off))
(defun SUBXri (rd rn rm off) (SUB*r* set$ lshift rd rn rm off))
(defun SUBWrs (rd rn rm off) (SUB*r* setw shift-encoded rd rn rm off))
(defun SUBXrs (rd rn rm off) (SUB*r* set$ shift-encoded rd rn rm off))

(defun SUBXrx (rd rn rm off)
(set$ rd (- rn (extended rm off))))

(defun SUBXrx64 (rd rn rm off)
(set$ rd (- rn (extended rm off))))

(defun SUBXrw (rd rn rm off)
(setw rd (- rn (extended rm off))))

(defun SBCSXr (rd rn rm)
(add-with-carry set$ rd CF (lnot rm) rn))

(defun SBCSWr (rd rn rm)
(add-with-carry setw rd CF (lnot rm) rn))

(defun SBCXr (rd rn rm)
(set$ rd (+ CF (lnot rm) rn)))

(defun SBCWr (rd rn rm)
(setw rd (+ CF (lnot rm) rn)))

(defun SUBSWrs (rd rn rm off)
(add-with-carry/clear-base rd rn (lnot (shift-encoded rm off)) 1))

(defun SUBSXrx (rd rn rm off)
(add-with-carry set$ rd rn (lnot (shift-encoded rm off)) 1))

(defun SUBSXrx64 (rd rn rm off)
(add-with-carry set$ rd rn (lnot (shift-encoded rm off)) 1))

(defun SUBSXrs (rd rn rm off)
(add-with-carry rd rn (lnot (shift-encoded rm off)) 1))
(add-with-carry set$ rd rn (lnot (shift-encoded rm off)) 1))

; seems suspect but probably works
(defun SUBSWrx (rd rn rm off)
(add-with-carry set$ rd rn (lnot (shift-encoded rm off)) 1))

(defun SUBSWri (rd rn imm off)
(add-with-carry/clear-base rd rn (lnot (lshift imm off)) 1))

(defun SUBSXri (rd rn imm off)
(add-with-carry rd rn (lnot (lshift imm off)) 1))
(add-with-carry set$ rd rn (lnot (lshift imm off)) 1))

(defmacro Mop*rrr (set op rd rn rm ra)
"(Mop*rrr set op rd rn rm ra) implements multiply-add, multiply-subtract
Expand All @@ -58,6 +127,19 @@
(defun MSUBWrrr (rd rn rm ra) (Mop*rrr setw - rd rn rm ra))
(defun MSUBXrrr (rd rn rm ra) (Mop*rrr set$ - rd rn rm ra))

(defun UMADDLrrr (rd rn rm ra) (set$ rd (cast-low 64 (+ ra (* rn rm)))))

(defun SMADDLrrr (rd rn rm ra) (set$ rd (cast-signed 64 (+ ra (* (cast-signed 64 rn) (cast-signed 64 rm))))))

(defun UMSUBLrrr (rd rn rm ra) (set$ rd (cast-low 64 (- ra (* (cast-signed 64 rn) (cast-signed 64 rm))))))

(defun SMSUBLrrr (rd rn rm ra) (set$ rd (cast-signed 64 (- ra (* (cast-signed 64 rn) (cast-signed 64 rm))))))

(defun UMULHrr (rd rn rm)
"multiplies rn and rm together and stores the high 64 bits of the resulting
128-bit value to the register rd"
(set$ rd (cast-high 64 (* (cast-unsigned 128 rn) (cast-unsigned 128 rm)))))

(defmacro *DIV*r (set div rd rn rm)
"(*DIV*r set div rd rn rm) implements the SDIV or UDIV instructions
on W or X registers, with div set to s/ or / respectively."
Expand All @@ -69,3 +151,6 @@
(defun SDIVXr (rd rn rm) (*DIV*r set$ s/ rd rn rm))
(defun UDIVWr (rd rn rm) (*DIV*r setw / rd rn rm))
(defun UDIVXr (rd rn rm) (*DIV*r set$ / rd rn rm))

(defun ADR (rd label)
(store-word rd (+ (get-program-counter) (cast-signed 64 label))))
39 changes: 38 additions & 1 deletion plugins/arm/semantics/aarch64-atomic.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
load and store are functions to load/store to/from the size of rs and rt.
acquire and release are booleans indicating whether load-acquire and
store-release ordering is to be enforced."
(let ((data (load rn)))
(let ((data (load rn)))
(when acquire (intrinsic 'load-acquire))
(when (= data rs)
(when release (intrinsic 'store-release))
Expand Down Expand Up @@ -62,6 +62,43 @@
(defun CASLH (rs _ rt rn) (CASordH rs rt rn false true))
(defun CASALH (rs _ rt rn) (CASordH rs rt rn true true))

(defun first (x y) (declare (visibility :private)) x)
(defun second (x y) (declare (visibility :private)) y)

(defmacro CASPord* (set load rs-pair rt-pair rn register-width acquire release)
"(CASP* set load store rs-pair rt-pair rn register-width acquire release)
implements a compare-and-swap-pair instruction for W and X registers.
set is the functions to set to a register in the pair.
register-width is 64 or 32, depending on the size of register used.
load either loads 128 bits or 64 (the size of the whole pair).
acquire and release are as in the CASord* macro."
(let ((data (load rn))
(lower (cast-low register-width data))
(upper (cast-high register-width data)))
(when acquire (intrinsic 'load-acquire))
(when (= data (register-pair-concat rs-pair))
(when release (intrinsic 'store-release))
(store-word rn (register-pair-concat rt-pair)))
(set$ (nth-reg-in-group rs-pair 0) (endian first upper lower))
(set$ (nth-reg-in-group rs-pair 1) (endian second upper lower))))

(defmacro CASPordX (rs-pair rt-pair rn acquire release)
"Specialisation of CASPord* for X registers."
(CASPord* set$ load-dword rs-pair rt-pair rn 64 acquire release))

(defmacro CASPordW (rs-pair rt-pair rn acquire release)
"Specialisation of CASPord* for W registers."
(CASPord* setw load-word rs-pair rt-pair rn 32 acquire release))

(defun CASPX (rs-pair _ rt-pair rn) (CASPordX rs-pair rt-pair rn false false))
(defun CASPAX (rs-pair _ rt-pair rn) (CASPordX rs-pair rt-pair rn true false))
(defun CASPLX (rs-pair _ rt-pair rn) (CASPordX rs-pair rt-pair rn false true))
(defun CASPALX (rs-pair _ rt-pair rn) (CASPordX rs-pair rt-pair rn true true))

(defun CASPW (rs-pair _ rt-pair rn) (CASPordW rs-pair rt-pair rn false false))
(defun CASPAW (rs-pair _ rt-pair rn) (CASPordW rs-pair rt-pair rn true false))
(defun CASPLW (rs-pair _ rt-pair rn) (CASPordW rs-pair rt-pair rn false true))
(defun CASPALW (rs-pair _ rt-pair rn) (CASPordW rs-pair rt-pair rn true true))

(defmacro CSop*r (set op rd rn rm cnd)
"(CSop*r set op rd rn rm cnd) implements the conditional select
Expand Down
Loading