progs/perftest.c: Use from Glibc syscall numbers.
[catacomb] / base / asm-common.h
index 18c61fc..9257d76 100644 (file)
 #define _ENDLIT .text .L$_subsec
 #define _LTORG .L$_subsec = .L$_subsec + 2; .text .L$_subsec
 
-// ELF section types.
-#if __ELF__
-#  if CPUFAM_ARMEL
-#    define _SECTTY(ty) %ty
-#  else
-#    define _SECTTY(ty) @ty
-#  endif
-#endif
-
-// Section selection.
-#define TEXT .text .L$_subsec
-#if ABI_WIN
-#  define RODATA .section .rdata, "dr"
-#elif __ELF__
-#  define RODATA .section .rodata, "a", _SECTTY(progbits)
-#else
-#  define RODATA TEXT
-#endif
-#define DATA .data
-
 // Announcing an internal function.
 #define INTFUNC(name)                                                  \
        TYPE_FUNC(name);                                                \
@@ -106,14 +86,32 @@ name:
 
 #if __ELF__
 
-#if __PIC__ || __PIE__
-#  define WANT_PIC 1
+// Section types.
+#if CPUFAM_ARMEL
+#  define _SECTTY(ty) %ty
+#else
+#  define _SECTTY(ty) @ty
 #endif
 
-#define TYPE_FUNC(name) .type name, STT_FUNC
+// Section selection.
+#define RODATA .section .rodata, "a", _SECTTY(progbits)
 
+// Additional symbol metadata.
+#define TYPE_FUNC(name) .type name, STT_FUNC
+#define TYPE_OBJ(name) .type name, STT_OBJECT
 #define SIZE_OBJ(name) .size name, . - name
 
+// Special arrangements for position-independent code.
+#if __PIC__ || __PIE__
+#  define WANT_PIC 1
+#endif
+
+// Don't make the stack executable by default.
+#ifndef FORCE_EXECUTABLE_STACK
+       .pushsection .note.GNU-stack, "", _SECTTY(progbits)
+       .popsection
+#endif
+
 #endif
 
 ///--------------------------------------------------------------------------
@@ -121,10 +119,14 @@ name:
 
 #if ABI_WIN
 
+// Function names need decorating on 32-bit i386.
 #if CPUFAM_X86
 #  define F(name) _##name
 #endif
 
+// Section selection.
+#define RODATA .section .rdata, "dr"
+
 #endif
 
 ///--------------------------------------------------------------------------
@@ -220,11 +222,11 @@ name:
 #  define INTADDR__1(addr, got) addr
 #endif
 
-// Permutations for SIMD instructions.  SHUF(A, B, C, D) is an immediate,
+// Permutations for SIMD instructions.  SHUF(D, C, B, A) is an immediate,
 // suitable for use in `pshufd' or `shufpd', which copies element A
 // (0 <= A < 4) of the source to element 0 of the destination, element B to
 // element 1, element C to element 2, and element D to element 3.
-#define SHUF(a, b, c, d) ((a) + 4*(b) + 16*(c) + 64*(d))
+#define SHUF(d, c, b, a) (64*(d) + 16*(c) + 4*(b) + (a))
 
 // Map register names to their individual pieces.
 
@@ -1114,6 +1116,11 @@ name:
 .macro endprologue
 .endm
 
+// cmov RD, RN, CC: set RD to RN if CC is satisfied, otherwise do nothing
+.macro cmov    rd, rn, cc
+       csel    \rd, \rn, \rd, \cc
+.endm
+
 // Notational improvement: write `csel.CC' etc., rather than `csel ..., CC'.
 #define _COND(_)                                                       \
        _(eq) _(ne) _(cs) _(cc) _(vs) _(vc) _(mi) _(pl)                 \
@@ -1121,7 +1128,7 @@ name:
        _(hs) _(lo)
 #define _INST(_)                                                       \
        _(ccmp) _(ccmn)                                                 \
-       _(csel)                                                         \
+       _(csel) _(cmov)                                                 \
        _(csinc) _(cinc) _(cset)                                        \
        _(csneg) _(cneg)                                                \
        _(csinv) _(cinv) _(csetm)
@@ -1178,6 +1185,18 @@ name:
 #  define ENDFUNC_HOOK(_)
 #endif
 
+// Section selection.
+#ifndef TEXT
+#  define TEXT .text .L$_subsec
+#endif
+#ifndef RODATA
+#  define RODATA TEXT
+#endif
+#ifndef DATA
+#  define DATA .data
+#endif
+
+// Symbol decoration.
 #ifndef F
 #  ifdef SYM_USCORE
 #    define F(name) _##name
@@ -1189,16 +1208,13 @@ name:
 #ifndef TYPE_FUNC
 #  define TYPE_FUNC(name)
 #endif
-
+#ifndef TYPE_OBJ
+#  define TYPE_OBJ(name)
+#endif
 #ifndef SIZE_OBJ
 #  define SIZE_OBJ(name)
 #endif
 
-#if __ELF__ && !defined(WANT_EXECUTABLE_STACK)
-       .pushsection .note.GNU-stack, "", _SECTTY(progbits)
-       .popsection
-#endif
-
 ///----- That's all, folks --------------------------------------------------
 
 #endif