News:

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

My first useful Function, comments wanted

Started by rags, March 22, 2005, 05:49:29 PM

Previous topic - Next topic

MichaelW

Quote from: hutch-- on April 02, 2005, 08:45:59 AM
It can also be a factor of what has been run before it so it may be worth changing the order of which procedures are tested. I guess you could set all of the procedures so they followed a seperate identical algo so they all had the same lead in.

I changed the code so TrimLe was running before both copies of block_ltrim:

_TrimLeadingSpaces: 567 cycles
TrimLeadingSpaces: 1254 cycles
TrimLe: 531 cycles
block_ltrim: 486 cycles
TrimLe: 535 cycles
_block_ltrim: 676 cycles

Then I changed to align 16 for both copies:

_TrimLeadingSpaces: 566 cycles
TrimLeadingSpaces: 1258 cycles
TrimLe: 531 cycles
block_ltrim: 678 cycles
TrimLe: 525 cycles
_block_ltrim: 673 cycles

Then I eliminated the extra call to TrimLe:

_TrimLeadingSpaces: 565 cycles
TrimLeadingSpaces: 1246 cycles
TrimLe: 525 cycles
block_ltrim: 649 cycles
_block_ltrim: 648 cycles

My memory regarding the align 16 test was obviously wrong. The block_ltrim code seems to be very sensitive to alignment (running on a P3).
eschew obfuscation

BoR0

Hello, I've written a similar algo in 5 minutes, so I decided to post it here too to check your opinions  :lol


.data
mystring db 9, 32, 32, 9, 32, 9, 9, 32, 9, "hi, BoR0 is cool :D",0

; 9 = tab
; 32 = spacing

.code
TrimStartSpacing PROC lpBuffer:DWORD
mov eax, lpBuffer

@@:
cmp byte ptr [eax], 32
jne tabcheck
inc eax
jmp @B
tabcheck:
cmp byte ptr [eax], 9
jne @F
inc eax
jmp @B
@@:

ret
TrimStartSpacing ENDP

start:

invoke TrimStartSpacing, ADDR mystring
invoke MessageBox, 0, eax, 0, 0

invoke ExitProcess, 0
end start


This function doesn't actually delete the tabs and spaces, but returns a valid pointer to the start of the text without the tabs and spaces. I think this is the fastest way.

Greets, BoR0  :U

hutch--

The idea is a good one but it only trims a single line, not a block of lines like the topic and examples.

Here is how to do it quickly.


OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE

align 4

ltrimx proc src:DWORD

    mov eax, [esp+4]
    sub eax, 1
  @@:
    add eax, 1
    cmp BYTE PTR [eax], 32
    je @B
    cmp BYTE PTR [eax], 9
    je @B

    ret 4

ltrimx endp

OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef
Download site for MASM32      New MASM Forum
https://masm32.com          https://masm32.com/board/index.php