23 July 2018, 11:25 | #221 |
Code Kitten
Join Date: Aug 2015
Location: Montreal/Canadia
Age: 52
Posts: 1,178
|
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. |
07 March 2019, 08:51 | #222 |
sysop
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.
|
07 March 2019, 11:13 | #223 |
Inviyya Dude!
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. |
07 March 2019, 20:25 | #224 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
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.
|
08 March 2019, 08:08 | #225 | |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Quote:
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). |
|
08 March 2019, 11:11 | #226 | |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
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:
|
|
08 March 2019, 12:09 | #227 | ||
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Quote:
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. 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. |
||
08 March 2019, 12:19 | #228 |
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. |
08 March 2019, 13:28 | #229 | |||
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
gcc is used a lot nowadays.
Quote:
Quote:
Quote:
|
|||
08 March 2019, 14:10 | #230 | |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
gcc isn't alone in the world.
What does this bring ? I could have replied exactly the same to what you wrote... Quote:
If performance is relevant then the functions are written in full asm and therefore there is no need of a wrapper. |
|
04 April 2019, 05:26 | #231 |
Code Kitten
Join Date: Aug 2015
Location: Montreal/Canadia
Age: 52
Posts: 1,178
|
|
04 April 2019, 09:48 | #232 | |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Quote:
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. |
|
04 April 2019, 15:00 | #233 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
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. |
04 April 2019, 16:06 | #234 | ||
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Quote:
Quote:
Yeah, everything has been said, but it's not me who resurrected the thread after nearly a month. |
||
05 May 2019, 22:11 | #235 |
Moderator
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. |
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 |
|
|