From 4a6e8a6efd18c8cd728c628dd48913ff79bc2d17 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 18 May 2025 12:25:03 -0700 Subject: [PATCH] mi: use common implementation of bit counting function Reduce a bit of unexplained magic, and use ISA extensions where available Signed-off-by: Alan Coopersmith Part-of: (cherry picked from commit 7aa1f121e4aeae295fb23acd0d474daad84d4f47) --- mi/micmap.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/mi/micmap.c b/mi/micmap.c index d42a1cc51..e08566ef4 100644 --- a/mi/micmap.c +++ b/mi/micmap.c @@ -33,6 +33,9 @@ #include #include + +#include "os/osdep.h" + #include "scrnintstr.h" #include "colormapst.h" #include "resource.h" @@ -327,7 +330,6 @@ miSetVisualTypesAndMasks(int depth, int visuals, int bitsPerRGB, Pixel redMask, Pixel greenMask, Pixel blueMask) { miVisualsPtr new, *prev, v; - int count; new = malloc(sizeof *new); if (!new) @@ -345,10 +347,7 @@ miSetVisualTypesAndMasks(int depth, int visuals, int bitsPerRGB, new->redMask = redMask; new->greenMask = greenMask; new->blueMask = blueMask; - count = (visuals >> 1) & 033333333333; - count = visuals - count - ((count >> 1) & 033333333333); - count = (((count + (count >> 3)) & 030707070707) % 077); /* HAKMEM 169 */ - new->count = count; + new->count = Ones(visuals); for (prev = &miVisuals; (v = *prev); prev = &v->next); *prev = new; return TRUE;