- (cond ((policy node (> space speed))
- (move eax function)
- (inst call (make-fixup "call_into_c" :foreign)))
- (t
- ;; Setup the NPX for C; all the FP registers need to be
- ;; empty; pop them all.
- (dotimes (i 8)
- (inst fstp fr0-tn))
-
- (inst call function)
- ;; To give the debugger a clue. XX not really internal-error?
- (note-this-location vop :internal-error)
-
- ;; Restore the NPX for lisp; ensure no regs are empty
- (dotimes (i 7)
- (inst fldz))
-
- (if (and results
- (location= (tn-ref-tn results) fr0-tn))
- ;; The return result is in fr0.
- (inst fxch fr7-tn) ; move the result back to fr0
- (inst fldz)) ; insure no regs are empty
- ))))
-
-(define-vop (alloc-number-stack-space)
- (:info amount)
- (:results (result :scs (sap-reg any-reg)))
+ ;; FIXME & OAOOM: This is brittle and error-prone to maintain two
+ ;; instances of the same logic, on in arch-assem.S, and one in
+ ;; c-call.lisp. If you modify this, modify that one too...
+ (cond ((and
+ ;; On safepoints builds, we currently use the out-of-line
+ ;; calling routine irrespectively of SPACE and SPEED policy.
+ ;; An inline version of said changes is left to the
+ ;; sufficiently motivated maintainer.
+ #!-sb-safepoint (policy node (> space speed)))
+ (move eax function)
+ (inst call (make-fixup "call_into_c" :foreign)))
+ (t
+ ;; Setup the NPX for C; all the FP registers need to be
+ ;; empty; pop them all.
+ (dotimes (i 8)
+ (inst fstp fr0-tn))
+
+ ;; Clear out DF: Darwin, Windows, and Solaris at least require
+ ;; this, and it should not hurt others either.
+ (inst cld)
+
+ (inst call function)
+ ;; To give the debugger a clue. FIXME: not really internal-error?
+ (note-this-location vop :internal-error)
+
+ ;; Restore the NPX for lisp; ensure no regs are empty
+ (dotimes (i 7)
+ (inst fldz))
+
+ (if (and results
+ (location= (tn-ref-tn results) fr0-tn))
+ ;; The return result is in fr0.
+ (inst fxch fr7-tn) ; move the result back to fr0
+ (inst fldz)) ; insure no regs are empty
+ ))))
+
+;;; While SBCL uses the FPU in 53-bit mode, most C libraries assume that
+;;; the FPU is in 64-bit mode. So we change the FPU mode to 64-bit with
+;;; the SET-FPU-WORD-FOR-C VOP before calling out to C and set it back
+;;; to 53-bit mode after coming back using the SET-FPU-WORD-FOR-LISP VOP.
+(define-vop (set-fpu-word-for-c)