26 June 2023, 10:31 | #1 |
Registered User
Join Date: May 2022
Location: Adelaide, South Australia, Australia
Posts: 209
|
Any reason to use assembly on the Amiga rather than C?
It seems that with modern optimising compilers and cross-compilation tools noone could write code for the Amiga better than gcc can, is there any reason to use assembly over C in 2023 for the Amiga (beyond novelty)?
|
26 June 2023, 10:39 | #2 | |
Alien Bleed
Join Date: Aug 2022
Location: UK
Posts: 4,713
|
Quote:
If you were developing new software, writing it in C makes sense since C has always been the main programming language for the Amiga. As for "nobody can beat gcc", that's just not true. When sections of TKG were ported to C, GCC made lousy instruction choices for some operations that were totally obvious to assembler programmers, and we're only fixed by muddying clean C with casts to effectively guide the compiler into producing the same code the human did. And this wasn't some obscure example where you need fringe knowledge it as a bit of arithmetic with some division and modulo in it. |
|
26 June 2023, 13:50 | #3 |
Registered User
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 1,161
|
I suspect the "nobody can beat GCC" thing is much more applicable (even if still not strictly true) true on current architectures than it is on m68k. After all, the last 20 years' worth of research and engineering effort around optimisation won't have been done with the 68000 architecture in mind.
|
26 June 2023, 13:59 | #4 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,371
|
Not really. There is sometimes the need for it if you need to access low-level features of a particular CPU (e.g. go to supervisor mode and access some of the control registers). Your average program should not do that, however.
|
26 June 2023, 14:02 | #5 | |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,371
|
Quote:
|
|
26 June 2023, 14:40 | #6 | |
Alien Bleed
Join Date: Aug 2022
Location: UK
Posts: 4,713
|
Quote:
https://github.com/mheyer32/alienbreed3d2/pull/88 The original assembler code for this used a 32/16 => 16r:16q operation and uses both components of the result. The code generated by the compiler would not do this until it was guided by type cast hint for the immediate. |
|
26 June 2023, 14:58 | #7 | |
Registered User
Join Date: Jun 2016
Location: europe
Posts: 1,076
|
Quote:
Anyway: 1. because you can (zero effs given) 2. because you want to challenge yourself 3. because you're tired of dealing with c/c++ as part of your job |
|
26 June 2023, 15:21 | #8 | |
Registered User
Join Date: Dec 2017
Location: Austin, TX
Age: 41
Posts: 415
|
Quote:
Compiler developers have been trying to improve autovectorization since the dawn of SSE and GCC still does a terrible job of it. Where ALU throughput matters and the algorithm can be vectorized we still lean heavily on intrinsics; the half-way house between C and assembly. For 68K I was unable to coerce GCC into generating code as efficient as this, which gave a great speed-up. |
|
26 June 2023, 15:58 | #9 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,371
|
That's a classic, and here the compiler misses indeed an optimization, namely understanding that 1000 fits into a UWORD and does not need to be handled as integer. Again, write to to gcc folks and get it fixed.
|
26 June 2023, 16:00 | #10 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,371
|
That is, in this generality, outright wrong. A C compiler can optimize for multiple targets, and can create code you find "unexpected" or "unpleasant", but it may also generate code you would probably not write in such a way yourself, though the speed or the size of the code is then nevertheless convincing.
The output of gcc on x64 at least nowadays sometimes really surprises me in the way what the compiler can actually do. |
26 June 2023, 16:05 | #11 | ||
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,371
|
It is actually better. The trouble is that x64 with all its extensions became such an unorthogonal beast.
Quote:
Quote:
In fact, this is how we work these days. Find bottlenecks, isolate them into separate classes, rewrite those classes with intrinsics. Nobody bothers writing in assembler anymore. |
||
26 June 2023, 16:15 | #12 |
Alien Bleed
Join Date: Aug 2022
Location: UK
Posts: 4,713
|
I think we are all losing sight of what I propose is the most important reason anyone might use assembler for programming on the Amiga: they just want/prefer to. It's not as if the platform is in any kind of competition commercially and the entire userbase is made up of enthusiasts. Everything anyone does with it is basically for fun.
I mostly use C++ and C for Amiga but I'll happily use assembler where I feel I can improve something beyond what the compiler can manage or if I want some especially hands on control of something. |
26 June 2023, 16:30 | #13 | ||||
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,366
|
Quote:
And on other cpus i suspect the compilers win mainly because nobody really challenges them. Quote:
Asm is the best coding school. Once you master it, you are a better coder overall because you know how things work. It provides more coding freedom. You do whatever you want. Obviously your code will be shorter and faster. In asm you can call any function located anywhere in the source, without prior declaration. Last time i've looked, in C you had to either pay attention to order, or define same thing several times. C syntax is simply horrible In asm you can have nice, aligned, one-comment per code line. Unlike C, in asm you will not run into undefined behaviours without even knowing it because the spec is so overcomplicated and nobody knows it fully. Do you want more ? (now i have the feeling this will end up in a flame war...) I am afraid they pay little attention to m68k these days. Quote:
Quote:
While overall true, again this does not apply for Amiga - where quite few people hopefully still write asm. |
||||
26 June 2023, 16:43 | #14 | ||||
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,371
|
Quote:
Quote:
The problem is "if you do what you want", you probably do not mind that you may "want something different in the future", and for that target, structure and notation helps, and asssembler is very bad providing it. Consider you need to change your algorithm later on because the use case of your program changed, or the data changed. Try to remember what you did 3 years ago in an assembler program. That can be very painful. Actually, that is pretty much the difference between "coding" and "engineering". And almost surely non-working, only after some painful debugging sessins, and not maintainable. Quote:
Quote:
But sure it is. Entire AmigaOs is a mixture of C and assembler, and only bottlenecks are in assembler. P96 works likewise. The heavy-duty algorithms are in assembler because it matters that the algorithms are fast. The higher level logic is in C because there it matters that you express the structure clearly to keep the code maintainable. |
||||
26 June 2023, 17:08 | #15 |
Registered User
Join Date: Jun 2015
Location: Germany
Posts: 1,938
|
I would also say that it is mostly about subjective reasons such as fun and personal preferences. If you address the bare 68000 configuration and have some ambitious goals, you certainly need every CPU-cycle and wouldn't want them wasted my a compiler producing suboptimal code (and even if it is only because the compiler can't possibly consider all constraints and side conditions that you can in assembly language).
To me assembly coding gives me a feeling of control which is due to the fact that I simply don't understand much about higher-level programming languages which abstract things away and do unexpected things under the hood I don't know about. I guess that feeling goes away with experience in programming in high-level languages but I never did that enough. I'm a microelectronics guy and understand about transistors and digital logic which makes assembly language close enough to my field of expertise. |
26 June 2023, 17:13 | #16 | ||||||||||
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,366
|
Quote:
Quote:
Quote:
Assembler does not need to provide anything special, nor do other languages. Quote:
Quote:
Quote:
That, because we're in "fail early and fail big" environment, as opposed to "fail silently and keep going". Quote:
Quote:
If in asm you swap argument types, be sure the code won't work at all and you'll quickly find out why. In C, especially C++, it may eventually make some silent, damaging conversions without telling you. Only right way to code is to not attempt to have the computer do it at your place, but verify yourself everything you do. Quote:
Why would i care with something overcomplicated, just because a few others can ? And are you sure you really know the full C spec, with all its details ? Perhaps you should read it again. Quote:
|
||||||||||
26 June 2023, 17:39 | #17 |
Registered User
Join Date: Jun 2016
Location: europe
Posts: 1,076
|
Not in the slightest. Handwritten m68k code by a good asm programmer > gcc code. Yes, there will occasionally be a small case, some weird trick, where gcc wins, but, in general, there is no way in hell gcc (or any c/c++ compiler) can produce faster and smaller code than handwritten m68k.
That's all I'm saying, based on my personal experience (writting m68k asm since 90's, last ~5 years pretty much all my spare time doing that). To give you an example... 68000-060 disassembler, supports old and new syntax, selectable target cpu/mmu/fpu, optional opcode hexdump, all code+data+strings+tables = 7184 bytes. Good luck doing that in c/c++. I'm not arguing about development time, efficiency, portability, .... I wouldn't even suggest anyone to use asm instead of c/c++. |
26 June 2023, 20:22 | #18 | ||
Ex nihilo nihil
Join Date: Oct 2017
Location: CH
Posts: 5,098
|
Quote:
Quote:
After 3 years, even a batch script can be very painful to understand without comments . And commenting code is "just" a good practice whatever language you code in. In this regard, using C is of no help at all. |
||
26 June 2023, 21:12 | #19 |
Alien Bleed
Join Date: Aug 2022
Location: UK
Posts: 4,713
|
Some of us are so lame, we write stuff C++ and even scripting languages to allow us to pretend we still write 68K ... https://github.com/0xABADCAFE/MC64000
|
26 June 2023, 22:28 | #20 | |||||||
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,371
|
Quote:
Now, try to maintain an assembly program. Quote:
Quote:
The point in "declarations" is to help you, not to struggle you. It provides a first level barrier for code checking. Quote:
Quote:
Quote:
Quote:
War time story, from another thread just in this forum: Do you know why the CON: handler only hides its window instead of closing it when pressing the iconification button? Because nobody understands how the console.device operates. It is opaque assembly code. If that would have been C code with proper data structures, it would be relatively straight foreward to update the code such that the console character map can exist without its window, but the way how the code operates (in assembler) is just opaque, and it is somewhat documented. In the assembler programming style. In other words: You have not yet had in contact to reality if you make such nonsense claims. Assembler code is to a good degree write-only code, probably understandable for its author. The expressiveness of the language (if you call it so) is not sufficient to document intentions of the author and encode it in the syntax. C is not perfect, but better. C++ is even better to formulate designs, but it already has "too many" features that can be easily misused to make thinks less readable rather than more readable. |
|||||||
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Chat GPT Amiga Assembly | rcman | Coders. Asm / Hardware | 3 | 26 March 2023 20:24 |
An Amiga coder was banned without a reason - is it ok? | litwr | project.EAB | 1 | 18 June 2021 20:38 |
Beginning Amiga Assembly Tutorial(s) | Curbie | Coders. Asm / Hardware | 15 | 29 May 2020 00:21 |
Beginning Amiga Assembly Programming | Hewitson | Coders. Tutorials | 32 | 09 October 2012 18:25 |
Amiga Assembly sources - Please help! | W4r3DeV1L | Amiga scene | 21 | 16 July 2008 08:13 |
|
|