Rename gdb/ChangeLog to gdb/ChangeLog-2021
[binutils-gdb.git] / gdb / testsuite / gdb.opencl / vec_comps.exp
blob4dd524729bb265604fc0b5f75ba7596cfd887ae9
1 # Copyright 2010-2021 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>. */
16 # Contributed by Ken Werner <ken.werner@de.ibm.com>.
18 # Tests component access of OpenCL vectors.
20 load_lib opencl.exp
22 if { [skip_opencl_tests] } {
23 unsupported "OpenCL support not detected"
24 return 0
27 set testfile "vec_comps"
28 set clprogram [remote_download target ${srcdir}/${subdir}/${testfile}.cl]
30 # Compile the generic OpenCL host app
31 if { [gdb_compile_opencl_hostapp "${clprogram}" "${testfile}" "" ] != "" } {
32 untested "failed to compile"
33 return -1
36 # Load the OpenCL app
37 clean_restart ${testfile}
39 # Set breakpoint at the OpenCL kernel
40 gdb_test "tbreak testkernel" \
41 "" \
42 "Set pending breakpoint" \
43 ".*Function \"testkernel\" not defined.*Make breakpoint pending.*y or \\\[n\\\]. $" \
44 "y"
46 gdb_run_cmd
47 gdb_test "" ".*reakpoint.*1.*testkernel.*" "run"
49 # Continue to the marker
50 gdb_breakpoint [gdb_get_line_number "marker" "${clprogram}"]
51 gdb_continue_to_breakpoint "marker"
53 # Check if the language was switched to opencl
54 gdb_test "show language" "The current source language is \"auto; currently opencl\"\."
56 # Retrieve some information about the OpenCL version and the availability of extensions
57 set opencl_version [get_integer_valueof "opencl_version" 0]
58 set have_cl_khr_fp64 [get_integer_valueof "have_cl_khr_fp64" 0]
59 set have_cl_khr_fp16 [get_integer_valueof "have_cl_khr_fp16" 0]
61 # Sanity checks
62 proc check_basic { name type size } {
63 gdb_test "ptype ${name}" "type = ${type}16"
64 gdb_test "p sizeof(${name})" " = [expr ${size} * 16]"
65 gdb_test "print/d ${name}" " = \\{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15\\}"
68 proc check_type { name type alttype } {
69 gdb_test "whatis ${name}.lo" "type = ${type}8"
70 gdb_test "whatis ${name}.hi" "type = ${type}8"
71 gdb_test "whatis ${name}.even" "type = ${type}8"
72 gdb_test "whatis ${name}.odd" "type = ${type}8"
73 gdb_test "whatis ${name}.low" "Invalid OpenCL vector component accessor low"
74 gdb_test "whatis ${name}.high" "Invalid OpenCL vector component accessor high"
76 gdb_test "whatis ${name}.hi.even" "type = ${type}4"
77 gdb_test "whatis ${name}.odd.odd.lo" "type = ${type}2"
78 gdb_test "whatis ${name}.even.hi.lo.odd" "type = ${alttype}|${type}"
80 gdb_test "whatis ${name}.x" "type = ${alttype}|${type}"
81 gdb_test "whatis ${name}.y" "type = ${alttype}|${type}"
82 gdb_test "whatis ${name}.z" "type = ${alttype}|${type}"
83 gdb_test "whatis ${name}.w" "type = ${alttype}|${type}"
84 gdb_test "whatis ${name}.v" "Invalid OpenCL vector component accessor v"
86 gdb_test "whatis ${name}.xy" "type = ${type}2"
87 gdb_test "whatis ${name}.xx" "type = ${type}2"
88 gdb_test "whatis ${name}.wy" "type = ${type}2"
89 gdb_test "whatis ${name}.zv" "Invalid OpenCL vector component accessor zv"
91 gdb_test "whatis ${name}.xyz" "type = ${type}3"
92 gdb_test "whatis ${name}.yxy" "type = ${type}3"
93 gdb_test "whatis ${name}.yzx" "type = ${type}3"
94 gdb_test "whatis ${name}.yzv" "Invalid OpenCL vector component accessor yzv"
96 gdb_test "whatis ${name}.xywz" "type = ${type}4"
97 gdb_test "whatis ${name}.zzyy" "type = ${type}4"
98 gdb_test "whatis ${name}.wwww" "type = ${type}4"
99 gdb_test "whatis ${name}.yxwv" "Invalid OpenCL vector component accessor yxwv"
100 gdb_test "whatis ${name}.zyxwv" "Invalid OpenCL vector component accessor zyxwv"
102 gdb_test "whatis ${name}.xy.x" "type = ${alttype}|${type}"
103 gdb_test "whatis ${name}.wzyx.yy" "type = ${type}2"
104 gdb_test "whatis ${name}.wzyx.yx.x" "type = ${alttype}|${type}"
105 gdb_test "whatis ${name}.xyzw.w" "type = ${alttype}|${type}"
106 gdb_test "whatis ${name}.xy.z" "Invalid OpenCL vector component accessor z"
108 gdb_test "whatis ${name}.s0" "type = ${alttype}|${type}"
109 gdb_test "whatis ${name}.s9" "type = ${alttype}|${type}"
110 gdb_test "whatis ${name}.sa" "type = ${alttype}|${type}"
111 gdb_test "whatis ${name}.sf" "type = ${alttype}|${type}"
112 gdb_test "whatis ${name}.sF" "type = ${alttype}|${type}"
113 gdb_test "whatis ${name}.sg" "Invalid OpenCL vector component accessor sg"
114 gdb_test "whatis ${name}.sG" "Invalid OpenCL vector component accessor sG"
115 gdb_test "whatis ${name}.Sg" "Invalid OpenCL vector component accessor Sg"
116 gdb_test "whatis ${name}.SG" "Invalid OpenCL vector component accessor SG"
118 gdb_test "whatis ${name}.s01" "type = ${type}2"
119 gdb_test "whatis ${name}.s00" "type = ${type}2"
120 gdb_test "whatis ${name}.sF0" "type = ${type}2"
121 gdb_test "whatis ${name}.S42" "type = ${type}2"
123 gdb_test "whatis ${name}.s567" "type = ${type}3"
124 gdb_test "whatis ${name}.S333" "type = ${type}3"
125 gdb_test "whatis ${name}.Sf0A" "type = ${type}3"
126 gdb_test "whatis ${name}.SB1D" "type = ${type}3"
127 gdb_test "whatis ${name}.s01g" "Invalid OpenCL vector component accessor s01g"
129 gdb_test "whatis ${name}.s9876" "type = ${type}4"
130 gdb_test "whatis ${name}.sFFFF" "type = ${type}4"
131 gdb_test "whatis ${name}.sCafe" "type = ${type}4"
132 gdb_test "whatis ${name}.Sf001" "type = ${type}4"
133 gdb_test "whatis ${name}.s1fg2" "Invalid OpenCL vector component accessor s1fg2"
134 gdb_test "whatis ${name}.s012345" "Invalid OpenCL vector component accessor s012345"
136 gdb_test "whatis ${name}.s00000000" "type = ${type}8"
137 gdb_test "whatis ${name}.s00224466" "type = ${type}8"
138 gdb_test "whatis ${name}.sDEADBEEF" "type = ${type}8"
139 gdb_test "whatis ${name}.Sa628c193" "type = ${type}8"
141 gdb_test "whatis ${name}.s876543210" "Invalid OpenCL vector component accessor s876543210"
142 gdb_test "whatis ${name}.s0123456789abcde" "Invalid OpenCL vector component accessor s0123456789abcde"
144 gdb_test "whatis ${name}.s0123456789aBcDeF" "type = ${type}16"
145 gdb_test "whatis ${name}.s0022446688AACCFF" "type = ${type}16"
146 gdb_test "whatis ${name}.S0123456776543210" "type = ${type}16"
147 gdb_test "whatis ${name}.sFEDCBA9876543210" "type = ${type}16"
149 gdb_test "whatis ${name}.sfedcba98.S0246" "type = ${type}4"
150 gdb_test "whatis ${name}.sfedcba98.S0246.s13" "type = ${type}2"
151 gdb_test "whatis ${name}.sfedcba98.S0246.s13.s0" "type = ${alttype}|${type}"
152 gdb_test "whatis ${name}.s0123456789abcdef.s22" "type = ${type}2"
154 gdb_test "whatis ${name}.hi.s7654.wx" "type = ${type}2"
155 gdb_test "whatis ${name}.s0123456789abcdef.even.lo" "type = ${type}4"
156 gdb_test "whatis ${name}.odd.xyzw.s23" "type = ${type}2"
157 gdb_test "whatis ${name}.xyzw.hi.odd" "type = ${alttype}|${type}"
159 gdb_test "ptype ${name}.lo" "type = ${type}8"
160 gdb_test "ptype ${name}.hi" "type = ${type}8"
161 gdb_test "ptype ${name}.even" "type = ${type}8"
162 gdb_test "ptype ${name}.odd" "type = ${type}8"
164 gdb_test "ptype ${name}.hi.even" "type = ${type}4"
165 gdb_test "ptype ${name}.odd.odd.lo" "type = ${type}2"
166 gdb_test "ptype ${name}.even.hi.lo.odd" "type = ${alttype}|${type}"
168 gdb_test "ptype ${name}.x" "type = ${alttype}|${type}"
169 gdb_test "ptype ${name}.y" "type = ${alttype}|${type}"
170 gdb_test "ptype ${name}.z" "type = ${alttype}|${type}"
171 gdb_test "ptype ${name}.w" "type = ${alttype}|${type}"
173 gdb_test "ptype ${name}.xy" "type = ${type}2"
174 gdb_test "ptype ${name}.xx" "type = ${type}2"
175 gdb_test "ptype ${name}.wy" "type = ${type}2"
177 gdb_test "ptype ${name}.xyz" "type = ${type}3"
178 gdb_test "ptype ${name}.yxy" "type = ${type}3"
179 gdb_test "ptype ${name}.yzx" "type = ${type}3"
181 gdb_test "ptype ${name}.xywz" "type = ${type}4"
182 gdb_test "ptype ${name}.zzyy" "type = ${type}4"
183 gdb_test "ptype ${name}.wwww" "type = ${type}4"
185 gdb_test "ptype ${name}.xy.x" "type = ${alttype}|${type}"
186 gdb_test "ptype ${name}.wzyx.yy" "type = ${type}2"
187 gdb_test "ptype ${name}.wzyx.yx.x" "type = ${alttype}|${type}"
188 gdb_test "ptype ${name}.xyzw.w" "type = ${alttype}|${type}"
190 gdb_test "ptype ${name}.s0" "type = ${alttype}|${type}"
191 gdb_test "ptype ${name}.s9" "type = ${alttype}|${type}"
192 gdb_test "ptype ${name}.sa" "type = ${alttype}|${type}"
193 gdb_test "ptype ${name}.sf" "type = ${alttype}|${type}"
194 gdb_test "ptype ${name}.sF" "type = ${alttype}|${type}"
196 gdb_test "ptype ${name}.s01" "type = ${type}2"
197 gdb_test "ptype ${name}.s00" "type = ${type}2"
198 gdb_test "ptype ${name}.sF0" "type = ${type}2"
199 gdb_test "ptype ${name}.S42" "type = ${type}2"
201 gdb_test "ptype ${name}.s567" "type = ${type}3"
202 gdb_test "ptype ${name}.S333" "type = ${type}3"
203 gdb_test "ptype ${name}.Sf0A" "type = ${type}3"
204 gdb_test "ptype ${name}.SB1D" "type = ${type}3"
206 gdb_test "ptype ${name}.s9876" "type = ${type}4"
207 gdb_test "ptype ${name}.sFFFF" "type = ${type}4"
208 gdb_test "ptype ${name}.sCafe" "type = ${type}4"
209 gdb_test "ptype ${name}.Sf001" "type = ${type}4"
211 gdb_test "ptype ${name}.s00000000" "type = ${type}8"
212 gdb_test "ptype ${name}.s00224466" "type = ${type}8"
213 gdb_test "ptype ${name}.sDEADBEEF" "type = ${type}8"
214 gdb_test "ptype ${name}.Sa628c193" "type = ${type}8"
216 gdb_test "ptype ${name}.s0123456789aBcDeF" "type = ${type}16"
217 gdb_test "ptype ${name}.s0022446688AACCFF" "type = ${type}16"
218 gdb_test "ptype ${name}.S0123456776543210" "type = ${type}16"
219 gdb_test "ptype ${name}.sFEDCBA9876543210" "type = ${type}16"
221 gdb_test "ptype ${name}.sfedcba98.S0246" "type = ${type}4"
222 gdb_test "ptype ${name}.sfedcba98.S0246.s13" "type = ${type}2"
223 gdb_test "ptype ${name}.sfedcba98.S0246.s13.s0" "type = ${alttype}|${type}"
224 gdb_test "ptype ${name}.s0123456789abcdef.s22" "type = ${type}2"
226 gdb_test "ptype ${name}.hi.s7654.wx" "type = ${type}2"
227 gdb_test "ptype ${name}.s0123456789abcdef.even.lo" "type = ${type}4"
228 gdb_test "ptype ${name}.odd.xyzw.s23" "type = ${type}2"
229 gdb_test "ptype ${name}.xyzw.hi.odd" "type = ${alttype}|${type}"
232 proc check_sizeof { name size } {
233 gdb_test "print sizeof (${name}.lo)" " = [expr $size * 8]"
234 gdb_test "print sizeof (${name}.hi)" " = [expr $size * 8]"
235 gdb_test "print sizeof (${name}.even)" " = [expr $size * 8]"
236 gdb_test "print sizeof (${name}.odd)" " = [expr $size * 8]"
238 gdb_test "print sizeof (${name}.hi.even)" " = [expr $size * 4]"
239 gdb_test "print sizeof (${name}.odd.odd.lo)" " = [expr $size * 2]"
240 gdb_test "print sizeof (${name}.even.hi.lo.odd)" " = $size"
242 gdb_test "print sizeof (${name}.x)" " = $size"
243 gdb_test "print sizeof (${name}.xy)" " = [expr $size * 2]"
244 gdb_test "print sizeof (${name}.xyz)" " = [expr $size * 4]"
245 gdb_test "print sizeof (${name}.xyzw)" " = [expr $size * 4]"
247 gdb_test "print sizeof (${name}.xy.x)" " = $size"
248 gdb_test "print sizeof (${name}.wzyx.yy)" " = [expr $size * 2]"
249 gdb_test "print sizeof (${name}.wzyx.yx.x)" " = $size"
250 gdb_test "print sizeof (${name}.xyzw.w)" " = $size"
252 gdb_test "print sizeof (${name}.s0)" " = $size"
253 gdb_test "print sizeof (${name}.s01)" " = [expr $size * 2]"
254 gdb_test "print sizeof (${name}.s012)" " = [expr $size * 4]"
255 gdb_test "print sizeof (${name}.s0123)" " = [expr $size * 4]"
256 gdb_test "print sizeof (${name}.s01234567)" " = [expr $size * 8]"
257 gdb_test "print sizeof (${name}.s0123456789abcdef)" " = [expr $size * 16]"
259 gdb_test "print sizeof (${name}.sfedcba98.S0246)" " = [expr $size * 4]"
260 gdb_test "print sizeof (${name}.sfedcba98.S0246.s13)" " = [expr $size * 2]"
261 gdb_test "print sizeof (${name}.sfedcba98.S0246.s13.s0)" " = $size"
262 gdb_test "print sizeof (${name}.s0123456789abcdef.s22)" " = [expr $size * 2]"
264 gdb_test "print sizeof (${name}.hi.s7654.wx)" " = [expr $size * 2]"
265 gdb_test "print sizeof (${name}.s0123456789abcdef.even.lo)" " = [expr $size * 4]"
266 gdb_test "print sizeof (${name}.odd.xyzw.s23)" " = [expr $size * 2]"
267 gdb_test "print sizeof (${name}.xyzw.hi.odd)" " = $size"
270 # OpenCL vector component access
271 proc check_access { name } {
272 gdb_test "print/d ${name}.lo" " = \\{0, 1, 2, 3, 4, 5, 6, 7\\}"
273 gdb_test "print/d ${name}.hi" " = \\{8, 9, 10, 11, 12, 13, 14, 15\\}"
274 gdb_test "print/d ${name}.even" " = \\{0, 2, 4, 6, 8, 10, 12, 14\\}"
275 gdb_test "print/d ${name}.odd" " = \\{1, 3, 5, 7, 9, 11, 13, 15\\}"
277 gdb_test "print/d ${name}.hi.even" " = \\{8, 10, 12, 14\\}"
278 gdb_test "print/d ${name}.odd.odd.lo" " = \\{3, 7\\}"
279 gdb_test "print/d ${name}.even.hi.lo.odd" " = 10"
281 gdb_test "print/d ${name}.x" " = 0"
282 gdb_test "print/d ${name}.y" " = 1"
283 gdb_test "print/d ${name}.z" " = 2"
284 gdb_test "print/d ${name}.w" " = 3"
286 gdb_test "print/d ${name}.xy" " = \\{0, 1\\}"
287 gdb_test "print/d ${name}.xx" " = \\{0, 0\\}"
288 gdb_test "print/d ${name}.wy" " = \\{3, 1\\}"
290 gdb_test "print/d ${name}.xyz" " = \\{0, 1, 2\\}"
291 gdb_test "print/d ${name}.yxy" " = \\{1, 0, 1\\}"
292 gdb_test "print/d ${name}.yzx" " = \\{1, 2, 0\\}"
294 gdb_test "print/d ${name}.xywz" " = \\{0, 1, 3, 2\\}"
295 gdb_test "print/d ${name}.zzyy" " = \\{2, 2, 1, 1\\}"
296 gdb_test "print/d ${name}.wwww" " = \\{3, 3, 3, 3\\}"
298 gdb_test "print/d ${name}.xy.x" " = 0"
299 gdb_test "print/d ${name}.wzyx.yy" " = \\{2, 2\\}"
300 gdb_test "print/d ${name}.wzyx.yx.x" " = 2"
301 gdb_test "print/d ${name}.xyzw.w" " = 3"
303 for {set i 0} {$i < 16} {incr i} {
304 gdb_test "print/d ${name}.s[format "%x" $i]" " = $i"
305 gdb_test "print/d ${name}.S[format "%x" $i]" " = $i"
306 if {$i > 9} {
307 gdb_test "print/d ${name}.s[format "%X" $i]" " = $i"
308 gdb_test "print/d ${name}.S[format "%X" $i]" " = $i"
312 gdb_test "print/d ${name}.s01" " = \\{0, 1\\}"
313 gdb_test "print/d ${name}.s00" " = \\{0, 0\\}"
314 gdb_test "print/d ${name}.sF0" " = \\{15, 0\\}"
315 gdb_test "print/d ${name}.S42" " = \\{4, 2\\}"
317 gdb_test "print/d ${name}.s567" " = \\{5, 6, 7\\}"
318 gdb_test "print/d ${name}.S333" " = \\{3, 3, 3\\}"
319 gdb_test "print/d ${name}.Sf0A" " = \\{15, 0, 10\\}"
320 gdb_test "print/d ${name}.SB1D" " = \\{11, 1, 13\\}"
322 gdb_test "print/d ${name}.s9876" " = \\{9, 8, 7, 6\\}"
323 gdb_test "print/d ${name}.sFFFF" " = \\{15, 15, 15, 15\\}"
324 gdb_test "print/d ${name}.sCafe" " = \\{12, 10, 15, 14\\}"
325 gdb_test "print/d ${name}.Sf001" " = \\{15, 0, 0, 1\\}"
327 gdb_test "print/d ${name}.s00000000" " = \\{0, 0, 0, 0, 0, 0, 0, 0\\}"
328 gdb_test "print/d ${name}.s00224466" " = \\{0, 0, 2, 2, 4, 4, 6, 6\\}"
329 gdb_test "print/d ${name}.sDEADBEEF" " = \\{13, 14, 10, 13, 11, 14, 14, 15\\}"
330 gdb_test "print/d ${name}.Sa628c193" " = \\{10, 6, 2, 8, 12, 1, 9, 3\\}"
332 gdb_test "print/d ${name}.s0123456789aBcDeF" " = \\{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15\\}"
333 gdb_test "print/d ${name}.s0022446688AACCEE" " = \\{0, 0, 2, 2, 4, 4, 6, 6, 8, 8, 10, 10, 12, 12, 14, 14\\}"
334 gdb_test "print/d ${name}.S0123456776543210" " = \\{0, 1, 2, 3, 4, 5, 6, 7, 7, 6, 5, 4, 3, 2, 1, 0\\}"
335 gdb_test "print/d ${name}.sFEDCBA9876543210" " = \\{15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0\\}"
337 gdb_test "print/d ${name}.sfedcba98.S0246" " = \\{15, 13, 11, 9\\}"
338 gdb_test "print/d ${name}.sfedcba98.S0246.s13" " = \\{13, 9\\}"
339 gdb_test "print/d ${name}.sfedcba98.S0246.s13.s0" " = 13"
340 gdb_test "print/d ${name}.s0123456789abcdef.s22" " = \\{2, 2\\}"
342 gdb_test "print/d ${name}.hi.s7654.wx" " = \\{12, 15\\}"
343 gdb_test "print/d ${name}.s0123456789abcdef.even.lo" " = \\{0, 2, 4, 6\\}"
344 gdb_test "print/d ${name}.odd.xyzw.s23" " = \\{5, 7\\}"
345 gdb_test "print/d ${name}.xyzw.hi.odd" " = 3"
347 # lvalue tests
348 for {set i 0} {$i < 16} {incr i} {
349 gdb_test_no_output "set variable ${name}.s[format "%x" $i] = [expr 15 - $i]"
350 gdb_test "print/d ${name}.s[format "%x" $i]" " = [expr 15 - $i]"
352 gdb_test "print/d ${name}" " = \\{15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0\\}"
354 gdb_test_no_output "set variable ${name}.s02468ace = ${name}.s13579bdf"
355 gdb_test "print/d ${name}" " = \\{14, 14, 12, 12, 10, 10, 8, 8, 6, 6, 4, 4, 2, 2, 0, 0\\}"
357 gdb_test_no_output "set variable ${name}.wzyx = ${name}.even.odd"
358 gdb_test "print/d ${name}" " = \\{0, 4, 8, 12, 10, 10, 8, 8, 6, 6, 4, 4, 2, 2, 0, 0\\}"
360 gdb_test_no_output "set variable ${name}.odd.lo = ${name}.hi.even"
361 gdb_test "print/d ${name}" " = \\{0, 6, 8, 4, 10, 2, 8, 0, 6, 6, 4, 4, 2, 2, 0, 0\\}"
363 gdb_test_no_output "set variable ${name}.hi.hi.hi = ${name}.lo.s1623.lo"
364 gdb_test "print/d ${name}" " = \\{0, 6, 8, 4, 10, 2, 8, 0, 6, 6, 4, 4, 2, 2, 6, 8\\}"
367 proc do_check { name type alttype size } {
368 check_basic ${name} ${type} ${size}
369 check_type ${name} ${type} ${alttype}
370 check_sizeof ${name} ${size}
371 check_access ${name}
374 do_check "c16" "char" "char" 1
375 do_check "uc16" "uchar" "unsigned char" 1
376 do_check "s16" "short" "short" 2
377 do_check "us16" "ushort" "unsigned short" 2
378 do_check "i16" "int" "int" 4
379 do_check "ui16" "uint" "unsigned int" 4
380 do_check "l16" "long" "long" 8
381 do_check "ul16" "ulong" "unsigned long" 8
382 if { ${have_cl_khr_fp16} } {
383 do_check "h16" "half" "half" 2
385 do_check "f16" "float" "float" 4
386 if { ${have_cl_khr_fp64} } {
387 do_check "d16" "double" "double" 8
390 # Delete the OpenCL program source
391 remote_file target delete ${clprogram}