From 853ec0cce2904c48297e3340d59d73b596d44c10 Mon Sep 17 00:00:00 2001 From: Trevor Hansen Date: Mon, 27 Jul 2026 20:40:14 +1000 Subject: [PATCH] Use the popcount64c bit-counting sequence in Dar_WordCountOnes The sequence currently used is popcount64a, which no GCC from 7 to 16 and no clang from 9 to 22 recognises as a population count, so it always emits 23 instructions. popcount64c is recognised by GCC 10 and later and clang 10 and later, which emit a single popcnt where the target has the instruction, and is 8 instructions shorter where it does not. --- src/opt/dar/darCut.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/opt/dar/darCut.c b/src/opt/dar/darCut.c index da1c9eafa6..49f36ca142 100644 --- a/src/opt/dar/darCut.c +++ b/src/opt/dar/darCut.c @@ -85,11 +85,10 @@ void Dar_ObjCutPrint( Aig_Man_t * p, Aig_Obj_t * pObj ) ***********************************************************************/ static inline int Dar_WordCountOnes( unsigned uWord ) { - uWord = (uWord & 0x55555555) + ((uWord>>1) & 0x55555555); - uWord = (uWord & 0x33333333) + ((uWord>>2) & 0x33333333); - uWord = (uWord & 0x0F0F0F0F) + ((uWord>>4) & 0x0F0F0F0F); - uWord = (uWord & 0x00FF00FF) + ((uWord>>8) & 0x00FF00FF); - return (uWord & 0x0000FFFF) + (uWord>>16); + uWord = uWord - ((uWord >> 1) & 0x55555555); + uWord = (uWord & 0x33333333) + ((uWord >> 2) & 0x33333333); + uWord = (uWord + (uWord >> 4)) & 0x0F0F0F0F; + return (int)((uWord * 0x01010101) >> 24); } /**Function*************************************************************