English Amiga Board


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

 
 
Thread Tools
Old 23 July 2018, 11:25   #221
ReadOnlyCat
Code Kitten
 
Join Date: Aug 2015
Location: Montreal/Canadia
Age: 52
Posts: 1,178
Quote:
Originally Posted by idrougge View Post
That's a totally pointless debate. Use whatever works for you.
Yes ... with a few caveats.

* What works when writing code is different than what works for reading code.
Oftentimes, shortcuts used to make code simpler to write go against readability and hinder maintainability in the long run.
I have suffered enough cases of "what the kitten is this code I wrote six months ago attempting to achieve?" that I have long made sure to make my code readable by future me rather than just writable by current me.
Coding is a never ending task, there are always enhancements to add or bugs to fix and being able to dive back into old code instantly is definitely a plus in these cases.

* Sharing code requires it to be readable with minimal effort.
When working as a team or simply when exchanging snippets of code, readability does help. Sure, one can adapt to others's writing style but if that happens frequently enough, the friction this creates becomes a pain. Making sure your way of writing code is readable by most people does help.

This said, having a style guide (code formatting, naming, etc.) is very different from a coding style (avoid globals like the plague, use functions not macros, optimize only after profiling and after features are implemented, decouple functionality, use DRY (Don't Repeat Yourself) for data, etc.).

And the former is much less important than the latter: not point in having a well formatted code base if the code is overly complicated, inefficient and slow.
ReadOnlyCat is offline  
Old 07 March 2019, 08:51   #222
Carston
sysop
 
Carston's Avatar
 
Join Date: Mar 2019
Location: Columbus
Posts: 6
I'm so glad I've found this thread. All the assembler-related stuff is so nostalgic to me.
Carston is offline  
Old 07 March 2019, 11:13   #223
Tigerskunk
Inviyya Dude!
 
Tigerskunk's Avatar
 
Join Date: Sep 2016
Location: Amiga Island
Posts: 2,770
Lot of good stuff in here.

I really want to bring more structure and best practices into my asm code base after I finished Inviyya.

I really want to bring more structure to my "function calls", especially when it comes to register usage. I don't use any stack saves, which can be a nightmare in the long run.
Tigerskunk is offline  
Old 07 March 2019, 20:25   #224
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by Steril707 View Post
I really want to bring more structure to my "function calls", especially when it comes to register usage. I don't use any stack saves, which can be a nightmare in the long run.
I just follow the most common m68k-ABI: d0/d1/a0/a1 are scratch registers, other registers must be saved before I can overwrite them. That makes it easy to interface with C code and the ABI really makes sense, most of the time. In some critical routines I don't save all registers, but this has to be thoroughly documented.
phx is offline  
Old 08 March 2019, 08:08   #225
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Quote:
Originally Posted by phx View Post
I just follow the most common m68k-ABI: d0/d1/a0/a1 are scratch registers, other registers must be saved before I can overwrite them. That makes it easy to interface with C code and the ABI really makes sense, most of the time. In some critical routines I don't save all registers, but this has to be thoroughly documented.
This is only Amiga ABI. Atari ST and MacOS 68k are different.
The secret isn't saving registers or not, it is that it has to be thoroughly documented.
Every routine must have some comment at start indicating what it does, what it takes, and what registers it alters (or preserves).
meynaf is offline  
Old 08 March 2019, 11:11   #226
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by meynaf View Post
This is only Amiga ABI.
I wrote "most common ABI", because the m68k Unix ABIs (e.g. V.4) are the same as Amiga (when we disregard the FPU). I know Atari is different, at least for some TOS calls it trashes a2 and d2 - but not for all? And the Atari C-compilers mostly still apply the "common ABI". Didn't know about MacOS.

Quote:
Every routine must have some comment at start indicating what it does, what it takes, and what registers it alters (or preserves).
True. But when you decide that your project follows an ABI you only have to document saved registers when they are different from the ABI. And it saves you from checking the notes of every function you call, as long as you can be sure it follows the ABI. That's quite convenient, less chaotic and compatible with C.
phx is offline  
Old 08 March 2019, 12:09   #227
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Quote:
Originally Posted by phx View Post
I wrote "most common ABI", because the m68k Unix ABIs (e.g. V.4) are the same as Amiga (when we disregard the FPU). I know Atari is different, at least for some TOS calls it trashes a2 and d2 - but not for all? And the Atari C-compilers mostly still apply the "common ABI". Didn't know about MacOS.
What Atari compilers ? Megamax (the most used back in the day) trashes D0-D3/A0-A1. MacOs uses D0-D2/A0-A1. Unix on m68k isn't representative.


Quote:
Originally Posted by phx View Post
True. But when you decide that your project follows an ABI you only have to document saved registers when they are different from the ABI. And it saves you from checking the notes of every function you call, as long as you can be sure it follows the ABI. That's quite convenient, less chaotic and compatible with C.
You have to check the notes of every function you call anyway, as you're calling it and you need to know all details about it.
Blindly following a convention isn't convenient : you're more often out of registers because you assume some regs are trashed where this isn't necessarily the case.
You also waste performance by saving regs where this isn't required.
Dynamic register usage isn't chaotic, it's just adaptative.
Being "compatible with C" is of no advantage if this destroys the asm part. I have rewritten enough C code into Asm to know that a few wrappers for inter-language function calls are more than enough.
You must just be consistent with register usage, passing the same value on the same register wherever possible. Then a lot less time is wasted in passing parameters and you will get shorter & faster code.
Following C conventions isn't writing Asm : Asm has its own advantages in comparison to other languages, but writing code like a compiler would is wasting them and it only makes it harder.
meynaf is offline  
Old 08 March 2019, 12:19   #228
roondar
Registered User
 
Join Date: Jul 2015
Location: The Netherlands
Posts: 3,410
Fascinating thread to read. I've seen some very good stuff here!

Looking at my own code, I think I'll try to follow one suggestion here (more than I usually do). It is indeed best to note not just what registers are used as parameters by functions, but also what registers are trashed/changed/etc.

And if I'm honest, the latter part is something I tend to forget to add. So I'll try to incorporate that more.
roondar is offline  
Old 08 March 2019, 13:28   #229
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by meynaf View Post
What Atari compilers ?
gcc is used a lot nowadays.

Quote:
Unix on m68k isn't representative.
Says you!

Quote:
Blindly following a convention isn't convenient : you're more often out of registers because you assume some regs are trashed where this isn't necessarily the case.
You also waste performance by saving regs where this isn't required.
For most functions of your project this is irrelevant. I prefer the convenience.

Quote:
I have rewritten enough C code into Asm to know that a few wrappers for inter-language function calls are more than enough.
But here you don't care to waste performance by wrappers?
phx is offline  
Old 08 March 2019, 14:10   #230
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Quote:
Originally Posted by phx View Post
gcc is used a lot nowadays.
gcc isn't alone in the world.


Quote:
Originally Posted by phx View Post
Says you!
What does this bring ? I could have replied exactly the same to what you wrote...


Quote:
Originally Posted by phx View Post
For most functions of your project this is irrelevant. I prefer the convenience.
It is relevant for most, if not all, functions.


Quote:
Originally Posted by phx View Post
But here you don't care to waste performance by wrappers?
If performance is relevant then the functions are written in full asm and therefore there is no need of a wrapper.
meynaf is offline  
Old 04 April 2019, 05:26   #231
ReadOnlyCat
Code Kitten
 
Join Date: Aug 2015
Location: Montreal/Canadia
Age: 52
Posts: 1,178
Quote:
Originally Posted by meynaf View Post
gcc isn't alone in the world.
Being used a lot does not mean it is alone.
Phx said that ABI was commonly used and active Gcc usage supports it. He never said that this was the only one in use so why are you responding that?
ReadOnlyCat is offline  
Old 04 April 2019, 09:48   #232
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Quote:
Originally Posted by ReadOnlyCat View Post
Being used a lot does not mean it is alone.
Phx said that ABI was commonly used and active Gcc usage supports it. He never said that this was the only one in use so why are you responding that?
This is the only example he could provide...
Anyway, the point is that he said Atari compilers mostly apply this ABI while this is not true. Only recent compilers like gcc do, and perhaps not all of them - while old ST compilers certainly did not.
Said otherwise, i disassembled quite a lot of ST code and never seen D0-D1/A0-A1 as the only scratch. Same for Mac code. So at the end this "standard" is a property of Amiga, maybe of unix if you want, but certainly not of 68k itself.
meynaf is offline  
Old 04 April 2019, 15:00   #233
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
Quote:
Originally Posted by meynaf View Post
This is the only example he could provide...

I have no time for your infamous hairsplitting on completely irrelevant side aspects. I prefer to spend my time with actually coding instead of just talking.

I said it is advantageous to follow the ABI, even in assembler, you said it is not. That's fine. Everybody will find that out for her/himself. Everything has been said.
phx is offline  
Old 04 April 2019, 16:06   #234
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Quote:
Originally Posted by phx View Post

I have no time for your infamous hairsplitting on completely irrelevant side aspects.
And I have no time for personal attacks that usually follow my valid points when the other has nothing more to say.


Quote:
Originally Posted by phx View Post
I prefer to spend my time with actually coding instead of just talking.
Good idea, but coding 100% asm is the only way to correctly get my point.


Quote:
Originally Posted by phx View Post
I said it is advantageous to follow the ABI, even in assembler, you said it is not. That's fine. Everybody will find that out for her/himself. Everything has been said.
Yeah, everything has been said, but it's not me who resurrected the thread after nearly a month.
meynaf is offline  
Old 05 May 2019, 22:11   #235
Photon
Moderator
 
Photon's Avatar
 
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,602
I will remind that the topic is 'neat coding style and good habits'. This applies to all syntaxes, so I will add that "this bickering is pointless" one day too late after May the Fourth. I hope you take it in good spirit, because that is how it's intended.

Bickering about what coding styles are neat and what habits are good, however, are 100% topical. Carry on, commanders.
Photon is offline  
 


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Neat idea - borderless WinUAE and Amiga wallpaper Bloodwych Amiga scene 8 12 January 2011 23:58
2000 - black screen... Chips good... PSU good... chiark support.Hardware 45 09 January 2009 05:41
Mitser Org'oeil, good platformer in old style s2325 Retrogaming General Discussion 2 23 November 2008 21:58
good retro racer in Lotus/Outrun style s2325 Retrogaming General Discussion 4 27 May 2007 20:57
very good new racing PC game in old style s2325 Retrogaming General Discussion 1 20 February 2007 22:34

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 03:28.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.09698 seconds with 15 queries