News:

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

This is too slow

Started by frktons, November 18, 2010, 03:10:21 AM

Previous topic - Next topic

hutch--

Frank,

Here is a quick scruffy that may do the job for you. It could be tweaked a bit more but it should be reasonably fast.


IF 0  ; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                      Build this template with "CONSOLE ASSEMBLE AND LINK"
ENDIF ; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm32\include\masm32rt.inc

    format_num_string PROTO :DWORD,:DWORD

    .code

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

    call main
    inkey
    exit

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

main proc

    LOCAL buffer[64]:BYTE
    LOCAL pbuf  :DWORD

    mov pbuf, ptr$(buffer)

    fn format_num_string,"1234567890",pbuf
    print pbuf,13,10

    fn format_num_string,"123456789",pbuf
    print pbuf,13,10

    fn format_num_string,"12345678",pbuf
    print pbuf,13,10

    fn format_num_string,"1234567",pbuf
    print pbuf,13,10

    fn format_num_string,"123456",pbuf
    print pbuf,13,10

    fn format_num_string,"12345",pbuf
    print pbuf,13,10

    fn format_num_string,"1234",pbuf
    print pbuf,13,10

    fn format_num_string,"123",pbuf
    print pbuf,13,10

    fn format_num_string,"12",pbuf
    print pbuf,13,10

    fn format_num_string,"1",pbuf
    print pbuf,13,10


    ret

main endp

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

format_num_string proc src:DWORD,dst:DWORD

    push ebx
    push esi
    push edi

  ; -----------------
  ; get source length
  ; -----------------
    mov ebx, src
    sub ebx, 1
  @@:
    add ebx, 1
    cmp BYTE PTR [ebx], 0
    jne @B
    sub ebx, src
  ; -----------------

    .data
  ; --------------------------------------------------
  ; store the initial spacing counter value in a table
  ; --------------------------------------------------
      align 4
      tbl1 dd 0,0,0,0,1,2,3,1,2,3,1,0

;     1=0 0
;     2=0 00
;     3=0 000
;     4=1 0000
;     5=2 00000
;     6=3 000000
;     7=1 0000000
;     8=2 00000000
;     9=3 000000000
;    10=1 0000000000

    .code

    mov ebx, [tbl1+ebx*4]

    mov esi, src
    mov edi, dst
    sub esi, 1

  stlp:
    add esi, 1
    movzx eax, BYTE PTR [esi]
    test eax, eax
    jz bye
    mov [edi], al
    add edi, 1

    sub ebx, 1                  ; dec the spacing counter
    jnz stlp                    ; loop back if its not zero

    cmp BYTE PTR [esi+1], 0     ; 1 byte look ahead
    je bye                      ; exit if char its zero terminator

    mov BYTE PTR [edi], ","     ; change the character here
    add edi, 1
    mov ebx, 3                  ; reset the spacing counter to 3

    jmp stlp

  bye:
    mov BYTE PTR [edi], 0

    pop edi
    pop esi
    pop ebx

    ret

format_num_string endp

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

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

oex

Quote from: frktons on November 18, 2010, 10:28:18 PM
│02 udw2str + GetNumberFormat      │    65   │   44.840 │   44.676 │   45.928 │   44.803 │
├──────────────────────────────────┼─────────┼──────────┼──────────┼──────────┼──────────┤
│03 wsprintf + GetNumberFormat     │    73   │   51.733 │   51.713 │   52.677 │   51.742 │
├──────────────────────────────────┼─────────┼──────────┼──────────┼──────────┼──────────┤
│04 Clive - IDIV and Stack         │   120   │    3.186 │    3.125 │    3.207 │    3.167 │
├──────────────────────────────────┼─────────┼──────────┼──────────┼──────────┼──────────┤
│05 Clive - reciprocal IMUL        │   157   │    2.110 │    2.101 │    2.111 │    2.049
├──────────────────────────────────┼─────────┼──────────┼──────────┼──────────┼──────────┤

I was thinking somewhere along the lines of the above but removed post because code tags cant contain other tags and it removes the formating
We are all of us insane, just to varying degrees and intelligently balanced through networking

http://www.hereford.tv

Antariy

