English Amiga Board Amiga Lore


Go Back   English Amiga Board > Coders > Coders. Asm / Hardware

 
 
Thread Tools
Old 15 May 2017, 14:27   #21
meynaf
68k wisdom
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon (France)
Age: 44
Posts: 2,362
Quote:
Originally Posted by ross View Post
Ok, alone in this crusade versus code illegality
Perhaps this could become a different category with its own ranking. But you're alone having sent code to me so far...
meynaf is offline  
AdSense AdSense  
Old 15 May 2017, 17:23   #22
Nightfox
Registered User

Nightfox's Avatar
 
Join Date: Apr 2016
Location: Australia
Posts: 194
I just submitted my entry. I don't expect to even come close to winning because I'm still an assembly n00b but hey this is great for learning.
Nightfox is offline  
Old 17 May 2017, 08:32   #23
meynaf
68k wisdom
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon (France)
Age: 44
Posts: 2,362
I currently have 4 submissions. Time for the first results :
1. paraj (15)
2. ross (19)
3. a/b (20)
4. sacredbanana -> nightfox (38)
All versions have been checked with my result testing program under winuae.

Now that you know where you are, you can of course submit new versions and get a better score.

Last edited by meynaf; 26 May 2017 at 15:05. Reason: sacredbanana renamed himself to nightfox
meynaf is offline  
Old 17 May 2017, 10:31   #24
ross
Vae victis!

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Posts: 434
arghh, and now paraj knows the instructions number to make a 2^18 in/out combo

ross is offline  
Old 17 May 2017, 12:35   #25
meynaf
68k wisdom
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon (France)
Age: 44
Posts: 2,362
And you know how much it takes for 100*100*2*2 as well
meynaf is offline  
Old 17 May 2017, 13:15   #26
a/b
Registered User

 
Join Date: Jun 2016
Location: europe
Posts: 55
Quote:
Originally Posted by meynaf View Post
All versions have been checked with my result testing program under winuae.
Could you please post or message me your testing program?
a/b is offline  
Old 17 May 2017, 13:36   #27
meynaf
68k wisdom
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon (France)
Age: 44
Posts: 2,362
Quote:
Originally Posted by a/b View Post
Could you please post or message me your testing program?
Ok, here's the code for testing :
Code:
 moveq #1,d7        ; x
.xloop
 moveq #1,d6        ; ~z
.zloop
 move.w #$99,d5     ; b
.bloop
 sub.l d0,d0        ; x=0, d0=0
 abcd d5,d0
 cmp.b d5,d0
 bne.s .bskip       ; b = invalid bcd
 move.w #$99,d4     ; a
.aloop
 sub.l d0,d0
 abcd d4,d0
 cmp.b d4,d0
 bne.s .askip        ; a = invalid bcd
 bsr.s .init
 abcd d0,d1
 move ccr,d3        ; ref ccr = d3
 move.l d1,a0       ; ref res = a0
 bsr.s .init
 bsr tstcode        ; call emu code
 move ccr,d2
 eor.b d3,d2
 andi.b #$15,d2     ; keep x,z,c
 bne.s .ohno        ; wrong ccr
 cmp.l a0,d1
 bne.s .ohno        ; wrong result
.askip
 dbf d4,.aloop
.bskip
 dbf d5,.bloop
 dbf d6,.zloop
 dbf d7,.xloop
; if we get there, everything is ok
 rts
.init
 move.b d4,d0
 move.b d5,d1
 move.b d7,d2
 mulu #$11,d2        ; x=c
 move d2,ccr
 btst #0,d6          ; z
 rts
.ohno
; abort here
meynaf is offline  
Old 17 May 2017, 15:30   #28
Nightfox
Registered User

Nightfox's Avatar
 
