News:

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

Code compare between PIV and Core quad. LEA v ADD

Started by hutch--, September 07, 2009, 12:18:55 PM

Previous topic - Next topic

hutch--

This is one of the first tests I wanted to do with the two boxes. In what is a near optimum case for a PIV, a mul by 4 using 2 adds versus a single LEA to do the same 4 times multiplication.

The test result shows the LEA instruction on a Core processor is faster relative to its clock cycle than the ADD instruction which is a reversion to the behaviour of a PIII where the PIV was deviant here.

These are the results I get.


Result 3 gig quad
-----------------

512
512
1329 ADD
937 LEA
1344 ADD
922 LEA
1343 ADD
922 LEA
1453 ADD
938 LEA
1328 ADD
938 LEA
1328 ADD
937 LEA
1344 ADD
922 LEA
1344 ADD
921 LEA
1351 average for ADD
929 average for LEA
Press any key to continue ...

Results 3.8 gig PIV
-------------------

512
512
1125 ADD
1391 LEA
1093 ADD
1375 LEA
1110 ADD
1375 LEA
1109 ADD
1391 LEA
1093 ADD
1375 LEA
1110 ADD
1375 LEA
1094 ADD
1390 LEA
1110 ADD
1375 LEA
1105 average for ADD
1380 average for LEA
Press any key to continue ...


While the PIV is faster on a best case pair of adds as it runs 800 meg faster, the LEA on the quad is both faster than the ADD on the quad and the PIV.

This is the test code.


; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
    include \masm32\include\masm32rt.inc
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

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

    .data?
      value dd ?

    .data
      item dd 0

    .code

start:
   
; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    call main
    inkey
    exit

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

main proc

    lcnt equ <2000000000>

    LOCAL addcnt :DWORD
    LOCAL leacnt :DWORD

    mov addcnt, 0
    mov leacnt, 0

    push esi

    mov eax, 128
    add eax, eax
    add eax, eax
    print str$(eax),13,10

    mov eax, 128
    lea eax, [0+eax*4]

    print str$(eax),13,10

  REPEAT 8

  ; ======================================

    invoke GetTickCount
    push eax

    mov esi, lcnt
  @@:
    mov eax, 128
    add eax, eax
    add eax, eax
    sub esi, 1
    jnz @B

    invoke GetTickCount
    pop ecx
    sub eax, ecx

    add addcnt, eax

    print str$(eax)," ADD",13,10

  ; ======================================

    invoke GetTickCount
    push eax

    mov esi, lcnt
  @@:
    mov eax, 128
    lea eax, [0+eax*4]
    sub esi, 1
    jnz @B

    invoke GetTickCount
    pop ecx
    sub eax, ecx

    add leacnt, eax

    print str$(eax)," LEA",13,10

  ; ======================================

  ENDM

    shr addcnt, 3
    shr leacnt, 3

    print str$(addcnt)," average for ADD",13,10
    print str$(leacnt)," average for LEA",13,10

    pop esi

    ret

main endp

; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

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

sinsi

Q6600, 2.4

512
512
1685 ADD
1170 LEA
1670 ADD
1170 LEA
1669 ADD
1170 LEA
1669 ADD
1170 LEA
1669 ADD
1170 LEA
1669 ADD
1170 LEA
1670 ADD
1170 LEA
1669 ADD
1170 LEA
1671 average for ADD
1170 average for LEA

Light travels faster than sound, that's why some people seem bright until you hear them.

jj2007


fearless

Q9550, 2.83
512
512
1406 ADD
984 LEA
1422 ADD
985 LEA
1406 ADD
984 LEA
1422 ADD
985 LEA
1406 ADD
984 LEA
1406 ADD
1000 LEA
1407 ADD
984 LEA
1406 ADD
985 LEA
1410 average for ADD
986 average for LEA
ƒearless

rags

PIV, 2.53

512
512
1735 ADD
1625 LEA
1625 ADD
1625 LEA
1625 ADD
1625 LEA
1812 ADD
1641 LEA
1609 ADD
1625 LEA
1625 ADD
1641 LEA
1640 ADD
1610 LEA
1640 ADD
1625 LEA
1663 average for ADD
1627 average for LEA
God made Man, but the monkey applied the glue -DEVO

katsyonak

Intel Core 2 Quad Q9550 @ 2.83GHz

512
512
1406 ADD
984 LEA
1407 ADD
1000 LEA
1406 ADD
984 LEA
1422 ADD
985 LEA
1406 ADD
984 LEA
1406 ADD
1000 LEA
1407 ADD
984 LEA
1422 ADD
984 LEA
1410 average for ADD
988 average for LEA
Press any key to continue ...

