def gen_xyzw_str(type_str, size):
    """Generates tests for each combination of xyzw up to the size given.
    For example: size=3 will generate all permutations of xyz"""
    xyzw_string = ''
    for length in range(size, size + 1):
        for index_subset, value_subset in zip(
                permutations(Data.swizzle_xyzw_list_dict[size][:size], length),
                permutations(Data.vals_list_dict[size][:size], length)):
            index_string = ''
            for index in index_subset:
                index_string += index
            val_list = append_fp_postfix(type_str,
                                         gen_ordered_values(index_string, type_str))
            val_string = ', '.join(val_list)
            test_string = swizzle_xyzw_rgba_assignment_template.substitute(
                type=type_str,
                size=size,
                testVecValues=generate_value_list(type_str, size),
                indexes=index_string,
                vecName=Data.vec_name_dict[size],
                orderedValues=val_string)
            xyzw_string += wrap_with_kernel(
                type_str,
                'XYZW_KERNEL_' + type_str + str(size) + index_string,
                'Swizzle assignment: vec<' + type_str + ', ' + str(size) + '>.'
                + index_string, test_string)
    return xyzw_string
def gen_elem_str(type_str, size):
    """Generates in order, reverse order, and swapped pairs
    of elements up to the given size.
    For example: size 4 will generate element sequences
      0, 1, 2, 3
      1, 0, 3, 2
      2, 3, 1, 0
      3, 2, 1, 0"""
    index_list = Data.swizzle_elem_list_dict[size][:size]
    index_string = ', '.join(index_list)
    test_string = swizzle_elem_assignment_template.substitute(
        type=type_str,
        size=size,
        testVecValues=generate_value_list(type_str, size),
        indexes=index_string,
        vecName=Data.vec_name_dict[size],
        orderedValues=', '.join(
            append_fp_postfix(type_str, gen_ordered_values(index_list, type_str))))
    if size == 1:
        return wrap_with_kernel(
            test_string, 'ELEM_KERNEL_' + type_str + str(size) +
            ''.join(Data.swizzle_elem_list_dict[size][:size]).replace(
                'sycl::elem::', ''), 'Swizzle assignment test for vec<' +
            type_str + ', ' + str(size) + '> .swizzle<' +
            ', '.join(Data.swizzle_elem_list_dict[size][:size]) + '>',
            test_string)
    index_list = swap_pairs(Data.swizzle_elem_list_dict[size][:size])
    index_string = ', '.join(index_list)
    test_string += swizzle_elem_assignment_template.substitute(
        type=type_str,
        size=size,
        testVecValues=generate_value_list(type_str, size),
        indexes=', '.join(
            swap_pairs(Data.swizzle_elem_list_dict[size][:size])),
        vecName=Data.vec_name_dict[size],
        orderedValues=', '.join(
            append_fp_postfix(type_str, gen_ordered_values(index_list, type_str))))
    index_list = swap_pairs(Data.swizzle_elem_list_dict[size][::-1])
    index_string = ', '.join(index_list)
    test_string += swizzle_elem_assignment_template.substitute(
        type=type_str,
        size=size,
        testVecValues=generate_value_list(type_str, size),
        indexes=', '.join(swap_pairs(Data.swizzle_elem_list_dict[size][::-1])),
        vecName=Data.vec_name_dict[size],
        orderedValues=', '.join(
            append_fp_postfix(type_str, gen_ordered_values(index_list, type_str))))
    index_list = Data.swizzle_elem_list_dict[size][::-1]
    index_string = ', '.join(index_list)
    test_string += swizzle_elem_assignment_template.substitute(
        type=type_str,
        size=size,
        testVecValues=generate_value_list(type_str, size),
        indexes=', '.join(Data.swizzle_elem_list_dict[size][::-1]),
        vecName=Data.vec_name_dict[size],
        orderedValues=', '.join(
            append_fp_postfix(type_str, gen_ordered_values(index_list, type_str))))
    return wrap_with_kernel(
        test_string, 'KERNEL_SWIZZLE_ASSIGNMENT_ELEM_' + type_str + str(size) +
        ''.join(Data.swizzle_elem_list_dict[size][:size]).replace(
            'sycl::elem::', ''), 'Swizzle assignment test for vec<' +
        type_str + ', ' + str(size) + '> .swizzle<' +
        ', '.join(Data.swizzle_elem_list_dict[size][:size]) + '>', test_string)
