flat assembler
Message board for the users of flat assembler.
Index
> Main > online compiler assembly tricks for you |
Author |
|
sylware 17 Oct 2022, 11:42
https://godbolt.org/noscript
You don't have to deal with the HORRIBLE AND INSANE SDK of those compilers. |
|||
17 Oct 2022, 11:42 |
|
Furs 17 Oct 2022, 13:18
They added noscript page, cool.
|
|||
17 Oct 2022, 13:18 |
|
revolution 17 Oct 2022, 14:39
It works on my JS-free browser. That is good.
|
|||
17 Oct 2022, 14:39 |
|
sylware 17 Oct 2022, 15:01
revolution wrote: Any normal person wouldn't even make it a function. It is just a single instruction. That makes me think about memcpy and memset which are now, on x86_64, accelerated using "rep movsX" and "rep stosX", then which should not be into the libc but generated inline by compilers. |
|||
17 Oct 2022, 15:01 |
|
revolution 17 Oct 2022, 15:08
Are there still HLL coders out there claiming the compilers can produce the best possible code ever, and how humans can't possibly do any better?
Just show them these results. |
|||
17 Oct 2022, 15:08 |
|
DimonSoft 17 Oct 2022, 21:13
They’ll just say it’s a corner case. Religion and HLL-oriented propaganda are still things.
|
|||
17 Oct 2022, 21:13 |
|
Furs 18 Oct 2022, 13:24
revolution wrote: Haha, I tried to default "return num * num;" code for ARM gcc trunk, and got this monstrosity i.e. pass -Ofast (or more typically -O2, or -O3) on the command line. |
|||
18 Oct 2022, 13:24 |
|
revolution 18 Oct 2022, 13:31
Furs wrote: ... did you enable optimizations? Since this would be trivial for a compiler. |
|||
18 Oct 2022, 13:31 |
|
revolution 19 Oct 2022, 06:12
Using -O3, this is suboptimal
Input: Code: int square(int num) { return num ^ (num << num); } Code: square(int): lsl r3, r0, r0 eors r0, r0, r3 bx lr Code: eor r0, r0, r0, lsl r0 bx lr |
|||
19 Oct 2022, 06:12 |
|
Furs 19 Oct 2022, 13:12
Sounds like a typical issue when it doesn't recognize more complicated patterns. At the instruction level passes (RTL stages in GCC) compiler optimizers are usually just pattern matching.
There's a lot of optimization passes before that (GIMPLE stages in GCC) which deal with overall code optimizations, not specific to a target instruction set, like removing redundant code and simplifying stuff, of course. |
|||
19 Oct 2022, 13:12 |
|
revolution 19 Oct 2022, 13:31
It knows the instruction with a fixed shift:
Code: return num ^ (num << 1); Code: eor r0, r0, r0, lsl #1 bx lr |
|||
19 Oct 2022, 13:31 |
|
revolution 25 Oct 2022, 11:57
This is also suboptimal.
Code: int square(int num) { return (num << num) ^ 0xffffffff ; } Code: square(int): lsls r0, r0, r0 mvns r0, r0 bx lr Code: square(int): mvn r0, r0, lsl r0 bx lr This is why your "smart"phone needs recharging every 10 minutes. Bad code generation. |
|||
25 Oct 2022, 11:57 |
|
Furs 25 Oct 2022, 13:03
revolution wrote: This is why your "smart"phone needs recharging every 10 minutes. Bad code generation. |
|||
25 Oct 2022, 13:03 |
|
revolution 26 Oct 2022, 05:38
It appears that arm gcc by default starts in thumb mode. So some of the above code might be because those instructions are not available.
So now using options -marm -O3 we can see this; Code: int square(int num) { return num * num > 0 ? num * num + 1 : num * num - 1 ; } Code: square(int): mul r0, r0, r0 cmp r0, #0 addne r0, r0, #1 mvneq r0, #0 bx lr Code: muls r0, r0, r0 addne r0, r0, #1 mvneq r0, #0 bx lr |
|||
26 Oct 2022, 05:38 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.