math-barriers.h 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Control when floating-point expressions are evaluated. x86 version.
  2. Copyright (C) 2007-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef X86_MATH_BARRIERS_H
  16. #define X86_MATH_BARRIERS_H 1
  17. #ifdef __SSE2_MATH__
  18. # define math_opt_barrier(x) \
  19. ({ __typeof(x) __x; \
  20. if (sizeof (x) <= sizeof (double) \
  21. || __builtin_types_compatible_p (__typeof (x), _Float128)) \
  22. __asm ("" : "=x" (__x) : "0" (x)); \
  23. else \
  24. __asm ("" : "=t" (__x) : "0" (x)); \
  25. __x; })
  26. # define math_force_eval(x) \
  27. do { \
  28. if (sizeof (x) <= sizeof (double) \
  29. || __builtin_types_compatible_p (__typeof (x), _Float128)) \
  30. __asm __volatile ("" : : "x" (x)); \
  31. else \
  32. __asm __volatile ("" : : "f" (x)); \
  33. } while (0)
  34. #else
  35. # define math_opt_barrier(x) \
  36. ({ __typeof (x) __x; \
  37. if (__builtin_types_compatible_p (__typeof (x), _Float128)) \
  38. { \
  39. __x = (x); \
  40. __asm ("" : "+m" (__x)); \
  41. } \
  42. else \
  43. __asm ("" : "=t" (__x) : "0" (x)); \
  44. __x; })
  45. # define math_force_eval(x) \
  46. do { \
  47. __typeof (x) __x = (x); \
  48. if (sizeof (x) <= sizeof (double) \
  49. || __builtin_types_compatible_p (__typeof (x), _Float128)) \
  50. __asm __volatile ("" : : "m" (__x)); \
  51. else \
  52. __asm __volatile ("" : : "f" (__x)); \
  53. } while (0)
  54. #endif
  55. #endif