Skip to content

Commit

Permalink
docs: Update benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
sp301415 committed Dec 13, 2023
1 parent 20b3a5b commit a1b0e79
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 25 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ fmt.Println(enc.DecryptLWEBool(ctOut)) // true
All results were measured from Intel i5-13400F. `ParamsBoolean` and `ParamsUint6` were used.
|Operation|Time|
|---------|-------|
|Programmable Bootstrapping|81.73ms ± 0%|
|Gate Bootstrapping|11.15ms ± 1%|
|Programmable Bootstrapping|74.68ms ± 0%|
|Gate Bootstrapping|10.71ms ± 1%|

## References
- TFHE: Fast Fully Homomorphic Encryption over the Torus (https://eprint.iacr.org/2018/421)
Expand Down
4 changes: 2 additions & 2 deletions tfhe/asm_bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/sp301415/tfhe-go/math/poly"
)

// monomialMulSubAddAssign multiplies X^(-d) - 1 to p0, and adds it to pOut.
// monomialMulSubAddAssign multiplies X^d - 1 to p0, and adds it to pOut.
//
// d is assumed to be in [-2N, 0]. p0 and pOut should not overlap.
func monomialMulSubAddAssign[T Tint](p0 poly.Poly[T], d int, pOut poly.Poly[T]) {
Expand All @@ -28,7 +28,7 @@ func monomialMulSubAddAssign[T Tint](p0 poly.Poly[T], d int, pOut poly.Poly[T])
}
}

// monomialMulSubAssign multiplies X^(-d) - 1 to p0, and writes it to pOut.
// monomialMulSubAssign multiplies X^d - 1 to p0, and writes it to pOut.
//
// d is assumed to be in [-2N, 0]. p0 and pOut should not overlap.
func monomialMulSubAssign[T Tint](p0 poly.Poly[T], d int, pOut poly.Poly[T]) {
Expand Down
26 changes: 5 additions & 21 deletions tfhe/asm_bootstrap_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,10 @@ func monomialMulSubAddAssign[T Tint](p0 poly.Poly[T], d int, pOut poly.Poly[T])
var z T
switch any(z).(type) {
case uint32:
monomialMulSubAddAssignUint32AVX2(
*(*[]uint32)(unsafe.Pointer(&p0)),
d,
*(*[]uint32)(unsafe.Pointer(&pOut)),
)
monomialMulSubAddAssignUint32AVX2(*(*[]uint32)(unsafe.Pointer(&p0)), d, *(*[]uint32)(unsafe.Pointer(&pOut)))

case uint64:
monomialMulSubAddAssignUint64AVX2(
*(*[]uint64)(unsafe.Pointer(&p0)),
d,
*(*[]uint64)(unsafe.Pointer(&pOut)),
)
monomialMulSubAddAssignUint64AVX2(*(*[]uint64)(unsafe.Pointer(&p0)), d, *(*[]uint64)(unsafe.Pointer(&pOut)))
}
return
}
Expand All @@ -57,26 +49,18 @@ func monomialMulSubAddAssign[T Tint](p0 poly.Poly[T], d int, pOut poly.Poly[T])
func monomialMulSubAssignUint32AVX2(p0 []uint32, d int, pOut []uint32)
func monomialMulSubAssignUint64AVX2(p0 []uint64, d int, pOut []uint64)

// monomialMulSubAssign multiplies X^(-d) - 1 to p0, and writes it to pOut.
// monomialMulSubAssign multiplies X^d - 1 to p0, and writes it to pOut.
//
// d is assumed to be in [-2N, 0]. p0 and pOut should not overlap.
func monomialMulSubAssign[T Tint](p0 poly.Poly[T], d int, pOut poly.Poly[T]) {
if cpu.X86.HasAVX2 {
var z T
switch any(z).(type) {
case uint32:
monomialMulSubAssignUint32AVX2(
*(*[]uint32)(unsafe.Pointer(&p0)),
d,
*(*[]uint32)(unsafe.Pointer(&pOut)),
)
monomialMulSubAssignUint32AVX2(*(*[]uint32)(unsafe.Pointer(&p0)), d, *(*[]uint32)(unsafe.Pointer(&pOut)))

case uint64:
monomialMulSubAssignUint64AVX2(
*(*[]uint64)(unsafe.Pointer(&p0)),
d,
*(*[]uint64)(unsafe.Pointer(&pOut)),
)
monomialMulSubAssignUint64AVX2(*(*[]uint64)(unsafe.Pointer(&p0)), d, *(*[]uint64)(unsafe.Pointer(&pOut)))
}
return
}
Expand Down

0 comments on commit a1b0e79

Please sign in to comment.