BlackVortex

Gee, a lot of quad-users here ...

Core 2 Duo E8400

512
512
1357 ADD
936 LEA
1326 ADD
999 LEA
1326 ADD
936 LEA
1326 ADD
936 LEA
1341 ADD
921 LEA
1341 ADD
936 LEA
1326 ADD
936 LEA
1326 ADD
936 LEA
1333 average for ADD
942 average for LEA

hutch--

gratsie all,

Its useful for everyonwe to know instruction comparisons of this type.

BlackVortex, what clock speed is the Duo you tested with, from the times it would have to be about 3 gig or faster. The other question, what FSB / memory speed are you using in it, 1333 ?
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

BlackVortex

Yes, I have it at stock speed 3ghz, and you're right about the fsb, here's some cpu-z information :

Number of cores 2 (max 2)
Number of threads 2 (max 2)
Name Intel Core 2 Duo E8400
Codename Wolfdale
Specification Intel(R) Core(TM)2 Duo CPU     E8400  @ 3.00GHz
Package (platform ID) Socket 775 LGA (0x0)
CPUID 6.7.A
Extended CPUID 6.17
Core Stepping E0
Technology 45 nm
Core Speed 3009.8 MHz
Multiplier x FSB 9.0 x 334.4 MHz
Rated Bus speed 1337.7 MHz
Stock frequency 3000 MHz
Instructions sets MMX, SSE, SSE2, SSE3, SSSE3, SSE4.1, EM64T
L1 Data cache 2 x 32 KBytes, 8-way set associative, 64-byte line size
L1 Instruction cache 2 x 32 KBytes, 8-way set associative, 64-byte line size
L2 cache 6144 KBytes, 24-way set associative, 64-byte line size
FID/VID Control yes
FID range 6.0x - 9.0x
Max VID 1.250 V

hutch--

This is the CPU-Z info on the quad I am using, very similar apart from the core count.


Processor 1                  ID = 0
        Number of cores        4 (max 4)
        Number of threads      4 (max 4)
        Name                   Intel Core 2 Quad Q9650
        Codename               Yorkfield
        Specification          Intel(R) Core(TM)2 Quad CPU    Q9650  @ 3.00GHz
        Package (platform ID)  Socket 775 LGA (0x4)
        CPUID                  6.7.A
        Extended CPUID         6.17
        Core Stepping          E0
        Technology             45 nm
        Core Speed             3000.2 MHz
        Multiplier x FSB       9.0 x 333.4 MHz
        Rated Bus speed        1333.4 MHz
        Stock frequency        3000 MHz
        Instructions sets MMX, SSE, SSE2, SSE3, SSSE3, SSE4.1, EM64T
        L1 Data cache          4 x 32 KBytes, 8-way set associative, 64-byte line size
        L1 Instruction cache   4 x 32 KBytes, 8-way set associative, 64-byte line size
        L2 cache               2 x 6144 KBytes, 24-way set associative, 64-byte line size
        FID/VID Control        yes
        FID range              6.0x - 9.0x
        Max VID                1.250 V
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php

ecube


512
512
3656 ADD
4328 LEA
2610 ADD
3562 LEA
3485 ADD
3437 LEA
3500 ADD
3469 LEA
3469 ADD
3468 LEA
3485 ADD
3484 LEA
3703 ADD
3657 LEA
3718 ADD
4032 LEA
3453 average for ADD
3679 average for LEA
Press any key to continue ...


on my old AMD 64 3000+ can't wait to test it on my quad once I get a new mobo. Can anyone else with a amd post? so far intel seems to be more lea friendly, but they're also newer cpu's so that could be it too.

BlackVortex

I'd like to see timings of an i5 or an i7   :'(   :(

Maybe a Phenom, too ...

FORTRANS

QuoteCan anyone else with a amd post?


PIII w/Win 2000

512
512
7811 ADD
8352 LEA
7041 ADD
7701 LEA
8682 ADD
7671 LEA
11407 ADD
8982 LEA
8593 ADD
8512 LEA
7811 ADD
8733 LEA
7771 ADD
8022 LEA
8882 ADD
7621 LEA
8499 average for ADD
8199 average for LEA
Press any key to continue ...

AMD 64 w/ Win XP

512
512
3000 ADD
3031 LEA
2000 ADD
3016 LEA
3015 ADD
3000 LEA
3297 ADD
3016 LEA
3016 ADD
3093 LEA
3032 ADD
3046 LEA
3188 ADD
3047 LEA
3062 ADD
3125 LEA
2951 average for ADD
3046 average for LEA
Press any key to continue ...


Regards,

Steve N.