News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Three methods to get screen width

Started by jj2007, December 22, 2021, 11:03:11 PM

Previous topic - Next topic

jj2007

The most complicated one is the fastest :cool:

Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz (SSE4)

8159    cycles for 100 * GetWindowRect (GetDesktopWindow)
264977  cycles for 100 * SystemParametersInfo
11585   cycles for 100 * GetSystemMetrics

8136    cycles for 100 * GetWindowRect (GetDesktopWindow)
264194  cycles for 100 * SystemParametersInfo
11662   cycles for 100 * GetSystemMetrics

8245    cycles for 100 * GetWindowRect (GetDesktopWindow)
263618  cycles for 100 * SystemParametersInfo
12209   cycles for 100 * GetSystemMetrics

8687    cycles for 100 * GetWindowRect (GetDesktopWindow)
261444  cycles for 100 * SystemParametersInfo
11482   cycles for 100 * GetSystemMetrics

23      bytes for GetWindowRect (GetDesktopWindow)
21      bytes for SystemParametersInfo
12      bytes for GetSystemMetrics

1366    = eax GetWindowRect (GetDesktopWindow)
1366    = eax SystemParametersInfo
1366    = eax GetSystemMetrics

TimoVJL

#1
Windows 7 x64AMD Athlon(tm) II X2 220 Processor (SSE3)

12471   cycles for 100 * GetWindowRect (GetDesktopWindow)
211996  cycles for 100 * SystemParametersInfo
28889   cycles for 100 * GetSystemMetrics
Windows 10 x64AMD Ryzen 5 3400G with Radeon Vega Graphics     (SSE4)

25531   cycles for 100 * GetWindowRect (GetDesktopWindow)
820     kCycles for 100 * SystemParametersInfo
192     kCycles for 100 * GetSystemMetrics

24      kCycles for 100 * GetWindowRect (GetDesktopWindow)
818     kCycles for 100 * SystemParametersInfo
191     kCycles for 100 * GetSystemMetrics

24      kCycles for 100 * GetWindowRect (GetDesktopWindow)
815     kCycles for 100 * SystemParametersInfo
190     kCycles for 100 * GetSystemMetrics

24      kCycles for 100 * GetWindowRect (GetDesktopWindow)
819     kCycles for 100 * SystemParametersInfo
191     kCycles for 100 * GetSystemMetrics

23      bytes for GetWindowRect (GetDesktopWindow)
21      bytes for SystemParametersInfo
12      bytes for GetSystemMetrics

1920    = eax GetWindowRect (GetDesktopWindow)
1920    = eax SystemParametersInfo
1920    = eax GetSystemMetrics


EDIT: GetWindowRect()32-bit
627
147
143
181
141
178
139
138
136
136

64-bit
498
135
136
94
96
94
93
93
93
93

May the source be with you

HSE

Not really  :biggrin:
Intel(R) Core(TM) i3-10100 CPU @ 3.60GHz (SSE4)

249492  cycles for 100 * GetWindowRect (GetDesktopWindow)
446     kCycles for 100 * SystemParametersInfo
164     kCycles for 100 * GetSystemMetrics

239     kCycles for 100 * GetWindowRect (GetDesktopWindow)
441     kCycles for 100 * SystemParametersInfo
164     kCycles for 100 * GetSystemMetrics

240     kCycles for 100 * GetWindowRect (GetDesktopWindow)
437     kCycles for 100 * SystemParametersInfo
164     kCycles for 100 * GetSystemMetrics

240     kCycles for 100 * GetWindowRect (GetDesktopWindow)
444     kCycles for 100 * SystemParametersInfo
166     kCycles for 100 * GetSystemMetrics

23      bytes for GetWindowRect (GetDesktopWindow)
21      bytes for SystemParametersInfo
12      bytes for GetSystemMetrics

1360    = eax GetWindowRect (GetDesktopWindow)
1360    = eax SystemParametersInfo
1360    = eax GetSystemMetrics


Can be a Wow64 trick?
Equations in Assembly: SmplMath

hutch--

As you only need to get the screen width once in an app, who cares.

jj2007

Quote from: hutch-- on December 23, 2021, 12:58:23 AM
As you only need to get the screen width once in an app, who cares.

I agree. Yet, it's strange that simple GetSystemMetrics needs so many cycles. It's ridiculously complicated :cool:

Address   Hex dump          Command                            Comments
74BE7D3F  /$  6A 0C         push 0C                            ; INT user32.GetSystemMetrics(Index)
74BE7D41  |.  68 A87DBE74   push 74BE7DA8
74BE7D46  |.  E8 E2E3FFFF   call 74BE612D
74BE7D4B  |.  8B75 08       mov esi, [ebp+8]
74BE7D4E  |.  83FE 5A       cmp esi, 5A
74BE7D51  |.  0F84 442E0000 je 74BEAB9B
74BE7D57  |.  81FE 00200000 cmp esi, 2000
74BE7D5D  |.  0F84 382E0000 je 74BEAB9B
74BE7D63  |.  E8 86E4FFFF   call 74BE61EE                      ; [user32.74BE61EE
74BE7D68  |.  833D 1C07C574 cmp dword ptr [74C5071C], 0
74BE7D6F  |.  75 08         jne short 74BE7D79
74BE7D71  |.  85C0          test eax, eax
74BE7D73  |.  0F84 FA2D0000 jz 74BEAB73
74BE7D79  |>  E8 4AE4FFFF   call 74BE61C8                      ; [user32.74BE61C8
74BE7D7E  |.  8945 08       mov [ebp+8], eax
74BE7D81  |.  8365 FC 00    and dword ptr [ebp-4], 00000000
74BE7D85  |.  56            push esi                           ; /Arg1
74BE7D86  |.  FF15 C004C574 call near [74C504C0]               ; \user32.74BE7C65
74BE7D8C  |.  8945 E4       mov [ebp-1C], eax
74BE7D8F  |.  C745 FC FEFFF mov dword ptr [ebp-4], -2
74BE7D96  |.  E8 2E000000   call 74BE7DC9                      ; [user32.74BE7DC9
74BE7D9B  |.  8B45 E4       mov eax, [ebp-1C]
74BE7D9E  |>  E8 CFE3FFFF   call 74BE6172
74BE7DA3  \.  C2 0400       retn 4

hutch--

You can tell its not written in MASM, only the fast OS code ever was but look for the "leave" mnemonic in some of the very low level OS stuff and you know what it was written with.