<commit_before>// cpuinfo_papi.cpp : Defines the entry point for the console application.
//


#include "cpuinfo.h"
#include <stdio.h>
#include <windows.h>


// The functions to initialize processor information,
// The only function a user should call is init_hwinfo -KSL

static int init_amd  ( struct wininfo * );
static int init_intel( struct wininfo * );

int init_hwinfo( struct wininfo * hwinfo) {
    volatile unsigned long val,val2, val3;
    SYSTEM_INFO sys_info;
	char vendor[13];
	int tmpmhz,retval;
	ULARGE_INTEGER t1, t2;



	// Initialize the entire array to 0
	memset(hwinfo, 0, sizeof(struct wininfo));

    GetSystemInfo(&sys_info); 

	hwinfo->arch = sys_info.wProcessorArchitecture;
	hwinfo->ncpu = sys_info.dwNumberOfProcessors;
	hwinfo->nnodes = 1;
	hwinfo->total_cpus = hwinfo->nnodes*hwinfo->ncpu;
	hwinfo->vendor = -1;

	if ( hwinfo->arch == PROCESSOR_ARCHITECTURE_INTEL );
	else 
		return -1;

// Lets see if CPUID exists, if not we are running on a PRE 486 processor	
 
	__asm {
		pushfd
		pop eax
		mov ebx, eax
		xor eax, 00200000h
		push eax
		popfd
		pushfd
		pop eax
		cmp eax, ebx
		jz NO_CPUID
		mov val, 1
		jmp END
	NO_CPUID:
		mov val, 0
	END:
	}
	if ( !val ) {
		return -1;
	}

	// Get the Vendor String
	__asm {
		mov EAX, 00h
		CPUID
		mov dword ptr[vendor], ebx
		mov dword ptr[vendor+4], edx
		mov dword ptr[vendor+8], ecx
	};


	vendor[12] = '\0';
	strcpy ( hwinfo->vendor_string, vendor );
	if ( !strcmp( vendor, "AuthenticAMD" ) )
		hwinfo->myvendor = AMD;
	else if ( !strcmp( vendor, "GenuineIntel") )
		hwinfo->myvendor = INTEL;
	else
		hwinfo->myvendor = UNKNOWN;


    // Get the standard information
	__asm {
		mov EAX, 01h
		CPUID
		mov val, eax
		mov val2, ebx
		mov val3, edx

	}

	hwinfo->family=((val&0xf00)>>8);
	hwinfo->processor_type=((val&0x3000)>>12);
	hwinfo->model=((val&0xf0)>>4);
	hwinfo->revision=(val&0xf);
	hwinfo->brand_id=(val2&0xff);

	// caclulate MHz
	__asm {
		rdtsc
		mov t1.LowPart, eax
		mov t1.HighPart, edx
	}
    Sleep(1000);
	__asm {
		rdtsc
		mov t2.LowPart, eax
		mov t2.HighPart, edx
	}
	tmpmhz = (int)((t2.QuadPart - t1.QuadPart)/1000000);
	hwinfo->mhz = tmpmhz;

	if ( hwinfo->myvendor == AMD )
		retval=init_amd( hwinfo );
	else if ( hwinfo->myvendor == INTEL )
		retval=init_intel( hwinfo );
	return retval;
}

