1cb93a386Sopenharmony_ci#include <metal_stdlib>
2cb93a386Sopenharmony_ci#include <simd/simd.h>
3cb93a386Sopenharmony_ciusing namespace metal;
4cb93a386Sopenharmony_cistruct Uniforms {
5cb93a386Sopenharmony_ci    half4 colorGreen;
6cb93a386Sopenharmony_ci    half4 colorRed;
7cb93a386Sopenharmony_ci};
8cb93a386Sopenharmony_cistruct Inputs {
9cb93a386Sopenharmony_ci};
10cb93a386Sopenharmony_cistruct Outputs {
11cb93a386Sopenharmony_ci    half4 sk_FragColor [[color(0)]];
12cb93a386Sopenharmony_ci};
13cb93a386Sopenharmony_ci
14cb93a386Sopenharmony_cithread bool operator==(const half2x2 left, const half2x2 right);
15cb93a386Sopenharmony_cithread bool operator!=(const half2x2 left, const half2x2 right);
16cb93a386Sopenharmony_ci
17cb93a386Sopenharmony_cithread bool operator==(const half3x3 left, const half3x3 right);
18cb93a386Sopenharmony_cithread bool operator!=(const half3x3 left, const half3x3 right);
19cb93a386Sopenharmony_ci
20cb93a386Sopenharmony_cithread bool operator==(const half4x4 left, const half4x4 right);
21cb93a386Sopenharmony_cithread bool operator!=(const half4x4 left, const half4x4 right);
22cb93a386Sopenharmony_ci
23cb93a386Sopenharmony_cithread bool operator==(const float2x2 left, const float2x2 right);
24cb93a386Sopenharmony_cithread bool operator!=(const float2x2 left, const float2x2 right);
25cb93a386Sopenharmony_ci
26cb93a386Sopenharmony_cithread bool operator==(const float3x3 left, const float3x3 right);
27cb93a386Sopenharmony_cithread bool operator!=(const float3x3 left, const float3x3 right);
28cb93a386Sopenharmony_ci
29cb93a386Sopenharmony_cithread bool operator==(const float4x4 left, const float4x4 right);
30cb93a386Sopenharmony_cithread bool operator!=(const float4x4 left, const float4x4 right);
31cb93a386Sopenharmony_cithread bool operator==(const half2x2 left, const half2x2 right) {
32cb93a386Sopenharmony_ci    return all(left[0] == right[0]) &&
33cb93a386Sopenharmony_ci           all(left[1] == right[1]);
34cb93a386Sopenharmony_ci}
35cb93a386Sopenharmony_cithread bool operator!=(const half2x2 left, const half2x2 right) {
36cb93a386Sopenharmony_ci    return !(left == right);
37cb93a386Sopenharmony_ci}
38cb93a386Sopenharmony_cithread half2x2& operator*=(thread half2x2& left, thread const half2x2& right) {
39cb93a386Sopenharmony_ci    left = left * right;
40cb93a386Sopenharmony_ci    return left;
41cb93a386Sopenharmony_ci}
42cb93a386Sopenharmony_cithread bool operator==(const half3x3 left, const half3x3 right) {
43cb93a386Sopenharmony_ci    return all(left[0] == right[0]) &&
44cb93a386Sopenharmony_ci           all(left[1] == right[1]) &&
45cb93a386Sopenharmony_ci           all(left[2] == right[2]);
46cb93a386Sopenharmony_ci}
47cb93a386Sopenharmony_cithread bool operator!=(const half3x3 left, const half3x3 right) {
48cb93a386Sopenharmony_ci    return !(left == right);
49cb93a386Sopenharmony_ci}
50cb93a386Sopenharmony_cithread bool operator==(const half4x4 left, const half4x4 right) {
51cb93a386Sopenharmony_ci    return all(left[0] == right[0]) &&
52cb93a386Sopenharmony_ci           all(left[1] == right[1]) &&
53cb93a386Sopenharmony_ci           all(left[2] == right[2]) &&
54cb93a386Sopenharmony_ci           all(left[3] == right[3]);
55cb93a386Sopenharmony_ci}
56cb93a386Sopenharmony_cithread bool operator!=(const half4x4 left, const half4x4 right) {
57cb93a386Sopenharmony_ci    return !(left == right);
58cb93a386Sopenharmony_ci}
59cb93a386Sopenharmony_cithread bool operator==(const float2x2 left, const float2x2 right) {
60cb93a386Sopenharmony_ci    return all(left[0] == right[0]) &&
61cb93a386Sopenharmony_ci           all(left[1] == right[1]);
62cb93a386Sopenharmony_ci}
63cb93a386Sopenharmony_cithread bool operator!=(const float2x2 left, const float2x2 right) {
64cb93a386Sopenharmony_ci    return !(left == right);
65cb93a386Sopenharmony_ci}
66cb93a386Sopenharmony_cithread float2x2& operator*=(thread float2x2& left, thread const float2x2& right) {
67cb93a386Sopenharmony_ci    left = left * right;
68cb93a386Sopenharmony_ci    return left;
69cb93a386Sopenharmony_ci}
70cb93a386Sopenharmony_cithread bool operator==(const float3x3 left, const float3x3 right) {
71cb93a386Sopenharmony_ci    return all(left[0] == right[0]) &&
72cb93a386Sopenharmony_ci           all(left[1] == right[1]) &&
73cb93a386Sopenharmony_ci           all(left[2] == right[2]);
74cb93a386Sopenharmony_ci}
75cb93a386Sopenharmony_cithread bool operator!=(const float3x3 left, const float3x3 right) {
76cb93a386Sopenharmony_ci    return !(left == right);
77cb93a386Sopenharmony_ci}
78cb93a386Sopenharmony_cithread bool operator==(const float4x4 left, const float4x4 right) {
79cb93a386Sopenharmony_ci    return all(left[0] == right[0]) &&
80cb93a386Sopenharmony_ci           all(left[1] == right[1]) &&
81cb93a386Sopenharmony_ci           all(left[2] == right[2]) &&
82cb93a386Sopenharmony_ci           all(left[3] == right[3]);
83cb93a386Sopenharmony_ci}
84cb93a386Sopenharmony_cithread bool operator!=(const float4x4 left, const float4x4 right) {
85cb93a386Sopenharmony_ci    return !(left == right);
86cb93a386Sopenharmony_ci}
87cb93a386Sopenharmony_cibool test_half_b() {
88cb93a386Sopenharmony_ci    bool ok = true;
89cb93a386Sopenharmony_ci    half2x2 m1 = half2x2(half2(1.0h, 2.0h), half2(3.0h, 4.0h));
90cb93a386Sopenharmony_ci    ok = ok && m1 == half2x2(half2(1.0h, 2.0h), half2(3.0h, 4.0h));
91cb93a386Sopenharmony_ci    half2x2 m3 = m1;
92cb93a386Sopenharmony_ci    ok = ok && m3 == half2x2(half2(1.0h, 2.0h), half2(3.0h, 4.0h));
93cb93a386Sopenharmony_ci    half2x2 m4 = half2x2(6.0h);
94cb93a386Sopenharmony_ci    ok = ok && m4 == half2x2(half2(6.0h, 0.0h), half2(0.0h, 6.0h));
95cb93a386Sopenharmony_ci    m3 *= m4;
96cb93a386Sopenharmony_ci    ok = ok && m3 == half2x2(half2(6.0h, 12.0h), half2(18.0h, 24.0h));
97cb93a386Sopenharmony_ci    half2x2 m5 = half2x2(m1[1].y);
98cb93a386Sopenharmony_ci    ok = ok && m5 == half2x2(half2(4.0h, 0.0h), half2(0.0h, 4.0h));
99cb93a386Sopenharmony_ci    m1 += m5;
100cb93a386Sopenharmony_ci    ok = ok && m1 == half2x2(half2(5.0h, 2.0h), half2(3.0h, 8.0h));
101cb93a386Sopenharmony_ci    half2x2 m7 = half2x2(half2(5.0h, 6.0h), half2(7.0h, 8.0h));
102cb93a386Sopenharmony_ci    ok = ok && m7 == half2x2(half2(5.0h, 6.0h), half2(7.0h, 8.0h));
103cb93a386Sopenharmony_ci    half3x3 m9 = half3x3(9.0h);
104cb93a386Sopenharmony_ci    ok = ok && m9 == half3x3(half3(9.0h, 0.0h, 0.0h), half3(0.0h, 9.0h, 0.0h), half3(0.0h, 0.0h, 9.0h));
105cb93a386Sopenharmony_ci    half4x4 m10 = half4x4(11.0h);
106cb93a386Sopenharmony_ci    ok = ok && m10 == half4x4(half4(11.0h, 0.0h, 0.0h, 0.0h), half4(0.0h, 11.0h, 0.0h, 0.0h), half4(0.0h, 0.0h, 11.0h, 0.0h), half4(0.0h, 0.0h, 0.0h, 11.0h));
107cb93a386Sopenharmony_ci    half4x4 m11 = half4x4(half4(20.0h, 20.0h, 20.0h, 20.0h), half4(20.0h, 20.0h, 20.0h, 20.0h), half4(20.0h, 20.0h, 20.0h, 20.0h), half4(20.0h, 20.0h, 20.0h, 20.0h));
108cb93a386Sopenharmony_ci    m11 -= m10;
109cb93a386Sopenharmony_ci    ok = ok && m11 == half4x4(half4(9.0h, 20.0h, 20.0h, 20.0h), half4(20.0h, 9.0h, 20.0h, 20.0h), half4(20.0h, 20.0h, 9.0h, 20.0h), half4(20.0h, 20.0h, 20.0h, 9.0h));
110cb93a386Sopenharmony_ci    return ok;
111cb93a386Sopenharmony_ci}
112cb93a386Sopenharmony_cibool test_comma_b() {
113cb93a386Sopenharmony_ci    float2x2 x;
114cb93a386Sopenharmony_ci    float2x2 y;
115cb93a386Sopenharmony_ci    return ((x = float2x2(float2(1.0, 2.0), float2(3.0, 4.0)) , y = 0.5 * float2x2(float2(2.0, 4.0), float2(6.0, 8.0))) , x == y);
116cb93a386Sopenharmony_ci}
117cb93a386Sopenharmony_cifragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
118cb93a386Sopenharmony_ci    Outputs _out;
119cb93a386Sopenharmony_ci    (void)_out;
120cb93a386Sopenharmony_ci    bool _0_ok = true;
121cb93a386Sopenharmony_ci    float2x2 _1_m1 = float2x2(float2(1.0, 2.0), float2(3.0, 4.0));
122cb93a386Sopenharmony_ci    _0_ok = _0_ok && _1_m1 == float2x2(float2(1.0, 2.0), float2(3.0, 4.0));
123cb93a386Sopenharmony_ci    float2x2 _2_m3 = _1_m1;
124cb93a386Sopenharmony_ci    _0_ok = _0_ok && _2_m3 == float2x2(float2(1.0, 2.0), float2(3.0, 4.0));
125cb93a386Sopenharmony_ci    float2x2 _3_m4 = float2x2(6.0);
126cb93a386Sopenharmony_ci    _0_ok = _0_ok && _3_m4 == float2x2(float2(6.0, 0.0), float2(0.0, 6.0));
127cb93a386Sopenharmony_ci    _2_m3 *= _3_m4;
128cb93a386Sopenharmony_ci    _0_ok = _0_ok && _2_m3 == float2x2(float2(6.0, 12.0), float2(18.0, 24.0));
129cb93a386Sopenharmony_ci    float2x2 _4_m5 = float2x2(_1_m1[1].y);
130cb93a386Sopenharmony_ci    _0_ok = _0_ok && _4_m5 == float2x2(float2(4.0, 0.0), float2(0.0, 4.0));
131cb93a386Sopenharmony_ci    _1_m1 += _4_m5;
132cb93a386Sopenharmony_ci    _0_ok = _0_ok && _1_m1 == float2x2(float2(5.0, 2.0), float2(3.0, 8.0));
133cb93a386Sopenharmony_ci    float2x2 _5_m7 = float2x2(float2(5.0, 6.0), float2(7.0, 8.0));
134cb93a386Sopenharmony_ci    _0_ok = _0_ok && _5_m7 == float2x2(float2(5.0, 6.0), float2(7.0, 8.0));
135cb93a386Sopenharmony_ci    float3x3 _6_m9 = float3x3(9.0);
136cb93a386Sopenharmony_ci    _0_ok = _0_ok && _6_m9 == float3x3(float3(9.0, 0.0, 0.0), float3(0.0, 9.0, 0.0), float3(0.0, 0.0, 9.0));
137cb93a386Sopenharmony_ci    float4x4 _7_m10 = float4x4(11.0);
138cb93a386Sopenharmony_ci    _0_ok = _0_ok && _7_m10 == float4x4(float4(11.0, 0.0, 0.0, 0.0), float4(0.0, 11.0, 0.0, 0.0), float4(0.0, 0.0, 11.0, 0.0), float4(0.0, 0.0, 0.0, 11.0));
139cb93a386Sopenharmony_ci    float4x4 _8_m11 = float4x4(float4(20.0, 20.0, 20.0, 20.0), float4(20.0, 20.0, 20.0, 20.0), float4(20.0, 20.0, 20.0, 20.0), float4(20.0, 20.0, 20.0, 20.0));
140cb93a386Sopenharmony_ci    _8_m11 -= _7_m10;
141cb93a386Sopenharmony_ci    _0_ok = _0_ok && _8_m11 == float4x4(float4(9.0, 20.0, 20.0, 20.0), float4(20.0, 9.0, 20.0, 20.0), float4(20.0, 20.0, 9.0, 20.0), float4(20.0, 20.0, 20.0, 9.0));
142cb93a386Sopenharmony_ci    _out.sk_FragColor = (_0_ok && test_half_b()) && test_comma_b() ? _uniforms.colorGreen : _uniforms.colorRed;
143cb93a386Sopenharmony_ci    return _out;
144cb93a386Sopenharmony_ci}
145