Comment by fooker

Comment by fooker 2 days ago

8 replies

It's funny how machine code is a high level language nowadays, for this example the CPU recognizes the zeroing pattern and does something quite a bit different.

dheatov 2 days ago

It's really impressive how powerful and efficient it has become. However, I find it so much more difficult to build mental model of it. I've been struggling with atomic and r/w barrier as there are sooo many ways the instructions could've been executed (or not executed!).

  • fooker 2 days ago

    It's a consequence of keeping our general purpose single threaded programming model the same for five decades.

    It has it's merits, but the underlying hardware has changed.

    Intel tried to push this responsibility to the compiler with Itanium but that failed catastrophicically, so we're back to the CPU pretending it's 1985.

Reubensson 2 days ago

What do you mean that cpu does something different? Isnt cpu doing what is being asked, that being xor with consequence of zeroing when given two same values.

  • IsTom 2 days ago

    I think OP means that it has come a long way from the simple mental model of µops being a direct execution of operations and with all the register renamings and so on

  • dooglius 2 days ago

    FTA:

    > And, having done that it removes the operation from the execution queue - that is the xor takes zero execution cycles!1 It’s essentially optimised out by the CPU

  • 12_throw_away 2 days ago

    > with consequence of zeroing when given two same values

    Right, it has the same consequence, but it doesn't actually perform the stated operation. ASM is just a now just a high level language that tells the computer to "please give me the same state that a PDP-11-like computer would give me upon executing these instructions."

  • fooker 2 days ago

    Same consequence yes.

    But it will not execute xor, nor will it actually zero out eax in most cases.

    It'll do something similar to constant propagation with the information that whenever xor eax, eax occurs; all uses of eax go through a simpler execution path until eax is overwritten.

  • horsawlarway 2 days ago

    No.

    It's emulating the zero result when it recognizes this pattern, usually by playing clever tricks with virtual registers.