Plaster
New
List
Login
text
default
anonymous
2019.05.14 20:26:24
(defun my-fast-fib (n) (declare (optimize (safety 0) (debug 0) (speed 3)) ; Give me C-level safety please (type fixnum n)) ; Type declaration (let* ((fib1 1) (fib2 1) (i 2) (fibo fib1)) (declare (type fixnum fib1 fib2 i fibo)) (loop while (< i n) do (setf fibo (the fixnum (+ fib1 fib2)) ; There are macros that ensure that we use fixnum versions of +, 1+, *, etc. this would let us skip the THE fib1 fib2 fib2 fibo i (the fixnum (1+ i)))) fibo))
Raw
Annotate
Repaste
Edit
Annotations
text
default
anonymous
2019.05.14 20:30:21
CL-USER> (disassemble #'my-fast-fib) ; disassembly for MY-FAST-FIB ; Size: 51 bytes. Origin: #x52D32449 ; 49: BB02000000 MOV EBX, 2 ; no-arg-parsing entry point ; 4E: 488BD3 MOV RDX, RBX ; 51: B904000000 MOV ECX, 4 ; 56: 488BC3 MOV RAX, RBX ; 59: EB13 JMP L1 ; 5B: 0F1F440000 NOP ; 60: L0: 488D0413 LEA RAX, [RBX+RDX] ; 64: 488BDA MOV RBX, RDX ; 67: 488BD0 MOV RDX, RAX ; 6A: 4883C102 ADD RCX, 2 ; 6E: L1: 4839F1 CMP RCX, RSI ; 71: 7CED JL L0 ; 73: 488BD0 MOV RDX, RAX ; 76: 488BE5 MOV RSP, RBP ; 79: F8 CLC ; 7A: 5D POP RBP ; 7B: C3 RET
Raw
Repaste
Edit