Division in Assembly
12/12/2025
HTTP/3 specification reserves a range of identifiers for streams and frame types. The range as 0x1f * N + 0x21 for non-negative integer values of N.
A received identifier should be validated against the reserved range. This involves subtrackting 33 and then validating if the result is a multiple of 31. The number 31 holds special importance in this context as it is represented by 2N - 1, or 0x0001_1111. This property influences the approaches used for validation.
Several strategies were considered to verify whether a value is a multiple of 31:
bit manipulation (summing every 5 bits) value to check if the sum is a multiple of 31.
lookup table
using divrem
Input % 31 == 0using integer division and multiplication
(Input / 31) * 31 == Inputmultiplication and bit shifting (divide by 2).