Skip to content

Instantly share code, notes, and snippets.

@j2kun

j2kun/test.mlir Secret

Created November 12, 2024 04:52
Show Gist options
  • Save j2kun/6f5256624426eb16112c0d70ac81a4fd to your computer and use it in GitHub Desktop.
Save j2kun/6f5256624426eb16112c0d70ac81a4fd to your computer and use it in GitHub Desktop.
module {
func.func @sum(%arg0: !secret.secret<memref<8xi8>>) -> !secret.secret<i8> {
%true = arith.constant true
%c7 = arith.constant 7 : index
%c6 = arith.constant 6 : index
%c5 = arith.constant 5 : index
%c4 = arith.constant 4 : index
%c3 = arith.constant 3 : index
%c24 = arith.constant 24 : index
%c16 = arith.constant 16 : index
%c2 = arith.constant 2 : index
%c1 = arith.constant 1 : index
%c0 = arith.constant 0 : index
%c0_i8 = arith.constant 0 : i8
%0 = secret.conceal %c0_i8 : i8 -> <i8>
%1 = affine.for %arg1 = 0 to 8 iter_args(%arg2 = %0) -> (!secret.secret<i8>) {
%2 = secret.cast %arg0 : !secret.secret<memref<8xi8>> to !secret.secret<memref<64xi1>>
%3 = secret.generic ins(%2 : !secret.secret<memref<64xi1>>) {
^bb0(%arg3: memref<64xi1>):
%8 = memref.load %arg3[%c16] : memref<64xi1>
secret.yield %8 : i1
} -> !secret.secret<i1>
%4 = secret.generic ins(%2 : !secret.secret<memref<64xi1>>) {
^bb0(%arg3: memref<64xi1>):
%8 = memref.load %arg3[%c24] : memref<64xi1>
secret.yield %8 : i1
} -> !secret.secret<i1>
%5 = secret.generic ins(%3, %4 : !secret.secret<i1>, !secret.secret<i1>) {
^bb0(%arg3: i1, %arg4: i1):
%8 = comb.truth_table %true, %arg3, %arg4 -> 83 : ui8
secret.yield %8 : i1
} -> !secret.secret<i1>
%6 = secret.generic {
%alloc = memref.alloc() : memref<8xi1>
secret.yield %alloc : memref<8xi1>
} -> !secret.secret<memref<8xi1>>
secret.generic ins(%5, %6 : !secret.secret<i1>, !secret.secret<memref<8xi1>>) {
^bb0(%arg3: i1, %arg4: memref<8xi1>):
memref.store %arg3, %arg4[%c0] : memref<8xi1>
secret.yield
}
secret.generic ins(%5, %6 : !secret.secret<i1>, !secret.secret<memref<8xi1>>) {
^bb0(%arg3: i1, %arg4: memref<8xi1>):
memref.store %arg3, %arg4[%c1] : memref<8xi1>
secret.yield
}
secret.generic ins(%5, %6 : !secret.secret<i1>, !secret.secret<memref<8xi1>>) {
^bb0(%arg3: i1, %arg4: memref<8xi1>):
memref.store %arg3, %arg4[%c2] : memref<8xi1>
secret.yield
}
secret.generic ins(%5, %6 : !secret.secret<i1>, !secret.secret<memref<8xi1>>) {
^bb0(%arg3: i1, %arg4: memref<8xi1>):
memref.store %arg3, %arg4[%c3] : memref<8xi1>
secret.yield
}
secret.generic ins(%5, %6 : !secret.secret<i1>, !secret.secret<memref<8xi1>>) {
^bb0(%arg3: i1, %arg4: memref<8xi1>):
memref.store %arg3, %arg4[%c4] : memref<8xi1>
secret.yield
}
secret.generic ins(%5, %6 : !secret.secret<i1>, !secret.secret<memref<8xi1>>) {
^bb0(%arg3: i1, %arg4: memref<8xi1>):
memref.store %arg3, %arg4[%c5] : memref<8xi1>
secret.yield
}
secret.generic ins(%5, %6 : !secret.secret<i1>, !secret.secret<memref<8xi1>>) {
^bb0(%arg3: i1, %arg4: memref<8xi1>):
memref.store %arg3, %arg4[%c6] : memref<8xi1>
secret.yield
}
secret.generic ins(%5, %6 : !secret.secret<i1>, !secret.secret<memref<8xi1>>) {
^bb0(%arg3: i1, %arg4: memref<8xi1>):
memref.store %arg3, %arg4[%c7] : memref<8xi1>
secret.yield
}
%7 = secret.cast %6 : !secret.secret<memref<8xi1>> to !secret.secret<i8>
affine.yield %7 : !secret.secret<i8>
}
return %1 : !secret.secret<i8>
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment