xref: /illumos-gate/usr/src/lib/libc/inc/base_inlines.h (revision 564d5236)
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 
306a3e8e86SRichard Lowe #include <sys/ccompile.h>
310ec57554Sraf #include <sys/types.h>
320ec57554Sraf 
330ec57554Sraf #if !defined(__lint) && defined(__GNUC__)
340ec57554Sraf 
350ec57554Sraf /*
36*564d5236SRichard Lowe  * At the moment these inlines exist only for sparc and sparcv9 and these
37*564d5236SRichard Lowe  * functions are implemented in C for x86.
380ec57554Sraf  */
390ec57554Sraf 
400ec57554Sraf #if defined(__sparc)
416a3e8e86SRichard Lowe extern __GNU_INLINE double
__mul_set(double x,double y,int * pe)420ec57554Sraf __mul_set(double x, double y, int *pe)
430ec57554Sraf {
440ec57554Sraf 	double __result;
450ec57554Sraf 	uint32_t __fsr;
460ec57554Sraf 	uint32_t *__addr = &__fsr;
470ec57554Sraf 
480ec57554Sraf 	__asm__ __volatile__(
496a3e8e86SRichard Lowe 	    "fmuld %4, %5, %0\n\t"
506a3e8e86SRichard Lowe 	    "st %%fsr, %3\n\t"
516a3e8e86SRichard Lowe 	    "ld %3, %2\n\t"
526a3e8e86SRichard Lowe 	    "and %2, 1, %2\n\t"
536a3e8e86SRichard Lowe 	    "st %2, %1"
546a3e8e86SRichard Lowe 	    : "=&e" (__result), "=m" (*pe), "=r" (__fsr), "=m" (*__addr)
556a3e8e86SRichard Lowe 	    : "e" (x), "e" (y));
560ec57554Sraf 	return (__result);
570ec57554Sraf }
580ec57554Sraf #endif	/* __sparc */
590ec57554Sraf 
600ec57554Sraf #if defined(__sparc)
616a3e8e86SRichard Lowe extern __GNU_INLINE double
__div_set(double x,double y,int * pe)620ec57554Sraf __div_set(double x, double y, int *pe)
630ec57554Sraf {
640ec57554Sraf 	double __result;
650ec57554Sraf 	uint32_t __fsr;
660ec57554Sraf 	uint32_t *__addr = &__fsr;
670ec57554Sraf 
680ec57554Sraf 	__asm__ __volatile__(
696a3e8e86SRichard Lowe 	    "fdivd %4, %5, %0\n\t"
706a3e8e86SRichard Lowe 	    "st %%fsr, %3\n\t"
716a3e8e86SRichard Lowe 	    "ld %3, %2\n\t"
726a3e8e86SRichard Lowe 	    "and %2, 1, %2\n\t"
736a3e8e86SRichard Lowe 	    "st %2, %1"
746a3e8e86SRichard Lowe 	    : "=&e" (__result), "=m" (*pe), "=r" (__fsr), "=m" (*__addr)
756a3e8e86SRichard Lowe 	    : "e" (x), "e" (y));
760ec57554Sraf 	return (__result);
770ec57554Sraf }
780ec57554Sraf #endif	/* __sparc */
790ec57554Sraf 
800ec57554Sraf #if defined(__sparc)
816a3e8e86SRichard Lowe extern __GNU_INLINE double
__dabs(double * x)820ec57554Sraf __dabs(double *x)
830ec57554Sraf {
840ec57554Sraf 	double __result;
850ec57554Sraf 
860ec57554Sraf 	__asm__ __volatile__(
870ec57554Sraf #if defined(__sparcv9)
886a3e8e86SRichard Lowe 	    "fabsd %1, %0"
890ec57554Sraf #else
906a3e8e86SRichard Lowe 	    "fabss %1, %0"
910ec57554Sraf #endif
926a3e8e86SRichard Lowe 	    : "=e" (__result)
936a3e8e86SRichard Lowe 	    : "0" (*x));
940ec57554Sraf 	return (__result);
950ec57554Sraf }
960ec57554Sraf #endif	/* __sparc */
970ec57554Sraf 
980ec57554Sraf #if defined(__sparc)
996a3e8e86SRichard Lowe extern  __GNU_INLINE void
__get_ieee_flags(__ieee_flags_type * b)1000ec57554Sraf __get_ieee_flags(__ieee_flags_type *b)
1010ec57554Sraf {
1020ec57554Sraf 	uint32_t __fsr;
1030ec57554Sraf 
1040ec57554Sraf 	/*
1050ec57554Sraf 	 * It's preferable to let the assembler insert the nops as
1060ec57554Sraf 	 * needed; however, it warns as it does so.  Add them here for now.
1070ec57554Sraf 	 */
1080ec57554Sraf 	__asm__ __volatile__(
1096a3e8e86SRichard Lowe 	    "st %%fsr, %0\n\t"
1106a3e8e86SRichard Lowe 	    "st %%g0, %1\n\t"
1116a3e8e86SRichard Lowe 	    "ld %1, %%fsr\n\t"
1126a3e8e86SRichard Lowe 	    "nop; nop; nop"
1136a3e8e86SRichard Lowe 	    : "=m" (*b), "=m" (__fsr));
1140ec57554Sraf }
1150ec57554Sraf #endif	/* __sparc */
1160ec57554Sraf 
1170ec57554Sraf #if defined(__sparc)
1186a3e8e86SRichard Lowe extern __GNU_INLINE void
__set_ieee_flags(__ieee_flags_type * b)1190ec57554Sraf __set_ieee_flags(__ieee_flags_type *b)
1200ec57554Sraf {
1210ec57554Sraf 	/*
1220ec57554Sraf 	 * It's preferable to let the assembler insert the nops as
1230ec57554Sraf 	 * needed; however, it warns as it does so.  Add them here for now.
1240ec57554Sraf 	 */
1250ec57554Sraf 	__asm__ __volatile__(
1266a3e8e86SRichard Lowe 	    "ld %0, %%fsr\n\t"
1276a3e8e86SRichard Lowe 	    "nop; nop; nop"
1286a3e8e86SRichard Lowe 	    : /* no outputs */
1296a3e8e86SRichard Lowe 	    : "m" (*b));
1300ec57554Sraf }
1310ec57554Sraf #endif	/* __sparc */
1320ec57554Sraf 
1330ec57554Sraf #endif	/* !__lint && __GNUC__ */
1340ec57554Sraf 
1350ec57554Sraf #endif	/* _BASE_INLINES_H */
136