News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Made a routine for checking cpuid stuff and a maybe a better MemCopy

Started by GabrielRavier, January 04, 2019, 06:32:04 AM

Previous topic - Next topic

aw27

Building with MASM the .asm listing then linking with polink to save 160 bytes (no rich PE in polink).
Result: 3040 bytes

TimoVJL

Didn't work in Windows 7 :(
/ALIGN:16 works in Windows XP and  Windows 10.
QuoteThe application was unable to start correctly (0x00000018). Click OK to close the application.
May the source be with you

aw27

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--

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.

aw27

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

Feature ?
Quote32/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
May the source be with you

GabrielRavier

My github profile
https://github.com/GabrielRavier

aw27

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

MulDiv simplify code in limited range
long long llFreq, llTime, llStart;
QueryPerformanceFrequency(&llFreq);
QueryPerformanceCounter(&llStart);
...
QueryPerformanceCounter(&llTime);
llTime = MulDiv(llTime - llStart, 1000, llFreq);
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
double dTime = (ll2-ll1) * 1000.0 / llf;
May the source be with you