Cygwin: access: Fix X_OK behaviour for backup operators and admins
[newlib-cygwin.git] / newlib / libm / machine / riscv / feholdexcept.c
blobc83a09bc127dcbc03853c653f16c20288292faaf
1 /*
2 (c) Copyright 2017 Michael R. Neilly
3 All rights reserved.
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions
7 are met:
9 * Redistributions of source code must retain the above copyright
10 notice, this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright
13 notice, this list of conditions and the following disclaimer in the
14 documentation and/or other materials provided with the distribution.
16 * Neither the names of the copyright holders nor the names of their
17 contributors may be used to endorse or promote products derived from
18 this software without specific prior written permission.
20 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 POSSIBILITY OF SUCH DAMAGE.
34 #include <fenv.h>
35 #include "riscv_math.h"
37 /* This implementation is intended to comply with the following
38 * specification:
40 * http://pubs.opengroup.org/onlinepubs/009695399/functions/feholdexcept.html
41 * Referred to as 'feholdexcept.html below.
43 * "The feholdexcept() function shall save the current floating-point
44 * environment in the object pointed to by envp, clear the
45 * floating-point status flags, and then install a non-stop (continue
46 * on floating-point exceptions) mode, if available, for all
47 * floating-point exceptions."
50 int feholdexcept(fenv_t *envp)
53 #ifdef __RISCV_HARD_FLOAT
55 /* Store the current FP environment in envp*/
57 fenv_t fcsr;
58 asm volatile("frcsr %0" : "=r"(fcsr));
59 *envp = fcsr;
61 /* Clear all flags */
63 asm volatile("csrrc zero, fflags, %0" : : "r"(FE_ALL_EXCEPT));
65 /* RISC-V does not raise FP traps so it is always in a "non-stop" mode */
67 /* Per 'feholdexcept.html:
69 * "The feholdexcept() function shall return zero if and only if
70 * non-stop floating-point exception handling was successfully
71 * installed."
74 #endif
76 return 0;