Welcome to GameHourz.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Skybuck's FasterSpawnGeneratorV3 (154 cycles for 100 threa..

 
   Game Forums (Home) -> Core War RSS
Next:  Skybuck's FastSpawnGeneratorV3 (154 cycles for 10..  
Author Message
Skybuck Flying

External


Since: May 25, 2006
Posts: 295



(Msg. 1) Posted: Fri Dec 07, 2007 6:12 pm
Post subject: Skybuck's FasterSpawnGeneratorV3 (154 cycles for 100 threads, final code size: 26 instructions, done no further optimizations possible. :)) (subject corrected)
Archived from groups: rec>games>corewar (more info?)

;redcode
;name FasterSpawnGeneratorV3
;author Skybuck Flying
;version 3
;history version 1,2 and 3 created on 7 december 2007

;
; version 3:
;
; Let's try to optimize further by for example using dual data variables and
such.
;
; If there was a division instruction which stored the remainder in a and
result in b then further optimization
; would be possible, now it's not possible
; only further optimization was one less variable used so code size a bit
smaller now.
;
; It looks pretty minimized so I see no further room for optimizations or
space gain without sacrificing program flexibility Wink
;
; So the code looks done and pretty much final... Smile
;
; Only 26 instructions used, nice !
; 154 cycles for 100 threads.
;

;
; version 2:
;
; Let's try to optimize it for even faster performance and less code size !
Wink =D
;
; By using only one spawn program pointer cycles have been reduced further
to:
;
; 154 cycles for 100 threads ! 4% improvement.
;


; version 1:
; Tested with 101 threads (nice figure to test with)
;
; Tested with 100 threads to compare against others: 162 cycles needed.
; Code Size: 31 not to bad ! Wink
; Beats John's implementation in cycles.
;
; and this is not even the optimized version lol Wink Smile
;
; Let's implement John's spawning algorithm but let's also try to write it
more efficient,
; meaning no stack and the generated spawn program will be placed before the
program start.

ProgramStart


mov #100, ThreadsToSpawn
sub #1, ThreadsToSpawn

mov.b ThreadsToSpawn, DivThreadsToSpawn
mov.ba ThreadsToSpawn, ModThreadsToSpawn

; algoritm is simple:
; just divide threads to spawn by 2
; just mod threads to spawn by 2
; use mod result as binary indicator
; place mov spawn, 0 at binary zero's in front of program start at spawn
program pointer
; place spl 1 for binary one's in front of program start at spawn program
pointer
; repeat until div result is zero.
;
; so we need two copies of threads to spawn, maybe later we can place it in
a dual data variable.
; but for now I don't want to complicate things... so for now we use two
copies or even three lol.

; initialize spawn program pointer
mov #(ProgramStart - SpawnProgramPointer), SpawnProgramPointer

; algorithm implementation:
LoopBegin

div.ab #2, DivThreadsToSpawn
mod.a #2, ModThreadsToSpawn

OutputBegin
jmz.a OutputDoubleThreadsMinusOne, ModThreadsToSpawn

OutputDoubleThreads
mov DoubleThreadsInstruction, <SpawnProgramPointer
jmp OutputEnd

OutputDoubleThreadsMinusOne
mov DoubleThreadsMinusOneInstruction, <SpawnProgramPointer
OutputEnd

mov.ba DivThreadsToSpawn, ModThreadsToSpawn

jmn LoopBegin, DivThreadsToSpawn
LoopEnd

; execute spawn program
jmp @SpawnProgramPointer

ProgramData
ModThreadsToSpawn
DivThreadsToSpawn
dat #0, #0 ; A = ModThreadsToSpawn, B = DivThreadsToSpawn

ThreadsToSpawn dat $0, #0

SpawnProgramPointer dat $0, $0

DoubleThreadsInstruction spl 1, 0
DoubleThreadsMinusOneInstruction mov DoubleThreadsInstruction, 0

ProgramEnd

 >> Stay informed about: Skybuck's FasterSpawnGeneratorV3 (154 cycles for 100 threa.. 
Back to top
Login to vote
CoreChild

External


Since: Nov 30, 2007
Posts: 13



(Msg. 2) Posted: Fri Dec 07, 2007 6:12 pm
Post subject: Re: Skybuck's FasterSpawnGeneratorV3 (154 cycles for 100 threads, [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Hi,

On Dec 7, 5:12 pm, "Skybuck Flying" <s....TakeThisOut@hotmail.com> wrote:
> ;redcode
> ;name FasterSpawnGeneratorV3

I've improved my code, lets see if you can beat this? For a fair
comparision you need to replace the second loop with jmp *stack.

Time to code and test original, approx 10 mins. Time to optimize and
test new version, approx 35 mins Razz

Cheers,

John

org demo

processes equ 100 ; doesn't work for 0 or 1 processes

stack dat 0, codeout

pspl spl 1
pmov mov.i -1, #0

demo mov #processes,pmov

procs sub #1, pmov
para mov pmov, {stack
mod #2, *stack
div #2, pmov
jmz para, *stack
mov pspl, *stack
jmn para, pmov

ploop mov }stack, >stack
jmn.a ploop, stack

codeout

end

 >> Stay informed about: Skybuck's FasterSpawnGeneratorV3 (154 cycles for 100 threa.. 
Back to top
Login to vote
CoreChild

External


