Re: [081/nnn] poly_int: brig vector elements
Hi Richard, Indeed, HSAIL doesn't so far support variable length vectors. If it ever will, there will be wider changes needed anyways. So, this patch LGTM. Pekka, A HSA/BRIG maintainer On Mon, Oct 23, 2017 at 7:32 PM, Richard Sandifordwrote: > This patch adds a brig-specific wrapper around TYPE_VECTOR_SUBPARTS, > since presumably it will never need to support variable vector lengths. > > > 2017-10-23 Richard Sandiford > Alan Hayward > David Sherwood > > gcc/brig/ > * brigfrontend/brig-util.h (gccbrig_type_vector_subparts): New > function. > * brigfrontend/brig-basic-inst-handler.cc > (brig_basic_inst_handler::build_shuffle): Use it instead of > TYPE_VECTOR_SUBPARTS. > (brig_basic_inst_handler::build_unpack): Likewise. > (brig_basic_inst_handler::build_pack): Likewise. > (brig_basic_inst_handler::build_unpack_lo_or_hi): Likewise. > (brig_basic_inst_handler::operator ()): Likewise. > (brig_basic_inst_handler::build_lower_element_broadcast): Likewise. > * brigfrontend/brig-code-entry-handler.cc > (brig_code_entry_handler::get_tree_cst_for_hsa_operand): Likewise. > (brig_code_entry_handler::get_comparison_result_type): Likewise. > (brig_code_entry_handler::expand_or_call_builtin): Likewise. > > Index: gcc/brig/brigfrontend/brig-util.h > === > --- gcc/brig/brigfrontend/brig-util.h 2017-10-02 09:10:56.960755788 +0100 > +++ gcc/brig/brigfrontend/brig-util.h 2017-10-23 17:22:46.882758777 +0100 > @@ -76,4 +76,12 @@ bool gccbrig_might_be_host_defined_var_p > /* From hsa.h. */ > bool hsa_type_packed_p (BrigType16_t type); > > +/* Return the number of elements in a VECTOR_TYPE. BRIG does not support > + variable-length vectors. */ > +inline unsigned HOST_WIDE_INT > +gccbrig_type_vector_subparts (const_tree type) > +{ > + return TYPE_VECTOR_SUBPARTS (type); > +} > + > #endif > Index: gcc/brig/brigfrontend/brig-basic-inst-handler.cc > === > --- gcc/brig/brigfrontend/brig-basic-inst-handler.cc2017-08-10 > 14:36:07.092506123 +0100 > +++ gcc/brig/brigfrontend/brig-basic-inst-handler.cc2017-10-23 > 17:22:46.882758777 +0100 > @@ -97,9 +97,10 @@ brig_basic_inst_handler::build_shuffle ( > output elements can originate from any input element. */ >vec *mask_offset_vals = NULL; > > + unsigned int element_count = gccbrig_type_vector_subparts (arith_type); > + >vec *input_mask_vals = NULL; > - size_t input_mask_element_size > -= exact_log2 (TYPE_VECTOR_SUBPARTS (arith_type)); > + size_t input_mask_element_size = exact_log2 (element_count); > >/* Unpack the tightly packed mask elements to BIT_FIELD_REFs > from which to construct the mask vector as understood by > @@ -109,7 +110,7 @@ brig_basic_inst_handler::build_shuffle ( >tree mask_element_type > = build_nonstandard_integer_type (input_mask_element_size, true); > > - for (size_t i = 0; i < TYPE_VECTOR_SUBPARTS (arith_type); ++i) > + for (size_t i = 0; i < element_count; ++i) > { >tree mask_element > = build3 (BIT_FIELD_REF, mask_element_type, mask_operand, > @@ -119,17 +120,15 @@ brig_basic_inst_handler::build_shuffle ( >mask_element = convert (element_type, mask_element); > >tree offset; > - if (i < TYPE_VECTOR_SUBPARTS (arith_type) / 2) > + if (i < element_count / 2) > offset = build_int_cst (element_type, 0); >else > - offset > - = build_int_cst (element_type, TYPE_VECTOR_SUBPARTS (arith_type)); > + offset = build_int_cst (element_type, element_count); > >CONSTRUCTOR_APPEND_ELT (mask_offset_vals, NULL_TREE, offset); >CONSTRUCTOR_APPEND_ELT (input_mask_vals, NULL_TREE, mask_element); > } > - tree mask_vec_type > -= build_vector_type (element_type, TYPE_VECTOR_SUBPARTS (arith_type)); > + tree mask_vec_type = build_vector_type (element_type, element_count); > >tree mask_vec = build_constructor (mask_vec_type, input_mask_vals); >tree offset_vec = build_constructor (mask_vec_type, mask_offset_vals); > @@ -158,7 +157,8 @@ brig_basic_inst_handler::build_unpack (t >vec *input_mask_vals = NULL; >vec *and_mask_vals = NULL; > > - size_t element_count = TYPE_VECTOR_SUBPARTS (TREE_TYPE (operands[0])); > + size_t element_count > += gccbrig_type_vector_subparts (TREE_TYPE (operands[0])); >tree vec_type = build_vector_type (element_type, element_count); > >for (size_t i = 0; i < element_count; ++i) > @@ -213,7 +213,7 @@ brig_basic_inst_handler::build_pack (tre > TODO: Reuse this for implementing 'bitinsert' >
[081/nnn] poly_int: brig vector elements
This patch adds a brig-specific wrapper around TYPE_VECTOR_SUBPARTS, since presumably it will never need to support variable vector lengths. 2017-10-23 Richard SandifordAlan Hayward David Sherwood gcc/brig/ * brigfrontend/brig-util.h (gccbrig_type_vector_subparts): New function. * brigfrontend/brig-basic-inst-handler.cc (brig_basic_inst_handler::build_shuffle): Use it instead of TYPE_VECTOR_SUBPARTS. (brig_basic_inst_handler::build_unpack): Likewise. (brig_basic_inst_handler::build_pack): Likewise. (brig_basic_inst_handler::build_unpack_lo_or_hi): Likewise. (brig_basic_inst_handler::operator ()): Likewise. (brig_basic_inst_handler::build_lower_element_broadcast): Likewise. * brigfrontend/brig-code-entry-handler.cc (brig_code_entry_handler::get_tree_cst_for_hsa_operand): Likewise. (brig_code_entry_handler::get_comparison_result_type): Likewise. (brig_code_entry_handler::expand_or_call_builtin): Likewise. Index: gcc/brig/brigfrontend/brig-util.h === --- gcc/brig/brigfrontend/brig-util.h 2017-10-02 09:10:56.960755788 +0100 +++ gcc/brig/brigfrontend/brig-util.h 2017-10-23 17:22:46.882758777 +0100 @@ -76,4 +76,12 @@ bool gccbrig_might_be_host_defined_var_p /* From hsa.h. */ bool hsa_type_packed_p (BrigType16_t type); +/* Return the number of elements in a VECTOR_TYPE. BRIG does not support + variable-length vectors. */ +inline unsigned HOST_WIDE_INT +gccbrig_type_vector_subparts (const_tree type) +{ + return TYPE_VECTOR_SUBPARTS (type); +} + #endif Index: gcc/brig/brigfrontend/brig-basic-inst-handler.cc === --- gcc/brig/brigfrontend/brig-basic-inst-handler.cc2017-08-10 14:36:07.092506123 +0100 +++ gcc/brig/brigfrontend/brig-basic-inst-handler.cc2017-10-23 17:22:46.882758777 +0100 @@ -97,9 +97,10 @@ brig_basic_inst_handler::build_shuffle ( output elements can originate from any input element. */ vec *mask_offset_vals = NULL; + unsigned int element_count = gccbrig_type_vector_subparts (arith_type); + vec *input_mask_vals = NULL; - size_t input_mask_element_size -= exact_log2 (TYPE_VECTOR_SUBPARTS (arith_type)); + size_t input_mask_element_size = exact_log2 (element_count); /* Unpack the tightly packed mask elements to BIT_FIELD_REFs from which to construct the mask vector as understood by @@ -109,7 +110,7 @@ brig_basic_inst_handler::build_shuffle ( tree mask_element_type = build_nonstandard_integer_type (input_mask_element_size, true); - for (size_t i = 0; i < TYPE_VECTOR_SUBPARTS (arith_type); ++i) + for (size_t i = 0; i < element_count; ++i) { tree mask_element = build3 (BIT_FIELD_REF, mask_element_type, mask_operand, @@ -119,17 +120,15 @@ brig_basic_inst_handler::build_shuffle ( mask_element = convert (element_type, mask_element); tree offset; - if (i < TYPE_VECTOR_SUBPARTS (arith_type) / 2) + if (i < element_count / 2) offset = build_int_cst (element_type, 0); else - offset - = build_int_cst (element_type, TYPE_VECTOR_SUBPARTS (arith_type)); + offset = build_int_cst (element_type, element_count); CONSTRUCTOR_APPEND_ELT (mask_offset_vals, NULL_TREE, offset); CONSTRUCTOR_APPEND_ELT (input_mask_vals, NULL_TREE, mask_element); } - tree mask_vec_type -= build_vector_type (element_type, TYPE_VECTOR_SUBPARTS (arith_type)); + tree mask_vec_type = build_vector_type (element_type, element_count); tree mask_vec = build_constructor (mask_vec_type, input_mask_vals); tree offset_vec = build_constructor (mask_vec_type, mask_offset_vals); @@ -158,7 +157,8 @@ brig_basic_inst_handler::build_unpack (t vec *input_mask_vals = NULL; vec *and_mask_vals = NULL; - size_t element_count = TYPE_VECTOR_SUBPARTS (TREE_TYPE (operands[0])); + size_t element_count += gccbrig_type_vector_subparts (TREE_TYPE (operands[0])); tree vec_type = build_vector_type (element_type, element_count); for (size_t i = 0; i < element_count; ++i) @@ -213,7 +213,7 @@ brig_basic_inst_handler::build_pack (tre TODO: Reuse this for implementing 'bitinsert' without a builtin call. */ - size_t ecount = TYPE_VECTOR_SUBPARTS (TREE_TYPE (operands[0])); + size_t ecount = gccbrig_type_vector_subparts (TREE_TYPE (operands[0])); size_t vecsize = int_size_in_bytes (TREE_TYPE (operands[0])) * BITS_PER_UNIT; tree wide_type = build_nonstandard_integer_type (vecsize, 1); @@ -275,9 +275,10 @@ brig_basic_inst_handler::build_unpack_lo { tree element_type = get_unsigned_int_type (TREE_TYPE (arith_type));