Quote from: oex on November 18, 2010, 11:13:48 PM
Quote from: frktons on November 18, 2010, 10:28:18 PM
│02 udw2str + GetNumberFormat      │    65   │   44.840 │   44.676 │   45.928 │   44.803 │
├──────────────────────────────────┼─────────┼──────────┼──────────┼──────────┼──────────┤
│03 wsprintf + GetNumberFormat     │    73   │   51.733 │   51.713 │   52.677 │   51.742 │
├──────────────────────────────────┼─────────┼──────────┼──────────┼──────────┼──────────┤
│04 Clive - IDIV and Stack         │   120   │    3.186 │    3.125 │    3.207 │    3.167 │
├──────────────────────────────────┼─────────┼──────────┼──────────┼──────────┼──────────┤
│05 Clive - reciprocal IMUL        │   157   │    2.110 │    2.101 │    2.111 │    2.049
├──────────────────────────────────┼─────────┼──────────┼──────────┼──────────┼──────────┤

I was thinking somewhere along the lines of the above but removed post because code tags cant contain other tags and it removes the formating

This will require to save previous clocks. Scan them after all. Scan the output string buffer for founding place where is needed to instert the [b][/b] tags. That is will be relatively slow for nothing :P I guess Frank not desire to do work which can be done by people  :lol

frktons

Quote from: hutch-- on November 18, 2010, 11:12:24 PM
Frank,

Here is a quick scruffy that may do the job for you. It could be tweaked a bit more but it should be reasonably fast.


IF 0  ; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤
                      Build this template with "CONSOLE ASSEMBLE AND LINK"
ENDIF ; ¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤

    include \masm32\include\masm32rt.inc

    format_num_string PROTO :DWORD,:DWORD

    .code

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

    call main
    inkey
    exit

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

main proc

    LOCAL buffer[64]:BYTE
    LOCAL pbuf  :DWORD

    mov pbuf, ptr$(buffer)

    fn format_num_string,"1234567890",pbuf
    print pbuf,13,10

    fn format_num_string,"123456789",pbuf
    print pbuf,13,10

    fn format_num_string,"12345678",pbuf
    print pbuf,13,10

    fn format_num_string,"1234567",pbuf
    print pbuf,13,10

    fn format_num_string,"123456",pbuf
    print pbuf,13,10

    fn format_num_string,"12345",pbuf
    print pbuf,13,10

    fn format_num_string,"1234",pbuf
    print pbuf,13,10

    fn format_num_string,"123",pbuf
    print pbuf,13,10

    fn format_num_string,"12",pbuf
    print pbuf,13,10

    fn format_num_string,"1",pbuf
    print pbuf,13,10


    ret

main endp

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

format_num_string proc src:DWORD,dst:DWORD

    push ebx
    push esi
    push edi

  ; -----------------
  ; get source length
  ; -----------------
    mov ebx, src
    sub ebx, 1
  @@:
    add ebx, 1
    cmp BYTE PTR [ebx], 0
    jne @B
    sub ebx, src
  ; -----------------

    .data
  ; --------------------------------------------------
  ; store the initial spacing counter value in a table
  ; --------------------------------------------------
      align 4
      tbl1 dd 0,0,0,0,1,2,3,1,2,3,1,0

;     1=0 0
;     2=0 00
;     3=0 000
;     4=1 0000
;     5=2 00000
;     6=3 000000
;     7=1 0000000
;     8=2 00000000
;     9=3 000000000
;    10=1 0000000000

    .code

    mov ebx, [tbl1+ebx*4]

    mov esi, src
    mov edi, dst
    sub esi, 1

  stlp:
    add esi, 1
    movzx eax, BYTE PTR [esi]
    test eax, eax
    jz bye
    mov [edi], al
    add edi, 1

    sub ebx, 1                  ; dec the spacing counter
    jnz stlp                    ; loop back if its not zero

    cmp BYTE PTR [esi+1], 0     ; 1 byte look ahead
    je bye                      ; exit if char its zero terminator

    mov BYTE PTR [edi], ","     ; change the character here
    add edi, 1
    mov ebx, 3                  ; reset the spacing counter to 3

    jmp stlp

  bye:
    mov BYTE PTR [edi], 0

    pop edi
    pop esi
    pop ebx

    ret

format_num_string endp

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

end start


Thanks Steve.  :U

To see if it is reasonably fast and how fast it is, you should insert it into the testbed.  :bg

It should be easy enough for everybody here to do it. It is much harder for me to convert
all the code posted into a suitable form.  :(

Please everybody, why don't you start to use the testbed and get used to it? It is not that hard I guess.

Quote from: Antariy on November 18, 2010, 11:22:11 PMI guess Frank not desire to do work which can be done by people  :lol

Yeah !!!! that's the point my friend.  :U


Frank
Mind is like a parachute. You know what to do in order to use it :-)

