feat(compiler): Add HLFHE.sub_int_eint (#54)

This commit is contained in:
Quentin Bourgerie
2021-07-19 11:41:14 +02:00
parent 143a2384fd
commit ed40b1ef91
5 changed files with 49 additions and 4 deletions

View File

@@ -48,6 +48,15 @@ def AddEintOp : HLFHE_Op<"add_eint"> {
}];
}
def SubIntEintOp : HLFHE_Op<"sub_int_eint"> {
let arguments = (ins AnyInteger:$a, EncryptedIntegerType:$b);
let results = (outs EncryptedIntegerType);
let verifier = [{
return ::mlir::zamalang::HLFHE::verifySubIntEintOp(*this);
}];
}
def MulEintIntOp : HLFHE_Op<"mul_eint_int"> {
let arguments = (ins EncryptedIntegerType:$a, AnyInteger:$b);
let results = (outs EncryptedIntegerType);

View File

@@ -8,10 +8,6 @@ namespace mlir {
namespace zamalang {
namespace HLFHE {
using mlir::zamalang::HLFHE::AddEintOp;
using mlir::zamalang::HLFHE::ApplyLookupTable;
using mlir::zamalang::HLFHE::EncryptedIntegerType;
bool verifyEncryptedIntegerInputAndResultConsistency(
::mlir::OpState &op, EncryptedIntegerType &input,
EncryptedIntegerType &result) {
@@ -70,6 +66,19 @@ bool verifyEncryptedIntegerInputsConsistency(::mlir::OpState &op,
return ::mlir::success();
}
::mlir::LogicalResult verifySubIntEintOp(SubIntEintOp &op) {
auto a = op.a().getType().cast<IntegerType>();
auto b = op.b().getType().cast<EncryptedIntegerType>();
auto out = op.getResult().getType().cast<EncryptedIntegerType>();
if (!verifyEncryptedIntegerInputAndResultConsistency(op, b, out)) {
return ::mlir::failure();
}
if (!verifyEncryptedIntegerAndIntegerInputsConsistency(op, b, a)) {
return ::mlir::failure();
}
return ::mlir::success();
}
::mlir::LogicalResult verifyMulEintIntOp(MulEintIntOp &op) {
auto a = op.a().getType().cast<EncryptedIntegerType>();
auto b = op.b().getType().cast<IntegerType>();

View File

@@ -0,0 +1,8 @@
// RUN: not zamacompiler %s 2>&1| FileCheck %s
// CHECK-LABEL: error: 'HLFHE.sub_int_eint' op should have the width of plain input equals to width of encrypted input + 1
func @sub_int_eint(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<2> {
%0 = constant 1 : i4
%1 = "HLFHE.sub_int_eint"(%0, %arg0): (i4, !HLFHE.eint<2>) -> (!HLFHE.eint<2>)
return %1: !HLFHE.eint<2>
}

View File

@@ -0,0 +1,8 @@
// RUN: not zamacompiler %s 2>&1| FileCheck %s
// CHECK-LABEL: error: 'HLFHE.sub_int_eint' op should have the width of encrypted inputs and result equals
func @sub_int_eint(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<3> {
%0 = constant 1 : i2
%1 = "HLFHE.sub_int_eint"(%0, %arg0): (i2, !HLFHE.eint<2>) -> (!HLFHE.eint<3>)
return %1: !HLFHE.eint<3>
}

View File

@@ -11,6 +11,17 @@ func @add_eint_int(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<2> {
return %1: !HLFHE.eint<2>
}
// CHECK-LABEL: func @sub_int_eint(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<2>
func @sub_int_eint(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<2> {
// CHECK-NEXT: %[[V1:.*]] = constant 1 : i3
// CHECK-NEXT: %[[V2:.*]] = "HLFHE.sub_int_eint"(%[[V1]], %arg0) : (i3, !HLFHE.eint<2>) -> !HLFHE.eint<2>
// CHECK-NEXT: return %[[V2]] : !HLFHE.eint<2>
%0 = constant 1 : i3
%1 = "HLFHE.sub_int_eint"(%0, %arg0): (i3, !HLFHE.eint<2>) -> (!HLFHE.eint<2>)
return %1: !HLFHE.eint<2>
}
// CHECK-LABEL: func @mul_eint_int(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<2>
func @mul_eint_int(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<2> {
// CHECK-NEXT: %[[V1:.*]] = constant 1 : i3