* [PATCH] Fix asm constraints in HP_TIMING_ACCUM (take 3)
[not found] <20050315094116.GH853@devserv.devel.redhat.com>
@ 2005-03-15 15:26 ` Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2005-03-15 15:26 UTC (permalink / raw)
To: Ulrich Drepper, Roland McGrath; +Cc: Glibc hackers
On Tue, Mar 15, 2005 at 04:41:16AM -0500, Jakub Jelinek wrote:
> The testcase newly added in #789 showed further problems.
> __newval >> 32 as well as __newval & 0xffffffff are long long, so must be
> cast to some 32-bit type.
> On x86-64, we know that (Diff) - GLRO(dl_hp_timing_overhead) is not an
> immediate, so don't need to put that as constraint.
Oops, further problems.
IA-32 has just 4 "q" registers, when -fpic takes %ebx, "=A" eats %eax and
%edx and "c" eats %ecx there are none left. Even without -fpic, there would
be sete %0 and afterwards movl %4, %%ebx would overwrite that.
2005-03-15 Jakub Jelinek <jakub@redhat.com>
[BZ #789]
* sysdeps/i386/i686/hp-timing.h (HP_TIMING_ACCUM): Fix asm constraints.
* sysdeps/x86_64/hp-timing.h (HP_TIMING_ACCUM): Make the addition
thread-safe. Subtract GLRO(dl_hp_timing_overhead) from Diff.
--- libc/sysdeps/i386/i686/hp-timing.h.jj 2004-03-08 12:01:51.000000000 +0100
+++ libc/sysdeps/i386/i686/hp-timing.h 2005-03-15 10:29:19.826506997 +0100
@@ -1,5 +1,5 @@
/* High precision, low overhead timing functions. i686 version.
- Copyright (C) 1998, 2002, 2003, 2004 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
@@ -119,26 +119,25 @@ typedef unsigned long long int hp_timing
/* We have to jump through hoops to get this correctly implemented. */
#define HP_TIMING_ACCUM(Sum, Diff) \
do { \
- char __not_done; \
+ int __not_done; \
hp_timing_t __oldval = (Sum); \
hp_timing_t __diff = (Diff) - GLRO(dl_hp_timing_overhead); \
do \
{ \
hp_timing_t __newval = __oldval + __diff; \
int __temp0, __temp1; \
- __asm__ __volatile__ ("xchgl %4, %%ebx\n\t" \
+ __asm__ __volatile__ ("xchgl %0, %%ebx\n\t" \
"lock; cmpxchg8b %1\n\t" \
- "sete %0\n\t" \
- "movl %4, %%ebx" \
- : "=q" (__not_done), "=m" (Sum), \
- "=A" (__oldval), "=c" (__temp0), \
- "=SD" (__temp1) \
- : "1" (Sum), "2" (__oldval), \
- "3" (__newval >> 32), \
- "4" (__newval & 0xffffffff) \
+ "sete %%bl\n\t" \
+ "xchgl %0, %%ebx" \
+ : "=SD" (__not_done), "=m" (Sum), \
+ "=A" (__oldval), "=c" (__temp0) \
+ : "m" (Sum), "2" (__oldval), \
+ "3" ((unsigned int) (__newval >> 32)), \
+ "0" ((unsigned int) __newval) \
: "memory"); \
} \
- while (__not_done); \
+ while ((unsigned char) __not_done); \
} while (0)
/* No threads, no extra work. */
--- libc/sysdeps/x86_64/hp-timing.h.jj 2004-03-23 15:51:54.000000000 +0100
+++ libc/sysdeps/x86_64/hp-timing.h 2005-03-14 16:09:22.000000000 +0100
@@ -1,5 +1,5 @@
/* High precision, low overhead timing functions. x86-64 version.
- Copyright (C) 2002, 2004 Free Software Foundation, Inc.
+ Copyright (C) 2002, 2004, 2005 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
@@ -31,7 +31,11 @@
/* The funny business for 32-bit mode is not required here. */
# undef HP_TIMING_ACCUM
-# define HP_TIMING_ACCUM(Sum, Diff) ((Sum) += (Diff))
-
+# define HP_TIMING_ACCUM(Sum, Diff) \
+ do { \
+ hp_timing_t __diff = (Diff) - GLRO(dl_hp_timing_overhead); \
+ __asm__ __volatile__ ("lock; addq %1, %0" \
+ : "=m" (Sum) : "r" (__diff), "m" (Sum) : "memory"); \
+ } while (0)
#endif /* hp-timing.h */
Jakub
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2005-03-15 15:26 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
[not found] <20050315094116.GH853@devserv.devel.redhat.com>
2005-03-15 15:26 ` [PATCH] Fix asm constraints in HP_TIMING_ACCUM (take 3) Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).