Skip to content

Instantly share code, notes, and snippets.

@airglow923
Created July 22, 2021 05:46
Show Gist options
  • Save airglow923/3da14418966a28e89541e14485f0001b to your computer and use it in GitHub Desktop.
Save airglow923/3da14418966a28e89541e14485f0001b to your computer and use it in GitHub Desktop.
AMD64 instructions

I don't have a reliable tool to measure the time taken to execute one or more instructions.

This is just to keep track of the assembly output for different C expressions.

The assembly is in AT&T syntax, but the comments will be written in Intel syntax as GitHub Markdown does not support AT&T syntax.

Arithmetic

Multiplication

GCC with -O3 optimizes the following code

unsigned times10(unsigned n) {
  return n * 10;
}

into

  leal  (%rdi,%rdi,4), %eax
  addl  %eax, %eax

Total 2 instructions

Division

GCC with -O3 optimizes the following code

unsigned divides10(unsigned n) {
  return n / 10;
}

into

  movl  %edi, %eax
  movl  $3435973837, %edx
  imulq %rdx, %rax
  shrq  $35, %rax

This article will be updated from time to time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment