Download Reference Manual
The Developer's Library for D
About Wiki Forums Source Search Contact

Changeset 3999

Show
Ignore:
Timestamp:
10/10/08 04:27:31 (1 month ago)
Author:
Don Clugston
Message:

Extended the list of features.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tango/math/internal/Cache.d

    r3995 r3999  
    8383    char[] vendor()     {return vendorID;} 
    8484    /// Returns processor string, for display purposes only 
    85     char[] processor()      {return processorName;} 
     85    char[] processor()      {return processorName;}     
    8686     
    8787    /// The data caches. If there are fewer than 5 physical caches levels, 
    8888    /// the remaining levels are set to uint.max (== entire memory space) 
    8989    CacheInfo[5] datacache; 
    90     /// Does it have an x87 FPU
    91     bool x87()          {return (features&FPU_BIT)!=0;} 
     90    /// Does it have an x87 FPU on-chip
     91    bool x87onChip()          {return (features&FPU_BIT)!=0;} 
    9292    /// Is MMX supported? 
    9393    bool mmx()          {return (features&MMX_BIT)!=0;} 
     
    154154    /// (1) Intel P6 (PentiumPro, PII, PIII, PM, Core, Core2). 
    155155    /// (2) AMD Athlon (K7, K8, K10). 
    156     /// (3) Intel NetBurst (Pentium 4, PentiumD). 
    157     /// (4) In-order (Pentium1, PMMX, Atom) 
    158     /// (5) Other cores, mostly in-order (Nx586, AMD K5, K6, Centaur C3, 
    159     ///       Cyrix, Transmeta, etc) 
     156    /// (3) Intel NetBurst (Pentium 4, Pentium D). 
     157    /// (4) In-order Pentium (Pentium1, PMMX) 
     158    /// Other early CPUs (Nx586, AMD K5, K6, Centaur C3, Transmeta, 
     159    ///   Cyrix, Rise) were mostly in-order. 
     160    /// Intel Atom and Centaur Isaiah are recent CPUs which do not fit 
     161    /// into existing categories. 
    160162    /// 
    161163    /// Within each dynasty, the optimisation techniques are largely 
     
    171173 
    172174private:     
     175public: 
     176    /// Processor type (vendor-dependent). 
     177    /// This should be visible ONLY for display purposes. 
     178    uint stepping, model, family; 
     179    uint numCacheLevels = 1; 
     180    private: 
    173181    bool probablyIntel; // true = _probably_ an Intel processor, might be faking 
    174182    bool probablyAMD; // true = _probably_ an AMD processor 
    175     /// Processor type (vendor-dependent). 
    176     /// This should be visible ONLY for display purposes. 
    177     uint stepping, model, family; 
    178183    char [12] vendorID; 
    179184    char [] processorName; 
    180185    char [48] processorNameBuffer; 
    181     uint numCacheLevels = 1; 
    182186    uint features = 0;     // mmx, sse, sse2, hyperthreading, etc 
    183     uint miscfeatures = 0; // popcnt, sse3, etc. 
    184     uint amdfeatures = 0;  // 3dnow!, mmxext, etc 
     187    uint miscfeatures = 0; // sse3, etc. 
     188    uint amdfeatures = 0;  // 3DNow!, mmxext, etc 
    185189    uint amdmiscfeatures = 0; // sse4a, sse5, svm, etc 
    186190    uint maxCores = 1; 
     
    189193    bool hyperThreadingBit()    { return (features&HTT_BIT)!=0;} 
    190194     
    191     // feature flags 
     195    // feature flags CPUID1_EDX 
    192196    enum : uint 
    193197    { 
     
    204208        IA64_BIT = 1<<30 
    205209    } 
    206     // feature flags misc    
     210    // feature flags misc CPUID1_ECX 
    207211    enum : uint 
    208212    { 
    209213        SSE3_BIT = 1, 
     214        PCLMULQDQ_BIT = 1<<1, // from AVX 
    210215        MWAIT_BIT = 1<<3, 
    211216        SSSE3_BIT = 1<<9, 
     217        FMA_BIT = 1<<12,     // from AVX 
    212218        CMPXCHG16B_BIT = 1<<13, 
    213219        SSE41_BIT = 1<<19, 
    214220        SSE42_BIT = 1<<20, 
    215         POPCNT_BIT = 1<<23 
     221        POPCNT_BIT = 1<<23, 
     222        AES_BIT = 1<<25, // AES instructions from AVX 
     223        OSXSAVE_BIT = 1<<27, // Used for AVX 
     224        AVX_BIT = 1<<28 
    216225    } 
    217226/+     
    218227    // Does it have Cyrix MMX extensions? (This works, but who cares?) 
    219     bool has6x86MMX()           {return ((features&FXSR_BIT)==0) && ((amdfeatures&FXR_OR_CYRIXMMX_BIT)!=0);} 
     228    bool has6x86MMX()           {return ((features&FXSR_BIT)==0) 
     229        && ((amdfeatures&FXR_OR_CYRIXMMX_BIT)!=0);}     
     230version(X86_64) {     
     231    bool hasAVXinHardware() { 
     232        // This only indicates hardware support, not OS support. 
     233        return (miscfeatures&AVX_BIT) && (miscfeatures&OSXSAVE_BIT); 
     234    } 
     235    // Is AVX supported (in both hardware & OS)? 
     236    bool Avx() { 
     237        if (!hasAVXinHardware()) return false; 
     238        // Check for OS support 
     239        uint xfeatures; 
     240        asm {mov ECX, 0; xgetbv; mov xfeatures, EAX; } 
     241        return (xfeatures&0x6)==6; 
     242    } 
     243    bool hasAvxFma() { 
     244        if (!AVX()) return false; 
     245        return (features&FMA_BIT)!=0;         
     246    } 
     247
    220248+/     
    221249    // AMD feature flags 
     
    288316                datacache[level].size=sizes[i]; 
    289317                datacache[level].associativity=ways[i]; 
    290                 if (level ==3 || x==0x2C || (x>=0x48 && x<=0x80) || x==0x86 || x==0x87 
     318                if (level == 3 || x==0x2C || (x>=0x48 && x<=0x80)  
     319                    || x==0x86 || x==0x87 
    291320                    || (x>=0x66 && x<=0x68) || (x>=0x39 && x<=0x3E) ){ 
    292321                    datacache[level].lineSize = 64;