[set] Insert coverage intersections by bitmap word

Coverage format 2 now reads intersection results a word at a time, but
still inserted every selected glyph separately. Add an internal
word-at-a-time set insertion path and use it when the output sink is an
hb_set_t, preserving the generic per-glyph fallback for other sinks.

This removes another about 121M instructions from Noto Nastaliq
dependency construction. The compile-only run now takes about 226ms
task-clock / 229ms elapsed and 2.83B instructions, over 2,000x faster
than the original 7:44.77 run.

Dependency graphs match the original output for Noto Nastaliq, Noto
Sans Duployan, Gulzar, Iran Nastaliq, Noto COLRv1, Amiri, and Source
Serif Variable Roman.

Tested with: meson test -C build

Assisted-by: OpenAI Codex <codex@openai.com>
This commit is contained in:
Behdad Esfahbod committed 2026-08-20 04:04:54 -06:00
1 parent f3a00d0086
commit 5bf0cfbc45
6 files changed
+51 -5

No files matched your search

+14 -5
View File
@@ -139,6 +139,19 @@ struct CoverageFormat2_4
return false;
}
static void add_intersected_bits (hb_set_t &set, hb_codepoint_t base, uint64_t bits)
{ set.add_bits (base, bits); }
template <typename IterableOut>
static void add_intersected_bits (IterableOut&& out, hb_codepoint_t base, uint64_t bits)
{
while (bits)
{
out << base + hb_ctz (bits);
bits &= bits - 1;
}
}
template <typename IterableOut,
hb_requires (hb_is_sink_of (IterableOut, hb_codepoint_t))>
void intersect_set (const hb_set_t &glyphs, IterableOut&& intersect_glyphs) const
@@ -161,11 +174,7 @@ struct CoverageFormat2_4
unsigned int end = last - cursor;
if (end < hb_bit_page_t::ELT_BITS - 1)
bits &= (uint64_t (1) << (end + 1)) - 1;
while (bits)
{
intersect_glyphs << cursor + hb_ctz (bits);
bits &= bits - 1;
}
add_intersected_bits (intersect_glyphs, cursor, bits);
}
}
}
+2
View File
@@ -135,7 +135,9 @@ struct hb_bit_page_t
}
void add (hb_codepoint_t g) { elt (g) |= mask (g); dirty (); }
void add_bits (hb_codepoint_t g, uint64_t bits) { elt (g) |= bits; dirty (); }
void del (hb_codepoint_t g) { elt (g) &= ~mask (g); dirty (); }
void del_bits (hb_codepoint_t g, uint64_t bits) { elt (g) &= ~bits; dirty (); }
void set (hb_codepoint_t g, bool value) { if (value) add (g); else del (g); }
bool get (hb_codepoint_t g) const { return elt (g) & mask (g); }
bool may_have (hb_codepoint_t g) const { return get (g); }
+2
View File
@@ -113,6 +113,8 @@ struct hb_bit_set_invertible_t
void add (hb_codepoint_t g) { unlikely (inverted) ? s.del (g) : s.add (g); }
void add_bits (hb_codepoint_t g, uint64_t bits)
{ unlikely (inverted) ? s.del_bits (g, bits) : s.add_bits (g, bits); }
bool add_range (hb_codepoint_t a, hb_codepoint_t b)
{ return unlikely (inverted) ? ((void) s.del_range (a, b), true) : s.add_range (a, b); }
+18
View File
@@ -161,6 +161,14 @@ struct hb_bit_set_t
page_t *page = page_for (g, true); if (unlikely (!page)) return;
page->add (g);
}
void add_bits (hb_codepoint_t g, uint64_t bits)
{
if (unlikely (!successful) || unlikely (!bits)) return;
assert (!(g & (page_t::ELT_BITS - 1)));
dirty ();
page_t *page = page_for (g, true); if (unlikely (!page)) return;
page->add_bits (g, bits);
}
bool add_range (hb_codepoint_t a, hb_codepoint_t b)
{
if (unlikely (!successful)) return true; /* https://github.com/harfbuzz/harfbuzz/issues/657 */
@@ -291,6 +299,16 @@ struct hb_bit_set_t
dirty ();
page->del (g);
}
void del_bits (hb_codepoint_t g, uint64_t bits)
{
if (unlikely (!successful) || unlikely (!bits)) return;
assert (!(g & (page_t::ELT_BITS - 1)));
page_t *page = page_for (g);
if (!page)
return;
dirty ();
page->del_bits (g, bits);
}
private:
void del_pages (int ds, int de)
+1
View File
@@ -87,6 +87,7 @@ struct hb_sparseset_t
uint32_t hash () const { return s.hash (); }
void add (hb_codepoint_t g) { s.add (g); }
void add_bits (hb_codepoint_t g, uint64_t bits) { s.add_bits (g, bits); }
bool add_range (hb_codepoint_t first, hb_codepoint_t last) { return s.add_range (first, last); }
template <typename T>
+14
View File
@@ -178,6 +178,20 @@ main (int argc, char **argv)
hb_always_assert (!s.get_singleton (&singleton));
}
/* Test word-at-a-time insertion. */
{
hb_set_t s;
s.add_bits (64, uint64_t (1) | (uint64_t (1) << 63));
hb_always_assert (s.get_population () == 2);
hb_always_assert (s.has (64));
hb_always_assert (s.has (127));
s.invert ();
s.add_bits (64, uint64_t (1) | (uint64_t (1) << 63));
hb_always_assert (s.has (64));
hb_always_assert (s.has (127));
}
/* Adding HB_SET_VALUE_INVALID */
{
hb_set_t s;