Comment by veltas

Comment by veltas a day ago

7 replies

I'm not them but whenever I've used it it's been for arch specific features like adding a debug breakpoint, synchronization, using system registers, etc.

Never for performance. If I wanted to hand optimise code I'd be more likely to use SIMD intrinsics, play with C until the compiler does the right thing, or write the entire function in a separate asm file for better highlighting and easier handing of state at ABI boundary rather than mid-function like the carry flags mentioned above.

vlovich123 19 hours ago

Generally inline assembly is much easier these days as a) the compiler can see into it and make optimizations b) you don’t have to worry about calling conventions

  • Someone 18 hours ago

    > the compiler can see into it and make optimizations

    Those writing assembler typically/often think/know they can do better than the compiler. That means that isn’t necessarily a good thing.

    (Similarly, veltas comment above about “play with C until the compiler does the right thing” is brittle. You don’t even need to change compiler flags to make it suddenly not do the right thing anymore (on the other hand, when compiling for a different version of the CPU architecture, the compiler can fix things, too)

    • kragen 17 hours ago

      It's rare that I see compiler-generated assembly without obvious drawbacks in it. You don't have to be an expert to spot them. But frequently the compiler also finds improvements I wouldn't have thought of. We're in the centaur-chess moment of compilers.

      Generally playing with the C until the compiler does the right thing is slightly brittle in terms of performance but not in terms of functionality. Different compiler flags or a different architecture may give you worse performance, but the code will still work.

      • EdwardDiego 7 hours ago

        Centaur-chess?

        • Someone 6 hours ago

          https://en.wikipedia.org/wiki/Advanced_chess:

          “Advanced chess is a form of chess in which each human player uses a computer chess engine to explore the possible results of candidate moves. With this computer assistance, the human player controls and decides the game.

          Also called cyborg chess or centaur chess, advanced chess was introduced for the first time by grandmaster Garry Kasparov, with the aim of bringing together human and computer skills to achieve the following results:

          - increasing the level of play to heights never before seen in chess;

          - producing blunder-free games with the qualities and the beauty of both perfect tactical play and highly meaningful strategic plans;

          - offering the public an overview of the mental processes of strong human chess players and powerful chess computers, and the combination of their forces.”

    • vardump 14 hours ago

      Of course you can often beat the compiler, humans still vectorize code better. And that interpreter/emulator switch-statement issue I mentioned in the other comment. There are probably a lot of other small niches.

      In general case you're right. Modern compilers are beasts.

    • veltas 18 hours ago

      > “play with C until the compiler does the right thing” is brittle

      It's brittle depending on your methods. If you understand a little about optimizers and give the compiler the hints it needs to do the right things, then that should work with any modern compiler, and is more portable (and easier) than hand-optimizing in assembly straight away.