mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-09 03:55:04 -05:00
feat(compiler): add HLFHE.neg_eint op
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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>();
|
||||
|
||||
7
compiler/tests/Dialect/HLFHE/op_neg_eint_err_result.mlir
Normal file
7
compiler/tests/Dialect/HLFHE/op_neg_eint_err_result.mlir
Normal 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>
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user