Author Topic: The fastest way to fill a dword array with string values  (Read 64228 times)

dedndave

  • Member
  • *****
  • Posts: 8829
  • Still using Abacus 2.0
    • DednDave
Re: The fastest way to fill a dword array with string values
« Reply #60 on: December 10, 2012, 10:50:09 PM »
you could add a little test to see if the CPU supports SSSE3
if it does not, skip that test and say "Frktons II Step requires SSSE3 support" and go on to the next test
Code: [Select]
    mov     eax,1
    cpuid
    test    ch,2
    jz      no_ssse3_support

note: .586 or higher required to assemble "cpuid" without hard-coding

frktons

  • Member
  • ***
  • Posts: 491
Re: The fastest way to fill a dword array with string values
« Reply #61 on: December 10, 2012, 10:56:40 PM »
you could add a little test to see if the CPU supports SSSE3
if it does not, skip that test and say "Frktons II Step requires SSSE3 support" and go on to the next test
Code: [Select]
    mov     eax,1
    cpuid
    test    ch,2
    jz      no_ssse3_support

note: .586 or higher required to assemble "cpuid" without hard-coding

Good idea my dear Master, I'm going to test it. Inter alia, one of my pc doesn't
have SSSE3 if I correctly remember.

frktons

  • Member
  • ***
  • Posts: 491
Re: The fastest way to fill a dword array with string values
« Reply #62 on: December 10, 2012, 11:03:25 PM »
OK, I updated the proggy, would you test it?


dedndave

  • Member
  • *****
  • Posts: 8829
  • Still using Abacus 2.0
    • DednDave
Re: The fastest way to fill a dword array with string values
« Reply #63 on: December 10, 2012, 11:39:34 PM »
 :t
Code: [Select]
------------------------------------------------------------------------
Intel(R) Pentium(R) 4 CPU 3.00GHz

Instructions: MMX, SSE1, SSE2, SSE3
------------------------------------------------------------------------
2270    cycles for Dedndave code - 5 GPRs
1940    cycles for Frktons I Step / 2 GPRs
1950    cycles for Frktons I Step / 4 GPRs
 Frktons II Step requires a PC with SSSE3
1165    cycles for Jochen / 5 XMM
------------------------------------------------------------------------
2242    cycles for Dedndave code - 5 GPRs
1962    cycles for Frktons I Step / 2 GPRs
1949    cycles for Frktons I Step / 4 GPRs
 Frktons II Step requires a PC with SSSE3
1176    cycles for Jochen / 5 XMM
------------------------------------------------------------------------
2248    cycles for Dedndave code - 5 GPRs
1939    cycles for Frktons I Step / 2 GPRs
1956    cycles for Frktons I Step / 4 GPRs
 Frktons II Step requires a PC with SSSE3
1161    cycles for Jochen / 5 XMM
------------------------------------------------------------------------
2268    cycles for Dedndave code - 5 GPRs
1947    cycles for Frktons I Step / 2 GPRs
1987    cycles for Frktons I Step / 4 GPRs
 Frktons II Step requires a PC with SSSE3
1191    cycles for Jochen / 5 XMM
------------------------------------------------------------------------

--- ok ---

dedndave

  • Member
  • *****
  • Posts: 8829
  • Still using Abacus 2.0
    • DednDave
Re: The fastest way to fill a dword array with string values
« Reply #64 on: December 10, 2012, 11:40:52 PM »
here's a little routine i wrote just for you, Frank   :biggrin:
Code: [Select]
CpuFeatures PROC

;call once during program initialization
;store the value returned in EAX (AL, actually) for feature verification
;
;0 = no extended features present
;1 = MMX
;2 = SSE
;3 = SSE2
;4 = SSE3
;5 = SSSE3
;6 = SSE4

        mov     eax,1
        cpuid
        bswap   edx          ;MMX -> bit 8, SSE1 -> bit 6, SSE2 -> bit 5
        xor     eax,eax
        test    dh,1         ;MMX
        jz      CpuF00

        inc     eax
        test    dl,40h       ;SSE1
        jz      CpuF00

        inc     eax
        test    dl,20h       ;SSE2
        jz      CpuF00

        inc     eax
        test    cl,1         ;SSE3
        jz      CpuF00

        inc     eax
        test    cl,2         ;SSSE3
        jz      CpuF00

        inc     eax
        test    ecx,80000h   ;SSE4
        jz      CpuF00

        inc     eax

CpuF00: ret

CpuFeatures ENDP

Code: [Select]
        .DATA?

bFeatures db ?

        .CODE

Start:  call    CpuFeatures
        mov     bFeatures,al
;
;
;