static int init_amd( struct wininfo * hwinfo ) {
  // Setup Model Information
  hwinfo->nrctr = 4;
  if ( IS_AMDATHLON(hwinfo) )<commit_msg>Fixes for determing mhz rating on a laptop, basically the tsc doesn't get updated unless the cpu is doing work on laptops with speedstep technology, because of this we need a loop that does busy work while the mhz rating is determined.<commit_after>// cpuinfo_papi.cpp : Defines the entry point for the console application.
// File by <NAME>
//


#include "cpuinfo.h"
#include <stdio.h>
#include <windows.h>


// Have to use the below function because sleep isn't reliable for determining
// Mhz on a laptop.....sigh.....--KSL
int mhz;
UINT_PTR mytimer;

void CALLBACK my_timer( UINT wTimerID, UINT msg, DWORD dwuser, DWORD dw1, DWORD dw2 );

void CALLBACK my_timer( UINT wTimerID, UINT msg, DWORD dwuser, DWORD dw1, DWORD dw2 ){
        static int count=0;
        static int mymhz=0;
        static ULARGE_INTEGER t1,t2;
        int tmpmhz=1;
        __asm {
                rdtsc
                mov t2.LowPart, eax
                mov t2.HighPart, edx
        }
        if ( count == 0 ){
                t1 = t2;
                count++;
                return;
        }
        else
                tmpmhz = (unsigned int)((t2.QuadPart-t1.QuadPart))/1000000;


        if ( tmpmhz > mymhz || mymhz == 0){
                t1 = t2;
                mymhz = tmpmhz;
                return;
        }
        else if ( count > 60 )
                mhz = mymhz;
        else if(tmpmhz!=mymhz){
                t1 = t2;
                count++;
                return;
        }
        timeKillEvent( mytimer );
}

// The functions to initialize processor information,
// The only function a user should call is init_hwinfo -KSL

static int init_amd  ( struct wininfo * );
static int init_intel( struct wininfo * );

int init_hwinfo( struct wininfo * hwinfo) {
    volatile unsigned long val,val2, val3;
    SYSTEM_INFO sys_info;
    char vendor[13];
    int tmpmhz,retval,dowork=0;
    ULARGE_INTEGER t1, t2;



	// Initialize the entire array to 0
	memset(hwinfo, 0, sizeof(struct wininfo));

    GetSystemInfo(&sys_info); 

	hwinfo->arch = sys_info.wProcessorArchitecture;
	hwinfo->ncpu = sys_info.dwNumberOfProcessors;
	hwinfo->nnodes = 1;
	hwinfo->total_cpus = hwinfo->nnodes*hwinfo->ncpu;
	hwinfo->vendor = -1;

	if ( hwinfo->arch == PROCESSOR_ARCHITECTURE_INTEL );
	else 
		return -1;

// Lets see if CPUID exists, if not we are running on a PRE 486 processor	
 
	__asm {
		pushfd
		pop eax
		mov ebx, eax
		xor eax, 00200000h
		push eax
		popfd
		pushfd
		pop eax
		cmp eax, ebx
		jz NO_CPUID
		mov val, 1
		jmp END
	NO_CPUID:
		mov val, 0
	END:
	}
	if ( !val ) {
		return -1;
	}

	// Get the Vendor String
	__asm {
		mov EAX, 00h
		CPUID
		mov dword ptr[vendor], ebx
		mov dword ptr[vendor+4], edx
		mov dword ptr[vendor+8], ecx
	};


	vendor[12] = '\0';
	strcpy ( hwinfo->vendor_string, vendor );
	if ( !strcmp( vendor, "AuthenticAMD" ) )
		hwinfo->myvendor = AMD;
	else if ( !strcmp( vendor, "GenuineIntel") )
		hwinfo->myvendor = INTEL;
	else
		hwinfo->myvendor = UNKNOWN;


    // Get the standard information
	__asm {
		mov EAX, 01h
		CPUID
		mov val, eax
		mov val2, ebx
		mov val3, edx

	}

	hwinfo->family=((val&0xf00)>>8);
	hwinfo->processor_type=((val&0x3000)>>12);
	hwinfo->model=((val&0xf0)>>4);
	hwinfo->revision=(val&0xf);
	hwinfo->brand_id=(val2&0xff);

        mytimer = timeSetEvent( 1000, 0, my_timer, 0, TIME_PERIODIC );
        while ( !mhz ){
		if ( dowork%100000000 )
                	Sleep (1);
	}
        hwinfo->mhz = mhz;


	if ( hwinfo->myvendor == AMD )
		retval=init_amd( hwinfo );
	else if ( hwinfo->myvendor == INTEL )
		retval=init_intel( hwinfo );
	return retval;
}

static int init_amd( struct wininfo * hwinfo ) {
  // Setup Model Information
  hwinfo->nrctr = 4;
  if ( IS_AMDATHLON(hwinfo) )
{'fraction_non_alphanumeric': 0.11499838030450275, 'fraction_numerical': 0.027858762552640103, 'mean_word_length': 2.7176399759181216, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 64, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 1, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '944988', 'n_tokens_mistral': 2538, 'n_tokens_neox': 2291, 'n_words': 641}