feat(CAPI): API to get the width of an eint/esint

This commit is contained in:
youben11
2022-11-15 19:02:13 +01:00
committed by Ayoub Benaissa
parent 5576d1d176
commit 5b46a74b7f
2 changed files with 19 additions and 0 deletions

View File

@@ -36,6 +36,12 @@ fheEncryptedSignedIntegerTypeGetChecked(MlirContext context, unsigned width);
/// If the type is an EncryptedSignedInteger
MLIR_CAPI_EXPORTED bool fheTypeIsAnEncryptedSignedIntegerType(MlirType);
/// \brief Get bitwidth of the encrypted integer type.
///
/// \return bitwidth of the encrypted integer or 0 if it's not an encrypted
/// integer
MLIR_CAPI_EXPORTED unsigned fheTypeIntegerWidthGet(MlirType);
#ifdef __cplusplus
}
#endif

View File

@@ -61,3 +61,16 @@ MlirTypeOrError fheEncryptedSignedIntegerTypeGetChecked(MlirContext ctx,
unsigned width) {
return IntegerTypeGetChecked<EncryptedSignedIntegerType>(ctx, width);
}
unsigned fheTypeIntegerWidthGet(MlirType integerType) {
mlir::Type type = unwrap(integerType);
auto eint = type.dyn_cast_or_null<EncryptedIntegerType>();
if (eint) {
return eint.getWidth();
}
auto esint = type.dyn_cast_or_null<EncryptedSignedIntegerType>();
if (esint) {
return esint.getWidth();
}
return 0;
}