feat(compiler): add HLFHE.neg_eint op

This commit is contained in:
youben11
2021-11-08 12:20:39 +01:00
committed by Ayoub Benaissa
parent 47cb4b0e70
commit cc4e403e7a
4 changed files with 40 additions and 0 deletions

View File

@@ -69,6 +69,21 @@ def SubIntEintOp : HLFHE_Op<"sub_int_eint"> {
}];
}
def NegEintOp : HLFHE_Op<"neg_eint"> {
let arguments = (ins EncryptedIntegerType:$a);
let results = (outs EncryptedIntegerType);
let builders = [
OpBuilder<(ins "Value":$a), [{
build($_builder, $_state, a.getType(), a);
}]>
];
let verifier = [{
return ::mlir::zamalang::HLFHE::verifyNegEintOp(*this);
}];
}
def MulEintIntOp : HLFHE_Op<"mul_eint_int"> {
let arguments = (ins EncryptedIntegerType:$a, AnyInteger:$b);
let results = (outs EncryptedIntegerType);

View File

@@ -79,6 +79,15 @@ bool verifyEncryptedIntegerInputsConsistency(::mlir::OpState &op,
return ::mlir::success();
}
::mlir::LogicalResult verifyNegEintOp(NegEintOp &op) {
auto a = op.a().getType().cast<EncryptedIntegerType>();
auto out = op.getResult().getType().cast<EncryptedIntegerType>();
if (!verifyEncryptedIntegerInputAndResultConsistency(op, a, out)) {
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,7 @@
// RUN: not zamacompiler --action=roundtrip %s 2>&1| FileCheck %s
// CHECK-LABEL: error: 'HLFHE.neg_eint' op should have the width of encrypted inputs and result equals
func @sub_int_eint(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<3> {
%1 = "HLFHE.neg_eint"(%arg0): (!HLFHE.eint<2>) -> (!HLFHE.eint<3>)
return %1: !HLFHE.eint<3>
}

View File

@@ -31,6 +31,15 @@ func @sub_int_eint(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<2> {
return %1: !HLFHE.eint<2>
}
// CHECK-LABEL: func @neg_eint(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<2>
func @neg_eint(%arg0: !HLFHE.eint<2>) -> !HLFHE.eint<2> {
// CHECK-NEXT: %[[V1:.*]] = "HLFHE.neg_eint"(%arg0) : (!HLFHE.eint<2>) -> !HLFHE.eint<2>
// CHECK-NEXT: return %[[V1]] : !HLFHE.eint<2>
%1 = "HLFHE.neg_eint"(%arg0): (!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:.*]] = arith.constant 1 : i3