English Amiga Board Amiga Lore


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

 
 
Thread Tools
Old 11 May 2017, 11:51   #1
meynaf
68k wisdom
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon (France)
Age: 44
Posts: 2,223
asm coding compo

Yes this is another coding competition idea.

The goal is : do the exact same work as ABCD D0,D1 without using ABCD,SBCD,NBCD instructions.
Targeted audience is any 68k asm coders, however it's especially fit for those who consider this kind of instruction as total useless...

Submit code by PM to me. Don't post code here.
I will regularly update results so that you know where you are in comparison to others (but no code shown before the end).
Deadline undecided yet -- will depend on the received submissions.

020+ stuff allowed, including pack/unpk.
Winner is shortest code in number of instructions. Code size and speed are irrelevant, however every longword of data (should there be some) will be counted as one extra instruction.

Note : if you have a proposal for 68k extensions it might be interesting to see if they can be used here and how efficient it becomes. However this is for academic purposes only, there is no compo on this category (would be too difficult to judge).
meynaf is offline  
AdSense AdSense  
Old 11 May 2017, 14:12   #2
a/b
Registered User

 
Join Date: Jun 2016
Location: europe
Posts: 18
No register other than d1 (=result) trashed, CC flags set identically?
Self-modifying allowed?
a/b is offline  
Old 11 May 2017, 14:40   #3
meynaf
68k wisdom
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon (France)
Age: 44
Posts: 2,223
Quote:
Originally Posted by a/b View Post
No register other than d1 (=result) trashed, CC flags set identically?
Yes.


Quote:
Originally Posted by a/b View Post
Self-modifying allowed?
Yeah, why not.
meynaf is offline  
Old 12 May 2017, 01:37   #4
ross
Vae victis!

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Posts: 218
I'm in too.
Tomorrow I send something, i've to better check.
ross is offline  
Old 14 May 2017, 14:40   #5
a/b
Registered User

 
Join Date: Jun 2016
Location: europe
Posts: 18
OK, I have a decent working version that passes all 40000 test cases. Before I put more time in to try to optimize it further, here are my assumptions:

Input:
- d0.b/d1.b = valid BCD
- ccr: X, Z
Output:
- d1.b = valid BCD result
- ccr: X/C set if carry is present, cleared otherwise
Z cleared if result is nonzero, unchanged otherwise
V/N undefined (=> I do not verify these two)
- other registers and other parts of d1 unchanged
Misc:
- code is not supposed to be called as a subroute (jsr/bsr/...) and rts is not part of it, and is not included in the instruction count.

Are these correct, am I missing something, or am I perhaps overcomplicating it?
a/b is offline  
Old 14 May 2017, 14:59   #6
ross
Vae victis!

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Posts: 218
Quote:
Originally Posted by a/b View Post
OK, I have a decent working version that passes all 40000 test cases.
Why not 2^16 test cases?

Bye,
ross
ross is offline  
Old 14 May 2017, 15:18   #7
a/b
Registered User

 
Join Date: Jun 2016
Location: europe
Posts: 18
d0/d1: $00-$99 (in BCD)
X: 0|1
Z: 0|1
100*100*2*2=40000 combinations

If we're supposed to support invalid BCD as input, then it would be:
256*256*2*2=262144 combinations
a/b is offline  
Old 14 May 2017, 16:08   #8
ross
Vae victis!

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Posts: 218
Quote:
Originally Posted by a/b View Post
d0/d1: $00-$99 (in BCD)
X: 0|1
Z: 0|1
100*100*2*2=40000 combinations

If we're supposed to support invalid BCD as input, then it would be:
256*256*2*2=262144 combinations
Yes, i mean 2^16 D0, D1 input value (with illegal $A-$F).
And you take to my attention that my algo take into account only 2^17 combination (D0, D1, X/C in and out).
I've totally forgotten Z provision...

Bye!
ross
ross is offline  
Old 14 May 2017, 16:16   #9
ross
Vae victis!

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Posts: 218
Quote:
Originally Posted by a/b View Post
Are these correct, am I missing something, or am I perhaps overcomplicating it?
Seems that i've 'overcomplicated' more than you
(i'm working on correcting Z, i've submitted the incomplete version two days ago).

ross is offline  
Old 14 May 2017, 16:39   #10
paraj
Registered User

 
Join Date: Feb 2017
Location: Denmark
Posts: 76
So we don't have to handle invalid BCD inputs? The original post says "do the exact same work as ABCD D0,D1" however the 68k manual could be interpreted as saying that the instruction is only guaranteed to work for valid BCD input and the output is undefined otherwise.

I'd be OK with restricting the input to only valid BCD as getting the other cases right isn't really much fun and restricts the possible implementations.
paraj is offline  
Old 14 May 2017, 16:43   #11
ross
Vae victis!

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Posts: 218
Quote:
Originally Posted by paraj View Post
So we don't have to handle invalid BCD inputs? The original post says "do the exact same work as ABCD D0,D1" however the 68k manual could be interpreted as saying that the instruction is only guaranteed to work for valid BCD input and the output is undefined otherwise.

I'd be OK with restricting the input to only valid BCD as getting the other cases right isn't really much fun and restricts the possible implementations.
Hi paraj, the same work is the same work
(I did somersaults to consider illegal cases too )

Why resticts the implementations? I think it amplifies them..

[EDIT: but meynaf choice, is the boss here]

Last edited by ross; 14 May 2017 at 16:50.
ross is offline  
Old 14 May 2017, 17:12   #12
a/b
Registered User

 
Join Date: Jun 2016
Location: europe
Posts: 18
Well, when I said 262144, that possibly isn't entirely correct. It's correct only if all the CPU models use the same algorithm. That would have to be verified.

