X-Git-Url: http://repo.macrolet.net/gitweb/?a=blobdiff_plain;f=src%2Fassembly%2Fx86-64%2Falloc.lisp;h=e40d38051015cf6e785fed992c5da07e238b89ee;hb=37b1ed8e9b6faa84832b8251998b5d0eb1f6b307;hp=cf4e3c8f673be4de76e49e34ada9586451b23b64;hpb=78fa16bf55be44cc16845be84d98023e83fb14bc;p=sbcl.git diff --git a/src/assembly/x86-64/alloc.lisp b/src/assembly/x86-64/alloc.lisp index cf4e3c8..e40d380 100644 --- a/src/assembly/x86-64/alloc.lisp +++ b/src/assembly/x86-64/alloc.lisp @@ -11,49 +11,128 @@ (in-package "SB!VM") -;;;; from signed/unsigned +;;;; Signed and unsigned bignums from word-sized integers. Argument +;;;; and return in the same register. No VOPs, as these are only used +;;;; as out-of-line versions: MOVE-FROM-[UN]SIGNED VOPs handle the +;;;; fixnum cases inline. -;;; KLUDGE: Why don't we want vops for this one and the next -;;; one? -- WHN 19990916 -#+sb-assembling ; We don't want a vop for this one. -(define-assembly-routine - (move-from-signed) - ((:temp eax unsigned-reg eax-offset) - (:temp ebx unsigned-reg ebx-offset)) - (inst mov ebx eax) - (inst shl ebx 1) - (inst jmp :o bignum) - (inst shl ebx 1) - (inst jmp :o bignum) - (inst shl ebx 1) - (inst jmp :o bignum) - (inst ret) - BIGNUM +;;; #+SB-ASSEMBLING as we don't need VOPS, just the asm routines: +;;; these are out-of-line versions called by VOPs. - (with-fixed-allocation (ebx bignum-widetag (+ bignum-digits-offset 1)) - (storew eax ebx bignum-digits-offset other-pointer-lowtag)) - - (inst ret)) - -#+sb-assembling ; We don't want a vop for this one either. -(define-assembly-routine - (move-from-unsigned) - ((:temp eax unsigned-reg eax-offset) - (:temp ebx unsigned-reg ebx-offset)) - - (inst bsr ebx eax) - (inst cmp ebx 61) - (inst jmp :z DONE) - (inst jmp :ge BIGNUM) - ;; Fixnum - (inst mov ebx eax) - (inst shl ebx 3) - DONE - (inst ret) - - BIGNUM - (with-fixed-allocation (ebx bignum-widetag (+ bignum-digits-offset 2)) - (storew eax ebx bignum-digits-offset other-pointer-lowtag)) - (inst ret)) +#+sb-assembling +(macrolet + ((def (reg) + `(define-assembly-routine (,(symbolicate "ALLOC-SIGNED-BIGNUM-IN-" reg)) + ((:temp number unsigned-reg ,(symbolicate reg "-OFFSET"))) + (inst push number) + (with-fixed-allocation (number bignum-widetag (+ bignum-digits-offset 1)) + (popw number bignum-digits-offset other-pointer-lowtag)) + (inst ret)))) + (def rax) + (def rcx) + (def rdx) + (def rbx) + (def rsi) + (def rdi) + (def r8) + (def r9) + (def r10) + (def r12) + (def r13) + (def r14) + (def r15)) +#+sb-assembling +(macrolet + ((def (reg) + `(define-assembly-routine (,(symbolicate "ALLOC-UNSIGNED-BIGNUM-IN-" reg)) + ((:temp number unsigned-reg ,(symbolicate reg "-OFFSET"))) + (inst push number) + (inst jmp :ns one-word-bignum) + ;; Two word bignum + (with-fixed-allocation (number bignum-widetag (+ bignum-digits-offset 2)) + (popw number bignum-digits-offset other-pointer-lowtag)) + (inst ret) + ONE-WORD-BIGNUM + (with-fixed-allocation (number bignum-widetag (+ bignum-digits-offset 1)) + (popw number bignum-digits-offset other-pointer-lowtag)) + (inst ret)))) + (def rax) + (def rcx) + (def rdx) + (def rbx) + (def rsi) + (def rdi) + (def r8) + (def r9) + (def r10) + (def r12) + (def r13) + (def r14) + (def r15)) +#+sb-assembling +(macrolet + ((def (reg) + (declare (ignorable reg)) + #!+sb-thread + (let* ((name (intern (format nil "ALLOC-TLS-INDEX-IN-~A" reg))) + (target-offset (intern (format nil "~A-OFFSET" reg))) + (other-offset (if (eql 'rax reg) + 'rcx-offset + 'rax-offset))) + ;; Symbol starts in TARGET, where the TLS-INDEX ends up in. + `(define-assembly-routine ,name + ((:temp other descriptor-reg ,other-offset) + (:temp target descriptor-reg ,target-offset)) + (let ((get-tls-index-lock (gen-label)) + (release-tls-index-lock (gen-label))) + (pseudo-atomic + ;; Save OTHER & push the symbol. RAX is either one of the two. + (inst push other) + (inst push target) + (emit-label get-tls-index-lock) + (let ((not-rax ,(if (eql 'rax reg) 'other 'target))) + (inst mov not-rax 1) + (zeroize rax-tn) + (inst cmpxchg (make-ea-for-symbol-value *tls-index-lock*) + not-rax :lock) + (inst jmp :ne get-tls-index-lock)) + ;; The symbol is now in OTHER. + (inst pop other) + ;; Now with the lock held, see if the symbol's tls index has been + ;; set in the meantime. + (loadw target other symbol-tls-index-slot other-pointer-lowtag) + (inst test target target) + (inst jmp :ne release-tls-index-lock) + ;; Allocate a new tls-index. + (load-symbol-value target *free-tls-index*) + (let ((not-error (gen-label)) + (error (generate-error-code nil 'tls-exhausted-error))) + (inst cmp target (ash tls-size word-shift)) + (inst jmp :l not-error) + (%clear-pseudo-atomic) + (inst jmp error) + (emit-label not-error)) + (inst add (make-ea-for-symbol-value *free-tls-index*) + n-word-bytes) + (storew target other symbol-tls-index-slot other-pointer-lowtag) + (emit-label release-tls-index-lock) + ;; No need for barriers on x86/x86-64 on unlock. + (store-symbol-value 0 *tls-index-lock*) + ;; Restore OTHER. + (inst pop other)) + (inst ret)))))) + (def rax) + (def rcx) + (def rdx) + (def rbx) + (def rsi) + (def rdi) + (def r8) + (def r9) + (def r10) + (def r12) + (def r13) + (def r14) + (def r15))