Join Date: Apr 2016
Location: Australia
Posts: 194
I can't hope to compete against you masters haha but I'm just happy I managed to get working code and learn a lot in the process
Nightfox is offline  
Old 17 May 2017, 20:17   #29
paraj
Registered User

 
Join Date: Feb 2017
Location: Denmark
Posts: 78
Didn't imagine everyone was using so many instructions, now I may have to look into also handling the rest of the cases

@sacredbanana: Hang in there, you'll quickly get a hang of the basics tricks (e.g. knowing which operations set which flags so you rarely have to use cmp, and making sure otherwise unused parts of registers still do work). Here you need to at least some of the time manipulate both BCD digits at once to get to a low instruction count. Hint: 6 is a magic value for BCD

For this exact challenge it's annoying that most operations clear the carry flag, there must be a more elegant way to handle it than the way I'm currently doing it.
paraj is offline  
Old 17 May 2017, 23:12   #30
Nightfox
Registered User

Nightfox's Avatar
 
Join Date: Apr 2016
Location: Australia
Posts: 194
Thank you Paraj, I am thinking about your hints and coming up with ideas. Whether they work or not is yet to be seen
Nightfox is offline  
Old 18 May 2017, 09:41   #31
meynaf
68k wisdom
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon (France)
Age: 44
Posts: 2,362
Quote:
Originally Posted by paraj View Post
For this exact challenge it's annoying that most operations clear the carry flag, there must be a more elegant way to handle it than the way I'm currently doing it.
It might be interesting to see how much the code could be reduced if we only had to care about X and not C. However I think the biggest pest here is Z.
meynaf is offline  
Old 19 May 2017, 19:38   #32
paraj
Registered User

 
Join Date: Feb 2017
Location: Denmark
Posts: 78
Quote:
Originally Posted by meynaf View Post
It might be interesting to see how much the code could be reduced if we only had to care about X and not C. However I think the biggest pest here is Z.
Yeah, but I was prepared for that since Z is so volatile. There's probably a good reason why so many instructions clear the C flag, it was just annoying here since it destroyed many of my plans.

EDIT: You can trivially reduce my code by 2 instructions if C doesn't need to be preserved.

Last edited by paraj; 19 May 2017 at 19:50.
paraj is offline  
Old 26 May 2017, 15:06   #33
meynaf
68k wisdom
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon (France)
Age: 44
Posts: 2,362
Is it time for final results now or does anyone want more time ?
meynaf is offline  
Old 26 May 2017, 18:18   #34
a/b
Registered User

 
Join Date: Jun 2016
Location: europe
Posts: 55
I'm done. I haven't spent much time on this after sending my update, a few hours resulted in another 15 instruction variant, 8 bytes shorter, but byte length and speed don't matter so I didn't bother sending another update...
a/b is offline  
Old 27 May 2017, 15:49   #35
paraj
Registered User

 
Join Date: Feb 2017
Location: Denmark
Posts: 78
Final results is ok with me as well so we can switch to "friendly mode". I briefly looked into getting the right results for all inputs, but it's too much work so I'm done.
paraj is offline  
Old 27 May 2017, 16:12   #36
Megol
Registered User

Megol's Avatar
 
Join Date: May 2014
Location: inside the emulator
Posts: 228
Quote:
Originally Posted by meynaf View Post
For this one, at least next time someone tells me bcd instructions are useless, i'll reply "okay but look at how hard it is to do their job when you don't have them"
They are useless for most code except doing tricks. Emulating them shows that emulating a mostly useless instruction is costly - why would that be interesting?

BCD arithmetic can be done faster in 32 bit chunks with no special instructions but in most cases translating the code to use standard binary encoding is even better.
Megol is offline  
Old 27 May 2017, 16:49   #37
meynaf
68k wisdom
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon (France)
Age: 44
Posts: 2,362
Quote:
Originally Posted by Megol View Post
They are useless for most code except doing tricks. Emulating them shows that emulating a mostly useless instruction is costly - why would that be interesting?
Sometimes these instructions can be useful and in these cases we can be happy we have them. Because doing the same work without, is cumbersome - as shown here.
BCD is not useless. Aside of score counting in games, decimal floating-point comes in mind.


