Re: Popcount optimization using AVX512

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Popcount optimization using AVX512
Дата
Msg-id 1666732.1712079828@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Popcount optimization using AVX512  (Alvaro Herrera <alvherre@alvh.no-ip.org>)
Ответы Re: Popcount optimization using AVX512
Список pgsql-hackers
Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
> On 2024-Apr-02, Nathan Bossart wrote:
>> Another idea I had is to turn pg_popcount() into a macro that just uses the
>> pg_number_of_ones array when called for few bytes:
>> 
>>     static inline uint64
>>     pg_popcount_inline(const char *buf, int bytes)
>>     {
>>         uint64        popcnt = 0;
>> 
>>         while (bytes--)
>>             popcnt += pg_number_of_ones[(unsigned char) *buf++];
>> 
>>         return popcnt;
>>     }
>> 
>>     #define pg_popcount(buf, bytes) \
>>         ((bytes < 64) ? \
>>          pg_popcount_inline(buf, bytes) : \
>>          pg_popcount_optimized(buf, bytes))
>> 
>> But again, I'm not sure this is really worth it for the current use-cases.

> Eh, that seems simple enough, and then you can forget about that case.

I don't like the double evaluation of the macro argument.  Seems like
you could get the same results more safely with

    static inline uint64
    pg_popcount(const char *buf, int bytes)
    {
        if (bytes < 64)
        {
            uint64        popcnt = 0;

            while (bytes--)
                popcnt += pg_number_of_ones[(unsigned char) *buf++];

            return popcnt;
        }
        return pg_popcount_optimized(buf, bytes);
    }

            regards, tom lane



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Alvaro Herrera
Дата:
Сообщение: Re: Popcount optimization using AVX512
Следующее
От: Ranier Vilela
Дата:
Сообщение: [MASSMAIL]Fix resource leak (src/backend/libpq/be-secure-common.c)