English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 09 October 2023, 17:34   #1521
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Quote:
Originally Posted by Karlos View Post
so something more like this then:

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;
    }
When your code ends up like this you may need to rethink what you are doing.
No. Variable val isn't altered.

It is more like :
Code:
int somecode (int val, int other_param) {
    int xx,yy,ret;
    if (val) {
        ret = xx = side_effect1(other_param);
    }
    if (val <= 0) {
        ret = yy = side_effect2(other_param);
    }
    if (val < 0) {
        ret = yy - xx;
    }
    return ret;
}
meynaf is offline  
Old 09 October 2023, 17:51   #1522
robinsonb5
Registered User
 
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 1,153
Quote:
Originally Posted by meynaf View Post
No. Variable val isn't altered.

It is more like :
Code:
int somecode (int val, int other_param) {
    int xx,yy,ret;
    if (val) {
        ret = xx = side_effect1(other_param);
    }
    if (val <= 0) {
        ret = yy = side_effect2(other_param);
    }
    if (val < 0) {
        ret = yy - xx;
    }
    return ret;
}

I trust xx and yy are initialised before the tests? Otherwise the compiler warning is correct.
robinsonb5 is offline  
Old 09 October 2023, 18:29   #1523
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Quote:
Originally Posted by robinsonb5 View Post
I trust xx and yy are initialised before the tests? Otherwise the compiler warning is correct.
The compiler warning is incorrect, even in case xx and yy are not initialised.
If you don't believe me, find a case where UMR occurs.
meynaf is offline  
Old 09 October 2023, 19:59   #1524
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,764
Quote:
Originally Posted by meynaf View Post
The compiler warning is incorrect
C# does this too, which is odd for clear cases like this.

This doesn't compile (it's not even a warning in C#, just an error):
Code:
int a;
int b = Environment.TickCount;

if (b == 0)
    a = 1;

if (b < 0)
    a = 2;

if (b > 0)
    a = 3;

Console.WriteLine(a);
While this is perfectly fine (no warnings):
Code:
int a;
int b = Environment.TickCount;

if (b == 0)
    a = 1;

else if (b < 0)
    a = 2;

else
    a = 3;

Console.WriteLine(a);
Thorham is offline  
Old 09 October 2023, 20:05   #1525
robinsonb5
Registered User
 
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 1,153
Quote:
Originally Posted by meynaf View Post
The compiler warning is incorrect, even in case xx and yy are not initialised.

OK yes, looking again I see there's no case where the third condition can execute without both the previous two having executed, so xx and yy are guaranteed to have a value by the time they're added.
robinsonb5 is offline  
Old 09 October 2023, 20:13   #1526
AestheticDebris
Registered User
 
Join Date: May 2023
Location: Norwich
Posts: 378
Quote:
Originally Posted by meynaf View Post
No, ASM code isn't required to follow the platform ABI. It only has to know that most OS calls are expected to trash D0-D1/A0-A1. Everywhere the OS isn't called (which is most of the code), the coder is free to do whatever he sees fit.
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 ?
Um, yes it is: https://devblogs.microsoft.com/oldne...8-00/?p=101088

Obviously that's a Windows centric article, but the principle remains the same regardless of OS. Even if you write assembly language, your program is supposed to remain within the constraints of the ABI. It won't necessarily fail if it doesn't, but you have wandered into the realm of "undefined behaviour" nonetheless.
AestheticDebris is offline  
Old 09 October 2023, 20:17   #1527
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,764
Quote:
Originally Posted by AestheticDebris View Post
Even if you write assembly language, your program is supposed to remain within the constraints of the ABI.
You can still use d0-d1/a0-a1 for whatever you want outside of function calls.
Thorham is offline  
Old 09 October 2023, 20:39   #1528
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Quote:
Originally Posted by Thorham View Post
This doesn't compile (it's not even a warning in C#, just an error):
What does the error message say ?



Quote:
Originally Posted by robinsonb5 View Post
OK yes, looking again I see there's no case where the third condition can execute without both the previous two having executed, so xx and yy are guaranteed to have a value by the time they're added.
This is what the compiler misses. It also misses that the return value is set in all possible cases.



Quote:
Originally Posted by AestheticDebris View Post
Um, yes it is: https://devblogs.microsoft.com/oldne...8-00/?p=101088

Obviously that's a Windows centric article, but the principle remains the same regardless of OS. Even if you write assembly language, your program is supposed to remain within the constraints of the ABI. It won't necessarily fail if it doesn't, but you have wandered into the realm of "undefined behaviour" nonetheless.
No. Definitely not. In no possible case will this ever apply to current AmigaOS.

