This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC 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]

Letter to DDJ


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.


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