Author Topic: Made a routine for checking cpuid stuff and a maybe a better MemCopy  (Read 2412 times)

AW

  • Member
  • *****
  • Posts: 2431
  • Let's Make ASM Great Again!
Re: Made a routine for checking cpuid stuff and a maybe a better MemCopy
« Reply #15 on: January 07, 2019, 07:02:32 AM »
Even better, 3328 bytes  :t

AW

  • Member
  • *****
  • Posts: 2431
  • Let's Make ASM Great Again!
Re: Made a routine for checking cpuid stuff and a maybe a better MemCopy
« Reply #16 on: January 11, 2019, 12:39:12 AM »
Building with MASM the .asm listing then linking with polink to save 160 bytes (no rich PE in polink).
Result: 3040 bytes

TimoVJL

  • Member
  • ***
  • Posts: 476
Re: Made a routine for checking cpuid stuff and a maybe a better MemCopy
« Reply #17 on: January 11, 2019, 01:02:13 AM »
Didn't work in Windows 7 :(
/ALIGN:16 works in Windows XP and  Windows 10.
Quote
The application was unable to start correctly (0x00000018). Click OK to close the application.
« Last Edit: January 11, 2019, 03:42:24 AM by TimoVJL »
May the source be with you

AW

  • Member
  • *****
  • Posts: 2431
  • Let's Make ASM Great Again!
Re: Made a routine for checking cpuid stuff and a maybe a better MemCopy
« Reply #18 on: January 11, 2019, 06:26:13 AM »
Windows 7 dislikes executables built with the /ALIGN option. I was not expecting that, may be I am missing something but right now I can not figure out what.
/ALIGN:4096 works though.

hutch--

  • Administrator
  • Member
  • ******
  • Posts: 6752
  • Mnemonic Driven API Grinder
    • The MASM32 SDK
Re: Made a routine for checking cpuid stuff and a maybe a better MemCopy
« Reply #19 on: January 11, 2019, 10:55:32 AM »
If it is what I think it is, a PE file should have the default /align:512   . It varies with OS versions but 512 works on all versions.
hutch at movsd dot com
http://www.masm32.com    :biggrin:  :skrewy:

AW

  • Member
  • *****
  • Posts: 2431
  • Let's Make ASM Great Again!
Re: Made a routine for checking cpuid stuff and a maybe a better MemCopy
« Reply #20 on: January 11, 2019, 11:02:01 PM »
The "good" news is that this 3040 byte program with /ALIGN:16 works in Windows 7 32-bit and Windows 8.1 32-bit (but not 64-bit). The "bad" news is that probably nobody in the World is using Windows 7 32-bit and Windows 8.1 32-bit.
Since it works in Windows 10 64-bit, but does not work on 64-bit editions of XP, 7 and 8, we may assume that it was a WoW64 bug that was finally corrected.

TimoVJL

  • Member
  • ***
  • Posts: 476
Re: Made a routine for checking cpuid stuff and a maybe a better MemCopy
« Reply #21 on: January 11, 2019, 11:13:58 PM »
Feature ?
Quote
32/32
   4
   SectionAlignment
   The alignment (in bytes) of sections when they are loaded into memory. It must be greater than or equal to FileAlignment. The default is the page size for the architecture.
36/36
   4
   FileAlignment
   The alignment factor (in bytes) that is used to align the raw data of sections in the image file. The value should be a power of 2 between 512 and 64 K, inclusive. The default is 512. If the SectionAlignment is less than the architecture's page size, then FileAlignment must match SectionAlignment.
A TestAndBench3 example (3 584 bytes) compiled with msvc 2010 SP1.
TestAndBench3src1.zip an example (3 072 bytes) using MulDiv
« Last Edit: January 12, 2019, 09:02:11 PM by TimoVJL »
May the source be with you

GabrielRavier

  • Regular Member
  • *
  • Posts: 18
Re: Made a routine for checking cpuid stuff and a maybe a better MemCopy
« Reply #22 on: January 11, 2019, 11:52:34 PM »
I'm using Win10 32-bit lol

AW

  • Member
  • *****
  • Posts: 2431
  • Let's Make ASM Great Again!
Re: Made a routine for checking cpuid stuff and a maybe a better MemCopy
« Reply #23 on: January 12, 2019, 12:59:27 AM »
OK, default /ALIGN is 4KB (https://docs.microsoft.com/en-us/cpp/build/reference/align-section-alignment?view=vs-2017).
If we set it to less than 4KB /FILEALIGNMENT must have the same value.
However /FILEALIGNMENT range is from 512 Bytes to 64 KB (the default is 512 B)
This appears to imply that /ALIGN can never be less than 512 Bytes, otherwise /FILEALIGNMENT will need to be less than 512 Bytes to match it but then will be out of range.
Looks clear like water, or may be not.

TimoVJL

  • Member
  • ***
  • Posts: 476
Re: Made a routine for checking cpuid stuff and a maybe a better MemCopy
« Reply #24 on: January 12, 2019, 10:39:54 PM »
MulDiv simplify code in limited range
Code: [Select]
long long llFreq, llTime, llStart;
QueryPerformanceFrequency(&llFreq);
QueryPerformanceCounter(&llStart);
...
QueryPerformanceCounter(&llTime);
llTime = MulDiv(llTime - llStart, 1000, llFreq);
Code: [Select]
LOCAL llFreq:QWORD, llTime:QWORD, llStart:QWORD
invoke QueryPerformanceFrequency, addr llFreq
invoke QueryPerformanceCounter, addr llStart
...
invoke QueryPerformanceCounter, addr llTime
mov eax, DWORD PTR llTime
;mov ecx, DWORD PTR llTime + 4
sub eax, DWORD PTR llStart
;sbb ecx, DWORD PTR llStart + 4
invoke MulDiv, eax, 1000, DWORD PTR llFreq
EDIT: using FPU
Code: [Select]
double dTime = (ll2-ll1) * 1000.0 / llf;
« Last Edit: January 19, 2019, 02:15:05 AM by TimoVJL »
May the source be with you