hutch--

 :bg

I am hard to get work out of.

Her is the same algo tidied up a bit with the stack frame removed and register usage reduced.


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

    .data
  ; --------------------------------------------------
  ; store the initial spacing counter value in a table
  ; --------------------------------------------------
      align 4
      tbl1 dd 0,0,0,0,1,2,3,1,2,3,1,0

;     1=0 0
;     2=0 00
;     3=0 000
;     4=1 0000
;     5=2 00000
;     6=3 000000
;     7=1 0000000
;     8=2 00000000
;     9=3 000000000
;    10=1 0000000000

    .code

OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE

format_num_string proc src:DWORD,dst:DWORD

  ; -----------------
  ; get source length
  ; -----------------
    mov ecx, [esp+4]
    sub ecx, 1
  @@:
    add ecx, 1
    cmp BYTE PTR [ecx], 0
    jne @B
    sub ecx, [esp+4]
  ; -----------------

    push esi

    mov ecx, [tbl1+ecx*4]       ; set the initial spacing from the table

    mov esi, [esp+4][4]
    mov edx, [esp+8][4]
    sub esi, 1

  stlp:
    add esi, 1
    movzx eax, BYTE PTR [esi]
    test eax, eax
    jz bye
    mov [edx], al
    add edx, 1
    sub ecx, 1                  ; dec the spacing counter
    jnz stlp                    ; loop back if its not zero

    cmp BYTE PTR [esi+1], 0     ; 1 byte look ahead
    je bye                      ; exit if char its zero terminator
    mov BYTE PTR [edx], ","     ; write the spacer. <<<<<< change the character here
    add edx, 1
    mov ecx, 3                  ; reset the spacing counter to 3
    jmp stlp

  bye:
    mov BYTE PTR [edx], 0       ; write terminator
    pop esi
    ret 8

format_num_string endp

OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef

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

frktons

To have a standard test all the routines have to convert the same array of values:

    NumToTest        DWORD 0
                     DWORD 9
                     DWORD 10
                     DWORD 99
                     DWORD 100
                     DWORD 999
                     DWORD 1000
                     DWORD 9999
                     DWORD 10000
                     DWORD 99999
                     DWORD 100000
                     DWORD 999999
                     DWORD 1000000
                     DWORD 9999999
                     DWORD 10000000
                     DWORD 99999999
                     DWORD 100000000
                     DWORD 999999999
                     DWORD 1000000000
                     DWORD 4294967295


After that the measurements can be reliable, and inserted into the testbed.

There are 2 files to get used to the testbed:

Readme.txt  and  Info Screen displayed with the key when
the program shows the results.

This is the final release of the testbed. If you want to use it for any purpose, get used to it.

The sources, the info, the screens, everything is included in the zip file.

Enjoy it and post your results. Press [C] and paste the content of clipboard into the forum.
That's all.

Frank
Mind is like a parachute. You know what to do in order to use it :-)

GregL

Frank,

I was just being dense, damn painkillers.  I wondered why the heck you were calling GetNumberFormat.  At least I used the testbed :bg

Also, some of us like commas and others like periods for the separators.  Use GetLocaleInfo with LCType flag set to LOCALE_STHOUSAND.


frktons

Quote from: GregL on November 19, 2010, 12:04:53 AM
Frank,

I was just being dense, damn painkillers.  I wondered why the heck you were calling GetNumberFormat.  At least I used the testbed :bg

Also, some of us like commas and others like periods for the separators.  Use GetLocaleInfo with LCType flag set to LOCALE_STHOUSAND.

I used GetNumberFormat to have the opportunity to make this thread and select the best code around to replace it.  :bg

I'm glad to know that you started to use it.  :U

Feel free to post the replacing code, when you get rid of the painkillers, and I'll gladly do that. For the time being I'm quite tired and here it is
night. Tomorrow I'll have a look at it. By the way the most simple solution is to replace yourself this line:


    Tsep        DD  ".",0   ;   used for thousand number separator - choose yours


with this


    Tsep        DD  ",",0   ;   used for thousand number separator - choose yours


As the comment says, choose yours.  :lol

Frank.
Mind is like a parachute. You know what to do in order to use it :-)

GregL

Frank,

The painkillers won't be going away any time soon. Have a good night.


frktons

Quote from: GregL on November 19, 2010, 12:19:27 AM
Frank,

The painkillers won't be going away any time soon. Have a good night.

Good night Greg, I'll stay some more time around. When I feel my eyes are closing, I'll go.  :P
Mind is like a parachute. You know what to do in order to use it :-)

