flat assembler
Message board for the users of flat assembler.

Index > Main > String length procedure optimization

Author
Thread Post new topic Reply to topic
Mac2004



Joined: 15 Dec 2003
Posts: 314
Mac2004 19 Mar 2009, 15:45
Hi!

This is my try to optimize string length procedure. I wonder if this could be more optimized by using general 32bit instructions. (Meaning, no mmx, sse or anything like that)

Here's my code

Code:
;*******************************************************************************
;STR_Get_length-      The procedure gets asciiz string length (32bit version).
;
;
; Input:  edx--> String pointer
;
; Output: ecx--> String length excluding terminating null.
;*******************************************************************************

STR_Get_length:

   push edx
    
        xor ecx,ecx                 ;Clear counter.

.get_loop:
       add ecx, 4                      ;Update counter.
        test dword[edx],0x000000ff
      jz .sub4

        test dword[edx],0x0000ff00
  jz .sub3
    
        test dword[edx],0x00ff0000
      jz .sub2

        test dword[edx],0xff000000
  jz  .sub1

       add edx, 4
  jmp .get_loop

.sub4: sub ecx,1                       ;Handle final counter fix up.
.sub3:     sub ecx,1
.sub2: sub ecx,1
.sub1: sub ecx,1

.done:
        pop edx 
     ret                             ;The end of procedure

    


regards,
Mac2004
Post 19 Mar 2009, 15:45
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 19 Mar 2009, 15:54
You should be aware, that running this on a string put at the end of memory block may cause page fault instead of giving the proper result.
Post 19 Mar 2009, 15:54
View user's profile Send private message Visit poster's website Reply with quote
Mac2004



Joined: 15 Dec 2003
Posts: 314
Mac2004 19 Mar 2009, 17:54
Ok, thanx. This procedure is used only on non paged enviroment (meaning paging disabled.)

Regards
Mac2004
Post 19 Mar 2009, 17:54
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 19 Mar 2009, 18:33
http://board.flatassembler.net/topic.php?p=71382#71382

But there are more threads about this matter that doesn't use SIMD but I can't search more now.
Post 19 Mar 2009, 18:33
View user's profile Send private message Reply with quote
Mac2004



Joined: 15 Dec 2003
Posts: 314
Mac2004 20 Mar 2009, 03:18
LocoDelAssembly: Thanx for the link, I will take look at it.

Regards
Mac2004
Post 20 Mar 2009, 03:18
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.