English Amiga Board


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

 
 
Thread Tools
Old 20 September 2023, 19:16   #21
Karlos
Alien Bleed
 
Karlos's Avatar
 
Join Date: Aug 2022
Location: UK
Posts: 4,165
I like constexpr. It's nice being able to write something quite expressive, knowing it's going to cost compile time only.
Karlos is offline  
Old 20 September 2023, 19:30   #22
Jobbo
Registered User
 
Jobbo's Avatar
 
Join Date: Jun 2020
Location: Druidia
Posts: 389
I like it too, but unfortunately that doesn't seem to be what constexpr does every time.
Seems it’s only a suggestion that the compiler might ignore at any point.

Last edited by Jobbo; 20 September 2023 at 19:39. Reason: was being a bit too grumpy
Jobbo is offline  
Old 20 September 2023, 19:43   #23
Karlos
Alien Bleed
 
Karlos's Avatar
 
Join Date: Aug 2022
Location: UK
Posts: 4,165
Quote:
Originally Posted by Jobbo View Post
I like it too, but unfortunately that doesn't seem to be what constexpr does every time.
Seems it’s only a suggestion that the compiler might ignore at any point.
It's allowed to. It can't anticipate certain side effects, so depending on what your constexpr qualified function does and how it's invoked, it may emit code or not. In the long running thread regarding C v asm, I posted a silly example of a compile time prime number generator. It compiles to a lookup table (and did, for 68K). It might amuse you.

https://eab.abime.net/showpost.php?p...&postcount=550

Last edited by Karlos; 20 September 2023 at 19:49.
Karlos is offline  
Old 22 September 2023, 10:52   #24
FSizzle
Registered User
 
