|
I have -o on. I can't seem to find how to change that at godbolt.org. I just remembered there's a GCC pragma where I can change it but I can't remember what it is, and so I'm googling now to figure out what it is.
Edit: Now I feel like an idiot. I thought -o did at least minimal optimizations but maybe the switch means something different unsuffixed.
#pragma GCC optimize("Os")
That reflects the default of my IoT build environment
It fixes it, so maybe I'm worrying over nothing. I wish I could actually check my production code, but it relies on the Arduino framework, and I can't run that at godbolt. I've tried disassembler extensions in VSCode but none work with platformIO because it makes its own CMake/ninja scripts for everything on the fly.
To err is human. Fortune favors the monsters.
|
|
|
|
|
honey the codewitch wrote: #pragma GCC optimize("Os")
It fixes it Awesome, I'm glad it's sorted out! Congratulations.
Don't rely on the optimization pass. The C++ standards are correct. It's just that the optimization pass can rearrange code, remove functions and/or use intrinsics instead.
The unoptimized code would be more standards compliant. 
|
|
|
|
|
In general you're right, but in this case, there are special considerations.
For starters, the toolchain is fixed to GCC, and other compilers simply don't have the backends to target what I target. So I have the luxury of using GCC specific things, and expecting GCC specific behavior, but I'm also saddled with GNU C++ vs STD C++ because the frameworks my code runs under require it, despite my code being (more) standard than GNU.
That being said, I am counting on those optimizations because this is IoT, and this is critical code paths. That's why I'm looking at the asm output in the first place.
To err is human. Fortune favors the monsters.
|
|
|
|
|
honey the codewitch wrote: I wish I could actually check my production code, but it relies on the Arduino framework, and I can't run that at godbolt. I've tried disassembler extensions in VSCode but none work with platformIO because it makes its own CMake/ninja scripts for everything on the fly. If you are comfortable looking at assembler then you could analyze your Arduino code with Ghidra.
|
|
|
|
|
Ooooh, you just made my morning. I was just looking for something like that and gave up at the time. Thanks.
Edit: NVM it wasn't what I was thinking. I might be able to use it on my firmware.bin but I'm not sure how I would match the symbols back up to the source without it being aware of my build environment so it could load the symbols for each library's C or C++ source translation unit.
To err is human. Fortune favors the monsters.
|
|
|
|
|
Sorry,
I was wrong, about N2975. It passed back in July with 17 Yes, 0 No and two abstains. I updated my post.
|
|
|
|
|
honey the codewitch wrote: But why is it only promoting it in one case?
Perhaps because 65 is already an int? Try this with printf("%c\n", 'A') and see what happens.
(Yes, a clever enough compiler could optimize the first assembly-language sequence to mov esi,65. Obviously, optimizers still have a way to go...)
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows.
-- 6079 Smith W.
|
|
|
|
|
Same result. *scratches head*
To err is human. Fortune favors the monsters.
|
|
|
|
|
So the char must be sign-extended. But that does not, and cannot (due to the as-if rule), mean that the compiler must make that happen at run time, it can trivially be done at compile time after all.
|
|
|
|
|
Hmmm,
I'm not really sure what you're saying here. You are obviously referring to the code optimization pass. But this sentence doesn't make sense.
harold aptroot wrote: But that does not, and cannot, mean that the compiler must make that happen at run time Nearly every compiler will perform the sign-extending at run time with optimization disabled, I just tested 4 MSVC versions few hours ago with the code at the top of this thread.
Sure, it can be trivially optimized away.
|
|
|
|
|
I decided against any further elaboration
|
|
|
|
|
harold aptroot wrote: I decided against any further elaboration Because there isn't anything to elaborate.
It's OK, we all make mistakes. I was waiting to see what you had to say though.
|
|
|
|
|
My mistake was talking to you at all. Don't worry, that won't happen again.
|
|
|
|
|
I have no idea what's happening here, I apologize if I've offended you. It wasn't intentional.
Are you OK?
|
|
|
|
|
Disclaimer: I have never used templates and rarely use C++, so this is just an observation...
It looks like there is something swish about the use of pin and Pin - it might be worth accessing Pin as pin in the test() method? or something like that.
Good luck!
|
|
|
|
|
Try consteval , rather than constexpr , for test()
PS: Stack Overflow is a good place for questions like this.
Paul Sanders.
If I had more time, I would have written a shorter letter - Blaise Pascal.
Some of my best work is in the undo buffer.
|
|
|
|
|
I can't use consteval because I can't target C++20
To err is human. Fortune favors the monsters.
|
|
|
|
|
Wordle 456 3/6
🟩⬛⬛🟨⬛
🟩🟩⬛⬛⬛
🟩🟩🟩🟩🟩
|
|
|
|
|
Wordle 456 3/6
⬜⬜🟩⬜⬜
🟩🟩🟩⬜⬜
🟩🟩🟩🟩🟩
|
|
|
|
|
Wordle 456 3/6
⬛⬛⬛🟨⬛
🟩⬛⬛🟨🟨
🟩🟩🟩🟩🟩
|
|
|
|
|
Wordle 456 3/6
🟨⬛⬛⬛⬛
🟩⬛⬛🟩🟩
🟩🟩🟩🟩🟩
|
|
|
|
|
Wordle 456 4/6
⬜⬜⬜🟨⬜
⬜🟨⬜🟨🟨
🟩🟩🟩⬜⬜
🟩🟩🟩🟩🟩
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
modified 18-Sep-22 3:51am.
|
|
|
|
|
I think you are cross threaded
Life should not be a journey to the grave with the intention of arriving safely in a pretty and well-preserved body, but rather to skid in broadside in a cloud of smoke, thoroughly used up, totally worn out, and loudly proclaiming “Wow! What a Ride!" - Hunter S Thompson - RIP
|
|
|
|
|
Dunno what happened there: I original posted this in the wrong place, but noticed, copied it, deleted it, and pasted in the right place.
Then I did Wordle, and thought I posted it's result ... maybe I got confused by a lack of caffeine / 5am start ...
Fixed now.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
"Common sense is so rare these days, it should be classified as a super power" - Random T-shirt
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Wordle 456 4/6
⬜⬜⬜🟨⬜
🟨⬜⬜⬜⬜
⬜🟨🟨🟩⬜
🟩🟩🟩🟩🟩
"A little time, a little trouble, your better day"
Badfinger
|
|
|
|