Skip to content

Instantly share code, notes, and snippets.

@filipinascimento
Last active March 23, 2019 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save filipinascimento/109a9960036a942281fd4124e2eed6d8 to your computer and use it in GitHub Desktop.
Save filipinascimento/109a9960036a942281fd4124e2eed6d8 to your computer and use it in GitHub Desktop.
Long vs int on x64 compile with clang -march=native -O0 -std=c11 test##.c -S -o test##.asm
--- test32.asm 2019-03-22 21:28:05.000000000 -0300
+++ test64.asm 2019-03-22 21:28:28.000000000 -0300
@@ -11,11 +11,10 @@
movq %rsp, %rbp
.cfi_def_cfa_register %rbp
movq %rdi, -8(%rbp)
- movl %esi, -12(%rbp)
- movq -8(%rbp), %rdi
- movl -12(%rbp), %esi
- movl %esi, %eax
- vcvttsd2si (%rdi,%rax,8), %eax
+ movq %rsi, -16(%rbp)
+ movq -8(%rbp), %rsi
+ movq -16(%rbp), %rdi
+ vcvttsd2si (%rsi,%rdi,8), %eax
popq %rbp
retq
.cfi_endproc
.section __TEXT,__text,regular,pure_instructions
.build_version macos, 10, 14
.globl _getElement ## -- Begin function getElement
.p2align 4, 0x90
_getElement: ## @getElement
.cfi_startproc
## %bb.0:
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset %rbp, -16
movq %rsp, %rbp
.cfi_def_cfa_register %rbp
movq %rdi, -8(%rbp)
movl %esi, -12(%rbp)
movq -8(%rbp), %rdi
movl -12(%rbp), %esi
movl %esi, %eax
vcvttsd2si (%rdi,%rax,8), %eax
popq %rbp
retq
.cfi_endproc
## -- End function
.subsections_via_symbols
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#define MYINT uint32_t
#define MYINTScan "%"SCNu32
double getElement(double* array, MYINT index){
return array[index];
}
.section __TEXT,__text,regular,pure_instructions
.build_version macos, 10, 14
.globl _getElement ## -- Begin function getElement
.p2align 4, 0x90
_getElement: ## @getElement
.cfi_startproc
## %bb.0:
pushq %rbp
.cfi_def_cfa_offset 16
.cfi_offset %rbp, -16
movq %rsp, %rbp
.cfi_def_cfa_register %rbp
movq %rdi, -8(%rbp)
movq %rsi, -16(%rbp)
movq -8(%rbp), %rsi
movq -16(%rbp), %rdi
vcvttsd2si (%rsi,%rdi,8), %eax
popq %rbp
retq
.cfi_endproc
## -- End function
.subsections_via_symbols
#include <stdio.h>
#include <stdlib.h>
#include <inttypes.h>
#define MYINT uint64_t
#define MYINTScan "%"SCNu64
double getElement(double* array, MYINT index){
return array[index];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment