[PATCH][X86] Add support for Read Time Stamp Counter intrinsics ('__rdtsc' and '__rdtscp').

Andrea Di Biagio andrea.dibiagio at gmail.com
Thu Apr 24 10:29:19 PDT 2014


On Thu, Apr 24, 2014 at 5:34 PM, Nadav Rotem <nrotem at apple.com> wrote:
> LGTM.
>

Thanks for the review!
Committed revision 207127.

As explained in my original message,
I will send another patch (a Clang patch) that:
1. Adds a definition for two new Builtinsx86:
   __builtin_ia32_rdtsc;
   __builtin_ia32_rdtscp;
2. Replaces the definition of intrinsic __rdtsc (in ia32intrin.h)
 with a simple call to the GCC builtin __builtin_ia32_rdtsc();
3. Adds a definition for the new intrinsic __rdtscp in file
ia32intrin.h. Intrinsic __rdtscp would be implemented with a simple
call to the GCC builtin __builtin_ia32_rdtscp();


> On Apr 24, 2014, at 8:00 AM, Andrea Di Biagio <andrea.dibiagio at gmail.com> wrote:
>
>> ping.
>>
>> On Thu, Apr 17, 2014 at 4:55 PM, Andrea Di Biagio
>> <andrea.dibiagio at gmail.com> wrote:
>>> Hi,
>>>
>>> this patch adds the support for two new x86 GCCBuiltin intrinsics:
>>> - int_x86_rdtsc;
>>> - int_x86_rdtscp.
>>>
>>> -- BACKGROUND --
>>> From the Intel manuals:
>>>
>>> Instruction
>>> RDTSC (Read Time-Stamp Counter)
>>>  Loads the current value of the processor’s time-stamp counter (a
>>> 64-bit MSR) into the EDX:EAX registers. The EDX register is loaded
>>> with the high-order 32 bits of the MSR and the EAX register is loaded
>>> with the low-order 32 bits.
>>>
>>> Instruction
>>> RDTSCP (Read Time-Stamp Counter and Processor ID)
>>>  Loads the current value of the processor’s time-stamp counter (a
>>> 64-bit MSR) into the EDX:EAX registers and also loads the IA32_TSC_AUX
>>> MSR (address C000_0103H) into the ECX register. The EDX register is
>>> loaded with the
>>> high-order 32 bits of the IA32_TSC MSR; the EAX register is loaded
>>> with the low-order 32 bits of the IA32_TSC MSR; and the ECX register
>>> is loaded with the low-order 32-bits of IA32_TSC_AUX MSR.
>>>
>>> Intrinsic __rdtsc
>>> - returns the content of the time stamp counter as a 64bit value.
>>>
>>> Intrinsic __rdtscp
>>> - Takes in input a pointer to int (unsigned int* __A). Returns the
>>> content of the time stamp counter as a 64bit value and stores the
>>> processor ID at the address pointed by the input (__A).
>>>
>>> -- WHAT WE HAVE
>>> Clang only provides a definition for intrinsic __rdtsc in ia32intrin.h.
>>> That means, ia32intrin.h does not define
>>> unsigned long long __rdtscp(unsigned int *__A);
>>>
>>> Intrinsic `__rdtsc` is currently implemented using inline assembly.
>>> On X86, ISD::READCYCLECOUNTER dag nodes have the same semantic as
>>> intrinsic __rdtsc (i.e. they both emit instruction RDTSC and return
>>> the value as a 'i64').
>>>
>>> -- CHANGES INTRODUCED BY THIS PATCH --
>>> This patch:
>>> 1. Adds two new X86 intrinsics named 'int_x86_rdtsc' and 'int_x86_rdtscp';
>>> 2. Teaches the backend how to lower the two new builtins;
>>> 3. Reuses a common function to lower 'int_x86_rdtsc',
>>> 'int_x86_rdtscp' and 'ISD::READCYCLECOUNTER' dag nodes.
>>> 4. Modernizes and extends the existing test 'rdtsc.ll' to verify that
>>> READCYCLECOUNTER and the two new intrinsics work for 64bit Subtargets
>>> and non-64bit subtargets.
>>> //
>>>
>>> A Clang patch would follow that:
>>> 1. Adds a definition for two new Builtinsx86:
>>>    __builtin_ia32_rdtsc;
>>>    __builtin_ia32_rdtscp;
>>> 2. Replaces the definition of intrinsic __rdtsc (in ia32intrin.h)
>>> with a simple call to the GCC builtin __builtin_ia32_rdtsc();
>>> 3. Adds a definition for the new intrinsic __rdtscp in file
>>> ia32intrin.h. Intrinsic __rdtscp would be implemented with a simple
>>> call to the GCC builtin __builtin_ia32_rdtscp();
>>>
>>> Please let me know if ok to submit.
>>>
>>> Thanks,
>>> Andrea Di Biagio
>>> SN Systems - Sony Computer Entertainment Group
>> <patch-rdtsc.diff>
>




More information about the llvm-commits mailing list