sharded-slab icon indicating copy to clipboard operation
sharded-slab copied to clipboard

feat: Make use of the last bit in Tid

Open ldm0 opened this issue 11 months ago • 2 comments

Previously Tid::LEN was set to MAX_SHARDS.trailing_zeros() + 1, and MAX_SHARDS was set to next_pow2(Self::MAX_THREADS - 1), which leads to several odd conbinations:


MAX_THREADS=128
MAX_SHARDS=128
Tid::LEN=8

7 bit is enough to encode 128 threads, as the thread id starts from 0 and ends with Tid::BITS, which makes the extra one bit redundant(I can't find the usage of it).


MAX_THREADS=129
MAX_SHARDS=128
Tid::LEN=8

As shards are indexed by Tid, number of shards shouldn't be less than number of threads.


Therefore, I changed the implementation:

  • Tid::LEN now equals to MAX_SHARDS.trailing_zeros()
  • MAX_SHARDS now equals to next_pow2(Self::MAX_THREADS)
  • DefaultConfig::MAX_THREADS were doubled leveraging the released bit

ldm0 avatar Jan 03 '25 07:01 ldm0