10ec5755raf/*
20ec5755raf * CDDL HEADER START
30ec5755raf *
40ec5755raf * The contents of this file are subject to the terms of the
50ec5755raf * Common Development and Distribution License (the "License").
60ec5755raf * You may not use this file except in compliance with the License.
70ec5755raf *
80ec5755raf * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90ec5755raf * or http://www.opensolaris.org/os/licensing.
100ec5755raf * See the License for the specific language governing permissions
110ec5755raf * and limitations under the License.
120ec5755raf *
130ec5755raf * When distributing Covered Code, include this CDDL HEADER in each
140ec5755raf * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150ec5755raf * If applicable, add the following below this CDDL HEADER, with the
160ec5755raf * fields enclosed by brackets "[]" replaced with your own identifying
170ec5755raf * information: Portions Copyright [yyyy] [name of copyright owner]
180ec5755raf *
190ec5755raf * CDDL HEADER END
200ec5755raf */
210ec5755raf
220ec5755raf/*
230ec5755raf * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
240ec5755raf * Use is subject to license terms.
250ec5755raf */
260ec5755raf
270ec5755raf#ifndef	_BASE_INLINES_H
280ec5755raf#define	_BASE_INLINES_H
290ec5755raf
306a3e8e8Richard Lowe#include <sys/ccompile.h>
310ec5755raf#include <sys/types.h>
320ec5755raf
330ec5755raf#if !defined(__lint) && defined(__GNUC__)
340ec5755raf
350ec5755raf/*
360ec5755raf * This file is intended to contain gcc-style inline assembly that corresponds
370ec5755raf * to base.il for all architectures.  At the moment these inlines exist only
380ec5755raf * for sparc and sparcv9 and these functions are implemented in C for x86.
390ec5755raf * They should be inlined here for gcc if a new x86 base.il is created.
400ec5755raf */
410ec5755raf
420ec5755raf#if defined(__sparc)
436a3e8e8Richard Loweextern __GNU_INLINE double
440ec5755raf__mul_set(double x, double y, int *pe)
450ec5755raf{
460ec5755raf	double __result;
470ec5755raf	uint32_t __fsr;
480ec5755raf	uint32_t *__addr = &__fsr;
490ec5755raf
500ec5755raf	__asm__ __volatile__(
516a3e8e8Richard Lowe	    "fmuld %4, %5, %0\n\t"
526a3e8e8Richard Lowe	    "st %%fsr, %3\n\t"
536a3e8e8Richard Lowe	    "ld %3, %2\n\t"
546a3e8e8Richard Lowe	    "and %2, 1, %2\n\t"
556a3e8e8Richard Lowe	    "st %2, %1"
566a3e8e8Richard Lowe	    : "=&e" (__result), "=m" (*pe), "=r" (__fsr), "=m" (*__addr)
576a3e8e8Richard Lowe	    : "e" (x), "e" (y));
580ec5755raf	return (__result);
590ec5755raf}
600ec5755raf#endif	/* __sparc */
610ec5755raf
620ec5755raf#if defined(__sparc)
636a3e8e8Richard Loweextern __GNU_INLINE double
640ec5755raf__div_set(double x, double y, int *pe)
650ec5755raf{
660ec5755raf	double __result;
670ec5755raf	uint32_t __fsr;
680ec5755raf	uint32_t *__addr = &__fsr;
690ec5755raf
700ec5755raf	__asm__ __volatile__(
716a3e8e8Richard Lowe	    "fdivd %4, %5, %0\n\t"
726a3e8e8Richard Lowe	    "st %%fsr, %3\n\t"
736a3e8e8Richard Lowe	    "ld %3, %2\n\t"
746a3e8e8Richard Lowe	    "and %2, 1, %2\n\t"
756a3e8e8Richard Lowe	    "st %2, %1"
766a3e8e8Richard Lowe	    : "=&e" (__result), "=m" (*pe), "=r" (__fsr), "=m" (*__addr)
776a3e8e8Richard Lowe	    : "e" (x), "e" (y));
780ec5755raf	return (__result);
790ec5755raf}
800ec5755raf#endif	/* __sparc */
810ec5755raf
820ec5755raf#if defined(__sparc)
836a3e8e8Richard Loweextern __GNU_INLINE double
840ec5755raf__dabs(double *x)
850ec5755raf{
860ec5755raf	double __result;
870ec5755raf
880ec5755raf	__asm__ __volatile__(
890ec5755raf#if defined(__sparcv9)
906a3e8e8Richard Lowe	    "fabsd %1, %0"
910ec5755raf#else
926a3e8e8Richard Lowe	    "fabss %1, %0"
930ec5755raf#endif
946a3e8e8Richard Lowe	    : "=e" (__result)
956a3e8e8Richard Lowe	    : "0" (*x));
960ec5755raf	return (__result);
970ec5755raf}
980ec5755raf#endif	/* __sparc */
990ec5755raf
1000ec5755raf#if defined(__sparc)
1016a3e8e8Richard Loweextern  __GNU_INLINE void
1020ec5755raf__get_ieee_flags(__ieee_flags_type *b)
1030ec5755raf{
1040ec5755raf	uint32_t __fsr;
1050ec5755raf
1060ec5755raf	/*
1070ec5755raf	 * It's preferable to let the assembler insert the nops as
1080ec5755raf	 * needed; however, it warns as it does so.  Add them here for now.
1090ec5755raf	 */
1100ec5755raf	__asm__ __volatile__(
1116a3e8e8Richard Lowe	    "st %%fsr, %0\n\t"
1126a3e8e8Richard Lowe	    "st %%g0, %1\n\t"
1136a3e8e8Richard Lowe	    "ld %1, %%fsr\n\t"
1146a3e8e8Richard Lowe	    "nop; nop; nop"
1156a3e8e8Richard Lowe	    : "=m" (*b), "=m" (__fsr));
1160ec5755raf}
1170ec5755raf#endif	/* __sparc */
1180ec5755raf
1190ec5755raf#if defined(__sparc)
1206a3e8e8Richard Loweextern __GNU_INLINE void
1210ec5755raf__set_ieee_flags(__ieee_flags_type *b)
1220ec5755raf{
1230ec5755raf	/*
1240ec5755raf	 * It's preferable to let the assembler insert the nops as
1250ec5755raf	 * needed; however, it warns as it does so.  Add them here for now.
1260ec5755raf	 */
1270ec5755raf	__asm__ __volatile__(
1286a3e8e8Richard Lowe	    "ld %0, %%fsr\n\t"
1296a3e8e8Richard Lowe	    "nop; nop; nop"
1306a3e8e8Richard Lowe	    : /* no outputs */
1316a3e8e8Richard Lowe	    : "m" (*b));
1320ec5755raf}
1330ec5755raf#endif	/* __sparc */
1340ec5755raf
1350ec5755raf#endif	/* !__lint && __GNUC__ */
1360ec5755raf
1370ec5755raf#endif	/* _BASE_INLINES_H */
138