TAG: code

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. :-)

There are no more results.