07 October 2023, 23:46 | #1501 |
Registered User
Join Date: Sep 2007
Location: Stockholm
Posts: 4,335
|
Which is why higher-level languages exist. Because errare humanum est.
The hardest-to-identify bugs I have encountered at work were when the type system was put out of play. And, luckily, I don’t work in rocketry or surgery. |
07 October 2023, 23:48 | #1502 | |
Registered User
Join Date: Sep 2007
Location: Stockholm
Posts: 4,335
|
Quote:
|
|
08 October 2023, 00:22 | #1503 | |||||
Registered User
Join Date: Sep 2007
Location: Stockholm
Posts: 4,335
|
This is a problem. I hope we some day get higher-level languages on the Amiga — so that we may concentrate on the work at hand instead of dealing with low-level details like what function in what library to allocate an object and how to track its lifetime.
Quote:
Quote:
Quote:
Quote:
That said, if you can implement that in assembly, you could just as well create that in C. Quote:
|
|||||
08 October 2023, 00:28 | #1504 |
Alien Bleed
Join Date: Aug 2022
Location: UK
Posts: 4,165
|
@idrougge
There are plenty of HLL for amiga/68k, including variants of C++ from this millenium and even higher level language tools like Hollywood that allow people to just get useful stuff done PDQ. |
08 October 2023, 00:41 | #1505 | |||||||
Registered User
Join Date: Sep 2007
Location: Stockholm
Posts: 4,335
|
Quote:
Quote:
That said, C# is in no way a C++ derivate. It is a Java derivative. Quote:
Quote:
Quote:
Quote:
Quote:
|
|||||||
08 October 2023, 00:47 | #1506 | |
Registered User
Join Date: Sep 2007
Location: Stockholm
Posts: 4,335
|
Quote:
Why is val written to repeatedly? An assembly programmer would never do this. Why is val evaluated repeatedly? An assembly programmer would never do this. Why isn’t the 0 case handled? An assembly programmer would never do this. |
|
08 October 2023, 01:11 | #1507 | |||
Alien Bleed
Join Date: Aug 2022
Location: UK
Posts: 4,165
|
Quote:
Quote:
Quote:
I agree the code is bad but some of your interpretation of it is equally bad. |
|||
09 October 2023, 10:23 | #1508 | ||||||||||||||||||
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Quote:
Quote:
Quote:
Quote:
This is what the "non existing registers" trick is for. Use d8,d9,a8,a9, and anything you can imagine so you can do your code without having to care that much about registers. Do actual register allocation once you're done. Quote:
In asm you could even do inter-function allocation, to pass same parameters always in same registers and avoid unneeded data moving. For example, a whole bunch of routines could get A2 pointing to some structure, regardless if they actually access it or not. One day, one may call a sub-routine that needs it : nothing to change, it's already there - in C two prototypes would need to be altered. Quote:
Quote:
Quote:
Quote:
Quote:
Now if you know of a language that has great macro implementation, i'd like to see it. Quote:
Quote:
Quote:
Quote:
Quote:
Quote:
It is not shitty code. But as soon as compiler fails, compiler defenders have to find an excuse. Quote:
If you meant ret instead of val, it is more efficient this way. Avoiding that write would have meant extra branching. Quote:
It is handled. Even Karlos could see this. |
||||||||||||||||||
09 October 2023, 11:03 | #1509 |
Alien Bleed
Join Date: Aug 2022
Location: UK
Posts: 4,165
|
|
09 October 2023, 11:45 | #1510 | |||||||
Registered User
Join Date: May 2023
Location: Norwich
Posts: 378
|
Quote:
Quote:
Asm is not immune to memory leaks, just as C is not immune to crashes, even though it may be more prone to crashed. Arguably, from an end user perspective, a crash is a far worse situation though since it almost inevitably means lost data. Quote:
Quote:
Modern languages just let you express what you want using the language syntax and then handle things like inlining or specialisation via the compiler. Quote:
Quote:
Quote:
|
|||||||
09 October 2023, 12:00 | #1511 |
Alien Bleed
Join Date: Aug 2022
Location: UK
Posts: 4,165
|
The code as written, absolutely stinks. So, you do what any C programmer would do and refactor it:
From this: Code:
if (val) { ret = something; } if (val <= 0) { ret = something_else; /* overwritten */ } if (val < 0) { ret = again_something_else; /* overwritten again */ } Code:
if (val < 0) { ret = again_something_else; } else if (val == 0) { ret = something_else; } else { ret = something; } Putting those into a simple function (Stack parameters, return in d0), you get: Code:
lea (4,sp),a0 move.l (a0)+,d1 move.l (a0)+,d0 move.l (a0)+,a1 move.l (a0),a0 tst.l d1 blt .L3 beq .L4 rts .L4: move.l a1,d0 rts .L3: move.l a0,d0 rts |
09 October 2023, 12:13 | #1512 | ||||||||||
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Quote:
Quote:
And even though higher level languages aim to reduce cognitive load, they don't actually reach the target. Quote:
Quote:
Quote:
Besides, the "two syntax" does not apply for asm. Quote:
Quote:
Quote:
Quote:
One day you will eventually know better than trusting compilers. Quote:
Again the code here has been simplified to the minimalistic way of reproducing the behaviour. I have explained this before. Both if (val) and if (val<=0) also compute something that is used as input in case if (val<0). |
||||||||||
09 October 2023, 13:35 | #1513 | ||||||||
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,233
|
Quote:
Quote:
Quote:
No, nonsense. You have scratches whatever the compiler makes scratches. Within a function, any decent compiler will allocate registers dynamically, even changing from line to line or functional block to block. Everything else is a "calling convention" that it follows - simply because its interfaces are also meant to be used from other languages. It is not the compiler that defines this interface, it is the ABI that does. That is, it is the AmigaOs ABI. Other systems used other ABIs. For example MacOs has "a5" as the "pointer to quickdraw globals", same as AmigaOs has "a6" as library basis. Quote:
Quote:
If a function has external linkage, it cannot do of course because it must assume that the function is to be called from some other places without having this "register allocation" available. Thus, "if it matters, make your function static" and let the compiler do the magic for you. Quote:
Quote:
Quote:
Morale of the story: Premature optimization is the root of all evil. It was a bullshit optimization from Motorola in first place, it was unnecessary, and if they had followed good programming practise *not* to use the ccr to store side-information, the thing would have been portable to begin with. |
||||||||
09 October 2023, 13:48 | #1514 |
Alien Bleed
Join Date: Aug 2022
Location: UK
Posts: 4,165
|
In what sense?
Code:
#include <stdio.h> int testA(int val, int something, int something_else, int again_something_else) { int ret; if (val) { ret = something; } if (val <= 0) { ret = something_else; } if (val < 0) { ret = again_something_else; } return ret; } int testB(int val, int something, int something_else, int again_something_else) { int ret; if (val < 0) { ret = again_something_else; } else if (val == 0) { ret = something_else; } else { ret = something; } return ret; } int main(void) { for (int i = -1; i<2; ++i) { if (testA(i, 2, 3, 5) != testB(i, 2, 3, 5)) { printf("Failed for %d\n", i); } else { printf("Passed for %d\n", i); } } return 0; } Code:
Passed for -1 Passed for 0 Passed for 1 |
09 October 2023, 14:26 | #1515 |
Registered User
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 1,153
|
|
09 October 2023, 14:50 | #1516 |
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
|
09 October 2023, 15:19 | #1517 | ||||||||||
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Quote:
Quote:
Quote:
By using that convention, the intent (use a register if possible) is clear. Quote:
Asm programmers can use whatever they want, on the contrary. Quote:
Giving names to objects is done by humans and error prone too. Quote:
I haven't said these functions were small enough to be candidates for inlining. Usually they are not. Oh, and in asm too you can choose between inlining or not, by using macros and/or conditional assembly. No magic either. ... with the small exception that the assembler is required to respect what you want to assemble, where the compiler is perfectly allowed to not inline the code even if you asked for it (it's just a hint, not a requirement). Quote:
Quote:
I already said it, doing this otherwise would have led to code duplication. Quote:
Quote:
|
||||||||||
09 October 2023, 16:18 | #1518 | |
Registered User
Join Date: May 2023
Location: Norwich
Posts: 378
|
Quote:
Um, ASM code is supposed to follow the platform ABI too, otherwise if the OS has to get involved at some point (e.g. stack unwinding) you have no guarantees that things will work correctly. It's not a C thing, it's an AmigaOS thing. If a C program wanted to shove the OS entirely out of the way, it could happily use whatever conventions it likes. |
|
09 October 2023, 16:47 | #1519 | |||
son of 68k
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
|
Quote:
The compiler didn't warn that the code looked strange, it said that some variables weren't initialized in all code paths - which is just plain wrong. To see this, use VS2022. Quote:
To port code from a 68k platform to another, everything platform specific (HW, OS calls) has to be replaced. The platform ABI is of absolutely no relevance ; if new code trashes more registers, just save them around the call. And, stack unwinding made by the OS ? Serious ? Quote:
I've seen compiled code using D0-D3/A0-A1 as scratch on an OS itself using D0-D2/A0-A2. |
|||
09 October 2023, 17:16 | #1520 | |
Alien Bleed
Join Date: Aug 2022
Location: UK
Posts: 4,165
|
Quote:
Code:
if (val) { ret = something; val = side_effect1(val); } if (val <= 0) { ret = something_else; val = side_effect2(val); } if (val < 0) { ret = again_something_else; } |
|
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 |
|
|