now, if you want to see if they have SSSE3....
Code: [Select]
        cmp     bFeatures,5
        jb      no_ssse3_support

frktons

  • Member
  • ***
  • Posts: 491
Re: The fastest way to fill a dword array with string values
« Reply #65 on: December 10, 2012, 11:54:20 PM »
here's a little routine i wrote just for you, Frank   :biggrin:
Code: [Select]
CpuFeatures PROC

;call once during program initialization
;store the value returned in EAX (AL, actually) for feature verification
;
;0 = no extended features present
;1 = MMX
;2 = SSE
;3 = SSE2
;4 = SSE3
;5 = SSSE3
;6 = SSE4

        mov     eax,1
        cpuid
        bswap   edx          ;MMX -> bit 8, SSE1 -> bit 6, SSE2 -> bit 5
        xor     eax,eax
        test    dh,1         ;MMX
        jz      CpuF00

        inc     eax
        test    dl,40h       ;SSE1
        jz      CpuF00

        inc     eax
        test    dl,20h       ;SSE2
        jz      CpuF00

        inc     eax
        test    cl,1         ;SSE3
        jz      CpuF00

        inc     eax
        test    cl,2         ;SSSE3
        jz      CpuF00

        inc     eax
        test    ecx,80000h   ;SSE4
        jz      CpuF00

        inc     eax

CpuF00: ret

CpuFeatures ENDP

Code: [Select]
        .DATA?

bFeatures db ?

        .CODE

Start:  call    CpuFeatures
        mov     bFeatures,al
;
;
;

now, if you want to see if they have SSSE3....
Code: [Select]
        cmp     bFeatures,5
        jb      no_ssse3_support

Thanks Dave, and here it is something I wrote for you  :biggrin::

Quote
----------------------------------------------------------------------
Intel(R) Core(TM)2 CPU          6600  @ 2.40GHz

Instructions: MMX, SSE1, SSE2, SSE3, SSSE3
----------------------------------------------------------------------
1915    cycles for Dedndave code - 5 GPRs
1837    cycles for Frktons I Step / 2 GPRs
1893    cycles for Frktons I Step / 4 GPRs
1318    cycles for Frktons II Step / 5 MMX
1365    cycles for Frktons II Step / 5 MMX without SSSE3
836     cycles for Jochen / 5 XMM
----------------------------------------------------------------------
1913    cycles for Dedndave code - 5 GPRs
1892    cycles for Frktons I Step / 2 GPRs
1893    cycles for Frktons I Step / 4 GPRs
1317    cycles for Frktons II Step / 5 MMX
1366    cycles for Frktons II Step / 5 MMX without SSSE3
836     cycles for Jochen / 5 XMM
----------------------------------------------------------------------

dedndave

  • Member
  • *****
  • Posts: 8829
  • Still using Abacus 2.0
    • DednDave
Re: The fastest way to fill a dword array with string values
« Reply #66 on: December 11, 2012, 12:23:31 AM »
------------------------------------------------------------------------
Intel(R) Pentium(R) 4 CPU 3.00GHz

Instructions: MMX, SSE1, SSE2, SSE3
------------------------------------------------------------------------
2250    cycles for Dedndave code - 5 GPRs
1943    cycles for Frktons I Step / 2 GPRs
1960    cycles for Frktons I Step / 4 GPRs
 Frktons II Step requires a PC with SSSE3
2148    cycles for Frktons II Step / 5 MMX without SSSE3
1161    cycles for Jochen / 5 XMM
------------------------------------------------------------------------
2242    cycles for Dedndave code - 5 GPRs
1952    cycles for Frktons I Step / 2 GPRs
1971    cycles for Frktons I Step / 4 GPRs
 Frktons II Step requires a PC with SSSE3
2268    cycles for Frktons II Step / 5 MMX without SSSE3
1161    cycles for Jochen / 5 XMM
------------------------------------------------------------------------
2271    cycles for Dedndave code - 5 GPRs
1950    cycles for Frktons I Step / 2 GPRs
1965    cycles for Frktons I Step / 4 GPRs
 Frktons II Step requires a PC with SSSE3
2149    cycles for Frktons II Step / 5 MMX without SSSE3
1166    cycles for Jochen / 5 XMM
------------------------------------------------------------------------
2240    cycles for Dedndave code - 5 GPRs
1941    cycles for Frktons I Step / 2 GPRs
1958    cycles for Frktons I Step / 4 GPRs
 Frktons II Step requires a PC with SSSE3
2144    cycles for Frktons II Step / 5 MMX without SSSE3
1166    cycles for Jochen / 5 XMM
------------------------------------------------------------------------
« Last Edit: December 11, 2012, 01:10:26 PM by dedndave »

