Mehdi Akiki

Posts tagged "assembly"

  • Published on

    Investigation · Part 17 of 20 · When the benchmark lies

    Why Sorted Data Can Make the Same Loop Faster

    The famous result says that a loop over sorted data is faster because of branch prediction. In my Rust version, sorting changed nothing, because the compiler removed the branch. With a branch that it could not remove, random data was 3 to 10 times slower.
  • Published on

    Investigation · Part 15 of 20 · When the benchmark lies

    Does Code Alignment Change the Speed of the Same Code?

    I placed the same 11-instruction loop at all 64 positions of a cache line, two copies each, and measured them in shuffled order. At one position the loop was 16 to 21 percent slower, in three runs out of three. The same bytes, a different address, a different speed.
  • Published on

    Investigation · Part 11 of 20 · When the benchmark lies

    Measuring Something Faster Than the Clock

    Timed one call at a time, a small hash function and an empty loop both take 15 ns: the clock measures itself. With more calls per measurement, the same function costs 0.79 ns per call, or 3.02 ns when each call waits for the previous one.
  • Published on

    Investigation · Part 8 of 10 · Types under the hood

    The Processor Has No Types: What add Does to Bits It Does Not Understand

    I compiled the same operations for i32 and u32. Addition produced one shared function, comparison used the same compare instruction with a different flag, and division and shifting used different instructions. Where the sign lives in the machine code is not where most people expect.
  • Published on

    Investigation · Part 2 of 10 · Types under the hood

    Does a Type Exist at Runtime? Following One Value From Source to Register

    I followed one u8 through the four stages of the Rust compiler: HIR, MIR, LLVM IR, and assembly. The type is a word, then a field, then a width, then nothing. The u8 and u32 versions of the same function compile to the same two instructions, and the one check a type does produce is the debug overflow guard.