anchor.diff:    (sys.lap-x86:xor32 :ecx :ecx)
     (sys.lap-x86:mov64 :r8 nil)
     (sys.lap-x86:sti)
  +  (:gc :no-frame)
     (sys.lap-x86:ret))
   
   (sys.int::define-lap-function %%switch-to-thread-via-wired-stack ()
  -  (:gc :no-frame)
     ;; Save frame pointer.
     (sys.lap-x86:gs)
  -  (sys.lap-x86:mov64 (:object nil #.+thread-frame-pointer+) :r10)
  +  (sys.lap-x86:mov64 (:object nil #.+thread-state-rbp+) :r10)
     ;; Save fpu state.
     (sys.lap-x86:gs)
     (sys.lap-x86:fxsave (:object nil #.+thread-fx-save-area+))
     ;; Save stack pointer.
     (sys.lap-x86:gs)
  -  (sys.lap-x86:mov64 (:object nil #.+thread-stack-pointer+) :r9)
  +  (sys.lap-x86:mov64 (:object nil #.+thread-state-rsp+) :r9)
     ;; Only partial state was saved.
     (sys.lap-x86:gs)
     (sys.lap-x86:mov64 (:object nil #.+thread-full-save-p+) nil)
  -  ;; Switch threads.
  -  (sys.lap-x86:mov32 :ecx #.sys.int::+msr-ia32-gs-base+)
  -  (sys.lap-x86:mov64 :rax :r11)
  -  (sys.lap-x86:mov64 :rdx :r11)
  -  (sys.lap-x86:shr64 :rdx 32)
  -  (sys.lap-x86:wrmsr)
  -  ;; Restore fpu state.
  -  (sys.lap-x86:gs)
  -  (sys.lap-x86:fxrstor (:object nil #.+thread-fx-save-area+))
  -  ;; Drop the locks on both threads. Must be done before touching the thread stack.
  -  (sys.lap-x86:mov64 :r12 (:constant :unlocked))
  -  (sys.lap-x86:mov64 (:object :r11 #.+thread-lock+) :r12)
  -  (sys.lap-x86:mov64 (:object :r8 #.+thread-lock+) :r12)
  -  ;; Check if the thread is in the interrupt save area.
  -  (sys.lap-x86:gs)
  -  (sys.lap-x86:cmp64 (:object nil #.+thread-full-save-p+) nil)
  -  (sys.lap-x86:jne FULL-RESTORE)
  -  ;; Restore stack pointer.
  -  (sys.lap-x86:gs)
  -  (sys.lap-x86:mov64 :rsp (:object nil #.+thread-stack-pointer+))
  -  ;; Restore frame pointer.
  -  (sys.lap-x86:gs)
  -  (sys.lap-x86:mov64 :rbp (:object nil #.+thread-frame-pointer+))
  -  ;; Reenable interrupts. Must be done before touching the thread stack.
  -  (sys.lap-x86:sti)
  -  ;; No value return.
  -  (sys.lap-x86:xor32 :ecx :ecx)
  -  (sys.lap-x86:mov64 :r8 nil)
  -  ;; Return, restoring RIP.
  -  (sys.lap-x86:ret)
  -  ;; Returning to an interrupted thread. Restore saved registers and stuff.
  -  FULL-RESTORE
  -  (sys.lap-x86:lea64 :rsp (:object :r11 #.+thread-interrupt-save-area+))
  -  (sys.lap-x86:pop :r15)
  -  (sys.lap-x86:pop :r14)
  -  (sys.lap-x86:pop :r13)
  -  (sys.lap-x86:pop :r12)
  -  (sys.lap-x86:pop :r11)
  -  (sys.lap-x86:pop :r10)
  -  (sys.lap-x86:pop :r9)
  -  (sys.lap-x86:pop :r8)
  -  (sys.lap-x86:pop :rdi)
  -  (sys.lap-x86:pop :rsi)
  -  (sys.lap-x86:pop :rbx)
  -  (sys.lap-x86:pop :rdx)
  -  (sys.lap-x86:pop :rcx)
  -  (sys.lap-x86:pop :rax)
  -  (sys.lap-x86:pop :rbp)
  -  (sys.lap-x86:iret))
  +  ;; Jump to common function.
  +  (sys.lap-x86:mov64 :r9 :r11)
  +  (sys.lap-x86:mov64 :r13 (:function %%switch-to-thread-common))
  +  (sys.lap-x86:jmp (:r13 #.(+ (- sys.int::+tag-object+) 8 (* sys.int::+fref-entry-point+ 8)))))
   
   (defun %reschedule ()
     ;; Interrupts must be off and the current thread's lock must be held.
  
positive.code:   (sys.lap-x86:ret)
    ;; Returning to an interrupted thread. Restore saved registers and stuff.
    FULL-RESTORE
    (sys.lap-x86:lea64 :rsp (:object :r10 #.+thread-interrupt-save-area+))
    (sys.lap-x86:pop :r15)
    (sys.lap-x86:pop :r14)
    (sys.lap-x86:pop :r13)
  
negative.code:   (:gc :no-frame)
    ;; Save frame pointer.
    (sys.lap-x86:gs)
    (sys.lap-x86:mov64 (:object nil #.+thread-state-rbp+) :rbp)
    ;; Save fpu state.
    (sys.lap-x86:gs)
    (sys.lap-x86:fxsave (:object nil #.+thread-fx-save-area+))
    ;; Save stack pointer.
    (sys.lap-x86:gs)
    (sys.lap-x86:mov64 (:object nil #.+thread-state-rsp+) :rsp)
    ;; Only partial state was saved.
    (sys.lap-x86:gs)
    (sys.lap-x86:mov64 (:object nil #.+thread-full-save-p+) nil)
    ;; Jump to common function.
    (sys.lap-x86:mov64 :r13 (:function %%switch-to-thread-common))
    (sys.lap-x86:jmp (:r13 #.(+ (- sys.int::+tag-object+) 8 (* sys.int::+fref-entry-point+ 8)))))
  
  (defun %reschedule-via-interrupt (interrupt-frame)
    ;; Interrupts must be off and the current thread's lock must be held.
  