Since: Nov 30, 2007
Posts: 13



(Msg. 3) Posted: Fri Dec 07, 2007 6:13 pm
Post subject: Re: Skybuck's FasterSpawnGeneratorV3 (154 cycles for 100 threads, [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Dec 7, 8:01 pm, "Skybuck Flying" <s....TakeThisOut@hotmail.com> wrote:
> What you mean with that ?

I mean my program is doing extra work by moving the generated code.
For a fair comparison, it should just jump to the generated code.
This makes it 18 cells, 140 cycles - see below.

John

processes equ 100

demo mov #processes,pmov

procs sub #1, pmov
para mov pmov, <stack
stack mod #2, demo-1
div #2, pmov
jmz para, @stack
mov pspl, @stack
jmn para, pmov
jmp @stack

pspl spl 1
pmov mov.i -1, #0

end
 >> Stay informed about: Skybuck's FasterSpawnGeneratorV3 (154 cycles for 100 threa.. 
Back to top
Login to vote
Skybuck Flying

External


Since: May 25, 2006
Posts: 295



(Msg. 4) Posted: Fri Dec 07, 2007 6:32 pm
Post subject: 8096 cycles for 8000 threads ! Nice ! ;) [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Interesting figure:

8096 cycles for 8000 threads.

This shows the algorithm and spawning of the threads is very efficient.

Almost one cycle per thread needed.

Bye,
Skybuck.
 >> Stay informed about: Skybuck's FasterSpawnGeneratorV3 (154 cycles for 100 threa.. 
Back to top
Login to vote
Skybuck Flying

External


Since: May 25, 2006
Posts: 295



(Msg. 5) Posted: Fri Dec 07, 2007 6:37 pm
Post subject: 14 cycles for 2 threads ! Still nice ! (The minimum number of threads parameter is 2) [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Another interesting figure:

14 cycles for 2 threads, the minimum number of threads as the parameter.

Still pretty nice.

That's about 7 cycles per thread.

Not too bad giving it's flexibility to spawn any number of threads Smile

Bye,
Skybuck.
 >> Stay informed about: Skybuck's FasterSpawnGeneratorV3 (154 cycles for 100 threa.. 
Back to top
Login to vote
Skybuck Flying

External


Since: May 25, 2006
Posts: 295



(Msg. 6) Posted: Fri Dec 07, 2007 9:01 pm
Post subject: Re: Skybuck's FasterSpawnGeneratorV3 (154 cycles for 100 threads, final code size: 26 instructions, done no further optimizations possible. :)) (subject corrected) [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

28 instructions/cells for you.

154 cycles for you.

My code beats you ! =D <- my code shorter instructions/cells Smile

"CoreChild" <grumpy3039.RemoveThis@hotmail.com> wrote in message
news:8cc1a596-71d6-4db9-930b-5e53c1a1c262@e25g2000prg.googlegroups.com...
> Hi,
>
> On Dec 7, 5:12 pm, "Skybuck Flying" <s....RemoveThis@hotmail.com> wrote:
>> ;redcode
>> ;name FasterSpawnGeneratorV3
>
> I've improved my code, lets see if you can beat this? For a fair
> comparision you need to replace the second loop with jmp *stack.

What you mean with that ?

I don't understand...

Bye,
Skybuck.
 >> Stay informed about: Skybuck's FasterSpawnGeneratorV3 (154 cycles for 100 threa.. 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Score Surface for 94nop - Hi, some anonymous person (still called "bvowk" for simplicity ;-) is so kind to provide access to a pile of computers. I have suggested to calculate one score surface for standard settings. It takes roughly 1000 times the time of one "no...

Bug in pMARS - Hi, either I don't know how EQUs work or I have found a bug in the parser of pMARS. So far I cound pin it down to: ;redcode-tiny ;name test ;assert CORESIZE == 800 v3 EQU 3 * (3 / 2 + 1) + 3 v4 EQU (CORESIZE - v3) dat.f v3, v4 With the..

KOTH.ORG: Status - ICWS Experimental 94 03/06/06 - Weekly Status on 03/06/06 -=- irc.KOTH.org is up! Meetings held in #corewars -=- Tons of new features on www.KOTH.org/koth.html pages -=- *FAQ* page located at: www.KOTH.org/corewar-faq.html Current Status of the KOTH.ORG ICWS Experimental 94..

KOTH.ORG: Status - MultiWarrior 94 03/06/06 - Weekly Status on 03/06/06 -=- irc.KOTH.org is up! Meetings held in #corewars -=- Tons of new features on www.KOTH.org/koth.html pages -=- *FAQ* page located at: www.KOTH.org/corewar-faq.html Current Status of the KOTH.ORG Multiwarrior 94 CoreWar..

KOTH.ORG: Status - 94 No Pspace 03/06/06 - Weekly Status on 03/06/06 -=- irc.KOTH.org is up! Meetings held in #corewars -=- Tons of new features on www.KOTH.org/koth.html pages -=- *FAQ* page located at: www.KOTH.org/corewar-faq.html Current Status of the KOTH.ORG 94 No Pspace CoreWar Hill...
   Game Forums (Home) -> Core War All times are: Ekaterinburg, Islamabad, Karachi, Tashkent (change)
Page 1 of 1

 
You can post new topics in this forum
You can 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



[ Contact us | Terms of Service/Privacy Policy ]