Quote:
Originally Posted by Megol View Post
BCD arithmetic can be done faster in 32 bit chunks with no special instructions but in most cases translating the code to use standard binary encoding is even better.
Nope - BCD is not faster in 32 bit chunks without regular bcd instructions.
We could of course translate to use standard binary but then why not translating everything to standard binary, including floats...


Quote:
Originally Posted by paraj View Post
Final results is ok with me as well so we can switch to "friendly mode". I briefly looked into getting the right results for all inputs, but it's too much work so I'm done.
Switching to friendly mode now, here's best code, from paraj :
Code:
    movem.l    d2-d4, -(a7)
    sne    d4              ; d4.b = $00 if Z, $ff otherwise
    unpk    d0, d2, #$76f6
    unpk    d1, d3, #$0000
    addx.w    d3, d2          ; $8?0? / $7?f? othewise (and combinations)
    move.w    d2, d3
    and.w    #$6060, d3      ; extract non-overflowed bits
    lsr.w    #4, d3
    sub.w    d3, d2          ; subtract 6 from digit if no overflow
    pack    d2, d1, #$0000
    or.b    d1, d4          ; d4.b = $00 if Z / <> $00 otherwise
    sne    d4              ; d4.b = $00 if Z / $ff otherwise
    add.w    d2, d2          ; C/X = top bit of result
    btst    #0, d4          ; Z
    movem.l    (a7)+, d2-d4
Another 15 insns has been submitted but first one is the winner obviously.
meynaf is offline  
Old 27 May 2017, 19:43   #38
ross
Vae victis!

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Posts: 434
Hi meynaf, maybe someone interested, can you show my full emulation code? (if mine is the best, logically).

Cheers,
ross
ross is offline  
Old 27 May 2017, 19:51   #39
a/b
Registered User

 
Join Date: Jun 2016
Location: europe
Posts: 55
Quote:
Originally Posted by meynaf View Post
... but first one is the winner obviously.
Maybe make that clear when you start a competition, so you are not contradicting yourself?

Now speaking of code, I like paraj's version better. I tried the unpack version but that was very early in the process, before I figured out most of the optimizations and couldn't make it as short as my other versions at the time, and then later I never truly revisited it. Whenever I started thinking about it, it was always hmm 3x pack/unpack and 2x movem followed by a nah, that wouldn't end up short enough. Yeah, dangers of local and global optimizations .
Grats!
a/b is offline  
Old 27 May 2017, 20:05   #40
meynaf
68k wisdom
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon (France)
Age: 44
Posts: 2,362
Quote:
Originally Posted by ross View Post
Hi meynaf, maybe someone interested, can you show my full emulation code? (if mine is the best, logically).
Nobody else submitted full emu code so you can show it of course.
But perhaps you don't have it anymore ?


Quote:
Originally Posted by a/b View Post
Maybe make that clear when you start a competition, so you are not contradicting yourself?
I didn't make that clear because i didn't think about that case.
But it seemed logical that the first one submitting something has some edge over other people doing the same later... I'm not contradicting myself.
Of course you can post your code here.

And it is not as if there was a price to win
meynaf is offline  
AdSense AdSense  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Anyone up for an ASM coding competition? DanScott Coders. Asm / Hardware 523 02 May 2017 09:24
4th tutorial on ASM- and HW-coding Vikke Coders. Asm / Hardware 11 10 April 2013 20:32
3rd tutorial on ASM- and HW-coding Vikke Coders. Asm / Hardware 6 26 March 2013 15:57
First tutorial on ASM- and HW-coding Vikke Coders. Asm / Hardware 46 18 March 2013 12:33
2nd tutorial on ASM- and HW-coding Vikke Coders. Asm / Hardware 10 17 March 2013 11:49

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 07:24.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Page generated in 0.22041 seconds with 12 queries