Actually that guy in the blog is probably just plain wrong even in the case of Windows. He is apparently confusing the language - which may do stack unwinding - with the operating system.
I'm not Windows internals specialist, but nevertheless...
Frankly, just compile a C program : there are no exceptions there, no stack unwinding of any sort. In C++ compiler settings you can even disable exceptions, to remove said stack unwinding.

And i can tell you for a fact that at least AmigaOS does not give a shit about what you put in your program's stack.

Anyway this is completely off. That D0-D1/A0-A1 are not scratch in some parts of an asm program, is totally different of what's in the stack.
The ABI only says what registers are supposed to be altered in case of an OS call, and this does not even apply to all OS functions.
meynaf is offline  
Old 09 October 2023, 21:45   #1529
Thorham
Computer Nerd
 
Thorham's Avatar
 
Join Date: Sep 2007
Location: Rotterdam/Netherlands
Age: 47
Posts: 3,764
Quote:
Originally Posted by meynaf View Post
What does the error message say ?
Use of unassigned local variable 'a'
Thorham is offline  
Old 09 October 2023, 21:48   #1530
Karlos
Alien Bleed
 
Karlos's Avatar
 
Join Date: Aug 2022
Location: UK
Posts: 4,165
The best compiler warning I ever saw came out of vbcc when compiling a Duff's Device example. It said, and I quote "This code is weird."
Karlos is offline  
Old 09 October 2023, 22:09   #1531
robinsonb5
Registered User
 
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 1,153
Quote:
Originally Posted by Karlos View Post
The best compiler warning I ever saw came out of vbcc when compiling a Duff's Device example. It said, and I quote "This code is weird."
I think my favourite compiler message of all came from older versions of GCC: "class only defines a private destructor and has no friends."

Quote:
Originally Posted by Meynaf
Actually that guy in the blog is probably just plain wrong even in the case of Windows.
I'd be *very* surprised if a blog post from Raymond Chen is wrong.
robinsonb5 is offline  
Old 09 October 2023, 23:31   #1532
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Quote:
Originally Posted by robinsonb5 View Post
I'd be *very* surprised if a blog post from Raymond Chen is wrong.
I don't care who the post is from (argument from authority).
It looks quite stupid that the OS does stack unwinding in the place of the compiler. It might however still be true in the case of Windows (which is rather crazy OS) and it could be interesting to disassemble some code to see what it does with the stack ; however, one 100% complete sure thing is that AmigaOS does *not* do anything like that. Neither do Atari TOS or MacOS 68k.
meynaf is offline  
Old 09 October 2023, 23:51   #1533
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
Quote:
Originally Posted by meynaf View Post
No. Variable val isn't altered.

It is more like :
Code:
int somecode (int val, int other_param) {
    int xx,yy,ret;
    if (val) {
        ret = xx = side_effect1(other_param);
    }
    if (val <= 0) {
        ret = yy = side_effect2(other_param);
    }
    if (val < 0) {
        ret = yy - xx;
    }
    return ret;
}
clang, gcc do not give a warning. Neither m68k-amigaos-gcc.
All tried with -Wall -Wextra

How do you get a warning?
alkis is offline  
Old 10 October 2023, 00:16   #1534
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Quote:
Originally Posted by alkis View Post
clang, gcc do not give a warning. Neither m68k-amigaos-gcc.
All tried with -Wall -Wextra

How do you get a warning?
VS2022 with maximum warning level.
meynaf is offline  
Old 10 October 2023, 10:44   #1535
robinsonb5
Registered User
 
Join Date: Mar 2012
Location: Norfolk, UK
Posts: 1,153
Quote:
Originally Posted by meynaf View Post
I don't care who the post is from (argument from authority).
I agree that his expert status doesn't constitute proof that the post is correct - but nonetheless a blog post published on Microsoft's own website, and written by an expert with 30 years' experience of Windows internals is not likely to be fundamentally wrong in its entire premise; the bar for dismissal is rather higher than "that doesn't seem right - he's probably confused."

Quote:
however, one 100% complete sure thing is that AmigaOS does *not* do anything like that. Neither do Atari TOS or MacOS 68k.
Agreed - we don't have to worry about this on the Amiga.
robinsonb5 is offline  
Old 10 October 2023, 11:57   #1536
Karlos
Alien Bleed
 
Karlos's Avatar
 
Join Date: Aug 2022
Location: UK
Posts: 4,165
The "Argument from authority" card is best used when dealing with a viewpoint that is inscrutable in some way, e.g. the case for a religious edict for which the only basis is "because it says so".