frktons

  • Member
  • ***
  • Posts: 491
Re: The fastest way to fill a dword array with string values
« Reply #67 on: December 11, 2012, 10:46:03 AM »
Some improvements before the final release:
Quote
------------------------------------------------------------------------
Intel(R) Core(TM)2 CPU          6600  @ 2.40GHz

Instructions: MMX, SSE1, SSE2, SSE3, SSSE3
------------------------------------------------------------------------
1925    cycles for Dedndave code - 5 GPRs
1882    cycles for Frktons I Step / 2 GPRs
1941    cycles for Frktons I Step / 4 GPRs
1896    cycles for Frktons I Step / 4 GPRs - no external tab
1096    cycles for Frktons II Step / 5 MMX with SSSE3
1206    cycles for Frktons II Step / 5 MMX without SSSE3
836     cycles for Jochen / 5 XMM
------------------------------------------------------------------------
1917    cycles for Dedndave code - 5 GPRs
1882    cycles for Frktons I Step / 2 GPRs
1917    cycles for Frktons I Step / 4 GPRs
1893    cycles for Frktons I Step / 4 GPRs - no external tab
1091    cycles for Frktons II Step / 5 MMX with SSSE3
1206    cycles for Frktons II Step / 5 MMX without SSSE3
836     cycles for Jochen / 5 XMM
------------------------------------------------------------------------

--- ok ---

Almost close to the target.  :t

dedndave

  • Member
  • *****
  • Posts: 8829
  • Still using Abacus 2.0
    • DednDave
Re: The fastest way to fill a dword array with string values
« Reply #68 on: December 11, 2012, 11:01:22 AM »
prescott w/htt
Code: [Select]
------------------------------------------------------------------------
Intel(R) Pentium(R) 4 CPU 3.00GHz

Instructions: MMX, SSE1, SSE2, SSE3
------------------------------------------------------------------------
2379    cycles for Dedndave code - 5 GPRs
1947    cycles for Frktons I Step / 2 GPRs
1961    cycles for Frktons I Step / 4 GPRs
1986    cycles for Frktons I Step / 4 GPRs - no external tab
 Frktons II Step requires a PC with SSSE3
2460    cycles for Frktons II Step / 5 MMX without SSSE3
1152    cycles for Jochen / 5 XMM
------------------------------------------------------------------------
2251    cycles for Dedndave code - 5 GPRs
1966    cycles for Frktons I Step / 2 GPRs
1961    cycles for Frktons I Step / 4 GPRs
1978    cycles for Frktons I Step / 4 GPRs - no external tab
 Frktons II Step requires a PC with SSSE3
2456    cycles for Frktons II Step / 5 MMX without SSSE3
1151    cycles for Jochen / 5 XMM
------------------------------------------------------------------------
« Last Edit: December 11, 2012, 01:10:59 PM by dedndave »

MichaelW

  • Global Moderator
  • Member
  • *****
  • Posts: 1209
Re: The fastest way to fill a dword array with string values
« Reply #69 on: December 11, 2012, 11:12:28 AM »
P4 Northwood:
Code: [Select]
------------------------------------------------------------------------
Intel(R) Pentium(R) 4 CPU 3.00GHz

Instructions: MMX, SSE1, SSE2
------------------------------------------------------------------------
2275    cycles for Dedndave code - 5 GPRs
1979    cycles for Frktons I Step / 2 GPRs
1996    cycles for Frktons I Step / 4 GPRs
2034    cycles for Frktons I Step / 4 GPRs - no external tab
 Frktons II Step requires a PC with SSSE3
2970    cycles for Frktons II Step / 5 MMX without SSSE3
896     cycles for Jochen / 5 XMM
------------------------------------------------------------------------
2330    cycles for Dedndave code - 5 GPRs
1970    cycles for Frktons I Step / 2 GPRs
1997    cycles for Frktons I Step / 4 GPRs
2734    cycles for Frktons I Step / 4 GPRs - no external tab
 Frktons II Step requires a PC with SSSE3
2937    cycles for Frktons II Step / 5 MMX without SSSE3
905     cycles for Jochen / 5 XMM
------------------------------------------------------------------------
Well Microsoft, here’s another nice mess you’ve gotten us into.

frktons

  • Member
  • ***
  • Posts: 491
Re: The fastest way to fill a dword array with string values
« Reply #70 on: December 11, 2012, 11:51:05 AM »
It looks like the MMX tech is a bit slow on pre-Core Duo CPUs.

We'll see the XMM one in action next.  :P

frktons

  • Member
  • ***
  • Posts: 491
