xref: /openbsd/lib/libm/arch/amd64/abi.h (revision f6aab3d8)
1 /*	$OpenBSD: abi.h,v 1.5 2016/09/12 19:47:01 guenther Exp $	*/
2 /*	$NetBSD: abi.h,v 1.2 2003/09/14 21:26:14 fvdl Exp $	*/
3 
4 /*
5  * Written by Frank van der Linden (fvdl@wasabisystems.com)
6  */
7 
8 /*
9  * The x86-64 ABI specifies that float, double and long double
10  * arguments are passed in SSE2 (xmm) registers. Unfortunately,
11  * there is no way to push those on to the FP stack, which is
12  * where the fancier instructions get their arguments from.
13  *
14  * Define some prologues and epilogues to store and retrieve
15  * xmm regs to local variables.
16  */
17 
18 #define ARG_DOUBLE_ONE		-8(%rsp)
19 #define ARG_DOUBLE_TWO		-16(%rsp)
20 #define ARG_FLOAT_ONE		-4(%rsp)
21 #define ARG_FLOAT_TWO		-8(%rsp)
22 
23 #define XMM_ONE_ARG_DOUBLE_PROLOGUE \
24 	movsd	%xmm0, ARG_DOUBLE_ONE
25 
26 #define XMM_TWO_ARG_DOUBLE_PROLOGUE \
27 	movsd	%xmm0, ARG_DOUBLE_ONE ; \
28 	movsd	%xmm1, ARG_DOUBLE_TWO
29 
30 #define XMM_ONE_ARG_FLOAT_PROLOGUE \
31 	movss	%xmm0, ARG_FLOAT_ONE
32 
33 #define XMM_TWO_ARG_FLOAT_PROLOGUE \
34 	movss	%xmm0, ARG_FLOAT_ONE ; \
35 	movss	%xmm1, ARG_FLOAT_TWO
36 
37 #define XMM_DOUBLE_EPILOGUE \
38 	fstpl ARG_DOUBLE_ONE ; \
39 	movsd ARG_DOUBLE_ONE, %xmm0
40 
41 #define XMM_FLOAT_EPILOGUE \
42 	fstps ARG_FLOAT_ONE ; \
43 	movss ARG_FLOAT_ONE, %xmm0
44 
45 #define FLDL_VAR(x)	fldl x(%rip)
46 
47 
48 /*
49  * We define a hidden alias with the prefix "_libm_" for each global symbol
50  * that may be used internally.  By referencing _libm_x instead of x, other
51  * parts of libm prevent overriding by the application and avoid unnecessary
52  * relocations.
53  */
54 #define _HIDDEN(x)		_libm_##x
55 #define _HIDDEN_ALIAS(x,y)			\
56 	STRONG_ALIAS(_HIDDEN(x),y);		\
57 	.hidden _HIDDEN(x)
58 #define _HIDDEN_FALIAS(x,y)			\
59 	_HIDDEN_ALIAS(x,y);			\
60 	.type _HIDDEN(x),@function
61 
62 /*
63  * For functions implemented in ASM that are used internally
64  *   END_STD(x)	Like DEF_STD() in C; for standard/reserved C names
65  *   END_NONSTD(x)	Like DEF_NONSTD() in C; for non-ISO C names
66  */
67 #define	END_STD(x)	END(x); _HIDDEN_FALIAS(x,x); END(_HIDDEN(x))
68 #define	END_NONSTD(x)	END_STD(x); .weak x
69