This is an archive of the discontinued LLVM Phabricator instance.

[libc.search] [PATCH 2/6] add ctz/clz for unsigned short
AcceptedPublic

Authored by SchrodingerZhu on Oct 21 2022, 1:29 PM.

Details

Reviewers
gchatelet
Summary

This patch adds support for calculating ctz/clz of unsigned short.
The idea is to use builtin_clzs/builtin_ctzs when available
or fallback to use unsigned int version with additional bit number
manipulations.

Diff Detail

Event Timeline

SchrodingerZhu created this revision.Oct 21 2022, 1:29 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptOct 21 2022, 1:29 PM
SchrodingerZhu requested review of this revision.Oct 21 2022, 1:29 PM

What would be the use case here?
I'd rather keep these functions to what's strictly required. The smallest the code base, the better.

@gchatelet Hi, this is intended to be used in https://reviews.llvm.org/D136490. SSE2 movemask operations on byte vectors will give 16-bit masks and we want to use that to locate available bucket slot in hash table.

@gchatelet Hi, this is intended to be used in https://reviews.llvm.org/D136490. SSE2 movemask operations on byte vectors will give 16-bit masks and we want to use that to locate available bucket slot in hash table.

I see, thx for the context.

I would like to get some tests as well.

Also __has_builtin only exists from gcc 10.0 on. You first need to check that it is defined first.

libc/src/__support/builtin_wrappers.h
50

sizeof is a function not a template, these should be parentheses and not brackets.

68

This is supposed to be __builtin_ctz right?

Address code reviews:

  • fix silly bugs created during my dream walking.
  • add unit tests
This revision is now accepted and ready to land.Oct 31 2022, 2:22 PM

@SchrodingerZhu are you planning to land this patch?
If so you'd need to use LLVM_LIBC_HAS_BUILTIN from libc/src/__support/compiler_features.h.