Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9256889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:05:00+00:00 2026-06-18T12:05:00+00:00

Disclaimer: Words cannot describe how much I detest AT&T style syntax I have a

  • 0

Disclaimer: Words cannot describe how much I detest AT&T style syntax

I have a problem that I hope is caused by register clobbering. If not, I have a much bigger problem.

The first version I used was

static unsigned long long rdtscp(void)
{
    unsigned int hi, lo;
    __asm__ __volatile__("rdtscp" : "=a"(lo), "=d"(hi));
    return (unsigned long long)lo | ((unsigned long long)hi << 32);
}

I notice there is no ‘clobbering’ stuff in this version. Whether or not this is a problem I don’t know… I suppose it depends if the compiler inlines the function or not. Using this version causes me problems that aren’t always reproducible.

The next version I found is

static unsigned long long rdtscp(void)
{
    unsigned long long tsc;
    __asm__ __volatile__(
        "rdtscp;"
        "shl $32, %%rdx;"
        "or %%rdx, %%rax"
        : "=a"(tsc)
        :
        : "%rcx", "%rdx");

    return tsc;
}

This is reassuringly unreadable and official looking, but like I said my issue isn’t always reproducible so I’m merely trying to rule out one possible cause of my problem.

The reason I believe the first version is a problem is that it is overwriting a register that previously held a function parameter.

What’s correct… version 1, or version 2, or both?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:05:02+00:00Added an answer on June 18, 2026 at 12:05 pm

    Here’s C++ code that will return the TSC and store the auxiliary 32-bits (Processor ID) into the reference parameter

    static inline uint64_t rdtscp( uint32_t & aux )
    {
        uint64_t rax,rdx;
        asm volatile ( "rdtscp\n" : "=a" (rax), "=d" (rdx), "=c" (aux) : : );
        return (rdx << 32) + rax;
    }
    

    It is better to do the shift and add to merge both 32-bit halves in C++ statement rather than inline, this allows the compiler to schedule those instructions as it sees fit.

    Update, about aux:
    The RDTSCP instruction returns the TSC (in two registers), and the Processor ID (aux) in a 3rd register (unlike the RDTSC instruction which only returns the TSC). The Processor ID is an MSR (Machine Specific Register) which therefore must be initialized by privileged system software, its purpose is to identify which "core" is executing the instruction. The value is therefore O/S dependent.

    See http://felixcloutier.com/x86/rdtscp

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this alert view (disclaimer) that pop up when app finish launching. It
Disclaimer: this is needed for an old and ugly codebase that I'd much rather
Disclaimer: I'm working in a project where exist an huge webapp that have an
Disclaimer: I know the basics of signing an APKs and I have a problem
Disclaimer: I'm a rails n00b. I'm playing around with a simple helper function that
Disclaimer : I'm quite a novice to RoR, but not with Ruby (if that
I have a page with a div id=videoFrame that holds the video tag. The
Disclaimer, I'm from a Java background. I don't do much C#. There's a great
I will preface my question with the disclaimer that I am fairly new to
So I have a bit of a problem. I am trying to make my

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.