1 /* Control when floating-point expressions are evaluated. Generic version.
2 Copyright (C) 2007-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
19 #ifndef _MATH_BARRIERS_H
20 #define _MATH_BARRIERS_H 1
22 /* math_opt_barrier evaluates and returns its floating-point argument
23 and ensures that the evaluation of any expression using the result
24 of math_opt_barrier is not moved before the call. math_force_eval
25 ensures that its floating-point argument is evaluated for its side
26 effects even if its value is apparently unused, and that the
27 evaluation of its argument is not moved after the call. Both these
28 macros are used to ensure the correct ordering of floating-point
29 expression evaluations with respect to accesses to the
30 floating-point environment. */
32 #define math_opt_barrier(x) \
33 ({ __typeof (x) __x = (x); __asm ("" : "+m" (__x)); __x; })
34 #define math_force_eval(x) \
35 ({ __typeof (x) __x = (x); __asm __volatile__ ("" : : "m" (__x)); })
37 #endif /* math-barriers.h */