xref: /illumos-gate/usr/src/lib/libm/common/C/libm.h (revision ddc0e0b5)
125c28e83SPiotr Jasiukajtis /*
225c28e83SPiotr Jasiukajtis  * CDDL HEADER START
325c28e83SPiotr Jasiukajtis  *
425c28e83SPiotr Jasiukajtis  * The contents of this file are subject to the terms of the
525c28e83SPiotr Jasiukajtis  * Common Development and Distribution License (the "License").
625c28e83SPiotr Jasiukajtis  * You may not use this file except in compliance with the License.
725c28e83SPiotr Jasiukajtis  *
825c28e83SPiotr Jasiukajtis  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
925c28e83SPiotr Jasiukajtis  * or http://www.opensolaris.org/os/licensing.
1025c28e83SPiotr Jasiukajtis  * See the License for the specific language governing permissions
1125c28e83SPiotr Jasiukajtis  * and limitations under the License.
1225c28e83SPiotr Jasiukajtis  *
1325c28e83SPiotr Jasiukajtis  * When distributing Covered Code, include this CDDL HEADER in each
1425c28e83SPiotr Jasiukajtis  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1525c28e83SPiotr Jasiukajtis  * If applicable, add the following below this CDDL HEADER, with the
1625c28e83SPiotr Jasiukajtis  * fields enclosed by brackets "[]" replaced with your own identifying
1725c28e83SPiotr Jasiukajtis  * information: Portions Copyright [yyyy] [name of copyright owner]
1825c28e83SPiotr Jasiukajtis  *
1925c28e83SPiotr Jasiukajtis  * CDDL HEADER END
2025c28e83SPiotr Jasiukajtis  */
2125c28e83SPiotr Jasiukajtis /*
2225c28e83SPiotr Jasiukajtis  * Copyright 2011 Nexenta Systems, Inc.  All rights reserved.
2325c28e83SPiotr Jasiukajtis  */
2425c28e83SPiotr Jasiukajtis /*
2525c28e83SPiotr Jasiukajtis  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
2625c28e83SPiotr Jasiukajtis  * Use is subject to license terms.
2725c28e83SPiotr Jasiukajtis  */
2825c28e83SPiotr Jasiukajtis 
2925c28e83SPiotr Jasiukajtis #ifndef	_LIBM_H
3025c28e83SPiotr Jasiukajtis #define	_LIBM_H
3125c28e83SPiotr Jasiukajtis 
3225c28e83SPiotr Jasiukajtis #include <sys/isa_defs.h>
3325c28e83SPiotr Jasiukajtis 
3425c28e83SPiotr Jasiukajtis #ifdef _ASM
3525c28e83SPiotr Jasiukajtis /* BEGIN CSTYLED */
3625c28e83SPiotr Jasiukajtis 
3725c28e83SPiotr Jasiukajtis /*
3825c28e83SPiotr Jasiukajtis  * Disable amd64 assembly code profiling for now.
3925c28e83SPiotr Jasiukajtis  */
4025c28e83SPiotr Jasiukajtis #if defined(__amd64)
4125c28e83SPiotr Jasiukajtis #undef PROF
4225c28e83SPiotr Jasiukajtis #endif
4325c28e83SPiotr Jasiukajtis 
4425c28e83SPiotr Jasiukajtis #include <sys/asm_linkage.h>
4525c28e83SPiotr Jasiukajtis 
4625c28e83SPiotr Jasiukajtis #define	NAME(x) x
4725c28e83SPiotr Jasiukajtis #define	TEXT	.section	".text"
4825c28e83SPiotr Jasiukajtis #define	DATA	.section	".data"
4925c28e83SPiotr Jasiukajtis #define	RO_DATA	.section	".rodata"
5025c28e83SPiotr Jasiukajtis #define	IDENT(x)	.ident	x
5125c28e83SPiotr Jasiukajtis 
5225c28e83SPiotr Jasiukajtis #if defined(__sparc)
5325c28e83SPiotr Jasiukajtis 
5425c28e83SPiotr Jasiukajtis #define	LIBM_ANSI_PRAGMA_WEAK(sym,stype) \
55*ddc0e0b5SRichard Lowe 	.weak __/**/sym;		 \
56*ddc0e0b5SRichard Lowe 	.type __/**/sym,#stype;		 \
57*ddc0e0b5SRichard Lowe __/**/sym	= sym
5825c28e83SPiotr Jasiukajtis 
5925c28e83SPiotr Jasiukajtis #ifndef SET_FILE
6025c28e83SPiotr Jasiukajtis #define	SET_FILE(x) \
6125c28e83SPiotr Jasiukajtis 	.file	x
6225c28e83SPiotr Jasiukajtis #endif	/* !defined(SET_FILE) */
6325c28e83SPiotr Jasiukajtis 
6425c28e83SPiotr Jasiukajtis #ifdef PIC
6525c28e83SPiotr Jasiukajtis /*
6625c28e83SPiotr Jasiukajtis  * One should *never* pass o7 to PIC_SETUP.
6725c28e83SPiotr Jasiukajtis  */
6825c28e83SPiotr Jasiukajtis #define	PIC_SETUP(via) \
6925c28e83SPiotr Jasiukajtis 9:	call	8f; \
7025c28e83SPiotr Jasiukajtis 	sethi	%hi(NAME(_GLOBAL_OFFSET_TABLE_)-(9b-.)),%via; \
7125c28e83SPiotr Jasiukajtis 8:	or	%via,%lo(NAME(_GLOBAL_OFFSET_TABLE_)-(9b-.)),%via; \
7225c28e83SPiotr Jasiukajtis 	add	%via,%o7,%via
7325c28e83SPiotr Jasiukajtis /*
7425c28e83SPiotr Jasiukajtis  * Must save/restore %o7 in leaf routines; may *not* use jmpl!
7525c28e83SPiotr Jasiukajtis  */
7625c28e83SPiotr Jasiukajtis #define	PIC_LEAF_SETUP(via) \
7725c28e83SPiotr Jasiukajtis 	or	%g0,%o7,%g1; \
7825c28e83SPiotr Jasiukajtis 9:	call	8f; \
7925c28e83SPiotr Jasiukajtis 	sethi	%hi(NAME(_GLOBAL_OFFSET_TABLE_)-(9b-.)),%via; \
8025c28e83SPiotr Jasiukajtis 8:	or	%via,%lo(NAME(_GLOBAL_OFFSET_TABLE_)-(9b-.)),%via; \
8125c28e83SPiotr Jasiukajtis 	add	%via,%o7,%via; \
8225c28e83SPiotr Jasiukajtis 	or	%g0,%g1,%o7
8325c28e83SPiotr Jasiukajtis #ifdef __sparcv9
8425c28e83SPiotr Jasiukajtis #define	PIC_SET(via,sym,dst)	ldx	[%via+sym],%dst
8525c28e83SPiotr Jasiukajtis #else	/* defined(__sparcv9) */
8625c28e83SPiotr Jasiukajtis #define	PIC_SET(via,sym,dst)	ld	[%via+sym],%dst
8725c28e83SPiotr Jasiukajtis #endif	/* defined(__sparcv9) */
8825c28e83SPiotr Jasiukajtis #else	/* defined(PIC) */
8925c28e83SPiotr Jasiukajtis #define	PIC_SETUP(via)
9025c28e83SPiotr Jasiukajtis #define	PIC_LEAF_SETUP(via)
9125c28e83SPiotr Jasiukajtis #ifdef __sparcv9
9225c28e83SPiotr Jasiukajtis /*
9325c28e83SPiotr Jasiukajtis  * g1 is used as scratch register in V9 mode
9425c28e83SPiotr Jasiukajtis  */
9525c28e83SPiotr Jasiukajtis #define	PIC_SET(via,sym,dst)	setx	sym,%g1,%dst
9625c28e83SPiotr Jasiukajtis #else	/* defined(__sparcv9) */
9725c28e83SPiotr Jasiukajtis #define	PIC_SET(via,sym,dst)	set	sym,%dst
9825c28e83SPiotr Jasiukajtis #endif	/* defined(__sparcv9) */
9925c28e83SPiotr Jasiukajtis #endif	/* defined(PIC) */
10025c28e83SPiotr Jasiukajtis 
10125c28e83SPiotr Jasiukajtis /*
10225c28e83SPiotr Jasiukajtis  * Workaround for 4337025: MCOUNT in asm_linkage.h does not support __sparcv9
10325c28e83SPiotr Jasiukajtis  */
10425c28e83SPiotr Jasiukajtis #if defined(PROF) && defined(__sparcv9)
10525c28e83SPiotr Jasiukajtis 
10625c28e83SPiotr Jasiukajtis #undef MCOUNT_SIZE
10725c28e83SPiotr Jasiukajtis #undef MCOUNT
10825c28e83SPiotr Jasiukajtis 
10925c28e83SPiotr Jasiukajtis #if !defined(PIC)
11025c28e83SPiotr Jasiukajtis #define	MCOUNT_SIZE	(9*4)	/* 9 instructions */
11125c28e83SPiotr Jasiukajtis #define	MCOUNT(x) \
11225c28e83SPiotr Jasiukajtis 	save	%sp, -SA(MINFRAME), %sp; \
11325c28e83SPiotr Jasiukajtis 	sethi	%hh(.L_/**/x/**/1), %o0; \
11425c28e83SPiotr Jasiukajtis 	sethi	%lm(.L_/**/x/**/1), %o1; \
11525c28e83SPiotr Jasiukajtis 	or	%o0, %hm(.L_/**/x/**/1), %o0; \
11625c28e83SPiotr Jasiukajtis 	or	%o1, %lo(.L_/**/x/**/1), %o1; \
11725c28e83SPiotr Jasiukajtis 	sllx	%o0, 32, %o0; \
11825c28e83SPiotr Jasiukajtis 	call	_mcount; \
11925c28e83SPiotr Jasiukajtis 	or	%o0, %o1, %o0; \
12025c28e83SPiotr Jasiukajtis 	restore; \
12125c28e83SPiotr Jasiukajtis 	.common .L_/**/x/**/1, 8, 8
12225c28e83SPiotr Jasiukajtis #elif defined(PIC32)
12325c28e83SPiotr Jasiukajtis #define	MCOUNT_SIZE	(10*4)	/* 10 instructions */
12425c28e83SPiotr Jasiukajtis #define	MCOUNT(x) \
12525c28e83SPiotr Jasiukajtis 	save	%sp,-SA(MINFRAME),%sp; \
12625c28e83SPiotr Jasiukajtis 1:	call	.+8; \
12725c28e83SPiotr Jasiukajtis 	sethi	%hi(_GLOBAL_OFFSET_TABLE_-(1b-.)),%o0; \
12825c28e83SPiotr Jasiukajtis 	sethi	%hi(.L_/**/x/**/1),%o1; \
12925c28e83SPiotr Jasiukajtis 	add	%o0,%lo(_GLOBAL_OFFSET_TABLE_-(1b-.)),%o0; \
13025c28e83SPiotr Jasiukajtis 	add	%o1,%lo(.L_/**/x/**/1),%o1; \
13125c28e83SPiotr Jasiukajtis 	add	%o0,%o7,%o0; \
13225c28e83SPiotr Jasiukajtis 	call	_mcount; \
13325c28e83SPiotr Jasiukajtis 	ldx	[%o0+%o1],%o0; \
13425c28e83SPiotr Jasiukajtis 	restore; \
13525c28e83SPiotr Jasiukajtis 	.common .L_/**/x/**/1,8,8
13625c28e83SPiotr Jasiukajtis #else	/* PIC13 */
13725c28e83SPiotr Jasiukajtis #define	MCOUNT_SIZE	(8*4)	/* 8 instructions */
13825c28e83SPiotr Jasiukajtis #define	MCOUNT(x) \
13925c28e83SPiotr Jasiukajtis 	save	%sp,-SA(MINFRAME),%sp; \
14025c28e83SPiotr Jasiukajtis 1:	call	.+8; \
14125c28e83SPiotr Jasiukajtis 	sethi	%hi(_GLOBAL_OFFSET_TABLE_-(1b-.)),%o0; \
14225c28e83SPiotr Jasiukajtis 	add	%o0,%lo(_GLOBAL_OFFSET_TABLE_-(1b-.)),%o0; \
14325c28e83SPiotr Jasiukajtis 	add	%o0,%o7,%o0; \
14425c28e83SPiotr Jasiukajtis 	call	_mcount; \
14525c28e83SPiotr Jasiukajtis 	ldx	[%o0+%lo(.L_/**/x/**/1)],%o0; \
14625c28e83SPiotr Jasiukajtis 	restore; \
14725c28e83SPiotr Jasiukajtis 	.common .L_/**/x/**/1,8,8
14825c28e83SPiotr Jasiukajtis #endif	/* !defined(PIC) */
14925c28e83SPiotr Jasiukajtis #endif /* defined(PROF) && defined(__sparcv9) */
15025c28e83SPiotr Jasiukajtis 
15125c28e83SPiotr Jasiukajtis #elif defined(__x86)
15225c28e83SPiotr Jasiukajtis 
15325c28e83SPiotr Jasiukajtis #define	LIBM_ANSI_PRAGMA_WEAK(sym,stype) \
154*ddc0e0b5SRichard Lowe 	.weak __/**/sym;		 \
155*ddc0e0b5SRichard Lowe 	.type __/**/sym,@stype;		 \
156*ddc0e0b5SRichard Lowe __/**/sym	= sym
15725c28e83SPiotr Jasiukajtis 
15825c28e83SPiotr Jasiukajtis #ifdef PIC
15925c28e83SPiotr Jasiukajtis #if defined(__amd64)
16025c28e83SPiotr Jasiukajtis #define	PIC_SETUP(x)
16125c28e83SPiotr Jasiukajtis #define	PIC_WRAPUP
16225c28e83SPiotr Jasiukajtis #define	PIC_F(x)	x@PLT
16325c28e83SPiotr Jasiukajtis #define	PIC_G(x)	x@GOTPCREL(%rip)
16425c28e83SPiotr Jasiukajtis #define	PIC_L(x)	x(%rip)
16525c28e83SPiotr Jasiukajtis #define	PIC_G_LOAD(insn,sym,dst) \
16625c28e83SPiotr Jasiukajtis 	movq	PIC_G(sym),%dst; \
16725c28e83SPiotr Jasiukajtis 	insn	(%dst),%dst
16825c28e83SPiotr Jasiukajtis #else
16925c28e83SPiotr Jasiukajtis #define	PIC_SETUP(label) \
17025c28e83SPiotr Jasiukajtis 	pushl	%ebx; \
17125c28e83SPiotr Jasiukajtis 	call	.label; \
17225c28e83SPiotr Jasiukajtis .label:	popl	%ebx; \
17325c28e83SPiotr Jasiukajtis 	addl	$_GLOBAL_OFFSET_TABLE_+[.-.label],%ebx
17425c28e83SPiotr Jasiukajtis #define	PIC_WRAPUP	popl	%ebx
17525c28e83SPiotr Jasiukajtis #define	PIC_F(x)	x@PLT
17625c28e83SPiotr Jasiukajtis #define	PIC_G(x)	x@GOT(%ebx)
17725c28e83SPiotr Jasiukajtis #define	PIC_L(x)	x@GOTOFF(%ebx)
17825c28e83SPiotr Jasiukajtis #define	PIC_G_LOAD(insn,sym,dst) \
17925c28e83SPiotr Jasiukajtis 	mov	PIC_G(sym),%dst; \
18025c28e83SPiotr Jasiukajtis 	insn	(%dst),%dst
18125c28e83SPiotr Jasiukajtis #endif
18225c28e83SPiotr Jasiukajtis #else	/* defined(PIC) */
18325c28e83SPiotr Jasiukajtis #define	PIC_SETUP(x)
18425c28e83SPiotr Jasiukajtis #define	PIC_WRAPUP
18525c28e83SPiotr Jasiukajtis #define	PIC_F(x)	x
18625c28e83SPiotr Jasiukajtis #define	PIC_G(x)	x
18725c28e83SPiotr Jasiukajtis #define	PIC_L(x)	x
18825c28e83SPiotr Jasiukajtis #define	PIC_G_LOAD(insn,sym,dst)	insn	sym,%dst
18925c28e83SPiotr Jasiukajtis #endif	/* defined(PIC) */
19025c28e83SPiotr Jasiukajtis 
19125c28e83SPiotr Jasiukajtis #else
19225c28e83SPiotr Jasiukajtis #error Unknown architecture
19325c28e83SPiotr Jasiukajtis #endif
19425c28e83SPiotr Jasiukajtis 
19525c28e83SPiotr Jasiukajtis /* END CSTYLED */
19625c28e83SPiotr Jasiukajtis #else	/* defined(_ASM) */
19725c28e83SPiotr Jasiukajtis 
19825c28e83SPiotr Jasiukajtis #include "libm_macros.h"
19925c28e83SPiotr Jasiukajtis #include "libm_protos.h"
20025c28e83SPiotr Jasiukajtis #include "libm_inlines.h"
20125c28e83SPiotr Jasiukajtis #include <math.h>
20225c28e83SPiotr Jasiukajtis #if defined(__SUNPRO_C)
20325c28e83SPiotr Jasiukajtis #include <sunmath.h>
20425c28e83SPiotr Jasiukajtis #endif
20525c28e83SPiotr Jasiukajtis 
20625c28e83SPiotr Jasiukajtis #endif	/* defined(_ASM) */
20725c28e83SPiotr Jasiukajtis 
20825c28e83SPiotr Jasiukajtis #endif	/* _LIBM_H */