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 <alan.coopersmith@oracle.com>
Part-of: <https://gitlab.freedesktop.org/xorg/xserver/-/merge_requests/1984>
(cherry picked from commit 7aa1f121e4)
This commit is contained in:
Alan Coopersmith 2025-05-18 12:25:03 -07:00
parent 061278dc23
commit 4a6e8a6efd

View file

@ -33,6 +33,9 @@
#include <X11/X.h>
#include <X11/Xproto.h>
#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;