From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20428 invoked by alias); 16 Jun 2010 19:21:10 -0000 Received: (qmail 20415 invoked by uid 22791); 16 Jun 2010 19:21:07 -0000 X-SWARE-Spam-Status: No, hits=-2.0 required=5.0 tests=AWL,BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_PASS,T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (74.125.121.35) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 16 Jun 2010 19:20:47 +0000 Received: from kpbe16.cbf.corp.google.com (kpbe16.cbf.corp.google.com [172.25.105.80]) by smtp-out.google.com with ESMTP id o5GJKiZ4029483 for ; Wed, 16 Jun 2010 12:20:44 -0700 Received: from yxg6 (yxg6.prod.google.com [10.190.2.134]) by kpbe16.cbf.corp.google.com with ESMTP id o5GJKgkh021661 for ; Wed, 16 Jun 2010 12:20:43 -0700 Received: by yxg6 with SMTP id 6so1483221yxg.9 for ; Wed, 16 Jun 2010 12:20:42 -0700 (PDT) MIME-Version: 1.0 Received: by 10.224.8.80 with SMTP id g16mr4345938qag.274.1276716038622; Wed, 16 Jun 2010 12:20:38 -0700 (PDT) Received: by 10.220.189.201 with HTTP; Wed, 16 Jun 2010 12:20:38 -0700 (PDT) In-Reply-To: <201006162016.18181.pedro@codesourcery.com> References: <201006071700.28706.pedro@codesourcery.com> <4C19222C.2000208@codesourcery.com> <201006162016.18181.pedro@codesourcery.com> Date: Wed, 16 Jun 2010 19:21:00 -0000 Message-ID: Subject: Re: [NEWS/RFA] Re: [gdbserver] x86 agent expression bytecode compiler (speed up conditional tracepoints) From: Doug Evans To: Pedro Alves , Ian Lance Taylor Cc: Stan Shebs , gdb-patches@sourceware.org, Eli Zaretskii , tromey@redhat.com Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org X-SW-Source: 2010-06/txt/msg00374.txt.bz2 On Wed, Jun 16, 2010 at 12:16 PM, Pedro Alves wrot= e: > On Wednesday 16 June 2010 20:12:44, Stan Shebs wrote: >> Doug Evans wrote: >> > On Mon, Jun 14, 2010 at 3:19 PM, Pedro Alves = wrote: >> > >> >> Thanks. =A0I've checked the whole thing in. >> >> >> > >> > I'm getting build failures that go away when compiling linux-x86-low.c= with -g. >> > >> > gcc is optimizing out the skipped over stuff I believe. >> > >> >> Hmm, this particular trickery was my idea, but it always seemed >> vulnerable to ever-smarter optimization. =A0Does anybody have any better >> strategy? =A0Declaring the asm volatile didn't work, because the compiler >> was whacking everything around it. >> >> The other approach is to build up instructions from bitfields, which is >> reliable but needs a lot of setup and helper routines. > > Quick thought: can we stick a couple of __attribute__((used))'s in the > macro, so the compiler doesn optimized things away, thinking they're > unused (given the uses are behind asm)? > >> >> Stan >> > >> > /* Our general strategy for emitting code is to avoid specifying raw >> > =A0 =A0bytes whenever possible, and instead copy a block of inline asm >> > =A0 =A0that is embedded in the function. =A0This is a little messy, be= cause >> > =A0 =A0we need to keep the compiler from discarding what looks like de= ad >> > =A0 =A0code, plus suppress various warnings. =A0*/ >> > >> > #define EMIT_ASM(NAME,INSNS) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0\ >> > =A0 { extern unsigned char start_ ## NAME, end_ ## NAME; =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0\ >> > =A0 =A0 add_insns (&start_ ## NAME, &end_ ## NAME - &start_ ## NAME); = =A0 =A0 =A0 \ >> > =A0 =A0 if (always_true ()) =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 \ >> > =A0 =A0 =A0 goto skipover ## NAME; =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0= =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0\ >> > =A0 =A0 __asm__ ("start_" #NAME ":\n\t" INSNS "\n\tend_" #NAME ":\n\t"= ); =A0 =A0\ >> > =A0 =A0 skipover ## NAME: =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 = =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 \ >> > =A0 =A0 ; } This worked with the gcc4.4.0 variant I was using. Ian: Is there a Right way to do this? 2010-06-16 Doug Evans * linux-x86-low.c (always_true): Change to global. (EMIT_ASM, EMIT_ASM32): Update. Index: linux-x86-low.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D RCS file: /cvs/src/src/gdb/gdbserver/linux-x86-low.c,v retrieving revision 1.19 diff -u -p -r1.19 linux-x86-low.c --- linux-x86-low.c 15 Jun 2010 10:44:48 -0000 1.19 +++ linux-x86-low.c 16 Jun 2010 19:15:21 -0000 @@ -1484,13 +1484,8 @@ add_insns (unsigned char *start, int len current_insn_ptr =3D buildaddr; } -/* A function used to trick optimizers. */ - -int -always_true (void) -{ - return 1; -} +/* Used to trick optimizers. */ +static volatile int always_true =3D 1; /* Our general strategy for emitting code is to avoid specifying raw bytes whenever possible, and instead copy a block of inline asm @@ -1501,7 +1496,7 @@ always_true (void) #define EMIT_ASM(NAME,INSNS) \ { extern unsigned char start_ ## NAME, end_ ## NAME; \ add_insns (&start_ ## NAME, &end_ ## NAME - &start_ ## NAME); \ - if (always_true ()) \ + if (always_true) \ goto skipover ## NAME; \ __asm__ ("start_" #NAME ":\n\t" INSNS "\n\tend_" #NAME ":\n\t"); \ skipover ## NAME: \ @@ -1513,7 +1508,7 @@ always_true (void) #define EMIT_ASM32(NAME,INSNS) \ { extern unsigned char start_ ## NAME, end_ ## NAME; \ add_insns (&start_ ## NAME, &end_ ## NAME - &start_ ## NAME); \ - if (always_true ()) \ + if (always_true) \ goto skipover ## NAME; \ __asm__ (".code32\n\tstart_" #NAME ":\n\t" INSNS "\n\tend_" #NAME ":\n= " \ "\t.code64\n\t"); \