Comparisons
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
comparison_table = fhe.LookupTable([...])
chunk_comparisons = comparison_table[packed_chunks]
# reduce chunk comparisons to comparison of numbers
result = chunk_comparisons[0]
for chunk_comparison in chunk_comparisons[1:]:
chunk_reduction_table = fhe.LookupTable([...])
shifted_chunk_comparison= chunk_comparison * 2**2 # (i.e., lhs_chunk << 2)
result = chunk_reduction_table[result + shifted_chunk_comparison]Notes
Pros
Cons
Example
Subtraction Trick
Requirements
1. fhe.ComparisonStrategy.ONE_TLU_PROMOTED
Pros
Cons
Example
2. fhe.ComparisonStrategy.THREE_TLU_CASTED
Notes
Pros
Cons
Example
3. fhe.ComparisonStrategy.TWO_TLU_BIGGER_PROMOTED_SMALLER_CASTED
Notes
Pros
Cons
Example
4. fhe.ComparisonStrategy.TWO_TLU_BIGGER_CASTED_SMALLER_PROMOTED
Notes
Pros
Cons
Example
Clipping Trick
Requirements
1. fhe.ComparisonStrategy.THREE_TLU_BIGGER_CLIPPED_SMALLER_CASTED
Notes
Pros
Cons
Example
2. fhe.ComparisonStrategy.TWO_TLU_BIGGER_CLIPPED_SMALLER_PROMOTED
Pros
Cons
Example
Summary
Strategy
Minimum # of TLUs
Maximum # of TLUs
Can increase the bit-width of the inputs
Last updated
Was this helpful?