Esempio n. 3
0
def gen_swizzle_test(type_str, convert_type_str, as_type_str, size):
    string = ''
    if size <= 4:
        for length in range(size, size + 1):
            for index_subset, value_subset in zip(
                    product(Data.swizzle_xyzw_list_dict[size][:size],
                            repeat=length),
                    product(Data.vals_list_dict[size][:size], repeat=length)):
                index_list = []
                val_list = []
                for index, value in zip(index_subset, value_subset):
                    index_list.append(index)
                    val_list.append(value)
                val_list = append_fp_postfix(type_str, val_list)
                index_string = ''.join(index_list)
                test_string = swizzle_template.substitute(
                    name=Data.vec_name_dict[size],
                    indexes=index_string,
                    type=type_str,
                    testVecValues=generate_value_list(type_str, size),
                    in_order_vals=', '.join(val_list),
                    reversed_vals=', '.join(val_list[::-1]),
                    in_order_pair_vals=', '.join(swap_pairs(val_list)),
                    reverse_order_pair_vals=', '.join(
                        swap_pairs(val_list[::-1])),
                    in_order_positions=''.join(
                        Data.swizzle_xyzw_list_dict[size][:size]),
                    size=size,
                    swiz_vals=Data.swizzle_elem_list_dict[size][::-1],
                    convert_type=convert_type_str,
                    as_type=as_type_str)
                if size > 1:
                    test_string += lo_hi_odd_even_template.substitute(
                        type=type_str, size=size)
                test_string += swizzle_elem_template.substitute(
                    type=type_str,
                    size=size,
                    in_order_swiz_indexes=', '.join(
                        Data.swizzle_elem_list_dict[size]),
                    reverse_order_swiz_indexes=', '.join(
                        Data.swizzle_elem_list_dict[size][::-1]),
                    in_order_reversed_pair_swiz_indexes=', '.join(
                        swap_pairs(Data.swizzle_elem_list_dict[size])),
                    reverse_order_reversed_pair_swiz_indexes=', '.join(
                        swap_pairs(Data.swizzle_elem_list_dict[size][::-1])))
                string += wrap_with_kernel(
                    type_str, 'KERNEL_' +
                    type_str.replace('cl::sycl::', '').replace(' ', '') +
                    str(size) + index_string,
                    'vec<' + type_str + ', ' + str(size) + '>.' + index_string,
                    test_string)
        if size == 4:
            for length in range(size, size + 1):
                for index_subset, value_subset in zip(
                        product(Data.swizzle_rgba_list_dict[size][:size],
                                repeat=length),
                        product(Data.vals_list_dict[size][:size],
                                repeat=length)):
                    index_list = []
                    val_list = []
                    for index, value in zip(index_subset, value_subset):
                        index_list.append(index)
                        val_list.append(value)
                    index_string = ''.join(index_list)
                    test_string = swizzle_template.substitute(
                        name=Data.vec_name_dict[size],
                        indexes=index_string,
                        type=type_str,
                        testVecValues=generate_value_list(type_str, size),
                        in_order_vals=', '.join(val_list),
                        reversed_vals=', '.join(val_list[::-1]),
                        in_order_pair_vals=', '.join(swap_pairs(val_list)),
                        reverse_order_pair_vals=', '.join(
                            swap_pairs(val_list[::-1])),
                        in_order_positions=''.join(
                            Data.swizzle_rgba_list_dict[size][:size]),
                        size=size,
                        swiz_vals=Data.swizzle_elem_list_dict[size][::-1],
                        convert_type=convert_type_str,
                        as_type=as_type_str)
                    test_string += lo_hi_odd_even_template.substitute(
                        type=type_str, size=size)
                    test_string += swizzle_elem_template.substitute(
                        type=type_str,
                        size=size,
                        in_order_swiz_indexes=', '.join(
                            Data.swizzle_elem_list_dict[size]),
                        reverse_order_swiz_indexes=', '.join(
                            Data.swizzle_elem_list_dict[size][::-1]),
                        in_order_reversed_pair_swiz_indexes=', '.join(
                            swap_pairs(Data.swizzle_elem_list_dict[size])),
                        reverse_order_reversed_pair_swiz_indexes=', '.join(
                            swap_pairs(
                                Data.swizzle_elem_list_dict[size][::-1])))
                    string += wrap_with_kernel(
                        type_str, 'KERNEL_' +
                        type_str.replace('cl::sycl::', '').replace(' ', '') +
                        str(size) + index_string, 'vec<' + type_str + ', ' +
                        str(size) + '>.' + index_string, test_string)
    else:
        test_string = swizzle_full_test_template.substitute(
            name=Data.vec_name_dict[size],
            type=type_str,
            size=size,
            testVecValues=generate_value_list(type_str, size),
            convert_type=convert_type_str,
            as_type=as_type_str,
            in_order_swiz_indexes=', '.join(Data.swizzle_elem_list_dict[size]),
            reverse_order_swiz_indexes=', '.join(
                Data.swizzle_elem_list_dict[size][::-1]),
            in_order_reversed_pair_swiz_indexes=', '.join(
                swap_pairs(Data.swizzle_elem_list_dict[size])),
            reverse_order_reversed_pair_swiz_indexes=', '.join(
                swap_pairs(Data.swizzle_elem_list_dict[size][::-1])),
            in_order_vals=', '.join(Data.vals_list_dict[size]),
            reversed_vals=', '.join(Data.vals_list_dict[size][::-1]),
            in_order_pair_vals=', '.join(swap_pairs(
                Data.vals_list_dict[size])),
            reverse_order_pair_vals=', '.join(
                swap_pairs(Data.vals_list_dict[size][::-1])))
        string += wrap_with_kernel(
            type_str, 'ELEM_KERNEL_' +
            type_str.replace('cl::sycl::', '').replace(' ', '') + str(size) +
            ''.join(Data.swizzle_elem_list_dict[size][:size]).replace(
                'cl::sycl::elem::', ''),
            'vec<' + type_str + ', ' + str(size) + '> .swizzle<' +
            ', '.join(Data.swizzle_elem_list_dict[size][:size]) + '>',
            test_string)
    return string