xref: /titanic_50/usr/src/lib/libm/common/C/libm.h (revision 1886f67eb9de99edbcda88765f2c603a30c87fc2)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
23  */
24 /*
25  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms.
27  */
28 
29 #ifndef	_LIBM_H
30 #define	_LIBM_H
31 
32 #include <sys/isa_defs.h>
33 
34 #ifdef _ASM
35 /* BEGIN CSTYLED */
36 
37 /*
38  * Disable amd64 assembly code profiling for now.
39  */
40 #if defined(__amd64)
41 #undef PROF
42 #endif
43 
44 #include <sys/asm_linkage.h>
45 
46 #define	NAME(x) x
47 #define	TEXT	.section	".text"
48 #define	DATA	.section	".data"
49 #define	RO_DATA	.section	".rodata"
50 #define	IDENT(x)	.ident	x
51 
52 #if defined(__sparc)
53 
54 #define	LIBM_ANSI_PRAGMA_WEAK(sym,stype) \
55 	.weak __/**/sym;		 \
56 	.type __/**/sym,#stype;		 \
57 __/**/sym	= sym
58 
59 #ifndef SET_FILE
60 #define	SET_FILE(x) \
61 	.file	x
62 #endif	/* !defined(SET_FILE) */
63 
64 #ifdef PIC
65 /*
66  * One should *never* pass o7 to PIC_SETUP.
67  */
68 #define	PIC_SETUP(via) \
69 9:	call	8f; \
70 	sethi	%hi(NAME(_GLOBAL_OFFSET_TABLE_)-(9b-.)),%via; \
71 8:	or	%via,%lo(NAME(_GLOBAL_OFFSET_TABLE_)-(9b-.)),%via; \
72 	add	%via,%o7,%via
73 /*
74  * Must save/restore %o7 in leaf routines; may *not* use jmpl!
75  */
76 #define	PIC_LEAF_SETUP(via) \
77 	or	%g0,%o7,%g1; \
78 9:	call	8f; \
79 	sethi	%hi(NAME(_GLOBAL_OFFSET_TABLE_)-(9b-.)),%via; \
80 8:	or	%via,%lo(NAME(_GLOBAL_OFFSET_TABLE_)-(9b-.)),%via; \
81 	add	%via,%o7,%via; \
82 	or	%g0,%g1,%o7
83 #ifdef __sparcv9
84 #define	PIC_SET(via,sym,dst)	ldx	[%via+sym],%dst
85 #else	/* defined(__sparcv9) */
86 #define	PIC_SET(via,sym,dst)	ld	[%via+sym],%dst
87 #endif	/* defined(__sparcv9) */
88 #else	/* defined(PIC) */
89 #define	PIC_SETUP(via)
90 #define	PIC_LEAF_SETUP(via)
91 #ifdef __sparcv9
92 /*
93  * g1 is used as scratch register in V9 mode
94  */
95 #define	PIC_SET(via,sym,dst)	setx	sym,%g1,%dst
96 #else	/* defined(__sparcv9) */
97 #define	PIC_SET(via,sym,dst)	set	sym,%dst
98 #endif	/* defined(__sparcv9) */
99 #endif	/* defined(PIC) */
100 
101 /*
102  * Workaround for 4337025: MCOUNT in asm_linkage.h does not support __sparcv9
103  */
104 #if defined(PROF) && defined(__sparcv9)
105 
106 #undef MCOUNT_SIZE
107 #undef MCOUNT
108 
109 #if !defined(PIC)
110 #define	MCOUNT_SIZE	(9*4)	/* 9 instructions */
111 #define	MCOUNT(x) \
112 	save	%sp, -SA(MINFRAME), %sp; \
113 	sethi	%hh(.L_/**/x/**/1), %o0; \
114 	sethi	%lm(.L_/**/x/**/1), %o1; \
115 	or	%o0, %hm(.L_/**/x/**/1), %o0; \
116 	or	%o1, %lo(.L_/**/x/**/1), %o1; \
117 	sllx	%o0, 32, %o0; \
118 	call	_mcount; \
119 	or	%o0, %o1, %o0; \
120 	restore; \
121 	.common .L_/**/x/**/1, 8, 8
122 #elif defined(PIC32)
123 #define	MCOUNT_SIZE	(10*4)	/* 10 instructions */
124 #define	MCOUNT(x) \
125 	save	%sp,-SA(MINFRAME),%sp; \
126 1:	call	.+8; \
127 	sethi	%hi(_GLOBAL_OFFSET_TABLE_-(1b-.)),%o0; \
128 	sethi	%hi(.L_/**/x/**/1),%o1; \
129 	add	%o0,%lo(_GLOBAL_OFFSET_TABLE_-(1b-.)),%o0; \
130 	add	%o1,%lo(.L_/**/x/**/1),%o1; \
131 	add	%o0,%o7,%o0; \
132 	call	_mcount; \
133 	ldx	[%o0+%o1],%o0; \
134 	restore; \
135 	.common .L_/**/x/**/1,8,8
136 #else	/* PIC13 */
137 #define	MCOUNT_SIZE	(8*4)	/* 8 instructions */
138 #define	MCOUNT(x) \
139 	save	%sp,-SA(MINFRAME),%sp; \
140 1:	call	.+8; \
141 	sethi	%hi(_GLOBAL_OFFSET_TABLE_-(1b-.)),%o0; \
142 	add	%o0,%lo(_GLOBAL_OFFSET_TABLE_-(1b-.)),%o0; \
143 	add	%o0,%o7,%o0; \
144 	call	_mcount; \
145 	ldx	[%o0+%lo(.L_/**/x/**/1)],%o0; \
146 	restore; \
147 	.common .L_/**/x/**/1,8,8
148 #endif	/* !defined(PIC) */
149 #endif /* defined(PROF) && defined(__sparcv9) */
150 
151 #elif defined(__x86)
152 
153 #define	LIBM_ANSI_PRAGMA_WEAK(sym,stype) \
154 	.weak __/**/sym;		 \
155 	.type __/**/sym,@stype;		 \
156 __/**/sym	= sym
157 
158 #ifdef PIC
159 #if defined(__amd64)
160 #define	PIC_SETUP(x)
161 #define	PIC_WRAPUP
162 #define	PIC_F(x)	x@PLT
163 #define	PIC_G(x)	x@GOTPCREL(%rip)
164 #define	PIC_L(x)	x(%rip)
165 #define	PIC_G_LOAD(insn,sym,dst) \
166 	movq	PIC_G(sym),%dst; \
167 	insn	(%dst),%dst
168 #else
169 #define	PIC_SETUP(label) \
170 	pushl	%ebx; \
171 	call	.label; \
172 .label:	popl	%ebx; \
173 	addl	$_GLOBAL_OFFSET_TABLE_+[.-.label],%ebx
174 #define	PIC_WRAPUP	popl	%ebx
175 #define	PIC_F(x)	x@PLT
176 #define	PIC_G(x)	x@GOT(%ebx)
177 #define	PIC_L(x)	x@GOTOFF(%ebx)
178 #define	PIC_G_LOAD(insn,sym,dst) \
179 	mov	PIC_G(sym),%dst; \
180 	insn	(%dst),%dst
181 #endif
182 #else	/* defined(PIC) */
183 #define	PIC_SETUP(x)
184 #define	PIC_WRAPUP
185 #define	PIC_F(x)	x
186 #define	PIC_G(x)	x
187 #define	PIC_L(x)	x
188 #define	PIC_G_LOAD(insn,sym,dst)	insn	sym,%dst
189 #endif	/* defined(PIC) */
190 
191 #else
192 #error Unknown architecture
193 #endif
194 
195 /* END CSTYLED */
196 #else	/* defined(_ASM) */
197 
198 #include "libm_macros.h"
199 #include "libm_protos.h"
200 #include "libm_inlines.h"
201 #include <math.h>
202 #if defined(__SUNPRO_C)
203 #include <sunmath.h>
204 #endif
205 
206 #endif	/* defined(_ASM) */
207 
208 #endif	/* _LIBM_H */
209