Use __volatile__ to access fpu control word

This commit is contained in:
H.J. Lu 2012-06-18 11:09:58 -07:00
parent 62c8cc6dbe
commit 3ee947b124
2 changed files with 20 additions and 5 deletions

View File

@ -1,3 +1,9 @@
2012-06-18 H.J. Lu <hongjiu.lu@intel.com>
[BZ #14117]
* sysdeps/x86_64/fpu_control.h (_FPU_GETCW): Add __volatile__.
(_FPU_SETCW): Likewise.
2012-06-15 H.J. Lu <hongjiu.lu@intel.com> 2012-06-15 H.J. Lu <hongjiu.lu@intel.com>
[BZ #14117] [BZ #14117]

View File

@ -1,5 +1,5 @@
/* FPU control word bits. x86-64 version. /* FPU control word bits. x86 version.
Copyright (C) 1993,1995,1996,1997,1998,2000,2001,2002 Free Software Foundation, Inc. Copyright (C) 1993-2012 Free Software Foundation, Inc.
This file is part of the GNU C Library. This file is part of the GNU C Library.
Contributed by Olaf Flebbe. Contributed by Olaf Flebbe.
@ -90,9 +90,18 @@
/* Type of the control word. */ /* Type of the control word. */
typedef unsigned int fpu_control_t __attribute__ ((__mode__ (__HI__))); typedef unsigned int fpu_control_t __attribute__ ((__mode__ (__HI__)));
/* Macros for accessing the hardware control word. */ /* Macros for accessing the hardware control word. "*&" is used to
#define _FPU_GETCW(cw) __asm__ ("fnstcw %0" : "=m" (*&cw)) work around a bug in older versions of GCC. __volatile__ is used
#define _FPU_SETCW(cw) __asm__ ("fldcw %0" : : "m" (*&cw)) to support combination of writing the control register and reading
it back. Without __volatile__, the old value may be used for reading
back under compiler optimization.
Note that the use of these macros is not sufficient anymore with
recent hardware nor on x86-64. Some floating point operations are
executed in the SSE/SSE2 engines which have their own control and
status register. */
#define _FPU_GETCW(cw) __asm__ __volatile__ ("fnstcw %0" : "=m" (*&cw))
#define _FPU_SETCW(cw) __asm__ __volatile__ ("fldcw %0" : : "m" (*&cw))
/* Default control word set at startup. */ /* Default control word set at startup. */
extern fpu_control_t __fpu_control; extern fpu_control_t __fpu_control;