flat assembler
Message board for the users of flat assembler.

Index > Main > Optimize str.len for FASMLIB

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
no need, you should read entire description of proc Razz

i consider buflen=0 an exceptional case most times. Allowing value 0 will be fine for me, but could let user overlook some bug, and it could be harder to find
Post 06 Jan 2007, 21:27
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7718
Location: Kraków, Poland
Tomasz Grysztar
vid wrote:
no need, you should read entire description of proc Razz

After I read the entire description I've got a feeling of contradiction. That's what I meant.
Post 06 Jan 2007, 21:47
View user's profile Send private message Visit poster's website Reply with quote
MCD



Joined: 21 Aug 2004
Posts: 604
Location: Germany
MCD
The_Grey_Beast wrote:
One optimization of design is to use "length-prefixed" strings, aka:
1 byte (or more if the string is long) representing the length
then follows the string
Those are called PASCAL-strings cause they are widely used in PASCAL.
f0dder wrote:
Two words: hybrid strings.
Those are used for example in Delphi. to be more precise, they use the following struc:
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

-||__/
.|+-~
.|| ||
Post 06 Jan 2007, 22:50
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Quote:
After I read the entire description I've got a feeling of contradiction. That's what I meant.
oh, now i understand academic approach. Razz

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 Sad ) Then, maybe the x86 version using dwords would be best for generic approach
Post 07 Jan 2007, 07:11
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Helle



Joined: 24 Feb 2007
Posts: 23
Location: Germany
Helle
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
Post 26 Feb 2007, 12:43
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.