Skip to content

Instantly share code, notes, and snippets.

@evilpie
Created August 29, 2011 19:43
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 evilpie/1179203 to your computer and use it in GitHub Desktop.
Save evilpie/1179203 to your computer and use it in GitHub Desktop.
Boolean vs Int in Javascript
; JavaScript Code : "!a"
movabsq $0xfff9800000000000, %r11 ; type tag of boolean (SpiderMonkey uses a trait of NaN-boxing)
cmpq %r11, %r9 ; compare with type tag of a
jne ((165)) ; if not equal jump to stub
xorl 1, %r15d ; xor value of a with 1, true is value 1 so 1^1 = 0, false is 0 so 1^0 = 1
; JavaScript Code: "a - 1"
movabsq $0xfff8800000000000, %r11 ; type tag of int
cmpq %r11, %r15
jne ((73)) ; jump if not int
subl $0x1, %r9d ; subtract 1
jo ((83)) ; jump if overflow
; JavaScript Code: "if (a)"
movabsq $0xfff9800000000000, %r11
cmpq %r11, %r15
jne ((86)) ; jump if not boolean
testl %r9d, %r9d ; test
jne ((95)) ; jump false
jmp ((100)) ; jump true
; JavaScript Code: "if (a == 1)
movabsq $0xfff8800000000000, %r11
cmpq %r11, %r12
jne ((70))
cmpl $0x1, %r15d
jne ((80))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment