Bitwise Operations
Chunked
# (example below is for bit-width of 8 and chunk size of 4)
# extract chunks of lhs using table lookups
lhs_chunks = [lhs.bits[0:4], lhs.bits[4:8]]
# extract chunks of rhs using table lookups
rhs_chunks = [rhs.bits[0:4], rhs.bits[4:8]]
# pack chunks of lhs and rhs using clear multiplications and additions
packed_chunks = []
for lhs_chunk, rhs_chunk in zip(lhs_chunks, rhs_chunks):
shifted_lhs_chunk = lhs_chunk * 2**4 # (i.e., lhs_chunk << 4)
packed_chunks.append(shifted_lhs_chunk + rhs_chunk)
# apply comparison table lookup to packed chunks
bitwise_table = fhe.LookupTable([...])
result_chunks = bitwise_table[packed_chunks]
# sum resulting chunks obtain the result
result = np.sum(result_chunks)Notes
Pros
Cons
Example
Packing Trick
Requirements
1. fhe.BitwiseStrategy.ONE_TLU_PROMOTED
Pros
Cons
Example
2. fhe.BitwiseStrategy.THREE_TLU_CASTED
Notes
Pros
Cons
Example
3. fhe.BitwiseStrategy.TWO_TLU_BIGGER_PROMOTED_SMALLER_CASTED
Notes
Pros
Cons
Example
4. fhe.BitwiseStrategy.TWO_TLU_BIGGER_CASTED_SMALLER_PROMOTED
Notes
Pros
Cons
Example
Summary
Strategy
Minimum # of TLUs
Maximum # of TLUs
Can increase the bit-width of the inputs
Shifts
With promotion
With casting
Last updated
Was this helpful?