mirror of
https://github.com/pseXperiments/icicle.git
synced 2026-01-06 22:24:06 -05:00
feat: add num_bits() function (#570)
## Describe the changes
adding a `num_bits()` function similar to
dcf73a5f96/ff/src/biginteger/mod.rs (L482)
this could be useful for small field optimizations
## Linked Issues
Resolves #
This commit is contained in:
@@ -124,6 +124,19 @@ public:
|
||||
*/
|
||||
static constexpr HOST_DEVICE_INLINE unsigned num_of_reductions() { return CONFIG::num_of_reductions; }
|
||||
|
||||
// count number of bits of the field element without leading zeros.
|
||||
static constexpr HOST_DEVICE_INLINE unsigned num_bits(const Field& x)
|
||||
{
|
||||
size_t size = sizeof(x.limbs_storage.limbs[0]) * 8;
|
||||
unsigned ret = size * TLC;
|
||||
for (unsigned i = TLC; i-- > 0;) {
|
||||
int leading = __clz(x.limbs_storage.limbs[i]);
|
||||
ret -= leading;
|
||||
if (leading != size) { break; }
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static constexpr unsigned slack_bits = 32 * TLC - NBITS;
|
||||
|
||||
struct Wide {
|
||||
|
||||
Reference in New Issue
Block a user