Antariy

I guess that Greg's suggestion is simple to implementation and worth enough - Western and European formats of separation is different.

And addition of this code at start of testbed seems to be easy...

invoke GetLocaleInfo,LOCALE_USER_DEFAULT,LOCALE_STHOUSAND,offset Tsep,4


...But I have results of non-breakable space for thousand separator, this is right in some degree, but most of users use "." as thousands separator here.
And main point is: in OEM encoding the non-breakable space have other code, and value returned by GetLocaleInfo should be translated to ANSI, otherwise separator looks like a letter and make mess.

frktons

Quote from: Antariy on November 19, 2010, 12:27:51 AM
I guess that Greg's suggestion is simple to implementation and worth enough - Western and European formats of separation is different.

And addition of this code at start of testbed seems to be easy...

push eax
mov edx,esp
invoke GetLocaleInfo,LOCALE_USER_DEFAULT,LOCALE_STHOUSAND,edx,4
pop Tsep

...But I have results of non-breakable space for thousand separator, this is right in some degree, but most of users use "." as thousands separator here.
And main point is: in OEM encoding the non-breakable space have other code, and value returned by GetLocaleInfo should be translated to ANSI, otherwise separator looks like a letter and make mess.

Alex, if you feel like, please try it in the last posted release and see what you get, after others can test it
and tell us if it works for different countries as well.

If you do, post the new package, or only the part you changed, and we'll give it a try.

Frank
Mind is like a parachute. You know what to do in order to use it :-)

Antariy

Quote from: frktons on November 19, 2010, 12:33:36 AM
Alex, if you feel like, please try it in the last posted release and see what you get, after others can test it
and tell us if it works for different countries as well.

Frank, if do this in that way, then needed to translate ANSI to OEM, to display things. Otherwise you can get this (as I)

├──────────────────────────────────┼─────────┼──────────┼──────────┼──────────┼──────────┤
│01 ustrv$ + GetNumberFormat       │    95   │  184а052 │  182а061 │  180а817 │  184а765 │
├──────────────────────────────────┼─────────┼──────────┼──────────┼──────────┼──────────┤
│02 udw2str + GetNumberFormat      │    65   │  181а947 │  180а363 │  181а235 │  181а365 │
├──────────────────────────────────┼─────────┼──────────┼──────────┼──────────┼──────────┤


CharToOem is good way to do things.
I get

├──────────────────────────────────┼─────────┼──────────┼──────────┼──────────┼──────────┤
│01 ustrv$ + GetNumberFormat       │    95   │   74 845 │   73 199 │   72 696 │   71 789 │
├──────────────────────────────────┼─────────┼──────────┼──────────┼──────────┼──────────┤
│02 udw2str + GetNumberFormat      │    65   │   71 465 │   72 461 │   72 418 │   72 388 │
├──────────────────────────────────┼─────────┼──────────┼──────────┼──────────┼──────────┤
│03 wsprintf + GetNumberFormat     │    73   │   90 419 │   90 686 │   89 978 │   89 189 │
├──────────────────────────────────┼─────────┼──────────┼──────────┼──────────┼──────────┤


For this code

mov ebx,offset Tsep
invoke GetLocaleInfo,LOCALE_USER_DEFAULT,LOCALE_STHOUSAND,ebx,4
invoke CharToOem,ebx,ebx




Alex

frktons

Thanks Alex.

As I said before:

Quote
By the way the most simple solution is to replace yoursefl this line:


    Tsep        DD  ".",0   ;   used for thousand number separator - choose yours


with this


    Tsep        DD  ",",0   ;   used for thousand number separator - choose yours


As the comment says, choose yours.  :lol

If somebody posts a working solution, I'll gladly insert it into testbed  :U
Mind is like a parachute. You know what to do in order to use it :-)

Antariy

Quote from: frktons on November 19, 2010, 12:52:12 AM
If somebody posts a working solution, I'll gladly insert it into testbed  :U


........
Main PROC
mov ebx,offset Tsep  ; THIS IS INSERTED
invoke GetLocaleInfo,LOCALE_USER_DEFAULT,LOCALE_STHOUSAND,ebx,4  ; THIS IS INSERTED
invoke CharToOem,ebx,ebx  ; THIS IS INSERTED

    mov RowInitialFile, One   
    mov RowFinalFile,   MaxRows   
    mov ColInitialFile, One   
    mov ColFinalFile,   MaxCols 
.........


:P



Alex