From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 19866 invoked by alias); 15 Mar 2005 15:26:04 -0000 Mailing-List: contact libc-hacker-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-hacker-owner@sources.redhat.com Received: (qmail 19815 invoked from network); 15 Mar 2005 15:26:03 -0000 Received: from unknown (HELO sunsite.mff.cuni.cz) (195.113.15.26) by sourceware.org with SMTP; 15 Mar 2005 15:26:03 -0000 Received: from sunsite.mff.cuni.cz (sunsite.mff.cuni.cz [127.0.0.1]) by sunsite.mff.cuni.cz (8.13.1/8.13.1) with ESMTP id j2FFPuHE014331; Tue, 15 Mar 2005 16:25:56 +0100 Received: (from jj@localhost) by sunsite.mff.cuni.cz (8.13.1/8.13.1/Submit) id j2FFPtPp014330; Tue, 15 Mar 2005 16:25:55 +0100 Date: Tue, 15 Mar 2005 15:26:00 -0000 From: Jakub Jelinek To: Ulrich Drepper , Roland McGrath Cc: Glibc hackers Subject: [PATCH] Fix asm constraints in HP_TIMING_ACCUM (take 3) Message-ID: <20050315152555.GE4961@sunsite.mff.cuni.cz> Reply-To: Jakub Jelinek References: <20050315094116.GH853@devserv.devel.redhat.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20050315094116.GH853@devserv.devel.redhat.com> User-Agent: Mutt/1.4.1i X-SW-Source: 2005-03/txt/msg00044.txt.bz2 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 [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 , 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