Skip to content

Instantly share code, notes, and snippets.

@patshaughnessy
Last active January 2, 2016 02:48
Show Gist options
  • Save patshaughnessy/8239185 to your computer and use it in GitHub Desktop.
Save patshaughnessy/8239185 to your computer and use it in GitHub Desktop.
x86_64 assembly language generated for MRI rb_obj_not (object.c line 186) with modified RTEST macro
-- Change RTEST:
//#define RTEST(v) !(((VALUE)(v) & ~Qnil) == 0)
#define RTEST(v) ((VALUE)(v) != Qnil && (VALUE)(v))
-- Recompile with -S flag:
clang -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wno-long-long -Wno-missing-field-initializers -Wunused-variable -Werror=pointer-arith -Werror=write-strings -Werror=declaration-after-statement -Werror=shorten-64-to-32 -Werror=implicit-function-declaration -Werror=division-by-zero -Werror=extra-tokens -pipe -D_FORTIFY_SOURCE=2 -fstack-protector -fno-strict-overflow -fvisibility=hidden -DRUBY_EXPORT -fPIE -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT -I. -I.ext/include/x86_64-darwin12.0 -I./include -I. -S -o object.o -c object.c
-- And here's the new assembly language - it's longer with a condition in the middle (See: je LBB7_2)
_rb_obj_not: ## @rb_obj_not
.cfi_startproc
Lfunc_begin7:
.loc 1 185 0 ## object.c:185:0
## BB#0:
pushq %rbp
Ltmp99:
.cfi_def_cfa_offset 16
Ltmp100:
.cfi_offset %rbp, -16
movq %rsp, %rbp
Ltmp101:
.cfi_def_cfa_register %rbp
##DEBUG_VALUE: rb_obj_not:obj <- RDI+0
movl $20, %eax
cmpq $8, %rdi
je LBB7_2
## BB#1:
Ltmp102:
##DEBUG_VALUE: rb_obj_not:obj <- RDI+0
xorl %ecx, %ecx
movl $20, %eax
.loc 1 186 0 prologue_end ## object.c:186:0
Ltmp103:
testq %rdi, %rdi
cmovneq %rcx, %rax
Ltmp104:
LBB7_2:
.loc 1 187 0 ## object.c:187:0
popq %rbp
ret
Ltmp105:
Lfunc_end7:
.cfi_endproc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment