description: max_eint_unsigned
program: |
  func.func @main(%arg0: !FHE.eint<4>, %arg1: !FHE.eint<4>) -> !FHE.eint<4> {
    %0 = "FHE.max_eint"(%arg0, %arg1) : (!FHE.eint<4>, !FHE.eint<4>) -> !FHE.eint<4>
    return %0 : !FHE.eint<4>
  }
tests:
  - inputs:
      - scalar: 0
      - scalar: 0
    outputs:
      - scalar: 0

  - inputs:
      - scalar: 0
      - scalar: 1
    outputs:
      - scalar: 1

  - inputs:
      - scalar: 0
      - scalar: 2
    outputs:
      - scalar: 2

  - inputs:
      - scalar: 0
      - scalar: 3
    outputs:
      - scalar: 3

  - inputs:
      - scalar: 0
      - scalar: 4
    outputs:
      - scalar: 4

  - inputs:
      - scalar: 0
      - scalar: 5
    outputs:
      - scalar: 5

  - inputs:
      - scalar: 0
      - scalar: 6
    outputs:
      - scalar: 6

  - inputs:
      - scalar: 0
      - scalar: 7
    outputs:
      - scalar: 7

  - inputs:
      - scalar: 1
      - scalar: 0
    outputs:
      - scalar: 1

  - inputs:
      - scalar: 1
      - scalar: 1
    outputs:
      - scalar: 1

  - inputs:
      - scalar: 1
      - scalar: 2
    outputs:
      - scalar: 2

  - inputs:
      - scalar: 1
      - scalar: 3
    outputs:
      - scalar: 3

  - inputs:
      - scalar: 1
      - scalar: 4
    outputs:
      - scalar: 4

  - inputs:
      - scalar: 1
      - scalar: 5
    outputs:
      - scalar: 5

  - inputs:
      - scalar: 1
      - scalar: 6
    outputs:
      - scalar: 6

  - inputs:
      - scalar: 1
      - scalar: 7
    outputs:
      - scalar: 7

  - inputs:
      - scalar: 2
      - scalar: 0
    outputs:
      - scalar: 2

  - inputs:
      - scalar: 2
      - scalar: 1
    outputs:
      - scalar: 2

  - inputs:
      - scalar: 2
      - scalar: 2
    outputs:
      - scalar: 2

  - inputs:
      - scalar: 2
      - scalar: 3
    outputs:
      - scalar: 3

  - inputs:
      - scalar: 2
      - scalar: 4
    outputs:
      - scalar: 4

  - inputs:
      - scalar: 2
      - scalar: 5
    outputs:
      - scalar: 5

  - inputs:
      - scalar: 2
      - scalar: 6
    outputs:
      - scalar: 6

  - inputs:
      - scalar: 2
      - scalar: 7
    outputs:
      - scalar: 7

  - inputs:
      - scalar: 3
      - scalar: 0
    outputs:
      - scalar: 3

  - inputs:
      - scalar: 3
      - scalar: 1
    outputs:
      - scalar: 3

  - inputs:
      - scalar: 3
      - scalar: 2
    outputs:
      - scalar: 3

  - inputs:
      - scalar: 3
      - scalar: 3
    outputs:
      - scalar: 3

  - inputs:
      - scalar: 3
      - scalar: 4
    outputs:
      - scalar: 4

  - inputs:
      - scalar: 3
      - scalar: 5
    outputs:
      - scalar: 5

  - inputs:
      - scalar: 3
      - scalar: 6
    outputs:
      - scalar: 6

  - inputs:
      - scalar: 3
      - scalar: 7
    outputs:
      - scalar: 7

  - inputs:
      - scalar: 4
      - scalar: 0
    outputs:
      - scalar: 4

  - inputs:
      - scalar: 4
      - scalar: 1
    outputs:
      - scalar: 4

  - inputs:
      - scalar: 4
      - scalar: 2
    outputs:
      - scalar: 4

  - inputs:
      - scalar: 4
      - scalar: 3
    outputs:
      - scalar: 4

  - inputs:
      - scalar: 4
      - scalar: 4
    outputs:
      - scalar: 4

  - inputs:
      - scalar: 4
      - scalar: 5
    outputs:
      - scalar: 5

  - inputs:
      - scalar: 4
      - scalar: 6
    outputs:
      - scalar: 6

  - inputs:
      - scalar: 4
      - scalar: 7
    outputs:
      - scalar: 7

  - inputs:
      - scalar: 5
      - scalar: 0
    outputs:
      - scalar: 5

  - inputs:
      - scalar: 5
      - scalar: 1
    outputs:
      - scalar: 5

  - inputs:
      - scalar: 5
      - scalar: 2
    outputs:
      - scalar: 5

  - inputs:
      - scalar: 5
      - scalar: 3
    outputs:
      - scalar: 5

  - inputs:
      - scalar: 5
      - scalar: 4
    outputs:
      - scalar: 5

  - inputs:
      - scalar: 5
      - scalar: 5
    outputs:
      - scalar: 5

  - inputs:
      - scalar: 5
      - scalar: 6
    outputs:
      - scalar: 6

  - inputs:
      - scalar: 5
      - scalar: 7
    outputs:
      - scalar: 7

  - inputs:
      - scalar: 6
      - scalar: 0
    outputs:
      - scalar: 6

  - inputs:
      - scalar: 6
      - scalar: 1
    outputs:
      - scalar: 6

  - inputs:
      - scalar: 6
      - scalar: 2
    outputs:
      - scalar: 6

  - inputs:
      - scalar: 6
      - scalar: 3
    outputs:
      - scalar: 6

  - inputs:
      - scalar: 6
      - scalar: 4
    outputs:
      - scalar: 6

  - inputs:
      - scalar: 6
      - scalar: 5
    outputs:
      - scalar: 6

  - inputs:
      - scalar: 6
      - scalar: 6
    outputs:
      - scalar: 6

  - inputs:
      - scalar: 6
      - scalar: 7
    outputs:
      - scalar: 7

  - inputs:
      - scalar: 7
      - scalar: 0
    outputs:
      - scalar: 7

  - inputs:
      - scalar: 7
      - scalar: 1
    outputs:
      - scalar: 7

  - inputs:
      - scalar: 7
      - scalar: 2
    outputs:
      - scalar: 7

  - inputs:
      - scalar: 7
      - scalar: 3
    outputs:
      - scalar: 7

  - inputs:
      - scalar: 7
      - scalar: 4
    outputs:
      - scalar: 7

  - inputs:
      - scalar: 7
      - scalar: 5
    outputs:
      - scalar: 7

  - inputs:
      - scalar: 7
      - scalar: 6
    outputs:
      - scalar: 7

  - inputs:
      - scalar: 7
      - scalar: 7
    outputs:
      - scalar: 7
---
description: max_eint_signed
program: |
  func.func @main(%arg0: !FHE.esint<4>, %arg1: !FHE.esint<4>) -> !FHE.esint<4> {
    %0 = "FHE.max_eint"(%arg0, %arg1) : (!FHE.esint<4>, !FHE.esint<4>) -> !FHE.esint<4>
    return %0 : !FHE.esint<4>
  }
tests:
  - inputs:
      - scalar: -4
        signed: true
      - scalar: -4
        signed: true
    outputs:
      - scalar: -4
        signed: true

  - inputs:
      - scalar: -4
        signed: true
      - scalar: -3
        signed: true
    outputs:
      - scalar: -3
        signed: true

  - inputs:
      - scalar: -4
        signed: true
      - scalar: -2
        signed: true
    outputs:
      - scalar: -2
        signed: true

  - inputs:
      - scalar: -4
        signed: true
      - scalar: -1
        signed: true
    outputs:
      - scalar: -1
        signed: true

  - inputs:
      - scalar: -4
        signed: true
      - scalar: 0
        signed: true
    outputs:
      - scalar: 0
        signed: true

  - inputs:
      - scalar: -4
        signed: true
      - scalar: 1
        signed: true
    outputs:
      - scalar: 1
        signed: true

  - inputs:
      - scalar: -4
        signed: true
      - scalar: 2
        signed: true
    outputs:
      - scalar: 2
        signed: true

  - inputs:
      - scalar: -4
        signed: true
      - scalar: 3
        signed: true
    outputs:
      - scalar: 3
        signed: true

  - inputs:
      - scalar: -3
        signed: true
      - scalar: -4
        signed: true
    outputs:
      - scalar: -3
        signed: true

  - inputs:
      - scalar: -3
        signed: true
      - scalar: -3
        signed: true
    outputs:
      - scalar: -3
        signed: true

  - inputs:
      - scalar: -3
        signed: true
      - scalar: -2
        signed: true
    outputs:
      - scalar: -2
        signed: true

  - inputs:
      - scalar: -3
        signed: true
      - scalar: -1
        signed: true
    outputs:
      - scalar: -1
        signed: true

  - inputs:
      - scalar: -3
        signed: true
      - scalar: 0
        signed: true
    outputs:
      - scalar: 0
        signed: true

  - inputs:
      - scalar: -3
        signed: true
      - scalar: 1
        signed: true
    outputs:
      - scalar: 1
        signed: true

  - inputs:
      - scalar: -3
        signed: true
      - scalar: 2
        signed: true
    outputs:
      - scalar: 2
        signed: true

  - inputs:
      - scalar: -3
        signed: true
      - scalar: 3
        signed: true
    outputs:
      - scalar: 3
        signed: true

  - inputs:
      - scalar: -2
        signed: true
      - scalar: -4
        signed: true
    outputs:
      - scalar: -2
        signed: true

  - inputs:
      - scalar: -2
        signed: true
      - scalar: -3
        signed: true
    outputs:
      - scalar: -2
        signed: true

  - inputs:
      - scalar: -2
        signed: true
      - scalar: -2
        signed: true
    outputs:
      - scalar: -2
        signed: true

  - inputs:
      - scalar: -2
        signed: true
      - scalar: -1
        signed: true
    outputs:
      - scalar: -1
        signed: true

  - inputs:
      - scalar: -2
        signed: true
      - scalar: 0
        signed: true
    outputs:
      - scalar: 0
        signed: true

  - inputs:
      - scalar: -2
        signed: true
      - scalar: 1
        signed: true
    outputs:
      - scalar: 1
        signed: true

  - inputs:
      - scalar: -2
        signed: true
      - scalar: 2
        signed: true
    outputs:
      - scalar: 2
        signed: true

  - inputs:
      - scalar: -2
        signed: true
      - scalar: 3
        signed: true
    outputs:
      - scalar: 3
        signed: true

  - inputs:
      - scalar: -1
        signed: true
      - scalar: -4
        signed: true
    outputs:
      - scalar: -1
        signed: true

  - inputs:
      - scalar: -1
        signed: true
      - scalar: -3
        signed: true
    outputs:
      - scalar: -1
        signed: true

  - inputs:
      - scalar: -1
        signed: true
      - scalar: -2
        signed: true
    outputs:
      - scalar: -1
        signed: true

  - inputs:
      - scalar: -1
        signed: true
      - scalar: -1
        signed: true
    outputs:
      - scalar: -1
        signed: true

  - inputs:
      - scalar: -1
        signed: true
      - scalar: 0
        signed: true
    outputs:
      - scalar: 0
        signed: true

  - inputs:
      - scalar: -1
        signed: true
      - scalar: 1
        signed: true
    outputs:
      - scalar: 1
        signed: true

  - inputs:
      - scalar: -1
        signed: true
      - scalar: 2
        signed: true
    outputs:
      - scalar: 2
        signed: true

  - inputs:
      - scalar: -1
        signed: true
      - scalar: 3
        signed: true
    outputs:
      - scalar: 3
        signed: true

  - inputs:
      - scalar: 0
        signed: true
      - scalar: -4
        signed: true
    outputs:
      - scalar: 0
        signed: true

  - inputs:
      - scalar: 0
        signed: true
      - scalar: -3
        signed: true
    outputs:
      - scalar: 0
        signed: true

  - inputs:
      - scalar: 0
        signed: true
      - scalar: -2
        signed: true
    outputs:
      - scalar: 0
        signed: true

  - inputs:
      - scalar: 0
        signed: true
      - scalar: -1
        signed: true
    outputs:
      - scalar: 0
        signed: true

  - inputs:
      - scalar: 0
        signed: true
      - scalar: 0
        signed: true
    outputs:
      - scalar: 0
        signed: true

  - inputs:
      - scalar: 0
        signed: true
      - scalar: 1
        signed: true
    outputs:
      - scalar: 1
        signed: true

  - inputs:
      - scalar: 0
        signed: true
      - scalar: 2
        signed: true
    outputs:
      - scalar: 2
        signed: true

  - inputs:
      - scalar: 0
        signed: true
      - scalar: 3
        signed: true
    outputs:
      - scalar: 3
        signed: true

  - inputs:
      - scalar: 1
        signed: true
      - scalar: -4
        signed: true
    outputs:
      - scalar: 1
        signed: true

  - inputs:
      - scalar: 1
        signed: true
      - scalar: -3
        signed: true
    outputs:
      - scalar: 1
        signed: true

  - inputs:
      - scalar: 1
        signed: true
      - scalar: -2
        signed: true
    outputs:
      - scalar: 1
        signed: true

  - inputs:
      - scalar: 1
        signed: true
      - scalar: -1
        signed: true
    outputs:
      - scalar: 1
        signed: true

  - inputs:
      - scalar: 1
        signed: true
      - scalar: 0
        signed: true
    outputs:
      - scalar: 1
        signed: true

  - inputs:
      - scalar: 1
        signed: true
      - scalar: 1
        signed: true
    outputs:
      - scalar: 1
        signed: true

  - inputs:
      - scalar: 1
        signed: true
      - scalar: 2
        signed: true
    outputs:
      - scalar: 2
        signed: true

  - inputs:
      - scalar: 1
        signed: true
      - scalar: 3
        signed: true
    outputs:
      - scalar: 3
        signed: true

  - inputs:
      - scalar: 2
        signed: true
      - scalar: -4
        signed: true
    outputs:
      - scalar: 2
        signed: true

  - inputs:
      - scalar: 2
        signed: true
      - scalar: -3
        signed: true
    outputs:
      - scalar: 2
        signed: true

  - inputs:
      - scalar: 2
        signed: true
      - scalar: -2
        signed: true
    outputs:
      - scalar: 2
        signed: true

  - inputs:
      - scalar: 2
        signed: true
      - scalar: -1
        signed: true
    outputs:
      - scalar: 2
        signed: true

  - inputs:
      - scalar: 2
        signed: true
      - scalar: 0
        signed: true
    outputs:
      - scalar: 2
        signed: true

  - inputs:
      - scalar: 2
        signed: true
      - scalar: 1
        signed: true
    outputs:
      - scalar: 2
        signed: true

  - inputs:
      - scalar: 2
        signed: true
      - scalar: 2
        signed: true
    outputs:
      - scalar: 2
        signed: true

  - inputs:
      - scalar: 2
        signed: true
      - scalar: 3
        signed: true
    outputs:
      - scalar: 3
        signed: true

  - inputs:
      - scalar: 3
        signed: true
      - scalar: -4
        signed: true
    outputs:
      - scalar: 3
        signed: true

  - inputs:
      - scalar: 3
        signed: true
      - scalar: -3
        signed: true
    outputs:
      - scalar: 3
        signed: true

  - inputs:
      - scalar: 3
        signed: true
      - scalar: -2
        signed: true
    outputs:
      - scalar: 3
        signed: true

  - inputs:
      - scalar: 3
        signed: true
      - scalar: -1
        signed: true
    outputs:
      - scalar: 3
        signed: true

  - inputs:
      - scalar: 3
        signed: true
      - scalar: 0
        signed: true
    outputs:
      - scalar: 3
        signed: true

  - inputs:
      - scalar: 3
        signed: true
      - scalar: 1
        signed: true
    outputs:
      - scalar: 3
        signed: true

  - inputs:
      - scalar: 3
        signed: true
      - scalar: 2
        signed: true
    outputs:
      - scalar: 3
        signed: true

  - inputs:
      - scalar: 3
        signed: true
      - scalar: 3
        signed: true
    outputs:
      - scalar: 3
        signed: true
