diff --git a/CLAUDE.md b/CLAUDE.md index 4d21be42..a7887baf 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -305,6 +305,12 @@ here). Add the flag to the invocation before pasting any output: - `objdump -dC -M intel --no-show-raw-insn` - `gcc -S -masm=intel` / `clang -S -masm=intel` +The doc comment of each hash policy (`fast_perfect_hash`, `minimal_perfect_hash`, +`two_level_hash`, `minimal_cover_hash`) carries the assembly of a call to its `hash`, as built by +`doc/modules/ROOT/examples/hash_call_.cpp` with clang 22, `-std=c++17 -O2` +(`-mbmi2` for `minimal_cover_hash`). It is a pasted snapshot: nothing checks it, so regenerate it +when a hash changes. The mangled `registry_state<...>::st` operand is written `st`. + ### Compiler Requirements Tests require these C++17 features (checked by Boost.Build): - auto nontype template params diff --git a/doc/modules/ROOT/examples/hash_call_fast_perfect_hash.cpp b/doc/modules/ROOT/examples/hash_call_fast_perfect_hash.cpp new file mode 100644 index 00000000..47eefebf --- /dev/null +++ b/doc/modules/ROOT/examples/hash_call_fast_perfect_hash.cpp @@ -0,0 +1,19 @@ +// Copyright (c) 2017-2026 Jean-Louis Leroy +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + +// clang-format off + +// tag::content[] +#include + +using namespace boost::openmethod; + +auto hash_of(type_id type) -> std::size_t { + return policies::fast_perfect_hash::fn::hash(type); +} +// end::content[] + +int main() { +} diff --git a/doc/modules/ROOT/examples/hash_call_minimal_cover_hash.cpp b/doc/modules/ROOT/examples/hash_call_minimal_cover_hash.cpp new file mode 100644 index 00000000..bf2bcf5b --- /dev/null +++ b/doc/modules/ROOT/examples/hash_call_minimal_cover_hash.cpp @@ -0,0 +1,27 @@ +// Copyright (c) 2017-2026 Jean-Louis Leroy +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + +// clang-format off + +#include +#include + +using namespace boost::openmethod; + +#if BOOST_OPENMETHOD_HAS_PEXT + +// tag::content[] +struct hashed_registry + : default_registry::with> {}; + +auto hash_of(type_id type) -> std::size_t { + return policies::minimal_cover_hash<>::fn::hash(type); +} +// end::content[] + +#endif + +int main() { +} diff --git a/doc/modules/ROOT/examples/hash_call_minimal_perfect_hash.cpp b/doc/modules/ROOT/examples/hash_call_minimal_perfect_hash.cpp new file mode 100644 index 00000000..f92ff000 --- /dev/null +++ b/doc/modules/ROOT/examples/hash_call_minimal_perfect_hash.cpp @@ -0,0 +1,23 @@ +// Copyright (c) 2017-2026 Jean-Louis Leroy +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + +// clang-format off + +// tag::content[] +#include +#include + +using namespace boost::openmethod; + +struct hashed_registry + : default_registry::with> {}; + +auto hash_of(type_id type) -> std::size_t { + return policies::minimal_perfect_hash<>::fn::hash(type); +} +// end::content[] + +int main() { +} diff --git a/doc/modules/ROOT/examples/hash_call_two_level_hash.cpp b/doc/modules/ROOT/examples/hash_call_two_level_hash.cpp new file mode 100644 index 00000000..9ee5b64b --- /dev/null +++ b/doc/modules/ROOT/examples/hash_call_two_level_hash.cpp @@ -0,0 +1,23 @@ +// Copyright (c) 2017-2026 Jean-Louis Leroy +// Distributed under the Boost Software License, Version 1.0. +// See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + +// clang-format off + +// tag::content[] +#include +#include + +using namespace boost::openmethod; + +struct hashed_registry + : default_registry::with> {}; + +auto hash_of(type_id type) -> std::size_t { + return policies::two_level_hash<>::fn::hash(type); +} +// end::content[] + +int main() { +} diff --git a/include/boost/openmethod/policies/fast_perfect_hash.hpp b/include/boost/openmethod/policies/fast_perfect_hash.hpp index adfdae45..d216d897 100644 --- a/include/boost/openmethod/policies/fast_perfect_hash.hpp +++ b/include/boost/openmethod/policies/fast_perfect_hash.hpp @@ -66,6 +66,22 @@ namespace policies { //! range of integers. In other words, a lot of space may be wasted in presence //! of large sets of type_ids. //! +//! The code generated for a call to `hash`, by x86-64 clang 22 with +//! `-O2`, where `st` stands for the registry's state: +//! +//! @code +//! auto hash_of(type_id type) -> std::size_t { +//! return policies::fast_perfect_hash::fn::hash(type); +//! } +//! @endcode +//! +//! @code +//! imul rdi, qword ptr [rip + st+48] +//! movzx eax, byte ptr [rip + st+56] +//! shrx rax, rdi, rax +//! ret +//! @endcode +//! //! @par Example //! include:policies.cpp#fast_perfect_hash //! diff --git a/include/boost/openmethod/policies/minimal_cover_hash.hpp b/include/boost/openmethod/policies/minimal_cover_hash.hpp index a1e626d5..44cf1f69 100644 --- a/include/boost/openmethod/policies/minimal_cover_hash.hpp +++ b/include/boost/openmethod/policies/minimal_cover_hash.hpp @@ -192,6 +192,20 @@ namespace policies { //! @tparam MaxBits Refuse a cover wider than this; the table is `8 << bits` //! bytes. //! +//! The code generated for a call to `hash`, by x86-64 clang 22 with +//! `-O2` and `-mbmi2`, where `st` stands for the registry's state: +//! +//! @code +//! auto hash_of(type_id type) -> std::size_t { +//! return policies::minimal_cover_hash<>::fn::hash(type); +//! } +//! @endcode +//! +//! @code +//! pext rax, rdi, qword ptr [rip + st+48] +//! ret +//! @endcode +//! //! @par Example //! include:policies.cpp#minimal_cover_hash //! diff --git a/include/boost/openmethod/policies/minimal_perfect_hash.hpp b/include/boost/openmethod/policies/minimal_perfect_hash.hpp index edecde7e..f699146b 100644 --- a/include/boost/openmethod/policies/minimal_perfect_hash.hpp +++ b/include/boost/openmethod/policies/minimal_perfect_hash.hpp @@ -102,6 +102,26 @@ namespace boost::openmethod::policies { //! defeats one multiplier usually defeats them all at that `Lambda` and //! `LoadPercent`; lower `Lambda` or `LoadPercent` instead. //! +//! The code generated for a call to `hash`, by x86-64 clang 22 with +//! `-O2`, where `st` stands for the registry's state: +//! +//! @code +//! auto hash_of(type_id type) -> std::size_t { +//! return policies::minimal_perfect_hash<>::fn::hash(type); +//! } +//! @endcode +//! +//! @code +//! imul rdi, qword ptr [rip + st+48] +//! movzx eax, byte ptr [rip + st+56] +//! shrx rax, rdi, rax +//! mov rcx, qword ptr [rip + st+72] +//! mov edx, dword ptr [rcx + 4*rax] +//! imul rdx, rdi +//! mulx rax, rax, qword ptr [rip + st+64] +//! ret +//! @endcode +//! //! @par Example //! include:policies.cpp#minimal_perfect_hash //! diff --git a/include/boost/openmethod/policies/two_level_hash.hpp b/include/boost/openmethod/policies/two_level_hash.hpp index f9ae833d..6a5818ac 100644 --- a/include/boost/openmethod/policies/two_level_hash.hpp +++ b/include/boost/openmethod/policies/two_level_hash.hpp @@ -86,6 +86,27 @@ namespace boost::openmethod::policies { //! a pathological input ask for a table orders of magnitude larger than the //! program needs. //! +//! The code generated for a call to `hash`, by x86-64 clang 22 with +//! `-O2`, where `st` stands for the registry's state: +//! +//! @code +//! auto hash_of(type_id type) -> std::size_t { +//! return policies::two_level_hash<>::fn::hash(type); +//! } +//! @endcode +//! +//! @code +//! imul rdi, qword ptr [rip + st+48] +//! movzx eax, byte ptr [rip + st+56] +//! shrx rax, rdi, rax +//! mov rcx, qword ptr [rip + st+72] +//! mov eax, dword ptr [rcx + 4*rax] +//! imul rax, rdi +//! movzx ecx, byte ptr [rip + st+64] +//! shrx rax, rax, rcx +//! ret +//! @endcode +//! //! @par Example //! include:policies.cpp#two_level_hash //!