From 879675451360f780f0d84a79102c86ba7146c534 Mon Sep 17 00:00:00 2001 From: Quentin Bourgerie Date: Fri, 13 Aug 2021 15:54:08 +0200 Subject: [PATCH] fix(compiler/lowlfhe): Fix wrong shift value for EncodeIntOp lowering That's work before because we enfoce 6 as global constraint while our runJit tests are on 7 bits --- .../LowLFHEToConcreteCAPI/LowLFHEToConcreteCAPI.cpp | 3 +-- compiler/lib/Support/CompilerTools.cpp | 2 +- compiler/lib/Support/V0Parameters.cpp | 2 +- compiler/tests/RunJit/hlfhe_sub_int_eint.mlir | 6 +++--- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/compiler/lib/Conversion/LowLFHEToConcreteCAPI/LowLFHEToConcreteCAPI.cpp b/compiler/lib/Conversion/LowLFHEToConcreteCAPI/LowLFHEToConcreteCAPI.cpp index b7ca84ce3..21eaa913c 100644 --- a/compiler/lib/Conversion/LowLFHEToConcreteCAPI/LowLFHEToConcreteCAPI.cpp +++ b/compiler/lib/Conversion/LowLFHEToConcreteCAPI/LowLFHEToConcreteCAPI.cpp @@ -149,8 +149,7 @@ struct LowLFHEEncodeIntOpPattern mlir::Value castedInt = rewriter.create( op.getLoc(), rewriter.getIntegerType(64), op->getOperands().front()); mlir::Value constantShiftOp = rewriter.create( - op.getLoc(), - rewriter.getI64IntegerAttr(64 - (op.getType().getP() - 1))); + op.getLoc(), rewriter.getI64IntegerAttr(64 - op.getType().getP())); mlir::Type resultType = rewriter.getIntegerType(64); rewriter.replaceOpWithNewOp(op, resultType, castedInt, diff --git a/compiler/lib/Support/CompilerTools.cpp b/compiler/lib/Support/CompilerTools.cpp index ae70d0a86..d6617cc9f 100644 --- a/compiler/lib/Support/CompilerTools.cpp +++ b/compiler/lib/Support/CompilerTools.cpp @@ -9,7 +9,7 @@ namespace mlir { namespace zamalang { // This is temporary while we doesn't yet have the high-level verification pass -FHECircuitConstraint defaultGlobalFHECircuitConstraint{.norm2 = 20, .p = 6}; +FHECircuitConstraint defaultGlobalFHECircuitConstraint{.norm2 = 10, .p = 7}; void initLLVMNativeTarget() { // Initialize LLVM targets. diff --git a/compiler/lib/Support/V0Parameters.cpp b/compiler/lib/Support/V0Parameters.cpp index d0e1ce089..2973bc231 100644 --- a/compiler/lib/Support/V0Parameters.cpp +++ b/compiler/lib/Support/V0Parameters.cpp @@ -119,7 +119,7 @@ V0Parameter *getV0Parameter(size_t norm, size_t p) { if (norm > NORM2_MAX) { return nullptr; } - if (p >= P_MAX) { + if (p > P_MAX) { return nullptr; } // - 1 is an offset as norm and p are in [1, ...] and not [0, ...] diff --git a/compiler/tests/RunJit/hlfhe_sub_int_eint.mlir b/compiler/tests/RunJit/hlfhe_sub_int_eint.mlir index d32834522..0a273f651 100644 --- a/compiler/tests/RunJit/hlfhe_sub_int_eint.mlir +++ b/compiler/tests/RunJit/hlfhe_sub_int_eint.mlir @@ -1,8 +1,8 @@ -// RUN: zamacompiler %s --run-jit --jit-args 2 2>&1| FileCheck %s +// RUN: zamacompiler %s --run-jit --jit-args 3 2>&1| FileCheck %s -// CHECK-LABEL: 3 +// CHECK-LABEL: 42 func @main(%arg0: !HLFHE.eint<7>) -> !HLFHE.eint<7> { - %0 = constant 1 : i8 + %0 = constant 45 : i8 %1 = "HLFHE.sub_int_eint"(%0, %arg0): (i8, !HLFHE.eint<7>) -> (!HLFHE.eint<7>) return %1: !HLFHE.eint<7> } \ No newline at end of file