1130145Sdas/*-
2130145Sdas * Copyright (c) 2004 David Schultz <das@FreeBSD.ORG>
3130145Sdas * All rights reserved.
4130145Sdas *
5130145Sdas * Redistribution and use in source and binary forms, with or without
6130145Sdas * modification, are permitted provided that the following conditions
7130145Sdas * are met:
8130145Sdas * 1. Redistributions of source code must retain the above copyright
9130145Sdas *    notice, this list of conditions and the following disclaimer.
10130145Sdas * 2. Redistributions in binary form must reproduce the above copyright
11130145Sdas *    notice, this list of conditions and the following disclaimer in the
12130145Sdas *    documentation and/or other materials provided with the distribution.
13130145Sdas *
14130145Sdas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15130145Sdas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16130145Sdas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17130145Sdas * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18130145Sdas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19130145Sdas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20130145Sdas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21130145Sdas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22130145Sdas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23130145Sdas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24130145Sdas * SUCH DAMAGE.
25130145Sdas *
26130145Sdas * $FreeBSD$
27130145Sdas */
28130145Sdas
29130145Sdas#include <sys/types.h>
30130145Sdas#include <fenv.h>
31130145Sdas
32130145Sdasconst fenv_t __fe_dfl_env = 0x0009804c8a70033fULL;
33130145Sdas
34130145Sdas/*
35130145Sdas * It doesn't pay to inline feupdateenv() because it includes one of
36130145Sdas * the rare uses of feraiseexcept() where the argument is not a
37130145Sdas * constant.  Thus, no dead code elimination can occur, resulting in
38130145Sdas * significant bloat.
39130145Sdas */
40130145Sdasint
41130145Sdasfeupdateenv(const fenv_t *envp)
42130145Sdas{
43130145Sdas	fenv_t fpsr;
44130145Sdas
45130145Sdas	__stfpsr(&fpsr);
46130145Sdas	__ldfpsr(*envp);
47130329Sdas	feraiseexcept((fpsr >> _FPUSW_SHIFT) & FE_ALL_EXCEPT);
48130145Sdas	return (0);
49130145Sdas}
50