It's less well applied in cases where the position you are arguing against can be tested or validated in some way. Using it to downplay someone's claim in this way amounts to saying "I know better than you and your expertise/experience in this area is irrelevant.". There's a reason someone is considered an expert in a given area. And while it's true that they can still be wrong, on the balance of probability it would be hubris to disregard their opinion for simply having that expertise.
Karlos is offline  
Old 10 October 2023, 12:12   #1537
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Quote:
Originally Posted by robinsonb5 View Post
I agree that his expert status doesn't constitute proof that the post is correct - but nonetheless a blog post published on Microsoft's own website, and written by an expert with 30 years' experience of Windows internals is not likely to be fundamentally wrong in its entire premise; the bar for dismissal is rather higher than "that doesn't seem right - he's probably confused."
Maybe, but having never seen this kind of affirmation anywhere else, along with the affirmation itself seeming illogical - and plain wrong in every system where this is easy to check (like on Amiga or similar platforms) -, this should at least raise some doubt. Is windows that different ?
If what he says is true, then the program isn't free of what it puts in the stack and even languages with no support for exceptions at all should do things for supporting the OS ones. Doesn't this sound plain crazy ?
I have few disassembly experience for windows, and the few i have traces back a few decades, but it did not suggest anything like that.
If the code omits the frame pointer, which i think is an option most compilers have, how can the OS possibly unwind the stack, knowing it could point to anything ?



Quote:
Originally Posted by Karlos View Post
The "Argument from authority" card is best used when dealing with a viewpoint that is inscrutable in some way, e.g. the case for a religious edict for which the only basis is "because it says so".

It's less well applied in cases where the position you are arguing against can be tested or validated in some way. Using it to downplay someone's claim in this way amounts to saying "I know better than you and your expertise/experience in this area is irrelevant.". There's a reason someone is considered an expert in a given area. And while it's true that they can still be wrong, on the balance of probability it would be hubris to disregard their opinion for simply having that expertise.
Your reasoning here is correct if the argument from authority is the only reason to dismiss the article - but it is not.
Search the web about stack unwinding : you will find many articles from many sources, but it is all about runtimes and specific languages, not operating systems.
I found nothing to back up this assertion. It has next to zero logic. It contradicts all personal experience i have. It is wrong for all platforms i know well.
But you're right at some point : yes it can be validated. So let's disassemble code and see what it does with the stack...
meynaf is offline  
Old 10 October 2023, 12:16   #1538
Karlos
Alien Bleed
 
Karlos's Avatar
 
Join Date: Aug 2022
Location: UK
Posts: 4,165
Quote:
Originally Posted by robinsonb5 View Post
I think my favourite compiler message of all came from older versions of GCC: "class only defines a private destructor and has no friends."
that's a good one. And yet it's entirely sensible in a way. A private destructor without any friends that can invoke it makes any instance of it it tricky to dispose of.
Karlos is offline  
Old 10 October 2023, 12:35   #1539
AestheticDebris
Registered User
 
Join Date: May 2023
Location: Norwich
Posts: 378
Quote:
Originally Posted by meynaf View Post
If what he says is true, then the program isn't free of what it puts in the stack and even languages with no support for exceptions at all should do things for supporting the OS ones. Doesn't this sound plain crazy ?
It's pretty much required for any OS that supports memory protection and virtual memory, because almost every instruction could theoretically generate an exception that the OS has to take care of and attempt to recover the process.

Quote:
Originally Posted by meynaf View Post
If the code omits the frame pointer, which i think is an option most compilers have, how can the OS possibly unwind the stack, knowing it could point to anything ?
The article is part of a series on how Windows supported the various CPUs it has run on over the years. I'd highly recommend those series to anyone with even a vague interest in assembly languages (and the blog in general to anyone who codes anything on Windows).

FWIW, on everything but 32-bit x86, unwind codes are used rather than frame pointers to unwind exceptions:

https://learn.microsoft.com/en-us/cp...?view=msvc-170
AestheticDebris is offline  
Old 10 October 2023, 13:12   #1540
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Quote:
Originally Posted by AestheticDebris View Post
It's pretty much required for any OS that supports memory protection and virtual memory, because almost every instruction could theoretically generate an exception that the OS has to take care of and attempt to recover the process.
Memory protection and virtual memory don't work this way, or at least they don't need to.
They don't have to care at all about what's in the stack.
When an instruction fails to access memory, be it due to real error or some paging, the only useful information is the instruction itself. It may then trigger an exception, or some page load from disk and a restart of said instruction.


Quote:
Originally Posted by AestheticDebris View Post
The article is part of a series on how Windows supported the various CPUs it has run on over the years. I'd highly recommend those series to anyone with even a vague interest in assembly languages (and the blog in general to anyone who codes anything on Windows).

FWIW, on everything but 32-bit x86, unwind codes are used rather than frame pointers to unwind exceptions:

https://learn.microsoft.com/en-us/cp...?view=msvc-170
That's very Windows specific.
Besides, they don't say what happens for programs who just don't want to catch any exception.

All this said, your original argument was for Amiga and we clearly see all we have here just does not apply there.
meynaf 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
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

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 09:29.

Top

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