From 483edf69cdc738c2315040ff9f98e4f25afdf4ae Mon Sep 17 00:00:00 2001 From: Mark Wooding Date: Wed, 14 Oct 2020 00:14:49 +0100 Subject: [PATCH] base/asm-common.h: Improve conditional instruction notation. 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 | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/base/asm-common.h b/base/asm-common.h index ebcba2c6..18c61fc1 100644 --- a/base/asm-common.h +++ b/base/asm-common.h @@ -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 ///-------------------------------------------------------------------------- -- 2.11.0