News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Code alignment test

Started by hutch--, April 28, 2006, 11:21:42 AM

Previous topic - Next topic

hutch--

If anyone has the time, could you build and run this test, its designed to test speed differences between aligned and unaligned labels at the start of an intensive loop.

These are the times I typically get with it. I would post the complete test piece but with the zero padding, it builds at 266k which is a bit big to post.


297 misaligned
297 aligned
609 misaligned
297 aligned
297 misaligned
297 aligned
297 misaligned
297 aligned
610 misaligned
297 aligned
312 misaligned
297 aligned
297 misaligned
297 aligned
297 misaligned
297 aligned
-----------------------------
377 misaligned average
297 aligned average
-----------------------------
Press any key to continue ...





; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

comment * -----------------------------------------------------
                        Build this  template with
                       "CONSOLE ASSEMBLE AND LINK"
        ----------------------------------------------------- *

    .code

start:
   
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

    call main
    inkey
    exit

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

align 16

main proc

    LOCAL lcnt  :DWORD
    LOCAL mcnt  :DWORD      ; misaligned count
    LOCAL acnt  :DWORD      ; aligned count

    mov acnt, 0             ; zero both counters
    mov mcnt, 0

    invoke SetPriorityClass,FUNC(GetCurrentProcess),REALTIME_PRIORITY_CLASS

    push esi

    invoke SleepEx,1,0

    REPEAT 8

  ; ********************************************

    invoke GetTickCount
    push eax
    mov esi, 400000000
    jmp @F

  REPEAT 2048
    db 0,0,0,0,0,0,0,0  ; 16k inline padding
  ENDM

  align 4
  nop
  nop
  nop
  nop
  nop
  nop
  nop       ;;; 13 nops
  nop
  nop
  nop
  nop
  nop
  nop
  ; ---------------------------
  @@:
    mov lcnt, 0     ; short intensive loop
    sub esi, 1
    jnz @B
  ; ---------------------------
    invoke GetTickCount
    pop ecx
    sub eax, ecx
    add mcnt, eax
    print str$(eax)," misaligned",13,10

    invoke SleepEx,1,0

  ; ********************************************

    invoke GetTickCount
    push eax
    mov esi, 400000000
    jmp @F

  REPEAT 2048
    db 0,0,0,0,0,0,0,0  ; 16k inline padding
  ENDM

  align 4
  ; ---------------------------
  @@:
    mov lcnt, 0     ; short intensive loop
    sub esi, 1
    jnz @B
  ; ---------------------------
    invoke GetTickCount
    pop ecx
    sub eax, ecx
    add acnt, eax
    print str$(eax)," aligned",13,10

    invoke SleepEx,1,0

  ; ********************************************

    ENDM

    pop esi

    print "-----------------------------",13,10
    shr mcnt, 3
    print str$(mcnt)," misaligned average",13,10
    shr acnt, 3
    print str$(acnt)," aligned average",13,10
    print "-----------------------------",13,10

    invoke SetPriorityClass,FUNC(GetCurrentProcess),NORMAL_PRIORITY_CLASS

    ret

main endp

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««

end start
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Ghirai

#1
Tested on AMD Athlon 64 3000+:

Quote656 misaligned
671 aligned
656 misaligned
656 aligned
657 misaligned
438 aligned
438 misaligned
437 aligned
657 misaligned
656 aligned
656 misaligned
672 aligned
657 misaligned
438 aligned
438 misaligned
437 aligned
-----------------------------
601 misaligned average
550 aligned average
-----------------------------

I removed 'inkey', it wouldn't let me compile.
MASM32 Project/RadASM mirror - http://ghirai.com/hutch/mmi.html

dsouza123


961 misaligned
921 aligned
922 misaligned
921 aligned
921 misaligned
611 aligned
611 misaligned
611 aligned
921 misaligned
921 aligned
921 misaligned
922 aligned
921 misaligned
611 aligned
611 misaligned
611 aligned
-----------------------------
848 misaligned average
766 aligned average
-----------------------------
Press any key to continue ...


Athlon Thunderbird 1300 Mhz
Windows XP

Roger

Hutch,

I ran it several times each gave the same result within 2% -3%

Processor used Pentium IV 2.28GHZ clock
OS WinXP  SP2

I tried it on my 486 with win95 and the system locked up.

:boohoo:
328 misaligned
329 aligned
656 misaligned
328 aligned
344 misaligned
328 aligned
328 misaligned
328 aligned
657 misaligned
344 aligned
328 misaligned
329 aligned
328 misaligned
344 aligned
328 misaligned
328 aligned
-----------------------------
412 misaligned average
332 aligned average
-----------------------------
Press any key to continue ...


Could you expound on your ideas here?

Regards Roger

hutch--

Roger,

What I have tried to do is isolate the external conditions that effect a timing on something as obscure as aligning a label. The SleepEx() OS yield is so each return gets the identical processor priority and the 16k of zero padding is so the code cache is broken for each looped iteration. The PIV I use is reasonably insensitive to code alignment but some of the old timers I have worked on responded a lot more to aligning code labels that were hit in loop code at high speed.

I think the later AMD hardware is more sensitive to code alignment as well but I have not yet run it on my Sempron 2.4.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Roger

Hutch,

Sorry I was too impatient, it didn't lock up results were:-

52123 misaligned
55560 aligned
52049 misaligned
52322 aligned
52100 misaligned
62318 aligned
51812 misaligned
51802 aligned
51929 misaligned
52127 aligned
51810 misaligned
57605 aligned
51902 misaligned
51794 aligned
51788 misaligned
51790 aligned
-------------
51939 misaligned
54414 aligned
---------------