Then there is another thing, if you are using WinUEA to test your code, what do you get?
I briefly checked the sources (gencpu.cpp, line 3339):
Code:
		printf ("\tuae_u16 newv_lo = (src & 0xF) + (dst & 0xF) + (GET_XFLG () ? 1 : 0);\n");
		printf ("\tuae_u16 newv_hi = (src & 0xF0) + (dst & 0xF0);\n");
		printf ("\tuae_u16 newv, tmp_newv;\n");
		printf ("\tint cflg;\n");
		printf ("\tnewv = tmp_newv = newv_hi + newv_lo;");
		printf ("\tif (newv_lo > 9) { newv += 6; }\n");
		printf ("\tcflg = (newv & 0x3F0) > 0x90;\n");
		printf ("\tif (cflg) newv += 0x60;\n");
		printf ("\tSET_CFLG (cflg);\n");
It doesn't validate input data. And there is also a 68040 check because apparently it doesn't modify N/V at all.
a/b is offline  
Old 14 May 2017, 17:32   #13
ross
Vae victis!

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Posts: 218
Quote:
Originally Posted by a/b View Post
Well, when I said 262144, that possibly isn't entirely correct. It's correct only if all the CPU models use the same algorithm. That would have to be verified.

Then there is another thing, if you are using WinUEA to test your code, what do you get?
I briefly checked the sources (gencpu.cpp, line 3339):
<snip>
It doesn't validate input data. And there is also a 68040 check because apparently it doesn't modify N/V at all.
I started assuming that all 68k processors did the same thing.
What do you mean by 'doesn't validate input data'?
You cannot restrict input data, the illegal value give defined, reproducible results so the hardware designer needed to respect the rules in later processors.
ABCD instruction was a pain for every 68k emulator, used very little but with strange behaviour and source of incompatibility.
And for N/V: undefined is undefined. $A-$F is illegal but defined

Bye!
ross
ross is offline  
Old 14 May 2017, 17:51   #14
paraj
Registered User

 
Join Date: Feb 2017
Location: Denmark
Posts: 76
Quote:
Originally Posted by ross View Post
Hi paraj, the same work is the same work
(I did somersaults to consider illegal cases too )

Why resticts the implementations? I think it amplifies them..

[EDIT: but meynaf choice, is the boss here]
Well it's probably just because I'm not as great a 68k-wizard as y'all (and I've done very little work with BCD before), but I have like 10 variants that work fine for legal inputs, but getting the exact same result as ABCD for all inputs is more tricky
paraj is offline  
Old 14 May 2017, 18:19   #15
ross
Vae victis!

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Posts: 218
Quote:
Originally Posted by paraj View Post
Well it's probably just because I'm not as great a 68k-wizard as y'all (and I've done very little work with BCD before), but I have like 10 variants that work fine for legal inputs, but getting the exact same result as ABCD for all inputs is more tricky
paraj, you are a great 68k programmer and you know it.
And yes, there is several variants working, but much more with illegal.

Said this, making the illegal value works is fun

Bye!
ross is offline  
Old 14 May 2017, 19:39   #16
Thorham
Computer Nerd

Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 40
Posts: 2,902
Quote:
Originally Posted by meynaf View Post
do the exact same work as ABCD D0,D1 without using ABCD,SBCD,NBCD instructions
It would be more interesting to do something that yields useful code.
Thorham is offline  
Old 14 May 2017, 20:15   #17
meynaf
68k wisdom
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon (France)
Age: 44
Posts: 2,223
Quote:
Originally Posted by a/b View Post
Are these correct, am I missing something, or am I perhaps overcomplicating it?
Seems your assumptions are correct. Asking for "exact" same work was probably a little bit overkill...

I don't regard "correct" handling of invalid values as a target. What's correct anyway, the result is totally bogus in these cases - which are not even detected. A more correct implementation would have been to set V and not alter the output - like DIV does - but heck, it's too late for that.
You may care about these values if you want, however that's just for the fun.

Same story for N,V.
Do all 680x0 behave the same in regard to these two bits and invalid values anyway ? If they don't, problem solved.


Quote:
Originally Posted by Thorham View Post
It would be more interesting to do something that yields useful code.
Create your own compo then.

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"
meynaf is offline  
Old 14 May 2017, 21:11   #18
paraj
Registered User

 
Join Date: Feb 2017
Location: Denmark
Posts: 76
Noted. I will try to finish an entry in the coming week then even if I'll be losing again (even without full results of the last compo I'm already badly beaten )

I'm very much looking forward to seeing how ross is achieving perfection because I'm having a really hard time keeping instruction count down when trying to handle all "illegal" cases.

Anyway I like the compo, it's been fun looking at BCD-numbers and exploring - for me - unknown instructions (*BCD,PACK,UNPK).
paraj is offline  
Old 15 May 2017, 12:51   #19
ross
Vae victis!

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Posts: 218
Ok, alone in this crusade versus code illegality

Final version submitted.

Bye,
ross
ross is offline  
Old 15 May 2017, 12:54   #20
ross
Vae victis!

ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Posts: 218
Quote:
Originally Posted by paraj View Post
I'm very much looking forward to seeing how ross is achieving perfection because I'm having a really hard time keeping instruction count down when trying to handle all "illegal" cases.
Hi paraj, my final code is FULL of code tricks.
Maybe can be better but sure is magic.

Bye!
ross
ross 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 05:38.


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