mirror of
https://github.com/zama-ai/concrete.git
synced 2026-02-09 03:55:04 -05:00
feat(compiler): Add HLFHE.sub_int_eint (#54)
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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>();
|
||||
|
||||
@@ -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>
|
||||
}
|
||||
@@ -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>
|
||||
}
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user