-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Asra <asraa@google.com>
- Loading branch information
Showing
4 changed files
with
220 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
// RUN: heir-opt --comb-to-cggi -cse %s | FileCheck %s | ||
|
||
// TODO(https://github.com/google/heir/issues/244): The Yosys optimizer pass | ||
// still needs functionality to split multi-bit inputs and outputs, this test | ||
// was generated by manually performing the splitting on the output of | ||
// tests/yosys_optimizer/add_one.mlir. | ||
|
||
module { | ||
// This function computes add_one to an i8 input split into bits and returns | ||
// the resulting i8 split into bits. | ||
// CHECK-LABEL: add_one | ||
// CHECK-NOT: secret | ||
func.func @add_one(%arg00: !secret.secret<i1>, %arg01: !secret.secret<i1>, %arg02: !secret.secret<i1>, %arg03: !secret.secret<i1>, %arg04: !secret.secret<i1>, %arg05: !secret.secret<i1>, %arg06: !secret.secret<i1>, %arg07: !secret.secret<i1>) -> (!secret.secret<i1>, !secret.secret<i1>, !secret.secret<i1>, !secret.secret<i1>, !secret.secret<i1>, !secret.secret<i1>, !secret.secret<i1>, !secret.secret<i1>) { | ||
// CHECK: [[FALSE:%.+]] = arith.constant false | ||
// CHECK: [[ENCFALSE:%.+]] = lwe.encode [[FALSE]] | ||
// CHECK: [[LWEFALSE:%.+]] = lwe.trivial_encrypt [[ENCFALSE]] | ||
// CHECK-COUNT-11: cggi.lut3 | ||
%false = arith.constant false | ||
%0:8 = secret.generic | ||
ins(%false, %arg00, %arg01, %arg02, %arg03, %arg04, %arg05, %arg06, %arg07 : i1, !secret.secret<i1>, !secret.secret<i1>, !secret.secret<i1>, !secret.secret<i1>, !secret.secret<i1>, !secret.secret<i1>, !secret.secret<i1>, !secret.secret<i1>) { | ||
^bb0(%FALSE : i1, %ARG00: i1, %ARG01: i1, %ARG02: i1, %ARG03: i1, %ARG04: i1, %ARG05: i1, %ARG06: i1, %ARG07: i1) : | ||
%2 = comb.truth_table %ARG00, %ARG01, %FALSE -> 6 : ui8 | ||
%3 = comb.truth_table %ARG00, %FALSE, %FALSE -> 1 : ui8 | ||
%5 = comb.truth_table %ARG00, %ARG01, %ARG02 -> 120 : ui8 | ||
%6 = comb.truth_table %ARG00, %ARG01, %ARG02 -> 128 : ui8 | ||
%8 = comb.truth_table %6, %ARG03, %FALSE -> 6 : ui8 | ||
%10 = comb.truth_table %6, %ARG03, %ARG04 -> 120 : ui8 | ||
%11 = comb.truth_table %6, %ARG03, %ARG04 -> 128 : ui8 | ||
%13 = comb.truth_table %11, %ARG05, %FALSE -> 6 : ui8 | ||
%15 = comb.truth_table %11, %ARG05, %ARG06 -> 120 : ui8 | ||
%16 = comb.truth_table %11, %ARG05, %ARG06 -> 128 : ui8 | ||
%18 = comb.truth_table %16, %ARG07, %FALSE -> 6 : ui8 | ||
secret.yield %18, %15, %13, %10, %8, %5, %2, %3 : i1, i1, i1, i1, i1, i1, i1, i1 | ||
} -> (!secret.secret<i1>, !secret.secret<i1>, !secret.secret<i1>, !secret.secret<i1>, !secret.secret<i1>, !secret.secret<i1>, !secret.secret<i1>, !secret.secret<i1>) | ||
// CHECK: return | ||
func.return %0#0, %0#1, %0#2, %0#3, %0#4, %0#5, %0#6, %0#7 : !secret.secret<i1>, !secret.secret<i1>, !secret.secret<i1>, !secret.secret<i1>, !secret.secret<i1>, !secret.secret<i1>, !secret.secret<i1>, !secret.secret<i1> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// RUN: heir-opt --comb-to-cggi %s | FileCheck %s | ||
|
||
module { | ||
// CHECK-NOT: secret | ||
// CHECK: @truth_table([[ARG:%.*]]: [[LWET:!lwe.lwe_ciphertext<.*>]]) -> [[LWET]] | ||
func.func @truth_table(%arg0: !secret.secret<i1>) -> !secret.secret<i1> { | ||
%0 = secret.generic | ||
ins(%arg0 : !secret.secret<i1>) { | ||
^bb0(%ARG0: i1) : | ||
secret.yield %ARG0 : i1 | ||
} -> (!secret.secret<i1>) | ||
// CHECK: return [[ARG]] : [[LWET]] | ||
func.return %0 : !secret.secret<i1> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// RUN: heir-opt --split-input-file --comb-to-cggi --cse %s | FileCheck %s | ||
|
||
// CHECK-NOT: secret | ||
// CHECK: @truth_table_all_secret([[ARG:%.*]]: [[LWET:!lwe.lwe_ciphertext<.*>]]) -> [[LWET]] | ||
func.func @truth_table_all_secret(%arg0: !secret.secret<i1>) -> !secret.secret<i1> { | ||
// CHECK: [[VAL:%.+]] = cggi.lut3([[ARG]], [[ARG]], [[ARG]]) | ||
%0 = secret.generic | ||
ins(%arg0: !secret.secret<i1>) { | ||
^bb0(%ARG0: i1) : | ||
%1 = comb.truth_table %ARG0, %ARG0, %ARG0 -> 6 : ui8 | ||
secret.yield %1 : i1 | ||
} -> (!secret.secret<i1>) | ||
// CHECK: return [[VAL]] : [[LWET]] | ||
func.return %0 : !secret.secret<i1> | ||
} | ||
|
||
// ----- | ||
|
||
// CHECK-NOT: secret | ||
// CHECK: @truth_table_partial_secret([[ARG:%.*]]: [[LWET:!lwe.lwe_ciphertext<.*>]]) -> [[LWET]] | ||
func.func @truth_table_partial_secret(%arg0: !secret.secret<i1>) -> !secret.secret<i1> { | ||
// CHECK: [[FALSE:%.+]] = arith.constant false | ||
%false = arith.constant false | ||
// CHECK: [[TRUE:%.+]] = arith.constant true | ||
%true = arith.constant true | ||
// CHECK: [[ENCFALSE:%.+]] = lwe.encode [[FALSE]] | ||
// CHECK: [[LWEFALSE:%.+]] = lwe.trivial_encrypt [[ENCFALSE]] | ||
// CHECK: [[ENCTRUE:%.+]] = lwe.encode [[TRUE]] | ||
// CHECK: [[LWETRUE:%.+]] = lwe.trivial_encrypt [[ENCTRUE]] | ||
// CHECK: [[VAL1:%.+]] = cggi.lut3([[LWEFALSE]], [[LWETRUE]], [[ARG]]) | ||
// CHECK: [[VAL2:%.+]] = cggi.lut3([[LWEFALSE]], [[LWETRUE]], [[VAL1]]) | ||
%0 = secret.generic | ||
ins(%false, %true, %arg0: i1, i1, !secret.secret<i1>) { | ||
^bb0(%FALSE: i1, %TRUE: i1, %ARG0: i1) : | ||
%1 = comb.truth_table %FALSE, %TRUE, %ARG0 -> 6 : ui8 | ||
%2 = comb.truth_table %FALSE, %TRUE, %1 -> 2 : ui8 | ||
secret.yield %2 : i1 | ||
} -> (!secret.secret<i1>) | ||
// CHECK: return [[VAL2]] : [[LWET]] | ||
func.return %0 : !secret.secret<i1> | ||
} |