Thread 105723937 - /g/ [Archived: 729 hours ago]

Anonymous
6/27/2025, 6:40:01 PM No.105723937
1750028371584774
1750028371584774
md5: 8c3d090859ceddcf477d94ba7fbd3e7b🔍
If optimizing compilers are so good, why are there no optimizing assemblers?
Replies: >>105724805 >>105725824 >>105726650
Anonymous
6/27/2025, 7:30:19 PM No.105724552
An optimizing compiler IS an optimizing assembler. C is converted to assembly, which is then optimized.
Or are you talking about a hyperoptimizer? Those already exist as well.
Replies: >>105724795 >>105726591 >>105727251
Anonymous
6/27/2025, 7:47:49 PM No.105724795
>>105724552
>An optimizing compiler IS an optimizing assembler.
No it is not.
>C is converted to assembly
No, it's converted to an IR, which is then converted to machine code. It never touches an assembly language.
Assembly isn't the same thing as machine code, you know. You only make the mistake because there are no transformations applied to an assembly language other than choosing the shortest encoding for an instruction. It's not even a real 1:1 mapping because of that.

Why doesn't nasm rewrite my subroutines, erase unused code paths and stores, perform tail-call optimization, optimize my register usage, etc.?
gcc can track things like unaliased pointers and perform code transformations that erases huge chunks of code and makes it go faster. Why can't assemblers do that?
Replies: >>105725254 >>105726426 >>105726561
Anonymous
6/27/2025, 7:48:48 PM No.105724805
>>105723937 (OP)
the CPU is an optimizing assembler
Replies: >>105724862
Anonymous
6/27/2025, 7:53:02 PM No.105724862
>>105724805
How do I write assembly code to help the CPU's optimizer as much as possible?
Replies: >>105724915
Anonymous
6/27/2025, 7:57:17 PM No.105724915
>>105724862
https://www.agner.org/optimize
check out 2, 3, 4
Replies: >>105725283
Anonymous
6/27/2025, 8:29:39 PM No.105725254
>>105724795
>>C is converted to assembly
>No, it's converted to an IR, which is then converted to machine code. It never touches an assembly language.
It is definitely converted into assembly. Are you an AI? You say things that are blatantly wrong yet are confident about it.

