Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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_<policy>.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
Expand Down
19 changes: 19 additions & 0 deletions doc/modules/ROOT/examples/hash_call_fast_perfect_hash.cpp
Original file line number Diff line number Diff line change
@@ -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 <boost/openmethod.hpp>

using namespace boost::openmethod;

auto hash_of(type_id type) -> std::size_t {
return policies::fast_perfect_hash::fn<default_registry>::hash(type);
}
// end::content[]

int main() {
}
27 changes: 27 additions & 0 deletions doc/modules/ROOT/examples/hash_call_minimal_cover_hash.cpp
Original file line number Diff line number Diff line change
@@ -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 <boost/openmethod.hpp>
#include <boost/openmethod/policies/minimal_cover_hash.hpp>

using namespace boost::openmethod;

#if BOOST_OPENMETHOD_HAS_PEXT

// tag::content[]
struct hashed_registry
: default_registry::with<policies::minimal_cover_hash<>> {};

auto hash_of(type_id type) -> std::size_t {
return policies::minimal_cover_hash<>::fn<hashed_registry>::hash(type);
}
// end::content[]

#endif

int main() {
}
23 changes: 23 additions & 0 deletions doc/modules/ROOT/examples/hash_call_minimal_perfect_hash.cpp
Original file line number Diff line number Diff line change
@@ -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 <boost/openmethod.hpp>
#include <boost/openmethod/policies/minimal_perfect_hash.hpp>

using namespace boost::openmethod;

struct hashed_registry
: default_registry::with<policies::minimal_perfect_hash<>> {};

auto hash_of(type_id type) -> std::size_t {
return policies::minimal_perfect_hash<>::fn<hashed_registry>::hash(type);
}
// end::content[]

int main() {
}
23 changes: 23 additions & 0 deletions doc/modules/ROOT/examples/hash_call_two_level_hash.cpp
Original file line number Diff line number Diff line change
@@ -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 <boost/openmethod.hpp>
#include <boost/openmethod/policies/two_level_hash.hpp>

using namespace boost::openmethod;

struct hashed_registry
: default_registry::with<policies::two_level_hash<>> {};

auto hash_of(type_id type) -> std::size_t {
return policies::two_level_hash<>::fn<hashed_registry>::hash(type);
}
// end::content[]

int main() {
}
16 changes: 16 additions & 0 deletions include/boost/openmethod/policies/fast_perfect_hash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<default_registry>::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
//!
Expand Down
14 changes: 14 additions & 0 deletions include/boost/openmethod/policies/minimal_cover_hash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<hashed_registry>::hash(type);
//! }
//! @endcode
//!
//! @code
//! pext rax, rdi, qword ptr [rip + st+48]
//! ret
//! @endcode
//!
//! @par Example
//! include:policies.cpp#minimal_cover_hash
//!
Expand Down
20 changes: 20 additions & 0 deletions include/boost/openmethod/policies/minimal_perfect_hash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<hashed_registry>::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
//!
Expand Down
21 changes: 21 additions & 0 deletions include/boost/openmethod/policies/two_level_hash.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<hashed_registry>::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
//!
Expand Down
Loading