flat assembler
Message board for the users of flat assembler.
Index
> Main > Optimize str.len for FASMLIB Goto page Previous 1, 2 |
Author |
|
Tomasz Grysztar 06 Jan 2007, 21:47
vid wrote: no need, you should read entire description of proc After I read the entire description I've got a feeling of contradiction. That's what I meant. |
|||
06 Jan 2007, 21:47 |
|
MCD 06 Jan 2007, 22:50
The_Grey_Beast wrote: One optimization of design is to use "length-prefixed" strings, aka: f0dder wrote: Two words: hybrid strings. Code: struc delphi_ansi_string txt { local .end ;align [i]depends on compiler setting[/i] dd 0;initial reference count dd .end-$;length .start db txt .end db 0 } I personally prefer the following struc for long initialized, dynamical-size strings: Code: struc str txt { align 16 .length dd .end-$ .start db txt .end db 0 } But back to classical 00-terminated strings. As f0dder pointed out correctly, it depends on whether the strings are supposed to be short or long on how much larger operands will provide a speed benefit. I agree that strlen is most likely be used with small/medium strings, so the whole operand size optimizing gives no benefit and the setup overhead outnumbers. This may be different if one is designing functions that operates on large blocks of memory. Also loops with larger operands not only tends to get larger and clumsy, but one will also need to write different versions of each string/memory function for each x86 compatible CPU-architecture to get both optimal speed and compatibility (PentiumPro(CMOVcc,MMX),3dNOW!,3dNOW!Extended,SSE1,SSE2,SSE3...). _________________ MCD - the inevitable return of the Mad Computer Doggy -||__/ .|+-~ .|| || |
|||
06 Jan 2007, 22:50 |
|
vid 07 Jan 2007, 07:11
Quote: After I read the entire description I've got a feeling of contradiction. That's what I meant. theorethically correct approach results in unreadability. i bet everyone understands how function beheaves in buflen=0 case, after reading description. back to topic: i agree about length. so you say overhead of initializing MMX / SSE is too big for smaller strings? (i don't know MMX/SSE well ) Then, maybe the x86 version using dwords would be best for generic approach |
|||
07 Jan 2007, 07:11 |
|
Helle 26 Feb 2007, 12:43
For tests an example (without checks) with SSE(2):
Code: format PE CONSOLE 4.0 entry start Include 'win32a.inc' ;Include 'D:\Programme\FlatAssembler\Include\win32a.inc' ;for me section '.code' code readable writeable executable text db 'FileLenght of String :',0 szEnv db '%s %4d',13,10,0 String db 'pokjhgskioUIOHR%(!§)AGJOjiioe328959askfakgj9e6t306rgrjhg409604tkmgoe',0 ;------------------------------------------------ start: lea eax,[String] mov edi,eax pxor xmm1,xmm1 ;xmm1 null @@: movdqu xmm0,[eax] ;read 16 byte of string add eax,16 pcmpeqb xmm0,xmm1 ;compare the 16 bytes of xmm0 with null (xmm1), set byte = 255 if equal (= null) and byte = 0 if not equal pmovmskb edx,xmm0 ;copy signum-bits to edx (dx) or edx,edx ;null ? jz @r ;yes, not found the null-byte of string (end of string) sub eax,17 test dl,255 jnz @f xchg dl,dh add eax,8 @@: inc eax shr dx,1 jnc @r sub eax,edi ;------------------------------------------------ invoke printf,szEnv,text, eax invoke getchar invoke ExitProcess,0 section '.idata' import data readable writeable library kernel32,'kernel32.dll',\ msvcrt,'msvcrt.dll' import kernel32,\ ExitProcess,'ExitProcess' import msvcrt,\ getchar,'getchar',\ printf,'printf' Gruss Helle |
|||
26 Feb 2007, 12:43 |
|
Goto page Previous 1, 2 < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.