---
# TODO: Rewrite/Remove
# The FHE.neg_eint op doesn't come with a well defined semantics as FHE.eint
# has an undefined behavior for under/overflow.
# For now we keep it, knowning the compiler/optimizer behavior but that could
# break at anytime.
description: neg_eint
program: |
  func.func @main(%arg0: !FHE.eint<7>) -> !FHE.eint<7> {
    %1 = "FHE.neg_eint"(%arg0): (!FHE.eint<7>) -> (!FHE.eint<7>)
    return %1: !FHE.eint<7>
  }
tests:
  - inputs:
    - scalar: 0
    outputs:
    - scalar: 0
  - inputs:
    - scalar: 1
    outputs:
    - scalar: 255
  - inputs:
    - scalar: 4
    outputs:
    - scalar: 252
  - inputs:
    - scalar: 250
    outputs:
    - scalar: 6
---
# TODO: Rewrite/Remove
# The FHE.neg_eint op doesn't come with a well defined semantics as FHE.eint
# has an undefined behavior for under/overflow.
# For now we keep it, knowning the compiler/optimizer behavior but that could
# break at anytime.
description: neg_eint_16bits
program: |
 func.func @main(%arg0: !FHE.eint<16>) -> !FHE.eint<16> {
    %1 = "FHE.neg_eint"(%arg0): (!FHE.eint<16>) -> (!FHE.eint<16>)
    return %1: !FHE.eint<16>
  }
