Anonymous avatar Anonymous committed 38b19fc

Set CPU flags

Comments (0)

Files changed (5)

 
 Time zone is GMT+2.
 
+0.75_02 Fri Jul 16 01:55:08 2010
+    => Set CPU flags.
+
 0.75_01 Mon Jul 12 03:12:33 2010
     => Disable bundled intrinsics for MinGW 4x.
     => Capture::Tiny is now a prereq.
     PUSHs( sv_2mortal( newSVpv( "____ecx"               , 0 ) ) );
     PUSHs( sv_2mortal( newSVuv( ecx                         ) ) );
 
-    PUSHs( sv_2mortal( newSVpv( "____CpuFeatures"       , 0 ) ) );
+    PUSHs( sv_2mortal( newSVpv( "CpuFeatures"           , 0 ) ) );
     PUSHs( sv_2mortal( newSVuv( CpuFeatures                 ) ) );
 
     PUSHs( sv_2mortal( newSVpv( "SteppingID"            , 0 ) ) );

lib/Sys/Info/Driver/Windows.pm

 use strict;
 use warnings;
 
-our $VERSION = '0.75_01';
+our $VERSION = '0.75_02';
 
 use base qw( Exporter );
 use Carp qw( croak    );

lib/Sys/Info/Driver/Windows/Device/CPU.pm

     Sys::Info::Driver::Windows::Device::CPU::WMI
 );
 use Sys::Info::Constants       qw( :windows_reg    );
-use Sys::Info::Driver::Windows qw( :info :reg :WMI );
+use Sys::Info::Driver::Windows::Constants;
+use Sys::Info::Driver::Windows qw( :info :reg :WMI CPUFeatures );
 use Carp                       qw( croak           );
 use Win32::OLE                 qw( in              );
 
                     or $self->_from_registry
                     or $self->SUPER::identify(@_)
                     or croak('Failed to identify CPU');
+        $self->_set_flags( \@cache );
         $self->{META_DATA} = [ @cache ];
     }
     return $self->_serve_from_cache(wantarray);
 
 # ------------------------[ P R I V A T E ]------------------------ #
 
+sub _set_flags {
+    my($self, $cpu) = @_;
+
+    my %feat = CPUFeatures();
+    my $c    = 'Sys::Info::Driver::Windows::Constants';
+
+    my $get_symbols = sub {
+        # fetch the related constants
+        my $regex = shift || die "Regex missing\n";
+        no strict qw( refs );
+        return grep { $_ =~ $regex } keys %{ $c . q{::} };
+    };
+
+    my $cf = $feat{CpuFeatures};
+    my $f  = $feat{Flags};
+    my $k  = $feat{KFBits};
+    my $ff = $feat{FeatureFlags};
+    my @flags;
+
+    foreach my $flag ( $get_symbols->( qr{ \A CF_ }xms ) ){
+        push @flags, $flag if $f & $c->$flag();
+    }
+
+    foreach my $flag ( $get_symbols->( qr{ \A KF_ }xms ) ){
+        push @flags, $flag if $k & $c->$flag();
+    }
+
+    foreach my $flag ( $get_symbols->( qr{ \A FT_ }xms ) ){
+        push @flags, $flag if $ff & $c->$flag();
+    }
+
+    foreach my $e ( @flags ) {
+        $e =~ s{ \A (?: CF|KF|FT )_ }{}xms;
+    }
+
+    my %fbuf = map { lc $_ => 1 } @flags;
+    @flags = sort keys %fbuf;
+
+    $cpu->[$_]{flags} = [ @flags ] for 0..$#{$cpu};
+    return;
+}
+
 # $REG->{'0/FeatureSet'}
 # $REG->{'0/Update Status'}
 sub _from_registry {
 
 diag $d->Dump;
 
+ok( defined $feat{$_}, "$_ CPU Feature defined" )
+    for qw(
+        APICPhysicalID
+        BrandIndex
+        BrandString
+        CLFLUSHcachelinesize
+        CPLQualifiedDebugStore
+        Count
+        CpuFeatures
+        ExIds
+        Extendedfamily
+        Extendedmodel
+        Family
+        FeatureFlags
+        FeatureInfo
+        Flags
+        Ids
+        KFBits
+        L2Associativity
+        L2CacheLineSize
+        L2CacheSizeK
+        MONITOR_MWAIT
+        Model
+        ProcessorType
+        SSE3NewInstructions
+        SteppingID
+        String
+        ThermalMonitor2
+        ____ebx
+        ____ecx
+    );
+
 ok( 1, 'The END' );
 
 1;
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.