I can run it again but it will have to be overnight as a batch job

Regards Roger4

hutch--

Roger,

Just drop the loop count down as its far too high for a 486, You only need about 500 ms or a bit longer to get consistent results.
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

Roger

Hutch,

What and spoil the joke!

Roger

P1

PIV 2GHz on W2K SP4
501 misaligned
401 aligned
400 misaligned
401 aligned
400 misaligned
401 aligned
441 misaligned
420 aligned
401 misaligned
400 aligned
401 misaligned
401 aligned
400 misaligned
411 aligned
400 misaligned
451 aligned
-----------------------------
418 misaligned average
410 aligned average
-----------------------------
Press any key to continue ...

Regards,  P1  :8)

jdoe

P4 1.68GHz
XP SP2


922 misaligned
480 aligned
511 misaligned
481 aligned
471 misaligned
470 aligned
471 misaligned
471 aligned
480 misaligned
551 aligned
541 misaligned
471 aligned
470 misaligned
481 aligned
471 misaligned
490 aligned
-----------------------------
542 misaligned average
486 aligned average
-----------------------------
Press any key to continue ...



MichaelW

P3-500
W2K SP4
With a bunch of stuff running

2384 misaligned
2383 aligned
2383 misaligned
2384 aligned
2383 misaligned
1593 aligned
1592 misaligned
1592 aligned
2384 misaligned
2393 aligned
2384 misaligned
2383 aligned
2384 misaligned
1602 aligned
1592 misaligned
1592 aligned
-----------------------------
2185 misaligned average
1990 aligned average
-----------------------------

eschew obfuscation

Jimg

#11
This is very strange.  I have run this many times, and the 5th and 6th aligned tests always blow up the aligned average.

Toshiba laptop, XP home, Celeron 2.0GHz, 496 MB ram.


422 misaligned
407 aligned
391 misaligned
391 aligned
391 misaligned
453 aligned
407 misaligned
391 aligned
390 misaligned
750 aligned
500 misaligned
781 aligned
422 misaligned
516 aligned
422 misaligned
391 aligned
-----------------------------
418 misaligned average
510 aligned average
-----------------------------
Press any key to continue ...

Edit--
Oops- was in debug mode.   Still strange timings in release mode-
422 misaligned
390 aligned
390 misaligned
391 aligned
391 misaligned
421 aligned
422 misaligned
390 aligned
406 misaligned
750 aligned
391 misaligned
781 aligned
407 misaligned
532 aligned
406 misaligned
406 aligned
-----------------------------
404 misaligned average
507 aligned average
-----------------------------
Press any key to continue ...

[attachment deleted by admin]

PBrennick

Windows XP on a SONY laptop using an AMD Athlon 1.00GHz, 256 MB RAM.

1442 misaligned
1242 aligned
1201 misaligned
1272 aligned
1202 misaligned
911 aligned
802 misaligned
871 aligned
1202 misaligned
1321 aligned
1202 misaligned
1422 aligned
1202 misaligned
921 aligned
802 misaligned
801 aligned
-----------------------------
1131 misaligned average
1095 aligned average
-----------------------------
Press any key to continue ...

Paul
The GeneSys Project is available from:
The Repository or My crappy website

Roger

Hutch,

I ran your test again on both machines and noticed funny results. I had assembled a second version without the Inkey instruction so it could be used in a .BAT file without needing keyboard input. On testing it I found that it gives consistently (20 -30 runs) different results.

With inkey

328 misaligned
328 aligned
656 misaligned
329 aligned
328 misaligned
328 aligned
328 misaligned
329 aligned
656 misaligned
375 aligned
328 misaligned
344 aligned
328 misaligned
343 aligned
328 misaligned
328 aligned
-----------------------------
410 misaligned average
338 aligned average
-----------------------------
Press any key to continue ...


Without inkey

328 misaligned
640 aligned
328 misaligned
328 aligned
328 misaligned
344 aligned
329 misaligned
328 aligned
328 misaligned
328 aligned
657 misaligned
328 aligned
328 misaligned
328 aligned
328 misaligned
328 aligned
-----------------------------
369 misaligned average
369 aligned average
-----------------------------


I see that the times are consistently 328 sometimes 329 except:-
With inkey;    The 3rd and 9th times are twice this at about 656 (ocasionally as low as 640) and the 14th time is often about 340
Without inkey;  It is the 2nd and 11th times which are twice the length and there are more slightly longer times, ~340, but I see less pattern in them.

You will appreciate that as the odd times are 'misaligned' and the even times are 'aligned' the difference in average times is totally dependent on when the 'long' times occur.

I am sure that Inkey is having some effect but I don't know what it might be. As it is executed at the end, and I assume its effects do not occur before the cause, I suppose it must be due to the space it takes in the executable file.

I did a file compare on the 2 .asm files just to make sure that the only differece was inkey.

On the 486 the max difference in times was only 4% but there was a pattern in that the 5th was always 3%-4% less than the 4th.


Hope this is of help, Regards Roger


tofu-sensei

594 misaligned
594 aligned
593 misaligned
594 aligned
594 misaligned
390 aligned
391 misaligned
391 aligned
594 misaligned
594 aligned
594 misaligned
593 aligned
594 misaligned
391 aligned
390 misaligned
390 aligned
-----------------------------
543 misaligned average
492 aligned average
-----------------------------