From b16bb7d562abe06cd111e8e42ec56498b437a413 Mon Sep 17 00:00:00 2001 From: Olof-Joachim Frahm Date: Thu, 7 Nov 2013 01:07:33 +0100 Subject: [PATCH] Implement LOGCOUNT via POPCNT instruction. --- src/compiler/x86-64/arith.lisp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) 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 -- 1.7.10.4