package TestCase::Value {
  use TestCase::Matrix4_16b;
  use TestCase::Matrix4_16s;
  use TestCase::Matrix4_16i;
  use TestCase::Matrix4_16l;
  use TestCase::Matrix4_16f;
  use TestCase::Matrix4_16d;
  use SPVM::Util (INT8_MIN, INT8_MAX, INT16_MIN, INT16_MAX, INT32_MIN, INT32_MAX, INT64_MIN, INT64_MAX, FLT_MIN, FLT_MAX, DBL_MIN, DBL_MAX);

  sub value_max_fields_byte : int () {
    my $mat1 : TestCase::Matrix4_16b;
    my $mat2 : TestCase::Matrix4_16b;
    my $mat3 : TestCase::Matrix4_16b;
    
    $mat1->{x11} = INT8_MIN();
    $mat1->{x21} = 21;
    $mat1->{x31} = 31;
    $mat1->{x41} = 41;
    
    $mat1->{x12} = 12;
    $mat1->{x22} = 22;
    $mat1->{x32} = 32;
    $mat1->{x42} = 42;
    
    $mat1->{x13} = 13;
    $mat1->{x23} = 23;
    $mat1->{x33} = 33;
    $mat1->{x43} = 43;
    
    $mat1->{x14} = 14;
    $mat1->{x24} = 24;
    $mat1->{x34} = 34;
    $mat1->{x44} = 44;

    $mat2->{x11} = 21;
    $mat2->{x21} = 31;
    $mat2->{x31} = 41;
    $mat2->{x41} = 51;
    
    $mat2->{x12} = 22;
    $mat2->{x22} = 32;
    $mat2->{x32} = 42;
    $mat2->{x42} = 52;
    
    $mat2->{x13} = 23;
    $mat2->{x23} = 33;
    $mat2->{x33} = 43;
    $mat2->{x43} = 53;
    
    $mat2->{x14} = 24;
    $mat2->{x24} = 34;
    $mat2->{x34} = 44;
    $mat2->{x44} = 54;
    
    $mat3->{x11} = (byte)($mat1->{x11} + $mat2->{x11});
    $mat3->{x21} = (byte)($mat1->{x21} + $mat2->{x21});
    $mat3->{x31} = (byte)($mat1->{x31} + $mat2->{x31});
    $mat3->{x41} = (byte)($mat1->{x41} + $mat2->{x41});
    
    $mat3->{x12} = (byte)($mat1->{x12} + $mat2->{x12});
    $mat3->{x22} = (byte)($mat1->{x22} + $mat2->{x22});
    $mat3->{x32} = (byte)($mat1->{x32} + $mat2->{x32});
    $mat3->{x42} = (byte)($mat1->{x42} + $mat2->{x42});
    
    $mat3->{x13} = (byte)($mat1->{x13} + $mat2->{x13});
    $mat3->{x23} = (byte)($mat1->{x23} + $mat2->{x23});
    $mat3->{x33} = (byte)($mat1->{x33} + $mat2->{x33});
    $mat3->{x43} = (byte)($mat1->{x43} + $mat2->{x43});
    
    $mat3->{x14} = (byte)($mat1->{x14} + $mat2->{x14});
    $mat3->{x24} = (byte)($mat1->{x24} + $mat2->{x24});
    $mat3->{x34} = (byte)($mat1->{x34} + $mat2->{x34});
    $mat3->{x44} = (byte)($mat1->{x44} + $mat2->{x44});

    unless ($mat3->{x11} == INT8_MIN() + 21) {
      return 0;
    }
    unless ($mat3->{x21} == 52) {
      return 0;
    }
    unless ($mat3->{x31} == 72) {
      return 0;
    }
    unless ($mat3->{x41} == 92) {
      return 0;
    }
    unless ($mat3->{x12} == 34) {
      return 0;
    }
    unless ($mat3->{x22} == 54) {
      return 0;
    }
    unless ($mat3->{x32} == 74) {
      return 0;
    }
    unless ($mat3->{x42} == 94) {
      return 0;
    }
    unless ($mat3->{x13} == 36) {
      return 0;
    }
    unless ($mat3->{x23} == 56) {
      return 0;
    }
    unless ($mat3->{x33} == 76) {
      return 0;
    }
    unless ($mat3->{x43} == 96) {
      return 0;
    }
    unless ($mat3->{x41} == 92) {
      return 0;
    }
    unless ($mat3->{x42} == 94) {
      return 0;
    }
    unless ($mat3->{x43} == 96) {
      return 0;
    }
    unless ($mat3->{x44} == 98) {
      return 0;
    }
    
    return 1;
  }

  sub value_max_fields_short : int () {
    my $mat1 : TestCase::Matrix4_16s;
    my $mat2 : TestCase::Matrix4_16s;
    my $mat3 : TestCase::Matrix4_16s;
    
    $mat1->{x11} = INT16_MIN();
    $mat1->{x21} = 21;
    $mat1->{x31} = 31;
    $mat1->{x41} = 41;
    
    $mat1->{x12} = 12;
    $mat1->{x22} = 22;
    $mat1->{x32} = 32;
    $mat1->{x42} = 42;
    
    $mat1->{x13} = 13;
    $mat1->{x23} = 23;
    $mat1->{x33} = 33;
    $mat1->{x43} = 43;
    
    $mat1->{x14} = 14;
    $mat1->{x24} = 24;
    $mat1->{x34} = 34;
    $mat1->{x44} = 44;

    $mat2->{x11} = 111;
    $mat2->{x21} = 121;
    $mat2->{x31} = 131;
    $mat2->{x41} = 141;
    
    $mat2->{x12} = 112;
    $mat2->{x22} = 122;
    $mat2->{x32} = 132;
    $mat2->{x42} = 142;
    
    $mat2->{x13} = 113;
    $mat2->{x23} = 123;
    $mat2->{x33} = 133;
    $mat2->{x43} = 143;
    
    $mat2->{x14} = 114;
    $mat2->{x24} = 124;
    $mat2->{x34} = 134;
    $mat2->{x44} = 144;
    
    $mat3->{x11} = (short)($mat1->{x11} + $mat2->{x11});
    $mat3->{x21} = (short)($mat1->{x21} + $mat2->{x21});
    $mat3->{x31} = (short)($mat1->{x31} + $mat2->{x31});
    $mat3->{x41} = (short)($mat1->{x41} + $mat2->{x41});
    
    $mat3->{x12} = (short)($mat1->{x12} + $mat2->{x12});
    $mat3->{x22} = (short)($mat1->{x22} + $mat2->{x22});
    $mat3->{x32} = (short)($mat1->{x32} + $mat2->{x32});
    $mat3->{x42} = (short)($mat1->{x42} + $mat2->{x42});
    
    $mat3->{x13} = (short)($mat1->{x13} + $mat2->{x13});
    $mat3->{x23} = (short)($mat1->{x23} + $mat2->{x23});
    $mat3->{x33} = (short)($mat1->{x33} + $mat2->{x33});
    $mat3->{x43} = (short)($mat1->{x43} + $mat2->{x43});
    
    $mat3->{x14} = (short)($mat1->{x14} + $mat2->{x14});
    $mat3->{x24} = (short)($mat1->{x24} + $mat2->{x24});
    $mat3->{x34} = (short)($mat1->{x34} + $mat2->{x34});
    $mat3->{x44} = (short)($mat1->{x44} + $mat2->{x44});
    
    unless ($mat3->{x11} == INT16_MIN() + 111) {
      return 0;
    }
    unless ($mat3->{x21} == 142) {
      return 0;
    }
    unless ($mat3->{x31} == 162) {
      return 0;
    }
    unless ($mat3->{x41} == 182) {
      return 0;
    }
    unless ($mat3->{x12} == 124) {
      return 0;
    }
    unless ($mat3->{x22} == 144) {
      return 0;
    }
    unless ($mat3->{x32} == 164) {
      return 0;
    }
    unless ($mat3->{x42} == 184) {
      return 0;
    }
    unless ($mat3->{x13} == 126) {
      return 0;
    }
    unless ($mat3->{x23} == 146) {
      return 0;
    }
    unless ($mat3->{x33} == 166) {
      return 0;
    }
    unless ($mat3->{x43} == 186) {
      return 0;
    }
    unless ($mat3->{x41} == 182) {
      return 0;
    }
    unless ($mat3->{x42} == 184) {
      return 0;
    }
    unless ($mat3->{x43} == 186) {
      return 0;
    }
    unless ($mat3->{x44} == 188) {
      return 0;
    }
    
    return 1;
  }

  sub value_max_fields_int : int () {
    my $mat1 : TestCase::Matrix4_16i;
    my $mat2 : TestCase::Matrix4_16i;
    my $mat3 : TestCase::Matrix4_16i;
    
    $mat1->{x11} = INT32_MIN();
    $mat1->{x21} = 21;
    $mat1->{x31} = 31;
    $mat1->{x41} = 41;
    
    $mat1->{x12} = 12;
    $mat1->{x22} = 22;
    $mat1->{x32} = 32;
    $mat1->{x42} = 42;
    
    $mat1->{x13} = 13;
    $mat1->{x23} = 23;
    $mat1->{x33} = 33;
    $mat1->{x43} = 43;
    
    $mat1->{x14} = 14;
    $mat1->{x24} = 24;
    $mat1->{x34} = 34;
    $mat1->{x44} = 44;

    $mat2->{x11} = 111;
    $mat2->{x21} = 121;
    $mat2->{x31} = 131;
    $mat2->{x41} = 141;
    
    $mat2->{x12} = 112;
    $mat2->{x22} = 122;
    $mat2->{x32} = 132;
    $mat2->{x42} = 142;
    
    $mat2->{x13} = 113;
    $mat2->{x23} = 123;
    $mat2->{x33} = 133;
    $mat2->{x43} = 143;
    
    $mat2->{x14} = 114;
    $mat2->{x24} = 124;
    $mat2->{x34} = 134;
    $mat2->{x44} = 144;
    
    $mat3->{x11} = $mat1->{x11} + $mat2->{x11};
    $mat3->{x21} = $mat1->{x21} + $mat2->{x21};
    $mat3->{x31} = $mat1->{x31} + $mat2->{x31};
    $mat3->{x41} = $mat1->{x41} + $mat2->{x41};
    
    $mat3->{x12} = $mat1->{x12} + $mat2->{x12};
    $mat3->{x22} = $mat1->{x22} + $mat2->{x22};
    $mat3->{x32} = $mat1->{x32} + $mat2->{x32};
    $mat3->{x42} = $mat1->{x42} + $mat2->{x42};
    
    $mat3->{x13} = $mat1->{x13} + $mat2->{x13};
    $mat3->{x23} = $mat1->{x23} + $mat2->{x23};
    $mat3->{x33} = $mat1->{x33} + $mat2->{x33};
    $mat3->{x43} = $mat1->{x43} + $mat2->{x43};
    
    $mat3->{x14} = $mat1->{x14} + $mat2->{x14};
    $mat3->{x24} = $mat1->{x24} + $mat2->{x24};
    $mat3->{x34} = $mat1->{x34} + $mat2->{x34};
    $mat3->{x44} = $mat1->{x44} + $mat2->{x44};
    
    unless ($mat3->{x11} == INT32_MIN() + 111) {
      return 0;
    }
    unless ($mat3->{x21} == 142) {
      return 0;
    }
    unless ($mat3->{x31} == 162) {
      return 0;
    }
    unless ($mat3->{x41} == 182) {
      return 0;
    }
    unless ($mat3->{x12} == 124) {
      return 0;
    }
    unless ($mat3->{x22} == 144) {
      return 0;
    }
    unless ($mat3->{x32} == 164) {
      return 0;
    }
    unless ($mat3->{x42} == 184) {
      return 0;
    }
    unless ($mat3->{x13} == 126) {
      return 0;
    }
    unless ($mat3->{x23} == 146) {
      return 0;
    }
    unless ($mat3->{x33} == 166) {
      return 0;
    }
    unless ($mat3->{x43} == 186) {
      return 0;
    }
    unless ($mat3->{x41} == 182) {
      return 0;
    }
    unless ($mat3->{x42} == 184) {
      return 0;
    }
    unless ($mat3->{x43} == 186) {
      return 0;
    }
    unless ($mat3->{x44} == 188) {
      return 0;
    }
    
    return 1;
  }

  sub value_max_fields_long : int () {
    my $mat1 : TestCase::Matrix4_16l;
    my $mat2 : TestCase::Matrix4_16l;
    my $mat3 : TestCase::Matrix4_16l;
    
    $mat1->{x11} = INT64_MIN();
    $mat1->{x21} = 21;
    $mat1->{x31} = 31;
    $mat1->{x41} = 41;
    
    $mat1->{x12} = 12;
    $mat1->{x22} = 22;
    $mat1->{x32} = 32;
    $mat1->{x42} = 42;
    
    $mat1->{x13} = 13;
    $mat1->{x23} = 23;
    $mat1->{x33} = 33;
    $mat1->{x43} = 43;
    
    $mat1->{x14} = 14;
    $mat1->{x24} = 24;
    $mat1->{x34} = 34;
    $mat1->{x44} = 44;

    $mat2->{x11} = 111;
    $mat2->{x21} = 121;
    $mat2->{x31} = 131;
    $mat2->{x41} = 141;
    
    $mat2->{x12} = 112;
    $mat2->{x22} = 122;
    $mat2->{x32} = 132;
    $mat2->{x42} = 142;
    
    $mat2->{x13} = 113;
    $mat2->{x23} = 123;
    $mat2->{x33} = 133;
    $mat2->{x43} = 143;
    
    $mat2->{x14} = 114;
    $mat2->{x24} = 124;
    $mat2->{x34} = 134;
    $mat2->{x44} = 144;
    
    $mat3->{x11} = $mat1->{x11} + $mat2->{x11};
    $mat3->{x21} = $mat1->{x21} + $mat2->{x21};
    $mat3->{x31} = $mat1->{x31} + $mat2->{x31};
    $mat3->{x41} = $mat1->{x41} + $mat2->{x41};
    
    $mat3->{x12} = $mat1->{x12} + $mat2->{x12};
    $mat3->{x22} = $mat1->{x22} + $mat2->{x22};
    $mat3->{x32} = $mat1->{x32} + $mat2->{x32};
    $mat3->{x42} = $mat1->{x42} + $mat2->{x42};
    
    $mat3->{x13} = $mat1->{x13} + $mat2->{x13};
    $mat3->{x23} = $mat1->{x23} + $mat2->{x23};
    $mat3->{x33} = $mat1->{x33} + $mat2->{x33};
    $mat3->{x43} = $mat1->{x43} + $mat2->{x43};
    
    $mat3->{x14} = $mat1->{x14} + $mat2->{x14};
    $mat3->{x24} = $mat1->{x24} + $mat2->{x24};
    $mat3->{x34} = $mat1->{x34} + $mat2->{x34};
    $mat3->{x44} = $mat1->{x44} + $mat2->{x44};
    
    unless ($mat3->{x11} == INT64_MIN() + 111) {
      return 0;
    }
    unless ($mat3->{x21} == 142) {
      return 0;
    }
    unless ($mat3->{x31} == 162) {
      return 0;
    }
    unless ($mat3->{x41} == 182) {
      return 0;
    }
    unless ($mat3->{x12} == 124) {
      return 0;
    }
    unless ($mat3->{x22} == 144) {
      return 0;
    }
    unless ($mat3->{x32} == 164) {
      return 0;
    }
    unless ($mat3->{x42} == 184) {
      return 0;
    }
    unless ($mat3->{x13} == 126) {
      return 0;
    }
    unless ($mat3->{x23} == 146) {
      return 0;
    }
    unless ($mat3->{x33} == 166) {
      return 0;
    }
    unless ($mat3->{x43} == 186) {
      return 0;
    }
    unless ($mat3->{x41} == 182) {
      return 0;
    }
    unless ($mat3->{x42} == 184) {
      return 0;
    }
    unless ($mat3->{x43} == 186) {
      return 0;
    }
    unless ($mat3->{x44} == 188) {
      return 0;
    }
    
    return 1;
  }

  sub value_max_fields_float : int () {
    my $mat1 : TestCase::Matrix4_16f;
    my $mat2 : TestCase::Matrix4_16f;
    my $mat3 : TestCase::Matrix4_16f;
    
    $mat1->{x11} = FLT_MIN();
    $mat1->{x21} = 21;
    $mat1->{x31} = 31;
    $mat1->{x41} = 41;
    
    $mat1->{x12} = 12;
    $mat1->{x22} = 22;
    $mat1->{x32} = 32;
    $mat1->{x42} = 42;
    
    $mat1->{x13} = 13;
    $mat1->{x23} = 23;
    $mat1->{x33} = 33;
    $mat1->{x43} = 43;
    
    $mat1->{x14} = 14;
    $mat1->{x24} = 24;
    $mat1->{x34} = 34;
    $mat1->{x44} = 44;

    $mat2->{x11} = 111;
    $mat2->{x21} = 121;
    $mat2->{x31} = 131;
    $mat2->{x41} = 141;
    
    $mat2->{x12} = 112;
    $mat2->{x22} = 122;
    $mat2->{x32} = 132;
    $mat2->{x42} = 142;
    
    $mat2->{x13} = 113;
    $mat2->{x23} = 123;
    $mat2->{x33} = 133;
    $mat2->{x43} = 143;
    
    $mat2->{x14} = 114;
    $mat2->{x24} = 124;
    $mat2->{x34} = 134;
    $mat2->{x44} = 144;
    
    $mat3->{x11} = $mat1->{x11} + $mat2->{x11};
    $mat3->{x21} = $mat1->{x21} + $mat2->{x21};
    $mat3->{x31} = $mat1->{x31} + $mat2->{x31};
    $mat3->{x41} = $mat1->{x41} + $mat2->{x41};
    
    $mat3->{x12} = $mat1->{x12} + $mat2->{x12};
    $mat3->{x22} = $mat1->{x22} + $mat2->{x22};
    $mat3->{x32} = $mat1->{x32} + $mat2->{x32};
    $mat3->{x42} = $mat1->{x42} + $mat2->{x42};
    
    $mat3->{x13} = $mat1->{x13} + $mat2->{x13};
    $mat3->{x23} = $mat1->{x23} + $mat2->{x23};
    $mat3->{x33} = $mat1->{x33} + $mat2->{x33};
    $mat3->{x43} = $mat1->{x43} + $mat2->{x43};
    
    $mat3->{x14} = $mat1->{x14} + $mat2->{x14};
    $mat3->{x24} = $mat1->{x24} + $mat2->{x24};
    $mat3->{x34} = $mat1->{x34} + $mat2->{x34};
    $mat3->{x44} = $mat1->{x44} + $mat2->{x44};
    
    unless ($mat3->{x11} == FLT_MIN() + 111) {
      return 0;
    }
    unless ($mat3->{x21} == 142) {
      return 0;
    }
    unless ($mat3->{x31} == 162) {
      return 0;
    }
    unless ($mat3->{x41} == 182) {
      return 0;
    }
    unless ($mat3->{x12} == 124) {
      return 0;
    }
    unless ($mat3->{x22} == 144) {
      return 0;
    }
    unless ($mat3->{x32} == 164) {
      return 0;
    }
    unless ($mat3->{x42} == 184) {
      return 0;
    }
    unless ($mat3->{x13} == 126) {
      return 0;
    }
    unless ($mat3->{x23} == 146) {
      return 0;
    }
    unless ($mat3->{x33} == 166) {
      return 0;
    }
    unless ($mat3->{x43} == 186) {
      return 0;
    }
    unless ($mat3->{x41} == 182) {
      return 0;
    }
    unless ($mat3->{x42} == 184) {
      return 0;
    }
    unless ($mat3->{x43} == 186) {
      return 0;
    }
    unless ($mat3->{x44} == 188) {
      return 0;
    }
    
    return 1;
  }
  
  sub value_max_fields_double : int () {
    my $mat1 : TestCase::Matrix4_16d;
    my $mat2 : TestCase::Matrix4_16d;
    my $mat3 : TestCase::Matrix4_16d;
    
    $mat1->{x11} = DBL_MIN();
    $mat1->{x21} = 21;
    $mat1->{x31} = 31;
    $mat1->{x41} = 41;
    
    $mat1->{x12} = 12;
    $mat1->{x22} = 22;
    $mat1->{x32} = 32;
    $mat1->{x42} = 42;
    
    $mat1->{x13} = 13;
    $mat1->{x23} = 23;
    $mat1->{x33} = 33;
    $mat1->{x43} = 43;
    
    $mat1->{x14} = 14;
    $mat1->{x24} = 24;
    $mat1->{x34} = 34;
    $mat1->{x44} = 44;

    $mat2->{x11} = 111;
    $mat2->{x21} = 121;
    $mat2->{x31} = 131;
    $mat2->{x41} = 141;
    
    $mat2->{x12} = 112;
    $mat2->{x22} = 122;
    $mat2->{x32} = 132;
    $mat2->{x42} = 142;
    
    $mat2->{x13} = 113;
    $mat2->{x23} = 123;
    $mat2->{x33} = 133;
    $mat2->{x43} = 143;
    
    $mat2->{x14} = 114;
    $mat2->{x24} = 124;
    $mat2->{x34} = 134;
    $mat2->{x44} = 144;
    
    $mat3->{x11} = $mat1->{x11} + $mat2->{x11};
    $mat3->{x21} = $mat1->{x21} + $mat2->{x21};
    $mat3->{x31} = $mat1->{x31} + $mat2->{x31};
    $mat3->{x41} = $mat1->{x41} + $mat2->{x41};
    
    $mat3->{x12} = $mat1->{x12} + $mat2->{x12};
    $mat3->{x22} = $mat1->{x22} + $mat2->{x22};
    $mat3->{x32} = $mat1->{x32} + $mat2->{x32};
    $mat3->{x42} = $mat1->{x42} + $mat2->{x42};
    
    $mat3->{x13} = $mat1->{x13} + $mat2->{x13};
    $mat3->{x23} = $mat1->{x23} + $mat2->{x23};
    $mat3->{x33} = $mat1->{x33} + $mat2->{x33};
    $mat3->{x43} = $mat1->{x43} + $mat2->{x43};
    
    $mat3->{x14} = $mat1->{x14} + $mat2->{x14};
    $mat3->{x24} = $mat1->{x24} + $mat2->{x24};
    $mat3->{x34} = $mat1->{x34} + $mat2->{x34};
    $mat3->{x44} = $mat1->{x44} + $mat2->{x44};
    
    unless ($mat3->{x11} == DBL_MIN() + 111) {
      return 0;
    }
    unless ($mat3->{x21} == 142) {
      return 0;
    }
    unless ($mat3->{x31} == 162) {
      return 0;
    }
    unless ($mat3->{x41} == 182) {
      return 0;
    }
    unless ($mat3->{x12} == 124) {
      return 0;
    }
    unless ($mat3->{x22} == 144) {
      return 0;
    }
    unless ($mat3->{x32} == 164) {
      return 0;
    }
    unless ($mat3->{x42} == 184) {
      return 0;
    }
    unless ($mat3->{x13} == 126) {
      return 0;
    }
    unless ($mat3->{x23} == 146) {
      return 0;
    }
    unless ($mat3->{x33} == 166) {
      return 0;
    }
    unless ($mat3->{x43} == 186) {
      return 0;
    }
    unless ($mat3->{x41} == 182) {
      return 0;
    }
    unless ($mat3->{x42} == 184) {
      return 0;
    }
    unless ($mat3->{x43} == 186) {
      return 0;
    }
    unless ($mat3->{x44} == 188) {
      return 0;
    }
    
    return 1;
  }
}