Debian Codegraph @

gcc/testsuite/jit.dg/test-vector-perm.c

raw
1 #include <stdlib.h>
2 #include <stdio.h>
3
4 #include "libgccjit.h"
5
6 #include "harness.h"
7
8 typedef int v4si __attribute__ ((vector_size (16)));
9
10 void
11 create_code (gcc_jit_context *ctxt, void *user_data)
12 {
13 gcc_jit_type *int_type =
14 gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT);
15 gcc_jit_type *v4si =
16 gcc_jit_type_get_vector (int_type, 4);
17
18 gcc_jit_function *func_vector =
19 gcc_jit_context_new_function (ctxt, NULL,
20 GCC_JIT_FUNCTION_EXPORTED,
21 int_type,
22 "vector",
23 0, NULL,
24 0);
25
26 gcc_jit_rvalue *elements[4]
27 = { gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 1),
28 gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 2),
29 gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 3),
30 gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 4),
31 };
32
33 gcc_jit_rvalue *vector
34 = gcc_jit_context_new_rvalue_from_vector (ctxt, NULL, v4si, 4, elements);
35
36 gcc_jit_rvalue *index
37 = gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 2);
38
39 gcc_jit_block *block_a = gcc_jit_function_new_block (func_vector, NULL);
40 gcc_jit_lvalue *value
41 = gcc_jit_context_new_vector_access (ctxt, NULL, vector, index);
42 gcc_jit_block_end_with_return (block_a, NULL, gcc_jit_lvalue_as_rvalue (value));
43
44 gcc_jit_function *func_vector_perm =
45 gcc_jit_context_new_function (ctxt, NULL,
46 GCC_JIT_FUNCTION_EXPORTED,
47 v4si,
48 "vector_perm",
49 0, NULL,
50 0);
51
52 gcc_jit_rvalue *elements2[4]
53 = { gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 5),
54 gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 6),
55 gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 7),
56 gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 8),
57 };
58
59 gcc_jit_rvalue *vector2
60 = gcc_jit_context_new_rvalue_from_vector (ctxt, NULL, v4si, 4, elements2);
61
62 gcc_jit_rvalue *mask_values[4]
63 = { gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 7),
64 gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 2),
65 gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 3),
66 gcc_jit_context_new_rvalue_from_int (ctxt, int_type, 0),
67 };
68
69 gcc_jit_rvalue *mask
70 = gcc_jit_context_new_rvalue_from_vector (ctxt, NULL, v4si, 4, mask_values);
71
72 gcc_jit_block *block_b = gcc_jit_function_new_block (func_vector_perm, NULL);
73 gcc_jit_rvalue *result = gcc_jit_context_new_rvalue_vector_perm (ctxt, NULL, vector, vector2, mask);
74 gcc_jit_block_end_with_return (block_b, NULL, result);
75 }
76
77 void
78 verify_code (gcc_jit_context *ctxt, gcc_jit_result *result)
79 {
80 CHECK_NON_NULL (result);
81
82 typedef int (*vector) ();
83 vector fn = (vector)gcc_jit_result_get_code (result, "vector");
84 CHECK_NON_NULL (fn);
85
86 int vector_access = fn ();
87 CHECK_VALUE (vector_access, 3);
88
89 typedef v4si (*vector_perm) ();
90 vector_perm perm_fn = (vector_perm)gcc_jit_result_get_code (result, "vector_perm");
91 CHECK_NON_NULL (perm_fn);
92
93 v4si vector_perm_res = perm_fn ();
94 v4si expected_vec = { 8, 3, 4, 1 };
95 CHECK_VECTOR_VALUE (4, vector_perm_res, expected_vec);
96 }