>Why doesn't nasm rewrite my subroutines, erase unused code paths and stores, perform tail-call optimization, optimize my register usage, etc.?
Because it is an assembler and not a hyperoptimizer. If you want to optimize parts of your code, use a hyperoptimizer. Or if you want to optimize ALL of your code, then don't write assembly at all but C or Rust.
Replies: >>105726456 >>105727251
Anonymous
6/27/2025, 8:32:39 PM No.105725283
>>105724915
Interesting. What if i want it to be portable across multiple generations of cpu?
Replies: >>105725406 >>105728845
Anonymous
6/27/2025, 8:44:03 PM No.105725406
>>105725283
general principles like avoiding unnecessary branching and (non-linear) memory access will continue to apply for the foreseeable future
Anonymous
6/27/2025, 9:20:40 PM No.105725824
>>105723937 (OP)
assembly is a direct representation of the cpus instructions, hence there is nothing to optimize, you are telling the cpu exactly what to do.
Replies: >>105726436
Anonymous
6/27/2025, 10:15:39 PM No.105726426
>>105724795
gnu as was literally invented for gcc compilation of c. There was one compiler that uses to directly compile to.machine code (vcc?) but all the others do asm.first and rely on a separate assembler.
Anonymous
6/27/2025, 10:16:49 PM No.105726436
>>105725824
not even remotely
Replies: >>105726539
Anonymous
6/27/2025, 10:18:43 PM No.105726456
>>105725254
>Or if you want to optimize ALL of your code, then don't write assembly at all but C or Rust.
Unless you're actually serious about it, when you write assembly anyway.
An old boss of mine used to be that serious, and was very good at it. I never bother, as I prefer to make my code more robust.
Replies: >>105726496
Anonymous
6/27/2025, 10:22:16 PM No.105726496
>>105726456
frankly I've always had an easier time writing and debugging x86_64 assembly code compared to C in terms of robustness. It's also just as portable as C in most real life cases since only x86_64 matters (or mattered thanks macos) but that argument has more validity in my mind.
Anonymous
6/27/2025, 10:28:00 PM No.105726539
>>105726436
yes it is, it generally maps 1:1 with each instruction the cpu has.
Replies: >>105726565
Anonymous
6/27/2025, 10:30:11 PM No.105726561
>>105724795
We’ve had peephole optimizers since 1970s and GCC has some flag for it too https://en.wikipedia.org/wiki/Peephole_optimization
But more complex optimizations don’t make any sense for asm. If you’re hand writing assembly then you must want to have precise control over the generated machine code, else why do it? It’s really only useful for cases like crypto (preventing timing attacks) weird high perf edge cases (ffmpeg) kernel bootstrap (just a few instructions that do some set up then jump to the rest of your code written in C) and finally educational purposes. Not one of these cases benefits from optimizations, in fact that’s precisely what we want to avoid, that’s why we’re writing asm in the first place.
Anonymous
6/27/2025, 10:30:51 PM No.105726565
>>105726539
You are a 0 IQ cretin
Replies: >>105726617
Anonymous
6/27/2025, 10:34:54 PM No.105726591
>>105724552
>An optimizing compiler IS an optimizing assembler. C is converted to assembly, which is then optimized.
You don't need C to have a compiler. There are compilers for Lisp, Pascal, Fortran, COBOL, BASIC, Haskell, ML, and a lot of other languages. Also it is not an optimizing assembler because it doesn't optimize assembly that you write, it optimizes the high-level language. Compilers do not always produce assembly either, a lot of them create the machine code directly as binary.
Anonymous
6/27/2025, 10:37:34 PM No.105726617
>>105726565
then you must be a -50 iq mongoloid
Replies: >>105726632
Anonymous
6/27/2025, 10:39:13 PM No.105726632
>>105726617
I accept your surrender. Next time, use google before embarassing yourself.
Replies: >>105726675
Anonymous
6/27/2025, 10:40:39 PM No.105726650
>>105723937 (OP)
>why are there no optimizing assemblers
with assembly you control what instructions are used and the sequence of instructions, so how exactly is an assembler supposed to optimize without rewriting your code?
Anonymous
6/27/2025, 10:42:29 PM No.105726675
>>105726632
you didn't say a single thing to support your argument.

and if you are somekind of mega tard thinking that the cpu having a OoE and a decoder makes this untrue, then please commit sudoku.
Replies: >>105726937
Anonymous
6/27/2025, 11:11:22 PM No.105726937
>>105726675
>you didn't say a single thing to support that 1+1=2
Meds, now.
Anonymous
6/27/2025, 11:50:02 PM No.105727251
>>105724552
>>105725254
Umm ackshually, nitpick, it’s a superoptimizer not a “hyperoptimizer,” there’s no such thing as the latter.
Anonymous
6/28/2025, 12:13:46 AM No.105727446
compiled languages have constraints and the compiler can optimize within those constraints, an assembler has no idea wtf you're trying to do and that retarded sequence of instructions you gave it might be intentional for all it knows
Anonymous
6/28/2025, 2:36:46 AM No.105728643
there are, kind of
MIPS assemblers will reorder instructions to make use of the branch delay slot
some assemblers have pseudo instructions that expand into multiple normal instructions
x86 has multiple ways of encoding the same instruction and assemblers will pick generate the smallest encoding
Anonymous
6/28/2025, 2:58:41 AM No.105728845
>>105725283
>What if i want it to be portable across multiple generations of cpu?
Write it in C, dummy. Extremely simple C is a better assembly than assembly, because the compiler understands uop instruction scheduling and how to keep execution units busy much better than humans can.
Replies: >>105728908
Anonymous
6/28/2025, 3:06:18 AM No.105728908
>>105728845
C is the worst language you can pick and it's not a replacement for assembly at all, unless it's the kind of program you can write in any language.