Last active
April 8, 2016 11:24
-
-
Save mcfedr/832e3553964a014621d5 to your computer and use it in GitHub Desktop.
Example of how V8 compiles recursion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;; --- Skip lots of stuf --- | |
;;; <@19,#13> compare-numeric-and-branch | |
0x49252d6f 47 83f800 cmp eax,0x0 | |
0x49252d72 50 0f843e000000 jz 118 (0x49252db6) | |
;;; <@20,#17> -------------------- B2 (unreachable/replaced) -------------------- | |
;;; <@24,#24> -------------------- B3 -------------------- | |
;;; <@27,#26> compare-numeric-and-branch | |
0x49252d78 56 83f802 cmp eax,0x2 ;; debug: position 81 | |
0x49252d7b 59 0f842a000000 jz 107 (0x49252dab) | |
;;; <@28,#30> -------------------- B4 (unreachable/replaced) -------------------- | |
;;; <@32,#37> -------------------- B5 -------------------- | |
;;; <@35,#39> compare-numeric-and-branch | |
0x49252d81 65 83f800 cmp eax,0x0 ;; debug: position 132 | |
0x49252d84 68 0f8c1c000000 jl 102 (0x49252da6) | |
;;; <@36,#43> -------------------- B6 (unreachable/replaced) -------------------- | |
;;; <@40,#61> -------------------- B7 -------------------- | |
;;; <@42,#65> sub-i | |
0x49252d8a 74 83e804 sub eax,0x4 ;; debug: position 163 | |
;; debug: position 210 | |
;;; <@44,#80> dummy-use | |
;;; <@46,#68> push-argument | |
0x49252d8d 77 687da6d25b push 0x5bd2a67d ;; object: 0x5bd2a67d <JS Global Object> | |
;;; <@48,#68> push-argument | |
0x49252d92 82 50 push eax | |
;;; <@50,#62> constant-t | |
0x49252d93 83 bf99b6d25b mov edi,0x5bd2b699 ;; debug: position 163 | |
;; object: 0x5bd2b699 <JS Function isEven (SharedFunctionInfo 0x5bd2b4f1)> | |
;;; <@52,#70> call-js-function | |
0x49252d98 88 8b7717 mov esi,[edi+0x17] ;; debug: position 210 | |
0x49252d9b 91 e8a0ffffff call 0 (0x49252d40) ;; code: OPTIMIZED_FUNCTION | |
;;; <@54,#71> lazy-bailout | |
;;; <@56,#73> return | |
0x49252da0 96 89ec mov esp,ebp | |
0x49252da2 98 5d pop ebp | |
0x49252da3 99 c20800 ret 0x8 | |
;;; --- Missing out the rest --- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isEven(i) { | |
if (i == 0) { | |
return true; | |
} | |
else if (i == 1) { | |
return false; | |
} | |
else if (i < 0) { | |
return isEven(i + 2); | |
} | |
else { | |
return isEven(i - 2); | |
} | |
} | |
function test() { | |
return isEven(100); | |
} | |
var i = 10000; | |
while (i-- > 0) test(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment