ffmpeg7: add implementation of __popcountsi2

from gcc/libgcc/libgcc2.c
This commit is contained in:
Jerome Duval
2025-10-21 16:35:32 +00:00
committed by Jérôme Duval
parent 167a24b9fa
commit 033b45f5e2
2 changed files with 23 additions and 1 deletions

View File

@@ -402,3 +402,25 @@ __ctzdi2 (UDWtype x)
count_trailing_zeros (ret, word);
return ret + add;
}
#define POPCOUNTCST2(x) (((UWtype) x << __CHAR_BIT__) | x)
#define POPCOUNTCST4(x) (((UWtype) x << (2 * __CHAR_BIT__)) | x)
#define POPCOUNTCST8(x) (((UWtype) x << (4 * __CHAR_BIT__)) | x)
#if W_TYPE_SIZE == __CHAR_BIT__
#define POPCOUNTCST(x) x
#elif W_TYPE_SIZE == 2 * __CHAR_BIT__
#define POPCOUNTCST(x) POPCOUNTCST2 (x)
#elif W_TYPE_SIZE == 4 * __CHAR_BIT__
#define POPCOUNTCST(x) POPCOUNTCST4 (POPCOUNTCST2 (x))
#elif W_TYPE_SIZE == 8 * __CHAR_BIT__
#define POPCOUNTCST(x) POPCOUNTCST8 (POPCOUNTCST4 (POPCOUNTCST2 (x)))
#endif
int
__popcountsi2 (UWtype x)
{
x = x - ((x >> 1) & POPCOUNTCST (0x55));
x = (x & POPCOUNTCST (0x33)) + ((x >> 2) & POPCOUNTCST (0x33));
x = (x + (x >> 4)) & POPCOUNTCST (0x0F);
return (x * POPCOUNTCST (0x01)) >> (W_TYPE_SIZE - __CHAR_BIT__);
}

View File

@@ -240,7 +240,7 @@ BUILD()
cc="gcc${gccSuffix/_/-}"
ccArgs="--cc=$cc --cxx=g++${secondaryArchSuffix/_/-}
--ld=gcc${secondaryArchSuffix/_/-}
--host-ld=gcc${secondaryArchSuffix/_/-} --extra-cflags=-fno-builtin-popcount"
--host-ld=gcc${secondaryArchSuffix/_/-}"
# Hack up base headers to make them think we're on GCC2 ABI
mkdir -p include_hacks include_hacks/os include_hacks/config