tools/cpuflags.c
author Radek Brich <radek.brich@devl.cz>
Sat, 10 May 2008 14:29:37 +0200
branchpyrit
changeset 95 ca7d4c665531
parent 70 4b84e90325c5
child 103 3b3257a410fe
permissions -rw-r--r--
build script fixes, add ldflags build option update and enhance demos fix bug in 4x grid oversampling warn if writePNG called while compiled without libpng make shapes in ShapeList const and add many other const needed due to snowball effect slightly optimize Camera::makeRayPacket using _mm_shuffle_ps make Vector SIMD vectorization disabled by default (causes problems) fix bug in implicit reflection of transmissive surfaces, when surface's reflection parameter is set to zero
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
68
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     1
/*
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     2
 * cpuflags
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     3
 *
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     4
 * Simple tool which detects CPU capabilities
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     5
 * and outputs appropriate compiler flags.
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     6
 *
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     7
 * Usage:
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     8
 *  cpuflags [gcc version] [intelc version]
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
     9
 *
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    10
 * Returns:
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    11
 *  [arch]
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    12
 *  [gcc flags]
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    13
 *  [intelc flags]
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    14
 *
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    15
 * The gcc/intelc version must be passed as floating point value,
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    16
 * e.g. 4.23
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    17
 *
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    18
 * Copyright (C) 2008  Radek Brich <radek@brich.org>
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    19
 *
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    20
 * Based on x86cpucaps
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    21
 * by Osamu Kayasono <jacobi@jcom.home.ne.jp>
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    22
 * http://members.jcom.home.ne.jp/jacobi/linux/softwares.html
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    23
 *
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    24
 * This program is free software; you can redistribute it and/or
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    25
 * modify it under the terms of the GNU General Public License
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    26
 * as published by the Free Software Foundation; either version 2
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    27
 * of the License, or (at your option) any later version.
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    28
 *
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    29
 * This program is distributed in the hope that it will be useful,
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    30
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    31
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    32
 * GNU General Public License for more details.
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    33
 *
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    34
 * You should have received a copy of the GNU General Public License
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    35
 * along with this program; if not, write to the Free Software
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    36
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    37
 */
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    38
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    39
#include <stdio.h>
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    40
#include <stdlib.h>
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    41
#include <string.h>
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    42
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    43
#define LEN_VENDORNAME 13
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    44
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    45
#define VENDOR_INTEL     1
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    46
#define VENDOR_AMD       2
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    47
#define VENDOR_CYRIX     3
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    48
#define VENDOR_CENTAUR   4
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    49
#define VENDOR_TRANSMETA 5
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    50
#define VENDOR_OTHERS    0
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    51
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    52
struct simdcaps
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    53
{
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    54
   unsigned int has_mmx;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    55
   unsigned int has_sse;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    56
   unsigned int has_sse2;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    57
   unsigned int has_sse3;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    58
   unsigned int has_ssse3;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    59
   unsigned int has_sse41;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    60
   unsigned int has_sse42;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    61
   unsigned int has_mmxext;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    62
   unsigned int has_3dnowext;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    63
   unsigned int has_3dnow;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    64
};
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    65
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    66
/* CPU caps */
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    67
#define FLAG_MMX      (1<<23)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    68
#define FLAG_SSE      (1<<25)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    69
#define FLAG_SSE2     (1<<26)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    70
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    71
/* CPU caps 2 */
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    72
#define FLAG_SSE3     (1<<0)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    73
#define FLAG_SSSE3    (1<<9)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    74
#define FLAG_SSE41    (1<<19)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    75
#define FLAG_SSE42    (1<<20)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    76
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    77
/* AMD CPU caps */
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    78
#define FLAG_MMXEXT   (1<<22)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    79
#define FLAG_3DNOWEXT (1<<30)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    80
#define FLAG_3DNOW    (1<<31)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    81
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    82
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    83
/* cpuid, from kernel source ( linux/include/asm-i386/processor.h ) */
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    84
inline void cpuid(int op, int *eax, int *ebx, int *ecx, int *edx)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    85
{
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    86
   __asm__("cpuid" : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) : "a" (op));
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    87
}
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    88
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    89
/*
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    90
 * check SIMD capabilities
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    91
 */
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    92
int x86cpucaps_simd(struct simdcaps *simd)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    93
{
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    94
   int ex[4];
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    95
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    96
   memset(&(*simd),0,sizeof(struct simdcaps));
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    97
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    98
   /* check CPU has CPUID */
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
    99
   cpuid(0,&ex[0],&ex[1],&ex[2],&ex[3]);
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   100
   if ( ex[0] < 1) return 1;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   101
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   102
   cpuid(0x80000001,&ex[0],&ex[1],&ex[2],&ex[3]);
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   103
   if ( (ex[3] & FLAG_MMXEXT ) == FLAG_MMXEXT) simd->has_mmxext = 1;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   104
   if ( (ex[3] & FLAG_3DNOW ) == FLAG_3DNOW) simd->has_3dnow = 1;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   105
   if ( (ex[3] & FLAG_3DNOWEXT ) == FLAG_3DNOWEXT) simd->has_3dnowext = 1;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   106
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   107
   cpuid(1,&ex[0],&ex[1],&ex[2],&ex[3]);
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   108
   if ( (ex[3] & FLAG_MMX  ) == FLAG_MMX ) simd->has_mmx = 1;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   109
   if ( (ex[3] & FLAG_SSE  ) == FLAG_SSE ) simd->has_sse = 1;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   110
   if ( (ex[3] & FLAG_SSE2 ) == FLAG_SSE2) simd->has_sse2 = 1;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   111
   if ( (ex[2] & FLAG_SSE3  ) == FLAG_SSE3 ) simd->has_sse3 = 1;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   112
   if ( (ex[2] & FLAG_SSSE3  ) == FLAG_SSSE3 ) simd->has_ssse3 = 1;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   113
   if ( (ex[2] & FLAG_SSE41  ) == FLAG_SSE41 ) simd->has_sse41 = 1;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   114
   if ( (ex[2] & FLAG_SSE42  ) == FLAG_SSE42 ) simd->has_sse42 = 1;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   115
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   116
   /* SSE CPU supports mmxext too */
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   117
   if (simd->has_sse == 1) simd->has_mmxext = 1;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   118
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   119
   return 0;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   120
}
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   121
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   122
/*
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   123
 * check CPU Family-Model-Stepping
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   124
 */
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   125
int x86cpucaps_cpumodel()
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   126
{
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   127
   int ex[4];
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   128
   int f = 0;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   129
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   130
   /* check CPU has CPUID */
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   131
   cpuid(0,&ex[0],&ex[1],&ex[2],&ex[3]);
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   132
   if ( ex[0] < 1) return f;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   133
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   134
   cpuid(1,&ex[0],&ex[1],&ex[2],&ex[3]);
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   135
   f = ex[0] & 0x0fff;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   136
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   137
   return f;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   138
}
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   139
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   140
/*
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   141
 * check CPU Vendor
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   142
 */
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   143
int x86cpucaps_vendor(char *vendorname)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   144
{
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   145
   int ex[4];
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   146
   int f = 0;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   147
   char vendorstr[LEN_VENDORNAME];
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   148
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   149
   /* check CPU has CPUID */
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   150
   cpuid(0,&ex[0],&ex[1],&ex[2],&ex[3]);
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   151
   if ( ex[0] < 1) return f;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   152
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   153
   /* read Vendor Strings */
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   154
   vendorstr[0] =  ex[1] & 0xff;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   155
   vendorstr[1] =  (ex[1] >> 8) & 0xff;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   156
   vendorstr[2] = (ex[1] >> 16) & 0xff;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   157
   vendorstr[3] = (ex[1] >> 24) & 0xff;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   158
   vendorstr[4] =  ex[3] & 0xff;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   159
   vendorstr[5] = (ex[3] >> 8) & 0xff;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   160
   vendorstr[6] = (ex[3] >> 16) & 0xff;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   161
   vendorstr[7] = (ex[3] >> 24) & 0xff;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   162
   vendorstr[8] =  ex[2] & 0xff;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   163
   vendorstr[9] = (ex[2] >> 8) & 0xff;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   164
   vendorstr[10]= (ex[2] >> 16) & 0xff;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   165
   vendorstr[11]= (ex[2] >> 24) & 0xff;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   166
   vendorstr[12]= '\0';
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   167
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   168
   if ( strcmp(vendorstr, "GenuineIntel") == 0 )
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   169
     f = VENDOR_INTEL;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   170
   else if ( strcmp(vendorstr, "AuthenticAMD") == 0 )
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   171
     f = VENDOR_AMD;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   172
   else if ( strcmp(vendorstr, "CyrixInstead") == 0 )
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   173
     f = VENDOR_CYRIX;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   174
   else if ( strcmp(vendorstr, "CentaurHauls") == 0 )
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   175
     f = VENDOR_CENTAUR;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   176
   else if ( strcmp(vendorstr, "GenuineTMx86") == 0 )
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   177
     f = VENDOR_TRANSMETA;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   178
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   179
   strncpy(vendorname, vendorstr, LEN_VENDORNAME);
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   180
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   181
   return f;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   182
}
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   183
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   184
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   185
int main(int argc, char **argv)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   186
{
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   187
   int family, model, stepping;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   188
   char *arch, *gccarch, *gccsimd, *iccarch, *icctune, *iccsimd;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   189
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   190
   int cpu_id = x86cpucaps_cpumodel();
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   191
   char vendorname[LEN_VENDORNAME];
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   192
   int vendor_id = x86cpucaps_vendor(vendorname);
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   193
   struct simdcaps simd;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   194
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   195
   float gccver = 999.;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   196
   float iccver = 999.;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   197
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   198
   if (argc > 1)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   199
     gccver = atof(argv[1]);
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   200
   if (argc > 2)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   201
     iccver = atof(argv[2]);
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   202
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   203
   family   = (cpu_id & 0xf00) >> 8;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   204
   model    = (cpu_id & 0x0f0) >> 4;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   205
   stepping =  cpu_id & 0x00f;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   206
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   207
   switch (vendor_id)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   208
   {
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   209
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   210
   case VENDOR_INTEL:
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   211
     if (family == 4)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   212
     {
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   213
       arch = "i486";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   214
     }
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   215
     else if (family == 5)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   216
     {
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   217
       if (model < 4) arch = "pentium";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   218
       else arch = "pentium-mmx";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   219
     }
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   220
     else if (family == 6)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   221
     {
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   222
       if (model <= 1) arch = "pentiumpro";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   223
       else if (model < 7) arch = "pentium2";
70
4b84e90325c5 a fix for CPU and compiler detection
Radek Brich <radek.brich@devl.cz>
parents: 68
diff changeset
   224
       else if (model < 12) arch = "pentium3";
4b84e90325c5 a fix for CPU and compiler detection
Radek Brich <radek.brich@devl.cz>
parents: 68
diff changeset
   225
       else if (model < 14) arch = "pentium-m";
4b84e90325c5 a fix for CPU and compiler detection
Radek Brich <radek.brich@devl.cz>
parents: 68
diff changeset
   226
       else if (model == 14) arch = "prescott"; // core
4b84e90325c5 a fix for CPU and compiler detection
Radek Brich <radek.brich@devl.cz>
parents: 68
diff changeset
   227
       else if (model == 15) arch = "core2";
68
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   228
     }
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   229
     else if (family > 6)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   230
     { /* family == 15 */
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   231
       arch = "pentium4";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   232
     }
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   233
     else
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   234
     {
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   235
       arch = "i386";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   236
     }
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   237
     break;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   238
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   239
   case VENDOR_AMD:
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   240
     if (family == 4)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   241
     {
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   242
       if (model <= 9) arch = "i486";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   243
       else arch = "i586";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   244
     }
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   245
     else if (family == 5)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   246
     {
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   247
       if (model <= 3) arch = "i586";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   248
       else if (model <= 7) arch = "k6";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   249
       else if (model == 8) arch = "k6-2";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   250
       else arch = "k6-3";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   251
     }
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   252
     else if (family == 6)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   253
     {
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   254
       if (model <= 3) arch = "athlon";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   255
       else if (model == 4) arch = "athlon-tbird";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   256
       else arch = "athlon-xp";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   257
     }
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   258
     else if (family > 6)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   259
     {
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   260
       arch = "k8";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   261
     }
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   262
     else
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   263
     {
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   264
       arch = "unknown";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   265
     }
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   266
     break;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   267
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   268
   case VENDOR_CYRIX:
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   269
     if (family == 4) arch = "i586";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   270
     else if (family == 5) arch = "i586";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   271
     else if (family == 6) arch = "i686";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   272
     else arch = "unknown";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   273
     break;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   274
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   275
   case VENDOR_CENTAUR:
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   276
     if (family == 5) arch = "i586";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   277
     else arch = "unknown";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   278
     break;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   279
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   280
   case VENDOR_TRANSMETA:
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   281
     arch = "i686";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   282
     break;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   283
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   284
   default:
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   285
     arch = "unknown";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   286
     break;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   287
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   288
   }
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   289
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   290
   /* some targets not supported by older gcc */
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   291
   gccarch = arch;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   292
   if (gccver < (float)4.3)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   293
   {
70
4b84e90325c5 a fix for CPU and compiler detection
Radek Brich <radek.brich@devl.cz>
parents: 68
diff changeset
   294
     if (!strcmp(gccarch, "core2")) gccarch = "pentium-m";
4b84e90325c5 a fix for CPU and compiler detection
Radek Brich <radek.brich@devl.cz>
parents: 68
diff changeset
   295
   }
4b84e90325c5 a fix for CPU and compiler detection
Radek Brich <radek.brich@devl.cz>
parents: 68
diff changeset
   296
   if (gccver < (float)3.41)
4b84e90325c5 a fix for CPU and compiler detection
Radek Brich <radek.brich@devl.cz>
parents: 68
diff changeset
   297
   {
4b84e90325c5 a fix for CPU and compiler detection
Radek Brich <radek.brich@devl.cz>
parents: 68
diff changeset
   298
     if (!strcmp(gccarch, "prescott")) gccarch = "pentium4";
4b84e90325c5 a fix for CPU and compiler detection
Radek Brich <radek.brich@devl.cz>
parents: 68
diff changeset
   299
     if (!strcmp(gccarch, "pentium-m")) gccarch = "pentium4";
68
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   300
   }
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   301
   if (gccver < (float)3.4)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   302
   {
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   303
     if (!strcmp(gccarch, "k8")) gccarch = "athlon-xp";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   304
   }
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   305
   if (gccver < (float)3.1)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   306
   {
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   307
     if (strstr(gccarch, "athlon-") != NULL)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   308
       gccarch = "athlon";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   309
     else if (strstr(gccarch, "k6-") != NULL)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   310
       gccarch = "k6";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   311
     else if (!strcmp(gccarch, "pentium-mmx"))
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   312
       gccarch = "pentium";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   313
     else if (!strcmp(gccarch, "pentium2")
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   314
     || !strcmp(gccarch, "pentium3")
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   315
     || !strcmp(gccarch, "pentium4"))
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   316
       gccarch = "pentiumpro";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   317
   }
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   318
   if (gccver < (float)3.0)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   319
   {
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   320
     if (!strcmp(gccarch, "athlon"))
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   321
       gccarch = "pentiumpro";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   322
     else if (!strcmp(gccarch, "k6"))
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   323
       gccarch = "pentium";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   324
   }
70
4b84e90325c5 a fix for CPU and compiler detection
Radek Brich <radek.brich@devl.cz>
parents: 68
diff changeset
   325
   if (gccver < (float)2.95)
68
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   326
   {
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   327
     if (!strcmp(gccarch, "pentiumpro"))
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   328
       gccarch = "i686";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   329
     else if (!strcmp(gccarch, "pentium"))
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   330
       gccarch = "i586";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   331
   }
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   332
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   333
   /* SIMD options */
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   334
   x86cpucaps_simd(&simd);
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   335
   gccsimd = "";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   336
   if (gccver >= 3.1) {
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   337
     if ( simd.has_3dnow || simd.has_3dnowext )
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   338
       gccsimd = "-m3dnow";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   339
     else
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   340
     {
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   341
       if (gccver >= 4.3)
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   342
       {
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   343
         if (simd.has_sse41 || simd.has_sse42) gccsimd = "-msse4 -mfpmath=sse";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   344
         else if (simd.has_ssse3) gccsimd = "-mssse3 -mfpmath=sse";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   345
       }
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   346
       else if ( gccver >= 3.4 && simd.has_sse3 ) gccsimd = "-msse3 -mfpmath=sse";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   347
       else if ( simd.has_sse2 ) gccsimd = "-msse2 -mfpmath=sse";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   348
       else if ( simd.has_sse ) gccsimd = "-msse";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   349
       else if ( simd.has_mmx ) gccsimd = "-mmmx";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   350
     }
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   351
   }
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   352
70
4b84e90325c5 a fix for CPU and compiler detection
Radek Brich <radek.brich@devl.cz>
parents: 68
diff changeset
   353
   /* IntelC options */
68
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   354
   iccarch = arch;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   355
   icctune = arch;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   356
   iccsimd = "";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   357
   if (simd.has_sse41 || simd.has_sse42) iccsimd = "-xS";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   358
   else if (simd.has_ssse3) iccsimd = "-xT";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   359
   else if (simd.has_sse3) iccsimd = "-msse3 -xP";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   360
   else if (simd.has_sse2) iccsimd = "-msse2";
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   361
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   362
   printf("%s\n", arch);
70
4b84e90325c5 a fix for CPU and compiler detection
Radek Brich <radek.brich@devl.cz>
parents: 68
diff changeset
   363
4b84e90325c5 a fix for CPU and compiler detection
Radek Brich <radek.brich@devl.cz>
parents: 68
diff changeset
   364
   /* GCC flags */
68
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   365
   if (gccver >= 4.2) gccarch = "native";
70
4b84e90325c5 a fix for CPU and compiler detection
Radek Brich <radek.brich@devl.cz>
parents: 68
diff changeset
   366
#ifdef __x86_64__
4b84e90325c5 a fix for CPU and compiler detection
Radek Brich <radek.brich@devl.cz>
parents: 68
diff changeset
   367
   /* do not output i386 flags on x86_64 */
4b84e90325c5 a fix for CPU and compiler detection
Radek Brich <radek.brich@devl.cz>
parents: 68
diff changeset
   368
   if (strcmp(gccarch, "core2") != 0 && strcmp(gccarch, "native") != 0)
4b84e90325c5 a fix for CPU and compiler detection
Radek Brich <radek.brich@devl.cz>
parents: 68
diff changeset
   369
     printf("%s\n", gccsimd);
4b84e90325c5 a fix for CPU and compiler detection
Radek Brich <radek.brich@devl.cz>
parents: 68
diff changeset
   370
   else
4b84e90325c5 a fix for CPU and compiler detection
Radek Brich <radek.brich@devl.cz>
parents: 68
diff changeset
   371
#endif
4b84e90325c5 a fix for CPU and compiler detection
Radek Brich <radek.brich@devl.cz>
parents: 68
diff changeset
   372
   printf("-march=%s %s\n", gccarch, gccsimd);
4b84e90325c5 a fix for CPU and compiler detection
Radek Brich <radek.brich@devl.cz>
parents: 68
diff changeset
   373
4b84e90325c5 a fix for CPU and compiler detection
Radek Brich <radek.brich@devl.cz>
parents: 68
diff changeset
   374
   /* IntelC flags */
68
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   375
   printf("-march=%s -mtune=%s %s\n", iccarch, icctune, iccsimd);
70
4b84e90325c5 a fix for CPU and compiler detection
Radek Brich <radek.brich@devl.cz>
parents: 68
diff changeset
   376
68
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   377
   return 0;
2c154aad7f33 added detection of optimal CPU flags for both GCC and IntelC
Radek Brich <radek.brich@devl.cz>
parents:
diff changeset
   378
}