This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Letter to DDJ
- From: Laurent GUERBY <laurent at guerby dot net>
- To: Andrew Haley <aph at gcc dot gnu dot org>
- Cc: gcc at gcc dot gnu dot org
- Date: Tue, 04 May 2004 21:46:12 +0200
- Subject: Re: Letter to DDJ
- References: <200405041648.i44GmOuI010642@redhat.com>
I believe you need to add a special instruction
to prevent the hardware to reorder the execution of rdtsc
leading to wrong measurement, I don't remember what it was
and the GCC asm for it though, may be someone else can help...
Laurent
On Tue, 2004-05-04 at 18:48, Andrew Haley wrote:
> The latest DDJ contains a horrible example of GCC extended asm.
> Here's my leter to the editor in response.
>
> I don't think I made any mistakes with my extended asm, but I thought
> I'd better run it by y'all before sending it.
>
> Andrew.
>
>
>
> From: Andrew Haley <aph@gcc.gnu.org>
> To: editors@ddj.com
> CC: kientzle@acm.org
> Subject: Optimization Techniques
> X-Mailer: VM 7.14 under Emacs 21.3.50.1
> Bcc: aph@redhat.com
>
> Dear DDJ,
>
> Tom Kientzle's fascinating article "Optimization Techniques" contains
> a rather long-winded and complicated defintion for readTSC() in GCC.
>
> The simple way to do it in GCC is
>
> inline long long readTSC(void)
> {
> long long result;
> __asm__ volatile ("rdtsc"
> : "=A"(result));
> return result;
> }
>
> (Of course, you may as well use "inline" here because there's no point
> in making a call to a single-instruction subroutine!)
>
> The "=A" constraint tells gcc that the result is returned in EDX:EAX,
> as per the gcc documentation for Machine Constraints:
>
> `A'
> Specifies the `a' or `d' registers. This is primarily useful
> for 64-bit integer values (when in 32-bit mode) intended to
> be returned with the `d' register holding the most
> significant bits and the `a' register holding the least
> significant bits.
>
> The "volatile" is essential because it tells gcc that the result might
> change; without this, gcc may only invoke readTSC() once.
>
> Regards,
> Andrew.
>