Back to index

glibc  2.9
fesetenv.c
Go to the documentation of this file.
00001 /* Install given floating-point environment.
00002    Copyright (C) 1997, 1999, 2000, 2002 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004    Contributed by David Huggins-Daines <dhd@debian.org>, 2000
00005    Based on the m68k version by
00006    Andreas Schwab <schwab@suse.de>
00007 
00008    The GNU C Library is free software; you can redistribute it and/or
00009    modify it under the terms of the GNU Lesser General Public
00010    License as published by the Free Software Foundation; either
00011    version 2.1 of the License, or (at your option) any later version.
00012 
00013    The GNU C Library is distributed in the hope that it will be useful,
00014    but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016    Lesser General Public License for more details.
00017 
00018    You should have received a copy of the GNU Lesser General Public
00019    License along with the GNU C Library; if not, write to the Free
00020    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00021    02111-1307 USA.  */
00022 
00023 #include <fenv.h>
00024 
00025 int
00026 fesetenv (const fenv_t *envp)
00027 {
00028   union { unsigned long long buf[4]; fenv_t env; } temp;
00029   unsigned long long *bufptr;
00030 
00031   /* Install the environment specified by ENVP.  But there are a few
00032      values which we do not want to come from the saved environment.
00033      Therefore, we get the current environment and replace the values
00034      we want to use from the environment specified by the parameter.  */
00035   bufptr = temp.buf;
00036   __asm__ (
00037           "fstd,ma %%fr0,8(%1)\n"
00038           : "=m" (temp) : "r" (bufptr) : "%r0");
00039 
00040   temp.env.__status_word &= ~(FE_ALL_EXCEPT
00041                          | (FE_ALL_EXCEPT << 27)
00042                          | FE_DOWNWARD);
00043   if (envp == FE_DFL_ENV)
00044     ;
00045   else if (envp == FE_NOMASK_ENV)
00046     temp.env.__status_word |= FE_ALL_EXCEPT;
00047   else
00048     temp.env.__status_word |= (envp->__status_word
00049                             & (FE_ALL_EXCEPT
00050                               | FE_DOWNWARD
00051                               | (FE_ALL_EXCEPT << 27)));
00052 
00053   /* Load the new environment. We use bufptr again since the 
00054      initial asm has modified the value of the register and here
00055      we take advantage of that to load in reverse order so fr0
00056      is loaded last and T-Bit is enabled. */
00057   __asm__ (
00058           "fldd,mb -8(%1),%%fr0\n"
00059           : : "m" (temp), "r" (bufptr) : "%r0" );
00060 
00061   /* Success.  */
00062   return 0;
00063 }
00064 libm_hidden_def (fesetenv)