(:result-types tagged-num)
(:policy :fast-safe)
(:generator 2
- (inst rlwinm res x
- (mod (- 32 posn) 32) ; effectively rotate right
- (- 32 size n-fixnum-tag-bits)
- (- 31 n-fixnum-tag-bits))))
+ (let ((phantom-bits (- (+ size posn) 30)))
+ (cond
+ ((plusp phantom-bits)
+ ;; The byte to be loaded into RES includes sign bits which are not
+ ;; present in the input X physically. RLWINM as used below would
+ ;; mask these out with 0 even for negative inputs.
+ (inst srawi res x phantom-bits)
+ (inst rlwinm res x
+ (mod (- 32 posn (- phantom-bits)) 32)
+ (- 32 size n-fixnum-tag-bits)
+ (- 31 n-fixnum-tag-bits)))
+ (t
+ (inst rlwinm res x
+ (mod (- 32 posn) 32) ; effectively rotate right
+ (- 32 size n-fixnum-tag-bits)
+ (- 31 n-fixnum-tag-bits)))))))
(define-vop (ldb-c/signed)
(:translate %%ldb)
(assert (= (64-bit-logcount (1- (ash 1 48))) 48))
(assert (= (64-bit-logcount (1- (ash 1 54))) 54))
\f
+(declaim (inline ppc-ldb-2))
+
+(defun ppc-ldb-2 (fun value)
+ (declare (type stream socket)
+ (type (signed-byte 32) value)
+ (optimize (speed 3) (safety 0) (space 1) (debug 1)
+ (compilation-speed 0)))
+ (funcall fun (ldb (byte 8 24) value))
+ (funcall fun (ldb (byte 8 16) value))
+ (funcall fun (ldb (byte 8 8) value))
+ (funcall fun (ldb (byte 8 0) value))
+ (values))
+
+(defun ppc-ldb-1 (fun)
+ (declare (optimize (speed 3) (safety 0) (space 1) (debug 1)
+ (compilation-speed 0)))
+ (loop
+ for param :across (make-array 1 :initial-element nil)
+ for size :across (make-array 1 :element-type 'fixnum :initial-element 3)
+ do (ppc-ldb-2 fun (if param size -1))))
+
+(let ((acc '()))
+ (ppc-ldb-1 (lambda (x)
+ (push x acc)))
+ (assert (equal acc '(#xff #xff #xff #xff))))
+\f