C# is killing me

Blame for this:

static inline uint64_t get_ts()
{
    uint32_t low, high;
    asm(“rdtsc”
        : “=a” (low),
          “=d” (high));
    ts = high;
    return ((uint64_t)high << 32) + low;
}

/* From kernel sources: include/asm-i386/processor.h / / * Generic CPUID function * clear %ecx since some cpus (Cyrix MII) do not set or clear %ecx * resulting in stale register contents being returned. / inline void cpuid(unsigned int op, unsigned int *eax, unsigned int *ebx, \ unsigned int *ecx, unsigned int *edx) { asm(“cpuid” : “=a” (eax), “=b” (ebx), “=c” (ecx), “=d” (*edx) : “0” (op), “c”(0)); }

/* Count the number of physical processor cores */ inline uint32_t get_num_cores() { uint32_t eax, ebx, ecx, edx;

/* figure out whether querying core count is allowed */
cpuid(0, &eax, &ebx, &ecx, &edx);

if (eax >= 4) {
    cpuid(4, &eax, &ebx, &ecx, &edx);
    eax = ((eax & 0xFC000000) >> 26) + 1;
}
else
    eax = 1;

return eax;

}

/* To figure out which CPU you’re on */ inline uint32_t get_apic_id() { uint32_t eax, ebx, ecx, edx; cpuid(1, &eax, &ebx, &ecx, &edx); return (ebx >> 24); }

And to all the non-geeks out there … sorry. :-)

This entry was posted in Blog and tagged . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

2 Comments

  1. t3rmin4t0r
    Posted August 18, 2007 at 7:50 pm | Permalink

    Dude, get to SSE2 land … it’s way more fun :)

    (and well, read intel’s perf lib asm)

  2. Anonymous
    Posted September 3, 2007 at 9:23 am | Permalink

    Hi. I am very happy here. I think that I will stand here for a long time.

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>