[all-commits] [llvm/llvm-project] 81e3e7: [libc] [search] implement hcreate(_r)/hsearch(_r)/...

Schrodinger ZHU Yifan via All-commits all-commits at lists.llvm.org
Tue Nov 28 18:02:39 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 81e3e7e5d455f85e070a27763c578df493716ae9
      https://github.com/llvm/llvm-project/commit/81e3e7e5d455f85e070a27763c578df493716ae9
  Author: Schrodinger ZHU Yifan <yifanzhu at rochester.edu>
  Date:   2023-11-28 (Tue, 28 Nov 2023)

  Changed paths:
    M libc/cmake/modules/LLVMLibCFlagRules.cmake
    M libc/cmake/modules/LLVMLibCObjectRules.cmake
    M libc/config/linux/aarch64/entrypoints.txt
    M libc/config/linux/aarch64/headers.txt
    M libc/config/linux/api.td
    M libc/config/linux/arm/entrypoints.txt
    M libc/config/linux/arm/headers.txt
    M libc/config/linux/riscv/entrypoints.txt
    M libc/config/linux/riscv/headers.txt
    M libc/config/linux/x86_64/entrypoints.txt
    M libc/config/linux/x86_64/headers.txt
    M libc/include/CMakeLists.txt
    A libc/include/llvm-libc-types/ACTION.h
    M libc/include/llvm-libc-types/CMakeLists.txt
    A libc/include/llvm-libc-types/ENTRY.h
    A libc/include/llvm-libc-types/struct_hsearch_data.h
    A libc/include/search.h.def
    M libc/spec/gnu_ext.td
    M libc/spec/posix.td
    M libc/spec/spec.td
    M libc/src/CMakeLists.txt
    M libc/src/__support/CMakeLists.txt
    A libc/src/__support/HashTable/CMakeLists.txt
    A libc/src/__support/HashTable/bitmask.h
    A libc/src/__support/HashTable/generic/bitmask_impl.inc
    A libc/src/__support/HashTable/randomness.h
    A libc/src/__support/HashTable/sse2/bitmask_impl.inc
    A libc/src/__support/HashTable/table.h
    M libc/src/__support/bit.h
    A libc/src/__support/hash.h
    A libc/src/__support/memory_size.h
    A libc/src/search/CMakeLists.txt
    A libc/src/search/hcreate.cpp
    A libc/src/search/hcreate.h
    A libc/src/search/hcreate_r.cpp
    A libc/src/search/hcreate_r.h
    A libc/src/search/hdestroy.cpp
    A libc/src/search/hdestroy.h
    A libc/src/search/hdestroy_r.cpp
    A libc/src/search/hdestroy_r.h
    A libc/src/search/hsearch.cpp
    A libc/src/search/hsearch.h
    A libc/src/search/hsearch/CMakeLists.txt
    A libc/src/search/hsearch/global.cpp
    A libc/src/search/hsearch/global.h
    A libc/src/search/hsearch_r.cpp
    A libc/src/search/hsearch_r.h
    M libc/test/src/CMakeLists.txt
    M libc/test/src/__support/CMakeLists.txt
    A libc/test/src/__support/HashTable/CMakeLists.txt
    A libc/test/src/__support/HashTable/bitmask_test.cpp
    A libc/test/src/__support/HashTable/group_test.cpp
    A libc/test/src/__support/HashTable/table_test.cpp
    M libc/test/src/__support/bit_test.cpp
    A libc/test/src/__support/hash_test.cpp
    A libc/test/src/__support/memory_size_test.cpp
    A libc/test/src/search/CMakeLists.txt
    A libc/test/src/search/hsearch_test.cpp

  Log Message:
  -----------
  [libc] [search] implement hcreate(_r)/hsearch(_r)/hdestroy(_r) (#73469)

This patch implements `hcreate(_r)/hsearch(_r)/hdestroy(_r)` as
specified in https://man7.org/linux/man-pages/man3/hsearch.3.html.

Notice that `neon/asimd` extension is not yet added in this patch. 

- The implementation is largely simplified from rust's
[`hashbrown`](https://github.com/rust-lang/hashbrown/blob/master/src/raw/mod.rs)
as we only consider fix-sized insertion-only hashtables. Technical
details are provided in code comments.

- This patch also contains a portable string hash function, which is
derived from [`aHash`](https://github.com/tkaitchuck/aHash)'s fallback
routine. Not using any SIMD acceleration, it has a good enough quality
(passing all SMHasher tests) and is not too bad in speed.

- Some general functionalities are added, such as `memory_size`,
`offset_to`(alignment), `next_power_of_two`, `is_power_of_two`.
`ctz/clz` are extended to support shorter integers.




More information about the All-commits mailing list