Re: The fastest way to fill a dword array with string values
« Reply #71 on: December 12, 2012, 03:45:32 PM »
I've almost finished the study. Here it is the fastest code
so far I could imagine, but still room to optimize.
Quote
------------------------------------------------------------------------
Intel(R) Core(TM)2 CPU          6600  @ 2.40GHz

Instructions: MMX, SSE1, SSE2, SSE3, SSSE3
------------------------------------------------------------------------
1950    cycles for Dedndave code - 5 GPRs
1924    cycles for Frktons I Step / 2 GPRs
1871    cycles for Frktons I Step / 4 GPRs
1888    cycles for Frktons I Step / 4 GPRs - no external tab
1079    cycles for Frktons II Step / 5 MMX with SSSE3
1199    cycles for Frktons II Step / 5 MMX without SSSE3
801     cycles for Frktons III Step / XMM/MMX with SSE2
831     cycles for Jochen / 5 XMM
------------------------------------------------------------------------
1916    cycles for Dedndave code - 5 GPRs
1930    cycles for Frktons I Step / 2 GPRs
1872    cycles for Frktons I Step / 4 GPRs
1915    cycles for Frktons I Step / 4 GPRs - no external tab
1083    cycles for Frktons II Step / 5 MMX with SSSE3
1209    cycles for Frktons II Step / 5 MMX without SSSE3
796     cycles for Frktons III Step / XMM/MMX with SSE2
831     cycles for Jochen / 5 XMM
------------------------------------------------------------------------

--- ok ---

dedndave

  • Member
  • *****
  • Posts: 8829
  • Still using Abacus 2.0
    • DednDave
Re: The fastest way to fill a dword array with string values
« Reply #72 on: December 12, 2012, 03:53:07 PM »
prescott w/htt
------------------------------------------------------------------------
Intel(R) Pentium(R) 4 CPU 3.00GHz

Instructions: MMX, SSE1, SSE2, SSE3
------------------------------------------------------------------------
2266    cycles for Dedndave code - 5 GPRs
1976    cycles for Frktons I Step / 2 GPRs
1994    cycles for Frktons I Step / 4 GPRs
2011    cycles for Frktons I Step / 4 GPRs - no external tab
 Frktons II Step requires a PC with SSSE3
2459    cycles for Frktons II Step / 5 MMX without SSSE3
1141    cycles for Frktons III Step / XMM/MMX with SSE2
1183    cycles for Jochen / 5 XMM
------------------------------------------------------------------------
2257    cycles for Dedndave code - 5 GPRs
1983    cycles for Frktons I Step / 2 GPRs
1973    cycles for Frktons I Step / 4 GPRs
1996    cycles for Frktons I Step / 4 GPRs - no external tab
 Frktons II Step requires a PC with SSSE3
2462    cycles for Frktons II Step / 5 MMX without SSSE3
1143    cycles for Frktons III Step / XMM/MMX with SSE2
1184    cycles for Jochen / 5 XMM
------------------------------------------------------------------------

sinsi

  • Guest
Re: The fastest way to fill a dword array with string values
« Reply #73 on: December 12, 2012, 05:28:04 PM »

------------------------------------------------------------
AMD Phenom(tm) II X6 1100T Processor

Instructions: MMX, SSE1, SSE2, SSE3
------------------------------------------------------------
948     cycles for Dedndave code - 5 GPRs
813     cycles for Frktons I Step / 2 GPRs
838     cycles for Frktons I Step / 4 GPRs
995     cycles for Frktons I Step / 4 GPRs - no external tab
 Frktons II Step requires a PC with SSSE3
1089    cycles for Frktons II Step / 5 MMX without SSSE3
747     cycles for Frktons III Step / XMM/MMX with SSE2
666     cycles for Jochen / 5 XMM
------------------------------------------------------------
950     cycles for Dedndave code - 5 GPRs
823     cycles for Frktons I Step / 2 GPRs
845     cycles for Frktons I Step / 4 GPRs
996     cycles for Frktons I Step / 4 GPRs - no external tab
 Frktons II Step requires a PC with SSSE3
1084    cycles for Frktons II Step / 5 MMX without SSSE3
749     cycles for Frktons III Step / XMM/MMX with SSE2
665     cycles for Jochen / 5 XMM
------------------------------------------------------------

--- ok ---

jj2007

  • Member
  • *****
  • Posts: 11526
  • Assembler is fun ;-)
    • MasmBasic
Re: The fastest way to fill a dword array with string values
« Reply #74 on: December 12, 2012, 06:53:03 PM »
Frktons I Step / 2 GPRs and Frktons I Step / 4 GPRs are remarkably fast but you should have a look at the output.