Join Date: Nov 2017
Location: Los Angeles
Posts: 49
constexpr is unfortunately flawed, making it not that useful imo (since you can't "trust" it). C++20 adds constinit and consteval which are probably what constexpr should have been, with far stronger compile-time guarantees.
FSizzle is offline  
Old 22 September 2023, 11:03   #25
Karlos
Alien Bleed
 
Karlos's Avatar
 
Join Date: Aug 2022
Location: UK
Posts: 4,165
Quote:
Originally Posted by FSizzle View Post
constexpr is unfortunately flawed, making it not that useful imo (since you can't "trust" it). C++20 adds constinit and consteval which are probably what constexpr should have been, with far stronger compile-time guarantees.
Trust it how? It's a hint, not a demand.
Karlos is offline  
Old 22 September 2023, 11:57   #26
FSizzle
Registered User
 
Join Date: Nov 2017
Location: Los Angeles
Posts: 49
Quote:
Originally Posted by Karlos View Post
Trust it how? It's a hint, not a demand.

I mean if you require compile time evaluation, you cannot "trust" that constexpr will give you what you want, because it is only a hint as you say.
FSizzle is offline  
Old 22 September 2023, 14:13   #27
Karlos
Alien Bleed
 
Karlos's Avatar
 
Join Date: Aug 2022
Location: UK
Posts: 4,165
Quote:
Originally Posted by FSizzle View Post
I mean if you require compile time evaluation, you cannot "trust" that constexpr will give you what you want, because it is only a hint as you say.
Sure. That said, I've yet to see it fail to produce a compile time evaluated result when the requirements for it are met. As soon as you add things that may have side effects, all bets are off.

Personally I tend to use it for simple decision making with "if conxtexpr" based on things like compile time type evaluation, as a way of reducing dependencies on various macros. An example would be the machine register definition in MC64K, which is just a union of supported word sizes (and pointers to them_:

https://github.com/IntuitionAmiga/MC...e/register.hpp

This allows the register to be accessed as a template, from other templated code at compile, always ensuring the correct element of the union is accessed. This comes in handy for other functions that are templated out, like vector operations

https://github.com/IntuitionAmiga/MC.../vec3.hpp#L117
https://github.com/IntuitionAmiga/MC.../vec3.hpp#L154

When these are eventually invoked for a scalar type, everything compile time evaluates to just accessing the union member in the expected way.

Last edited by Karlos; 22 September 2023 at 14:19.
Karlos is offline  
Old 22 September 2023, 21:13   #28
Photon
Moderator
 
Photon's Avatar
 
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,604
Tell everyone I'm back! - there are 100 ribbons on the old oak tree.

As for the C etc whatever: It really is lovely to hardware code in Assembly. The only reason for not running is because you mistyped an include filename, or misspelled a CPU instruction or symbol name, and the only reason for a program crash is again, only because of a mistake that you made. An oasis in a world gone crazy.

Not the accumulated tries and fails with any and all excuses to fail to compile or do so and crash, while all the time the code remains unchanged. Mostly only C/C++ and other "still in beta" languages suffer from this. AMOS, Basics etc were finished and provide a platform to target.
Photon is offline  
Old 22 September 2023, 21:58   #29
Jobbo
Registered User
 
Jobbo's Avatar
 
Join Date: Jun 2020
Location: Druidia
Posts: 389
Photon, that definitely all true!!!

On Amiga I use C for my own productivity given the limited time I have and the sorts of things I'd like to make.

But absolutely it'll bite you hard at times. This is normally because the optimizer is bending the rules in ways that aren't obvious.

For example, I had to add memory barriers in one instance because it would reorder things before/after when I enable interrupts. That can be very bad!
Jobbo is offline  
Old 23 September 2023, 09:56   #30
hop
Registered User
 
Join Date: Apr 2019
Location: UK
Posts: 172
My bucket list includes writing an Amiga game in ASM, so I hope this forum is monitored by some old hands for a few more years because I'm bound to get stuck. I made a good start a year or so ago, but got sidetracked writing a mod to p61 converter in (minimal) C++ so it could form part of the toolchain.
hop is offline  
Old 23 September 2023, 10:57   #31
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,233
Quote:
Originally Posted by Photon View Post
Not the accumulated tries and fails with any and all excuses to fail to compile or do so and crash, while all the time the code remains unchanged. Mostly only C/C++ and other "still in beta" languages suffer from this. AMOS, Basics etc were finished and provide a platform to target.
Unlike AMOS, C and C++ are looked at by an ISO commitee, and thus they only change when there is a consensus between experts to make a change. C90 is particularly stable - it hasn't been changed since >30 years since now, so calling it "beta" is really nonsense. You probably do not understand it well enough then.


Note, again, that I'm not saying that "C is the perfect language". It certainly is not, it has a couple of odditities you must be aware of, but it is a much better choice for many problems than assembler. But what is the right choice depends of course on the problem you want to solve. There is also AREXX and shell script on the Amiga, and certainly AMOS has also its merits even though I have personally not used it.



I personally use whatever is appropriate to solve a problem. That includes also java, C++, python (we do a lot in python recently), bash, it was also C# (even though it has "Micrsoft" written all over it) or whatever else it takes. It is like with human languages. Learn a language, learn a culture. The more you master, the better...
Thomas Richter is offline  
Old 23 September 2023, 11:12   #32
Karlos
Alien Bleed
 
Karlos's Avatar
 
Join Date: Aug 2022
Location: UK
Posts: 4,165
Quote:
Originally Posted by Thomas Richter View Post
I personally use whatever is appropriate to solve a problem. That includes also java, C++, python (we do a lot in python recently), bash, it was also C# (even though it has "Micrsoft" written all over it) or whatever else it takes. It is like with human languages. Learn a language, learn a culture. The more you master, the better...
OMG you left out Rust! Rust is the only language that saves the developer from the horrors of memory, concurrency and the hideous dangers of variables that, you know, vary. Or at least that's what the indoctrination session... I mean introduction lesson said
Karlos is offline  
Old 23 September 2023, 11:28   #33
meynaf
son of 68k
 
meynaf's Avatar
 
Join Date: Nov 2007
Location: Lyon / France
Age: 51
Posts: 5,323
Quote:
Originally Posted by Thomas Richter View Post
Learn a language, learn a culture.
Except one that is the "wrong tool", huh ?
meynaf is offline  
Old 23 September 2023, 12:06   #34
Karlos
Alien Bleed
 
Karlos's Avatar
 
Join Date: Aug 2022
Location: UK
Posts: 4,165
Quote:
Originally Posted by meynaf View Post
Except one that is the "wrong tool", huh ?
I think the argument is that there are better tools depending on the task. You can carve wood with just a knife, but chisels, saws, planes and sanders all exist for good reasons.
Karlos is offline  
Old 23 September 2023, 12:28   #35
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
I think the argument is that there are better tools depending on the task. You can carve wood with just a knife, but chisels, saws, planes and sanders all exist for good reasons.
I don't think the comparison works. As chisels, saws, planes and sanders are not internally converted by some process to knives.
meynaf is offline  
Old 23 September 2023, 12:48   #36
Karlos
Alien Bleed
 
Karlos's Avatar
 
Join Date: Aug 2022
Location: UK
Posts: 4,165
Quote:
Originally Posted by meynaf View Post
I don't think the comparison works. As chisels, saws, planes and sanders are not internally converted by some process to knives.
Assembler is the knife here. Compilers haven't generally depended on producing assembly language for a separate assembler stage for decades. So no. Your woodworking tools don't need to be turned into knives. That's a throwback to say the least.

Compilers that retain the ability to produce assembly language today primarily do so that it can be inspected, debugged etc. Depending on the language and tooling you are using there may not even be any option to even generate assembly code. If you want to see it, you'd need to disassemble it.

In some cases trying to generate the assembly per source is counter productive or outright misleading because you may want to use whole-program/link-time optimisations where all of the notionally separate code from each source unit goes through a final round of optimisation that makes changes that are simply not representable in the assembly output of a single source unit.
Karlos is offline  
Old 23 September 2023, 12:57   #37
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
Assembler is the knife here. Compilers haven't generally depended on producing assembly language for a separate assembler stage for decades. So no. Your woodworking tools don't need to be turned into knives. That's a throwback to say the least.

Compilers that retain the ability to produce assembly language today primarily do so that it can be inspected, debugged etc. Depending on the language and tooling you are using there may not even be any option to even generate assembly code. If you want to see it, you'd need to disassemble it.

In some cases trying to generate the assembly per source is counter productive or outright misleading because you may want to use whole-program/link-time optimisations where all of the notionally separate code from each source unit goes through a final round of optimisation that makes changes that are simply not representable in the assembly output of a single source unit.
Come on, ML and ASM are basically the same thing.
And even if you don't admit this evidence, all these tools still need to be converted to some unique tool at one stage or another, and this is machine language.
And cpus take 100% of their time executing ML and absolutely nothing else.
So no, your tool comparison does not work.
meynaf is offline  
Old 23 September 2023, 13:12   #38
Karlos
Alien Bleed
 
Karlos's Avatar
 
Join Date: Aug 2022
Location: UK
Posts: 4,165
Quote:
Come on, ML and ASM are basically the same thing
Are they though? Assemblers are allowed to make optimisations too. I think Bruce was fighting with the results of that, at some point. If you are doing some exact cycle counting or code size work (which is more likely if you are using it in the first place) the assembler changing an instruction for another with the same overall side effects isn't particularly desirable

Then you have macro expansions and other things that insert code you didn't explicitly write.

So while assembler is as close as you'll get to the object code in a human readable format, it's not identical, unless you explicitly disable any optimisation passes, never use any macos, always specify the exact, specific mnemonic for the operation at all times, etc. and don't rely on any "generic" variants like add (always using add, adda, addi, etc).
Karlos is offline  
Old 23 September 2023, 13:31   #39
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
Are they though? Assemblers are allowed to make optimisations too. I think Bruce was fighting with the results of that, at some point. If you are doing some exact cycle counting or code size work (which is more likely if you are using it in the first place) the assembler changing an instruction for another with the same overall side effects isn't particularly desirable
Hopefully assemblers are allowed to make optimisations. This way we don't need to care about branch sizes anymore, what a relief.
But you can turn them off if you want to. You can even do that locally.


Quote:
Originally Posted by Karlos View Post
Then you have macro expansions and other things that insert code you didn't explicitly write.

So while assembler is as close as you'll get to the object code in a human readable format, it's not identical, unless you explicitly disable any optimisation passes, never use any macos, always specify the exact, specific mnemonic for the operation at all times, etc. and don't rely on any "generic" variants like add (always using add, adda, addi, etc).
That doesn't make your comparison more valid.
As you seem to have ignored my all these tools still need to be converted to some unique tool at one stage or another, and this is machine language...
Tools are distinct, with no conversion. Computer languages are all converted to ML in one way or another. This is very different.
meynaf is offline  
Old 23 September 2023, 14:45   #40
Thomas Richter
Registered User
 
Join Date: Jan 2019
Location: Germany
Posts: 3,233
Quote:
Originally Posted by meynaf View Post
Except one that is the "wrong tool", huh ?
Assembler? Yes, for almost everything it is the wrong tool. Not for everything. Low-level driver code that interfaces hardware is probably the only exception that comes to my mind. P96 drivers are (to some degree) in assembler. For example, higher level code, like GUIs, are not the domain of assembler. It's just more work, and no benefit at all.
Thomas Richter 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
Best settings to keep laptop cool and quiet? MartinW support.FS-UAE 11 20 July 2019 18:11
Quiet in 'ere... meltdown Nostalgia & memories 7 04 July 2019 12:51
Quiet/Low sound on A600 8bitbubsy support.Hardware 9 24 October 2009 10:00
quiet ambient mods Marcuz request.Modules 17 07 December 2008 11:38
wanting a quiet scsi HDD rare_j support.Hardware 8 27 October 2006 13:39

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

Top

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