chiark / gitweb /
base/asm-common.h: Improve conditional instruction notation.
authorMark Wooding <mdw@distorted.org.uk>
Tue, 13 Oct 2020 23:14:49 +0000 (00:14 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Tue, 13 Oct 2020 23:14:49 +0000 (00:14 +0100)
ARM64 conditional instructions -- `ccmp', `csel', etc. -- are
inexplicably notated differently from conditional branches.  The latter
are rather pleasantly written as `b.CC TARGET', while the former are,
disappointingly, `csel RD, RN, RM, CC' and similar, with the condition
tacked on the end.

Fix this by introducing aliases `csel.CC' and suchlike for all of the
conditional instructions.

base/asm-common.h

index ebcba2c67835f06447348cc8d703ec66490b78d2..18c61fc1a13dc564668ee64124850250393825cd 100644 (file)
@@ -1114,6 +1114,54 @@ name:
 .macro endprologue
 .endm
 
+// Notational improvement: write `csel.CC' etc., rather than `csel ..., CC'.
+#define _COND(_)                                                       \
+       _(eq) _(ne) _(cs) _(cc) _(vs) _(vc) _(mi) _(pl)                 \
+       _(ge) _(lt) _(gt) _(le) _(hi) _(ls) _(al) _(nv)                 \
+       _(hs) _(lo)
+#define _INST(_)                                                       \
+       _(ccmp) _(ccmn)                                                 \
+       _(csel)                                                         \
+       _(csinc) _(cinc) _(cset)                                        \
+       _(csneg) _(cneg)                                                \
+       _(csinv) _(cinv) _(csetm)
+#define _CONDVAR(cc) _definstvar cc;
+#define _INSTVARS(inst)                                                        \
+       .macro _definstvar cc;                                          \
+         .macro inst.\cc args:vararg; inst \args, \cc; .endm;          \
+       .endm;                                                          \
+       _COND(_CONDVAR);                                                \
+       .purgem _definstvar;
+       _INST(_INSTVARS)
+#undef _COND
+#undef _INST
+#undef _CONDVAR
+#undef _INSTVARS
+
+// Flag bits for `ccmp' and friends.
+#define CCMP_N 8
+#define CCMP_Z 4
+#define CCMP_C 2
+#define CCMP_V 1
+
+// Flag settings for satisfying conditions.
+#define CCMP_MI CCMP_N
+#define CCMP_PL 0
+#define CCMP_EQ CCMP_Z
+#define CCMP_NE 0
+#define CCMP_CS CCMP_C
+#define CCMP_HS CCMP_C
+#define CCMP_CC 0
+#define CCMP_LO 0
+#define CCMP_VS CCMP_V
+#define CCMP_VC 0
+#define CCMP_HI CCMP_C
+#define CCMP_LS 0
+#define CCMP_LT CCMP_N
+#define CCMP_GE 0
+#define CCMP_LE CCMP_N
+#define CCMP_GT 0
+
 #endif
 
 ///--------------------------------------------------------------------------