Debian Codegraph @

clang/test/SemaOpenCL/half-float16-vector-compatibility.cl

raw
1 // RUN: %clang_cc1 -triple amdgcn-- -target-cpu gfx1100 -verify -S -o - %s
2 // REQUIRES: amdgpu-registered-target
3
4 #pragma OPENCL EXTENSION cl_khr_fp16 : enable
5
6 typedef int int4 __attribute__((ext_vector_type(4)));
7 typedef float float4 __attribute__((ext_vector_type(4)));
8
9 typedef half half2 __attribute__((ext_vector_type(2)));
10 typedef half half3 __attribute__((ext_vector_type(3)));
11 typedef half half4 __attribute__((ext_vector_type(4)));
12 typedef half half8 __attribute__((ext_vector_type(8)));
13 typedef half half16 __attribute__((ext_vector_type(16)));
14
15 typedef _Float16 float16_2 __attribute__((ext_vector_type(2)));
16 typedef _Float16 float16_3 __attribute__((ext_vector_type(3)));
17 typedef _Float16 float16_4 __attribute__((ext_vector_type(4)));
18 typedef _Float16 float16_8 __attribute__((ext_vector_type(8)));
19 typedef _Float16 float16_16 __attribute__((ext_vector_type(16)));
20
21 void test_half_vector_to_float16(float16_2 f16_2, float16_3 f16_3, float16_4 f16_4, float16_8 f16_8, float16_16 f16_16) {
22 half2 h2 = f16_2; // expected-no-error
23 half3 h3 = f16_3; // expected-no-error
24 half4 h4 = f16_4; // expected-no-error
25 half8 h8 = f16_8; // expected-no-error
26 half16 h16 = f16_16; // expected-no-error
27 }
28
29 void test_float16_vector_to_half(half2 h2, half3 h3, half4 h4, half8 h8, half16 h16) {
30 float16_2 f16_2 = h2; // expected-no-error
31 float16_3 f16_3 = h3; // expected-no-error
32 float16_4 f16_4 = h4; // expected-no-error
33 float16_8 f16_8 = h8; // expected-no-error
34 float16_16 f16_16 = h16; // expected-no-error
35 }
36
37 half4 test_return_half4_from_float16_vector(float16_4 f16_4) {
38 return f16_4; // expected-no-error
39 }
40
41 float16_4 test_return_float16_4_from_half4(half4 h4) {
42 return h4; // expected-no-error
43 }
44
45 half4 test_explicit_cast_half4_to_float16_vector(half4 h4) {
46 return (float16_4)h4; // expected-no-error
47 }
48
49 float16_4 test_explicit_cast_float16_4_to_half4(float16_4 f16_4) {
50 return (half4)f16_4; // expected-no-error
51 }
52
53 half4 test_builtin_image_load_2d_2(half4 v4f16, int i32, __amdgpu_texture_t tex) {
54 return __builtin_amdgcn_image_load_2d_v4f16_i32(100, i32, i32, tex, 120, 110); // expected-no-error
55 }
56
57 half4 test_builtin_amdgcn_image_sample_2d_v4f16_f32(half4 v4f16, int i32, float f32, __amdgpu_texture_t tex, int4 vec4i32) {
58 return __builtin_amdgcn_image_sample_2d_v4f16_f32(100, f32, f32, tex, vec4i32, 0, 120, 110); // expected-no-error
59 }
60
61 void test_half_mismatch_vector_size_error(float16_2 f16_2, float16_3 f16_3, float16_4 f16_4, float16_8 f16_8, float16_16 f16_16) {
62 half2 h2 = f16_3 ; // expected-error{{initializing '__private half2' (vector of 2 'half' values) with an expression of incompatible type '__private float16_3' (vector of 3 '_Float16' values)}}
63 half3 h3 = f16_2; // expected-error{{initializing '__private half3' (vector of 3 'half' values) with an expression of incompatible type '__private float16_2' (vector of 2 '_Float16' values)}}
64 half4 h4 = f16_8; // expected-error{{initializing '__private half4' (vector of 4 'half' values) with an expression of incompatible type '__private float16_8' (vector of 8 '_Float16' values)}}
65 half8 h8 = f16_4; // expected-error{{initializing '__private half8' (vector of 8 'half' values) with an expression of incompatible type '__private float16_4' (vector of 4 '_Float16' values)}}
66 half16 h16 = f16_4; // expected-error{{initializing '__private half16' (vector of 16 'half' values) with an expression of incompatible type '__private float16_4' (vector of 4 '_Float16' values)}}
67 }
68
69 void test_float16_mismatch_vector_size_error(half2 h2, half3 h3, half4 h4, half8 h8, half16 h16) {
70 float16_2 f16_2 = h3; // expected-error{{initializing '__private float16_2' (vector of 2 '_Float16' values) with an expression of incompatible type '__private half3' (vector of 3 'half' values)}}
71 float16_3 f16_3 = h2; // expected-error{{initializing '__private float16_3' (vector of 3 '_Float16' values) with an expression of incompatible type '__private half2' (vector of 2 'half' values)}}
72 float16_4 f16_4 = h8; // expected-error{{initializing '__private float16_4' (vector of 4 '_Float16' values) with an expression of incompatible type '__private half8' (vector of 8 'half' values)}}
73 float16_8 f16_8 = h4; // expected-error{{initializing '__private float16_8' (vector of 8 '_Float16' values) with an expression of incompatible type '__private half4' (vector of 4 'half' values)}}
74 float16_16 f16_16 = h4; // expected-error{{initializing '__private float16_16' (vector of 16 '_Float16' values) with an expression of incompatible type '__private half4' (vector of 4 'half' values)}}
75 }