flat assembler
Message board for the users of flat assembler.

Index > Main > HELP: swaping between 3 array (fast routine)?

Author
Thread Post new topic Reply to topic
xspeed



Joined: 16 Aug 2007
Posts: 22
xspeed
hey here is the problem i am trying to swap three array around like this

array 1=a1[]=0 to 1000000 elements, containing number from 0 to 255
array 2=a2[]=0 to 255 elements, containing random numbers
array 3=a3[]=0 to 1000000 elements,contain no number
count=1000000*4

basic routine
for n from 0 to 100000 by 1 do
a3[n]=a2[a1[n]]
end for

basic asm routine

long1 equ[esp+4] ;location of a1[0]
long2 equ[esp+8] ;location of a2[0]
long3 equ[esp+16];location of a3[0]
long4 equ[esp+20];location of count
mov ecx,0
loopme:
mov eax,long1
add eax,ecx
mov eax,dword ptr [eax] ;eax contain a1[ecx\4];ecx=ecx+4
lea eax,[eax*4]
mov ebx,long2
add ebx,eax
mov ebx,dword ptr [ebx];ebx contain a2[a1[ecx\4]]
mov eax,long3
add eax,ecx
mov dword ptr [eax],ebx
add ecx,4
mov ebx,long4
mov ebx,[ebx]
cmp ecx,ebx
je loopme
ret 8
Post 16 Aug 2007, 14:59
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
Code:
array 1=a1[]=0 to 1000000 elements, containing number from 0 to 255
array 2=a2[]=0 to 255 elements, containing random numbers
array 3=a3[]=0 to 1000000 elements,contain no number
count=1000000*4

basic routine
for n from 0 to 100000 by 1 do
a3[n]=a2[a1[n]]
end for 

Very ^^^ odd "BASIC" ; Confused

FASM code:

    mov esi,a1
    mov ebx,a2
    mov edi,a3

    xor eax,eax       ; MOV EAX,0 Laughing
    mov ecx,1000000   ; 1 M decimal or 999'999 only Question

@@: mov  al,[esi+ecx]
    mov  al,[ebx+eax]
    mov  [edi+ecx],al
    loop  @b
    


Note:

dword ptr is crap and has been banned from FASM Wink

_________________
Bug Nr.: 12345

Title: Hello World program compiles to 100 KB !!!

Status: Closed: NOT a Bug
Post 16 Aug 2007, 21:10
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3170
Location: Denmark
f0dder
NTOSKRNL_VXE wrote:
dword ptr is crap and has been banned from FASM Wink

Not really, in fasm it's just called "dword". And in the code snippet by the original poster, it wasn't necessary, not even for MASM, since the data size with register use is implicit.

_________________
Image - carpe noctem
Post 16 Aug 2007, 22:56
View user's profile Send private message Visit poster's website Reply with quote
xspeed



Joined: 16 Aug 2007
Posts: 22
xspeed
hey thank

basic routine
for n from 0 to 100000 by 1 do
a3[n]=a2[a1[n]]
end for

Very ^^^ odd "BASIC" ;

^^^ maple v9.5 a math program with programming language

basic:
for n=0 to 100000
a3[n]=a2[a1[n]]
next

i hooked fasm to maple 9.5

my routine take about 75->90 tickcount for one run

8749 tickcount for 100

for i from 0 to 99 by 1 do
for n from 0 to 100000 by 1 do
a3[n]=a2[a1[n]]
end do
end do

too slow

874 ticket for 100 would be nice
874 ticket for 1000 would be really nice

something like the basic routine for transferring a2[n]=a1[n] with rep movsb
Post 17 Aug 2007, 16:56
View user's profile Send private message Reply with quote
DOS386



Joined: 08 Dec 2006
Posts: 1901
DOS386
> my routine take about 75->90 tickcount

Tested mine ?

> something like the basic routine for transferring a2[n]=a1[n] with rep movsb

SORRY but MOVSx doesn't index via a 3rd array ... just post a feature request for SSSSSE 5 Idea
Post 18 Aug 2007, 05:24
View user's profile Send private message Reply with quote
Mac2004



Joined: 15 Dec 2003
Posts: 313
Mac2004
xspeed: Could you please use code tags? Smile Your code is much more readable that way...

regards,
Mac2004
Post 18 Aug 2007, 07:06
View user's profile Send private message Reply with quote
xspeed



Joined: 16 Aug 2007
Posts: 22
xspeed
NTOSKRNL_VXE=60->70 tickcount*100 times=6547
tickcount=GetTickCount in kernel32.lib/dll

6547=6.547 sec

can you reduce it down to .654 sec for 100 times with 1000001 long value elements=4000004 bytes?
Post 20 Aug 2007, 14:32
View user's profile Send private message Reply with quote
Plue



Joined: 15 Dec 2005
Posts: 151
Plue
The elements are all dword sized, right?

Edit:
This is my fastest yet:
Code:
  mov eax, [v_a] ; eax <- address of a[0]
  mov ebx, [v_b] ; ebx <- address of b[0]
  mov ecx, [v_c] ; ecx <- address of c[0]
  
  mov edx, 100000*4 ; edx <- counter
  
  lp:
  sub edx, 4
  mov esi, [eax+edx]
  mov esi, [ebx+esi]
  mov [ecx+edx], esi
  jnz lp    

You can probably get it much faster by changing the algorithm a bit. What do you need it for?
Post 20 Aug 2007, 19:56
View user's profile Send private message Reply with quote
xspeed



Joined: 16 Aug 2007
Posts: 22
xspeed
direct swapping them would be the fastest but i dont know how

anyone have a clue on how to swap them faster?

plue: for a new encode/media format file
Post 23 Aug 2007, 16:07
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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.