tests:
  - inputs:
    - scalar: 0
    outputs:
    - scalar: 0
  - inputs:
    - scalar: 1
    outputs:
    - scalar: 131071
  - inputs:
    - scalar: 131071
    outputs:
    - scalar: 1
---
description: neg_eint_3bits
program: |
  func.func @main(%arg0: !FHE.eint<3>) -> !FHE.eint<3> {
    %1 = "FHE.neg_eint"(%arg0): (!FHE.eint<3>) -> (!FHE.eint<3>)
    return %1: !FHE.eint<3>
  }
tests:
  - inputs:
    - scalar: 0
    outputs:
    - scalar: 0
  - inputs:
    - scalar: 1
    outputs:
    - scalar: 15
  - inputs:
    - scalar: 4
    outputs:
    - scalar: 12
  - inputs:
    - scalar: 13
    outputs:
    - scalar: 3
---
description: apply_lookup_table_multiple_precision
program: |
  func.func @main(%arg0: !FHE.eint<6>, %arg1: !FHE.eint<3>) -> !FHE.eint<6> {
     %tlu_7 = arith.constant dense<[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63]> : tensor<64xi64>
     %tlu_3 = arith.constant dense<[0, 1, 2, 3, 4, 5, 6, 7]> : tensor<8xi64>
     %a = "FHE.apply_lookup_table"(%arg0, %tlu_7): (!FHE.eint<6>, tensor<64xi64>) -> (!FHE.eint<6>)
     %b = "FHE.apply_lookup_table"(%arg1, %tlu_3): (!FHE.eint<3>, tensor<8xi64>) -> (!FHE.eint<6>)
     %a_plus_b = "FHE.add_eint"(%a, %b): (!FHE.eint<6>, !FHE.eint<6>) -> (!FHE.eint<6>)
     return %a_plus_b: !FHE.eint<6>
  }
