| 1 |
#include <stdlib.h> |
| 2 |
#include <stdio.h> |
| 3 |
#include <string.h> |
| 4 |
#include <time.h> |
| 5 |
|
| 6 |
#include "libgccjit.h" |
| 7 |
|
| 8 |
#include "harness.h" |
| 9 |
|
| 10 |
void |
| 11 |
create_code (gcc_jit_context *ctxt, void *user_data) |
| 12 |
{ |
| 13 |
/* Let's try to inject the equivalent of: |
| 14 |
|
| 15 |
int __attribute__ ((__vector_size__ (8))) convert_vec(double __attribute__ ((__vector_size__ (16))) double_vec) |
| 16 |
{ |
| 17 |
return __builtin_convertvector (double_vec, int __attribute__ ((__vector_size__ (8)))); |
| 18 |
} |
| 19 |
*/ |
| 20 |
gcc_jit_type *int_type = |
| 21 |
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_INT); |
| 22 |
gcc_jit_type *int_vector_type = |
| 23 |
gcc_jit_type_get_vector (int_type, 2); |
| 24 |
gcc_jit_type *double_type = |
| 25 |
gcc_jit_context_get_type (ctxt, GCC_JIT_TYPE_DOUBLE); |
| 26 |
gcc_jit_type *double_vector_type = |
| 27 |
gcc_jit_type_get_vector (double_type, 2); |
| 28 |
|
| 29 |
/* Build the convert_vec. */ |
| 30 |
gcc_jit_param *param = |
| 31 |
gcc_jit_context_new_param (ctxt, NULL, double_vector_type, "double_vec"); |
| 32 |
gcc_jit_function *convert_vec = |
| 33 |
gcc_jit_context_new_function (ctxt, NULL, |
| 34 |
GCC_JIT_FUNCTION_EXPORTED, |
| 35 |
int_vector_type, |
| 36 |
"convert_vec", |
| 37 |
1, ¶m, |
| 38 |
0); |
| 39 |
gcc_jit_block *block = gcc_jit_function_new_block (convert_vec, NULL); |
| 40 |
|
| 41 |
gcc_jit_lvalue *var = gcc_jit_function_new_local (convert_vec, NULL, double_vector_type, "mem_vec"); |
| 42 |
gcc_jit_block_add_assignment (block, NULL, var, gcc_jit_param_as_rvalue (param)); |
| 43 |
|
| 44 |
gcc_jit_block_end_with_return (block, |
| 45 |
NULL, |
| 46 |
gcc_jit_context_convert_vector (ctxt, NULL, gcc_jit_lvalue_as_rvalue (var), int_vector_type)); |
| 47 |
} |
| 48 |
|
| 49 |
void |
| 50 |
verify_code (gcc_jit_context *ctxt, gcc_jit_result *result) |
| 51 |
{ |
| 52 |
CHECK_NON_NULL (result); |
| 53 |
|
| 54 |
typedef int __attribute__ ((__vector_size__ (8))) (*convert_vec)(double __attribute__ ((__vector_size__ (16))) double_vec); |
| 55 |
double __attribute__ ((__vector_size__ (16))) double_vec = { 3.2, 7.9 }; |
| 56 |
convert_vec func = (convert_vec)gcc_jit_result_get_code (result, "convert_vec"); |
| 57 |
int __attribute__ ((__vector_size__ (8))) res = func (double_vec); |
| 58 |
int __attribute__ ((__vector_size__ (8))) expected = { 3, 7 }; |
| 59 |
CHECK_VECTOR_VALUE (2, res, expected); |
| 60 |
} |