From: Olof-Joachim Frahm Date: Thu, 7 Nov 2013 00:07:33 +0000 (+0100) Subject: Implement LOGCOUNT via POPCNT instruction. X-Git-Url: http://repo.macrolet.net/gitweb/?a=commitdiff_plain;h=b16bb7d562abe06cd111e8e42ec56498b437a413;p=sbcl.git Implement LOGCOUNT via POPCNT instruction. --- diff --git a/src/compiler/x86-64/arith.lisp b/src/compiler/x86-64/arith.lisp index f455bff..1026743 100644 --- a/src/compiler/x86-64/arith.lisp +++ b/src/compiler/x86-64/arith.lisp @@ -1197,6 +1197,20 @@ constant shift greater than word length"))) (inst mov mask #x0101010101010101) (inst imul result mask) (inst shr result 56))) + +;; only marginally faster then the regular one, but shorter +;; might be unavailable though +(define-vop (unsigned-byte-64-count/popcnt) + (:translate logcount) + (:note "inline (unsigned-byte 64) logcount using popcnt instruction") + (:policy :fast-safe) + (:guard (member :popcnt *backend-subfeatures*)) + (:args (arg :scs (unsigned-reg) :target result)) + (:arg-types unsigned-num) + (:results (result :scs (unsigned-reg))) + (:result-types positive-fixnum) + (:generator 1 + (inst popcnt arg result))) ;;;; binary conditional VOPs