This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: Update sysdeps/x86_64/fpu_control.h


On Mon, Jun 18, 2012 at 9:54 AM, Roland McGrath <roland@hack.frob.com> wrote:
>> > Why *&? ?That seems like a no-op. ?There should be a comment explaining the
>>
>> "*&" was added by Ulrich on Aug 26, 1996, ?I couldn't find anything beyond
>> that. ?It could be a workaround for a compiler bug.
>
> And so it is. ?Just a comment saying so is enough.
>
>> > need for volatile.
>>
>> __volatile__ was added by
>>
>> http://sourceware.org/ml/libc-alpha/2004-11/msg00150.html
>
> That should have added a comment saying why it's necessary (as we have some
> similar comments somewhere else about the same issue). ?Since it didn't,
> add the comment now.
>

Here is the updated patch.  OK to install?

Thanks.


-- 
H.J.
---
PATCH: Use __volatile__ to access fpu control word

	[BZ #14117]
	* sysdeps/x86_64/fpu_control.h (_FPU_GETCW): Add __volatile__.
	(_FPU_SETCW): Likewise.

diff --git a/sysdeps/x86_64/fpu_control.h b/sysdeps/x86_64/fpu_control.h
index 61bc30e..0c16940 100644
--- a/sysdeps/x86_64/fpu_control.h
+++ b/sysdeps/x86_64/fpu_control.h
@@ -1,5 +1,5 @@
-/* FPU control word bits.  x86-64 version.
-   Copyright (C) 1993,1995,1996,1997,1998,2000,2001,2002 Free
Software Foundation, Inc.
+/* FPU control word bits.  x86 version.
+   Copyright (C) 1993-2012 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Olaf Flebbe.

@@ -90,9 +90,18 @@
 /* Type of the control word.  */
 typedef unsigned int fpu_control_t __attribute__ ((__mode__ (__HI__)));

-/* Macros for accessing the hardware control word.  */
-#define _FPU_GETCW(cw) __asm__ ("fnstcw %0" : "=m" (*&cw))
-#define _FPU_SETCW(cw) __asm__ ("fldcw %0" : : "m" (*&cw))
+/* Macros for accessing the hardware control word.  "*&" is used to
+   work around a bug in older versions of GCC.  __volatile__ is used
+   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.  */
 extern fpu_control_t __fpu_control;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]