/*-1* SPDX-License-Identifier: BSD-4-Clause2*3* Copyright (c) 2003 Peter Wemm.4* Copyright (c) 1990 Andrew Moore, Talke Studio5* All rights reserved.6*7* Redistribution and use in source and binary forms, with or without8* modification, are permitted provided that the following conditions9* are met:10* 1. Redistributions of source code must retain the above copyright11* notice, this list of conditions and the following disclaimer.12* 2. Redistributions in binary form must reproduce the above copyright13* notice, this list of conditions and the following disclaimer in the14* documentation and/or other materials provided with the distribution.15* 3. All advertising materials mentioning features or use of this software16* must display the following acknowledgement:17* This product includes software developed by the University of18* California, Berkeley and its contributors.19* 4. Neither the name of the University nor the names of its contributors20* may be used to endorse or promote products derived from this software21* without specific prior written permission.22*23* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND24* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE25* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE26* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE27* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL28* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS29* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)30* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT31* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY32* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF33* SUCH DAMAGE.34*/3536#ifndef _MACHINE_IEEEFP_H_37#define _MACHINE_IEEEFP_H_3839/* Deprecated historical FPU control interface */4041#include <x86/x86_ieeefp.h>4243static __inline fp_rnd_t44fpgetround(void)45{46unsigned short _cw;4748__fnstcw(&_cw);49return ((fp_rnd_t)((_cw & FP_RND_FLD) >> FP_RND_OFF));50}5152static __inline fp_rnd_t53fpsetround(fp_rnd_t _m)54{55fp_rnd_t _p;56unsigned short _cw, _newcw;5758__fnstcw(&_cw);59_p = (fp_rnd_t)((_cw & FP_RND_FLD) >> FP_RND_OFF);60_newcw = _cw & ~FP_RND_FLD;61_newcw |= (_m << FP_RND_OFF) & FP_RND_FLD;62__fnldcw(_cw, _newcw);63return (_p);64}6566static __inline fp_prec_t67fpgetprec(void)68{69unsigned short _cw;7071__fnstcw(&_cw);72return ((fp_prec_t)((_cw & FP_PRC_FLD) >> FP_PRC_OFF));73}7475static __inline fp_prec_t76fpsetprec(fp_prec_t _m)77{78fp_prec_t _p;79unsigned short _cw, _newcw;8081__fnstcw(&_cw);82_p = (fp_prec_t)((_cw & FP_PRC_FLD) >> FP_PRC_OFF);83_newcw = _cw & ~FP_PRC_FLD;84_newcw |= (_m << FP_PRC_OFF) & FP_PRC_FLD;85__fnldcw(_cw, _newcw);86return (_p);87}8889/*90* Get or set the exception mask.91* Note that the x87 mask bits are inverted by the API -- a mask bit of 192* means disable for x87 and SSE, but for fp*mask() it means enable.93*/9495static __inline fp_except_t96fpgetmask(void)97{98unsigned short _cw;99100__fnstcw(&_cw);101return ((~_cw & FP_MSKS_FLD) >> FP_MSKS_OFF);102}103104static __inline fp_except_t105fpsetmask(fp_except_t _m)106{107fp_except_t _p;108unsigned short _cw, _newcw;109110__fnstcw(&_cw);111_p = (~_cw & FP_MSKS_FLD) >> FP_MSKS_OFF;112_newcw = _cw & ~FP_MSKS_FLD;113_newcw |= (~_m << FP_MSKS_OFF) & FP_MSKS_FLD;114__fnldcw(_cw, _newcw);115return (_p);116}117118static __inline fp_except_t119fpgetsticky(void)120{121unsigned _ex;122unsigned short _sw;123124__fnstsw(&_sw);125_ex = (_sw & FP_STKY_FLD) >> FP_STKY_OFF;126return ((fp_except_t)_ex);127}128129static __inline fp_except_t130fpresetsticky(fp_except_t _m)131{132struct {133unsigned _cw;134unsigned _sw;135unsigned _other[5];136} _env;137fp_except_t _p;138139_m &= FP_STKY_FLD >> FP_STKY_OFF;140_p = fpgetsticky();141if ((_p & ~_m) == _p)142return (_p);143if ((_p & ~_m) == 0) {144__fnclex();145return (_p);146}147__fnstenv(&_env);148_env._sw &= ~_m;149__fldenv(&_env);150return (_p);151}152153#endif /* !_MACHINE_IEEEFP_H_ */154155156