xref: /illumos-gate/usr/src/lib/libc/inc/base_inlines.h (revision 6a3e8e86)
10ec57554Sraf /*
20ec57554Sraf  * CDDL HEADER START
30ec57554Sraf  *
40ec57554Sraf  * The contents of this file are subject to the terms of the
50ec57554Sraf  * Common Development and Distribution License (the "License").
60ec57554Sraf  * You may not use this file except in compliance with the License.
70ec57554Sraf  *
80ec57554Sraf  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90ec57554Sraf  * or http://www.opensolaris.org/os/licensing.
100ec57554Sraf  * See the License for the specific language governing permissions
110ec57554Sraf  * and limitations under the License.
120ec57554Sraf  *
130ec57554Sraf  * When distributing Covered Code, include this CDDL HEADER in each
140ec57554Sraf  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150ec57554Sraf  * If applicable, add the following below this CDDL HEADER, with the
160ec57554Sraf  * fields enclosed by brackets "[]" replaced with your own identifying
170ec57554Sraf  * information: Portions Copyright [yyyy] [name of copyright owner]
180ec57554Sraf  *
190ec57554Sraf  * CDDL HEADER END
200ec57554Sraf  */
210ec57554Sraf 
220ec57554Sraf /*
230ec57554Sraf  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
240ec57554Sraf  * Use is subject to license terms.
250ec57554Sraf  */
260ec57554Sraf 
270ec57554Sraf #ifndef	_BASE_INLINES_H
280ec57554Sraf #define	_BASE_INLINES_H
290ec57554Sraf 
30*6a3e8e86SRichard Lowe #include <sys/ccompile.h>
310ec57554Sraf #include <sys/types.h>
320ec57554Sraf 
330ec57554Sraf #if !defined(__lint) && defined(__GNUC__)
340ec57554Sraf 
350ec57554Sraf /*
360ec57554Sraf  * This file is intended to contain gcc-style inline assembly that corresponds
370ec57554Sraf  * to base.il for all architectures.  At the moment these inlines exist only
380ec57554Sraf  * for sparc and sparcv9 and these functions are implemented in C for x86.
390ec57554Sraf  * They should be inlined here for gcc if a new x86 base.il is created.
400ec57554Sraf  */
410ec57554Sraf 
420ec57554Sraf #if defined(__sparc)
43*6a3e8e86SRichard Lowe extern __GNU_INLINE double
440ec57554Sraf __mul_set(double x, double y, int *pe)
450ec57554Sraf {
460ec57554Sraf 	double __result;
470ec57554Sraf 	uint32_t __fsr;
480ec57554Sraf 	uint32_t *__addr = &__fsr;
490ec57554Sraf 
500ec57554Sraf 	__asm__ __volatile__(
51*6a3e8e86SRichard Lowe 	    "fmuld %4, %5, %0\n\t"
52*6a3e8e86SRichard Lowe 	    "st %%fsr, %3\n\t"
53*6a3e8e86SRichard Lowe 	    "ld %3, %2\n\t"
54*6a3e8e86SRichard Lowe 	    "and %2, 1, %2\n\t"
55*6a3e8e86SRichard Lowe 	    "st %2, %1"
56*6a3e8e86SRichard Lowe 	    : "=&e" (__result), "=m" (*pe), "=r" (__fsr), "=m" (*__addr)
57*6a3e8e86SRichard Lowe 	    : "e" (x), "e" (y));
580ec57554Sraf 	return (__result);
590ec57554Sraf }
600ec57554Sraf #endif	/* __sparc */
610ec57554Sraf 
620ec57554Sraf #if defined(__sparc)
63*6a3e8e86SRichard Lowe extern __GNU_INLINE double
640ec57554Sraf __div_set(double x, double y, int *pe)
650ec57554Sraf {
660ec57554Sraf 	double __result;
670ec57554Sraf 	uint32_t __fsr;
680ec57554Sraf 	uint32_t *__addr = &__fsr;
690ec57554Sraf 
700ec57554Sraf 	__asm__ __volatile__(
71*6a3e8e86SRichard Lowe 	    "fdivd %4, %5, %0\n\t"
72*6a3e8e86SRichard Lowe 	    "st %%fsr, %3\n\t"
73*6a3e8e86SRichard Lowe 	    "ld %3, %2\n\t"
74*6a3e8e86SRichard Lowe 	    "and %2, 1, %2\n\t"
75*6a3e8e86SRichard Lowe 	    "st %2, %1"
76*6a3e8e86SRichard Lowe 	    : "=&e" (__result), "=m" (*pe), "=r" (__fsr), "=m" (*__addr)
77*6a3e8e86SRichard Lowe 	    : "e" (x), "e" (y));
780ec57554Sraf 	return (__result);
790ec57554Sraf }
800ec57554Sraf #endif	/* __sparc */
810ec57554Sraf 
820ec57554Sraf #if defined(__sparc)
83*6a3e8e86SRichard Lowe extern __GNU_INLINE double
840ec57554Sraf __dabs(double *x)
850ec57554Sraf {
860ec57554Sraf 	double __result;
870ec57554Sraf 
880ec57554Sraf 	__asm__ __volatile__(
890ec57554Sraf #if defined(__sparcv9)
90*6a3e8e86SRichard Lowe 	    "fabsd %1, %0"
910ec57554Sraf #else
92*6a3e8e86SRichard Lowe 	    "fabss %1, %0"
930ec57554Sraf #endif
94*6a3e8e86SRichard Lowe 	    : "=e" (__result)
95*6a3e8e86SRichard Lowe 	    : "0" (*x));
960ec57554Sraf 	return (__result);
970ec57554Sraf }
980ec57554Sraf #endif	/* __sparc */
990ec57554Sraf 
1000ec57554Sraf #if defined(__sparc)
101*6a3e8e86SRichard Lowe extern  __GNU_INLINE void
1020ec57554Sraf __get_ieee_flags(__ieee_flags_type *b)
1030ec57554Sraf {
1040ec57554Sraf 	uint32_t __fsr;
1050ec57554Sraf 
1060ec57554Sraf 	/*
1070ec57554Sraf 	 * It's preferable to let the assembler insert the nops as
1080ec57554Sraf 	 * needed; however, it warns as it does so.  Add them here for now.
1090ec57554Sraf 	 */
1100ec57554Sraf 	__asm__ __volatile__(
111*6a3e8e86SRichard Lowe 	    "st %%fsr, %0\n\t"
112*6a3e8e86SRichard Lowe 	    "st %%g0, %1\n\t"
113*6a3e8e86SRichard Lowe 	    "ld %1, %%fsr\n\t"
114*6a3e8e86SRichard Lowe 	    "nop; nop; nop"
115*6a3e8e86SRichard Lowe 	    : "=m" (*b), "=m" (__fsr));
1160ec57554Sraf }
1170ec57554Sraf #endif	/* __sparc */
1180ec57554Sraf 
1190ec57554Sraf #if defined(__sparc)
120*6a3e8e86SRichard Lowe extern __GNU_INLINE void
1210ec57554Sraf __set_ieee_flags(__ieee_flags_type *b)
1220ec57554Sraf {
1230ec57554Sraf 	/*
1240ec57554Sraf 	 * It's preferable to let the assembler insert the nops as
1250ec57554Sraf 	 * needed; however, it warns as it does so.  Add them here for now.
1260ec57554Sraf 	 */
1270ec57554Sraf 	__asm__ __volatile__(
128*6a3e8e86SRichard Lowe 	    "ld %0, %%fsr\n\t"
129*6a3e8e86SRichard Lowe 	    "nop; nop; nop"
130*6a3e8e86SRichard Lowe 	    : /* no outputs */
131*6a3e8e86SRichard Lowe 	    : "m" (*b));
1320ec57554Sraf }
1330ec57554Sraf #endif	/* __sparc */
1340ec57554Sraf 
1350ec57554Sraf #endif	/* !__lint && __GNUC__ */
1360ec57554Sraf 
1370ec57554Sraf #endif	/* _BASE_INLINES_H */
138