0

In my project I need to determine what SIMD instruction set the CPU supports. The problem is that when I try to do a test compile I get a series of errors that repeat several times like the compiler is parsing the code multiple times. The reason for determining supported SIMD instructions is because I'm trying to adapt John the Ripper's DES bitslice implementation for use on a GPGPU (in particular CUDA) for both Windows & Linux.

So, here's where my error occurs on line 37

// File Name: Arch.h
// Purpose: Determine CPU architecture (x86 or x86-64) and to determine instruction set supported by
//          the CPU (MMX, SSE2 or neither)
// 
// Authors: Daniel Beard and Michael Campbell

//If CPU is x86-64 then use x86-64 include
#if defined(__amd64__) || defined(__amd64) || defined(__x86_64__) || defined(__x86_64) || defined(_M_X64)
#include "x86-64.h"
#endif

//Determine if CPU architecture is 32-bit, then determine which compiler is being used, finally determine if GCC (GNUC) or MS Visual C++ compiler is being used
#if defined(i386) || defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__) || defined(_M_IX86)
    #if defined(__GNUC__) 
    #define cpuid(func,ax,bx,cx,dx)\
        __asm__ __volatile__ ("cpuid":\
        "=a" (ax), "=b" (bx), "=c" (cx), "=d" (dx) : "a" (func));
    int a,b,c,d;
    cpuid(0x1,a,b,c,d);
    if ((d & 0x17)== 1)
    {
        #include "x86-mmx.h"
    }
    else if (d & 0x1A) == 1)
    {
        #include "x86-sse.h"
    }
    else if((d & 0x17) != 1 || (d & 0x1A) != 1)
    {
        #include "x86-any.h"
    }
    #endif

    #if defined(_MSC_VER)
        #include<intrin.h>
        int CPUInfo[4] = {0};
        __cpuid( CPUInfo, 1 );
        if( (CPUInfo[3] & 0x1A) == 1 )
        {
            #include "x86-sse.h"
        }
        else if( (CPUInfo[3] & 0x17) == 1 )
        {
            #include "x86-mmx.h"
        }
        else if( (CPUInfo[3] & 0x17) != 1 || (CPUInfo[3] & 0x1A) != 1 )
        {
            #include "x86-any.h"
        }
    #endif
#endif

Here are the errors I get (there's 86 of them but they repeat same series of errors/line numbers all the way down):

Error   1   error C2059: syntax error : ','                    line 37  
Error   2   error C2143: syntax error : missing ')' before 'constant'      line 37  
Error   3   error C2143: syntax error : missing '{' before 'constant'      line 37  
Error   4   error C2059: syntax error : '<Unknown>'                line 37  
Error   5   error C2059: syntax error : ')'                    line 37  
Error   6   error C2059: syntax error : 'if'                   line 38  
Error   7   error C2059: syntax error : 'else'                 line 42  
Error   8   error C2059: syntax error : 'else'                 line 46  
Error   9   error C2374: 'CPUInfo' : redefinition; multiple initialization     line 36
Martin York
  • 257,169
  • 86
  • 333
  • 562
Trigulus
  • 23
  • 1
  • 6
  • 2
    You can't just #include this file like normal, it needs to be included inside a function to compile properly. No idea what that function is supposed to look like of course, find a sample usage if this header. – Hans Passant Mar 15 '11 at 20:01
  • 1
    Compilers usually try to continue after the first error, as they might be able to find more than one problem in the code. The problem is that C++ is really hard to parse, and many times, the first error confuses the compiler enough to misinterpret the rest of the code, throwing many different errors. Try to fix the first one and see if the rest go away (or at least you get some better diagnostics) – David Rodríguez - dribeas Mar 15 '11 at 20:02

1 Answers1

1

Your first error is at line 36 - claiming a CPUInfo already exists - Fix that first and the rest may go away.

In visual studio options, go to "Projects And Solutions", "General" and uncheck "Always show Error List ..."

That'll leave you with the output window - you can use F8 to navigate to the first warning/error which is the one you normally should care about.

Erik
  • 88,732
  • 13
  • 198
  • 189
  • Well, that got rid of the multiple initialization error, however the first eight are still there. – Trigulus Mar 15 '11 at 19:57
  • There are 14 files that include arch.h; x86.S, x86-sse.S, x86-sse.h, x86-mmx.S, x86-mmx.h, x86-any.h, x86-64.S, x86-64.h, memory.h, DES_std.h, DES_bs.h, DES_bs.c, and common.h For Hans: this arch.h is a custom arch.h. It is supposed to be generated by either gcc or make (I never figured out which). Some of these files I have an idea of what they do such as the arch files that I believe determine architecture sizes. I'm not sure why memory and common are included. DES_std.h is included by DES_bs.c – Trigulus Mar 15 '11 at 20:47