SHARE
TWEET

Untitled

a guest Oct 14th, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #lang typed/racket
  2. (require x64asm)
  3.  
  4. (define-cast ->int
  5.   #:type (-> Integer)
  6.   #:ctype (_fun -> _int))
  7.  
  8. (define-λ! get-1000 ->int
  9.   (mov rax (imm32 1000))
  10.   (ret))
  11.  
  12. (get-1000)
  13.  
  14. (define-cast int->int
  15.   #:type (Integer -> Integer)
  16.   #:ctype (_fun _int64 -> _int64))
  17.  
  18. (define-λ! fib int->int #:labels (start l1 l2 l3)
  19.   (define arg0 (if (eq? (system-type )'windows) rcx rdi))
  20.   (:! start)
  21.   (push rbp)
  22.   (mov rbp rsp)
  23.   (sub rsp (imm8 16))
  24.  
  25.   (cmp arg0 (imm8 2))
  26.   (jg (rel8 l1))
  27.   (mov rax (imm32 1))
  28.   (leave)
  29.   (ret)
  30.  
  31.   (:! l1)
  32.   (sub arg0 (imm8 1))
  33.   (mov (mref 64 rbp - 8 ) arg0)
  34.   (call (rel32 start))
  35.   (mov (mref 64 rbp - 16) rax)
  36.   (mov arg0 (mref 64 rbp - 8))
  37.   (sub arg0 (imm8 1))
  38.   (call (rel32 start))
  39.   (add rax (mref 64 rbp - 16))
  40.   (leave)
  41.   (ret)
  42.   )
  43.  
  44. (fib 40)
  45.  
  46. (define-cast dd->d
  47.   #:type (Flonum Flonum -> Flonum)
  48.   #:ctype (_fun _double _double -> _double))
  49.  
  50. (define my-fl*
  51.   (parameterize ([current-context (make-context)])
  52.     (define entry (label))
  53.     (:! entry)
  54.     (addsd xmm0 xmm1)
  55.     (ret)
  56.  
  57.     (emit-code!)
  58.     (dd->d (label-addr entry))
  59.     ))
  60.  
  61. (my-fl* 100.0 200.0)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top