tests:
  - inputs:
    - scalar: 23
    - scalar: 7
    outputs:
    - scalar: 30
---
description: apply_lookup_table_random_func
program: |
  func.func @main(%arg0: !FHE.eint<6>) -> !FHE.eint<6> {
     %tlu = arith.constant dense<[16, 91, 16, 83, 80, 74, 21, 96, 1, 63, 49, 122, 76, 89, 74, 55, 109, 110, 103, 54, 105, 14, 66, 47, 52, 89, 7, 10, 73, 44, 119, 92, 25, 104, 123, 100, 108, 86, 29, 121, 118, 52, 107, 48, 34, 37, 13, 122, 107, 48, 74, 59, 96, 36, 50, 55, 120, 72, 27, 45, 12, 5, 96, 12]> : tensor<64xi64>
     %1 = "FHE.apply_lookup_table"(%arg0, %tlu): (!FHE.eint<6>, tensor<64xi64>) -> (!FHE.eint<6>)
     return %1: !FHE.eint<6>
  }
tests:
  - inputs:
    - scalar: 5
    outputs:
    - scalar: 74
  - inputs:
    - scalar: 62
    outputs:
    - scalar: 96
  - inputs:
    - scalar: 0
    outputs:
    - scalar: 16
  - inputs:
    - scalar: 63
    outputs:
    - scalar: 12
