mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-09 03:55:04 -05:00
refactor(compiler): Move ceilLog2 to separate header file
This commit is contained in:
committed by
Quentin Bourgerie
parent
1200a46e49
commit
5ce3fd5f43
20
compiler/include/zamalang/Support/math.h
Normal file
20
compiler/include/zamalang/Support/math.h
Normal file
@@ -0,0 +1,20 @@
|
||||
#ifndef ZAMALANG_SUPPORT_MATH_H_
|
||||
#define ZAMALANG_SUPPORT_MATH_H_
|
||||
|
||||
// Calculates (T)ceil(log2f(v))
|
||||
// TODO: Replace with some fancy bit twiddling hack
|
||||
template <typename T> static T ceilLog2(const T v) {
|
||||
T tmp = v;
|
||||
T log2 = 0;
|
||||
|
||||
while (tmp >>= 1)
|
||||
log2++;
|
||||
|
||||
// If more than MSB set, round to next highest power of 2
|
||||
if (v & ~((T)1 << log2))
|
||||
log2 += 1;
|
||||
|
||||
return log2;
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -3,6 +3,7 @@
|
||||
#include <zamalang/Dialect/HLFHE/IR/HLFHEDialect.h>
|
||||
#include <zamalang/Dialect/HLFHE/IR/HLFHEOps.h>
|
||||
#include <zamalang/Dialect/HLFHE/IR/HLFHETypes.h>
|
||||
#include <zamalang/Support/math.h>
|
||||
|
||||
#include <limits>
|
||||
#include <llvm/ADT/APInt.h>
|
||||
@@ -183,22 +184,6 @@ static llvm::APInt denseCstTensorNorm2Sq(mlir::ConstantOp cstOp) {
|
||||
return accu;
|
||||
}
|
||||
|
||||
// Calculates (T)ceil(log2f(v))
|
||||
// TODO: Replace with some fancy bit twiddling hack
|
||||
template <typename T> static T ceilLog2(const T v) {
|
||||
T tmp = v;
|
||||
T log2 = 0;
|
||||
|
||||
while (tmp >>= 1)
|
||||
log2++;
|
||||
|
||||
// If more than MSB set, round to next highest power of 2
|
||||
if (v & ~((T)1 << log2))
|
||||
log2 += 1;
|
||||
|
||||
return log2;
|
||||
}
|
||||
|
||||
// Calculates the square of the 2-norm of a 1D tensor of signless
|
||||
// integers by conservatively assuming that the dynamic values are the
|
||||
// maximum for the integer width. Aborts if the tensor type `tTy` is
|
||||
|
||||
Reference in New Issue
Block a user