Re: [eigen] Performance gap between gcc and msvc ?

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


On 06/18/10 08:45 PM, Thomas Capricelli wrote:
If that might help, I use the following code in one of my project to get a working 'cpuid' across compilers:
(inside a proper #ifdef for x86/amd64, of course):

#if defined(__GNUC__)
#    if defined(__PIC__)&&  defined(__i386__)
#    define cpuid(abcd,func) \
         __asm__ __volatile__ ("xchgl %%ebx, %%esi;cpuid; xchgl %%ebx,%%esi": "=a" (abcd[0]), "=S" (abcd[1]), "=c" (abcd[2]), "=d" (abcd[3]) : "a" (func));
#    else
#    define cpuid(abcd,func) \
         __asm__ __volatile__ ("cpuid": "=a" (abcd[0]), "=b" (abcd[1]), "=c" (abcd[2]), "=d" (abcd[3]) : "a" (func) );
#    endif
#elif defined(_MSC_VER)
#    define cpuid(abcd,func) __cpuid((int*)abcd,func)
#endif

#ifndef cpuid
#error "Failed to find a way to get cpuid() for this architecture."
#endif

(and wikipedia describes what you can get, very useful :-)

Thomas
Unfortunately, I don't think it is quite that easy with Solaris x86/x64
with Sun Studio (most of the available GCC are too ancient to work with
Eigen or other modern C++ libraries).  This is about as simple as I
could make it, but I don't know assembler.  Adapted from
http://blogs.sun.com/JoeBonasera/entry/detecting_hardware_virtualization_support_for

#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <ctype.h>

int __cpuid(uint32_t* abcd, size_t size, uint32_t func) {

static const char devname[] = "/dev/cpu/self/cpuid";

#define EAX     0
#define EBX     1
#define ECX     2
#define EDX     3

        int device;
        /*
         * open cpuid device
         */
        device = open(devname, O_RDONLY);
        if (device == -1) goto fail;

        if (pread(device, abcd, size, func) != size) goto fail;

        (void) close(device);

    return 0;

fail:
        printf("Fail %i\n", device);
        (void) close(device);
        return 1;
}

int main() {
        uint32_t regs[4];

    __cpuid(regs, sizeof(regs), 2);

    printf("Cache and TLB Descriptor\n");
    printf("EAX=%10x\n", regs[EAX]);
    printf("EBX=%10x\n", regs[EBX]);
    printf("ECX=%10x\n", regs[ECX]);
    printf("EDX=%10x\n", regs[EDX]);

    __cpuid(regs, sizeof(regs), 0x80000006);

    printf("Extended L2 Cache Features\nECX=%10x\n", regs[ECX]);

    return 0;
}

Somebody please tell me it is easy on Mac OS X (my primary development
platform).


--
Rodney Sparapani       Center for Patient Care and Outcomes Research
Sr. Biostatistician               http://www.mcw.edu/pcor
4 wheels good, 2 wheels better!   Medical College of Wisconsin (MCW)
WWLD?:  What Would Lombardi Do?   Milwaukee, WI, USA




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/