@@ -445,20 +445,20 @@ brig_release_data (void)
static BrigAlignment8_t
get_alignment (BrigType16_t type)
{
- BrigType16_t bit_type ;
- bit_type = bittype_for_type (type) ;
+ unsigned bit_size ;
+ bit_size = hsa_type_bit_size (type) ;
- if (bit_type == BRIG_TYPE_B1)
+ if (bit_size == 1)
return BRIG_ALIGNMENT_1;
- if (bit_type == BRIG_TYPE_B8)
+ if (bit_size == 8)
return BRIG_ALIGNMENT_1;
- if (bit_type == BRIG_TYPE_B16)
+ if (bit_size == 16)
return BRIG_ALIGNMENT_2;
- if (bit_type == BRIG_TYPE_B32)
+ if (bit_size == 32)
return BRIG_ALIGNMENT_4;
- if (bit_type == BRIG_TYPE_B64)
+ if (bit_size == 64)
return BRIG_ALIGNMENT_8;
- if (bit_type == BRIG_TYPE_B128)
+ if (bit_size == 128)
return BRIG_ALIGNMENT_16;
gcc_unreachable ();
}
@@ -621,71 +621,6 @@ emit_bb_label_directive (hsa_bb *hbb)
brig_insn_count++;
}
-BrigType16_t
-bittype_for_type (BrigType16_t t)
-{
- switch (t)
- {
- case BRIG_TYPE_B1:
- return BRIG_TYPE_B1;
-
- case BRIG_TYPE_U8:
- case BRIG_TYPE_S8:
- case BRIG_TYPE_B8:
- return BRIG_TYPE_B8;
-
- case BRIG_TYPE_U16:
- case BRIG_TYPE_S16:
- case BRIG_TYPE_B16:
- case BRIG_TYPE_F16:
- return BRIG_TYPE_B16;
-
- case BRIG_TYPE_U32:
- case BRIG_TYPE_S32:
- case BRIG_TYPE_B32:
- case BRIG_TYPE_F32:
- case BRIG_TYPE_U8X4:
- case BRIG_TYPE_U16X2:
- case BRIG_TYPE_S8X4:
- case BRIG_TYPE_S16X2:
- case BRIG_TYPE_F16X2:
- return BRIG_TYPE_B32;
-
- case BRIG_TYPE_U64:
- case BRIG_TYPE_S64:
- case BRIG_TYPE_F64:
- case BRIG_TYPE_B64:
- case BRIG_TYPE_U8X8:
- case BRIG_TYPE_U16X4:
- case BRIG_TYPE_U32X2:
- case BRIG_TYPE_S8X8:
- case BRIG_TYPE_S16X4:
- case BRIG_TYPE_S32X2:
- case BRIG_TYPE_F16X4:
- case BRIG_TYPE_F32X2:
-
- return BRIG_TYPE_B64;
-
- case BRIG_TYPE_B128:
- case BRIG_TYPE_U8X16:
- case BRIG_TYPE_U16X8:
- case BRIG_TYPE_U32X4:
- case BRIG_TYPE_U64X2:
- case BRIG_TYPE_S8X16:
- case BRIG_TYPE_S16X8:
- case BRIG_TYPE_S32X4:
- case BRIG_TYPE_S64X2:
- case BRIG_TYPE_F16X8:
- case BRIG_TYPE_F32X4:
- case BRIG_TYPE_F64X2:
- return BRIG_TYPE_B128;
-
- default:
- gcc_assert (seen_error ());
- return t;
- }
-}
-
/* Map a normal HSAIL type to the type of the equivalent BRIG operand
holding such, for constants and registers. */
@@ -401,9 +401,8 @@ hsa_needs_cvt (BrigType16_t dtype, BrigType16_t stype)
/* float <-> int conversions are real converts. */
if (hsa_type_float_p (dtype) != hsa_type_float_p (stype))
return true;
- /* When both types have different size (equivalent to different
- underlying bit types), then we need CVT as well. */
- if (bittype_for_type (dtype) != bittype_for_type (stype))
+ /* When both types have different size, then we need CVT as well. */
+ if (hsa_type_bit_size (dtype) != hsa_type_bit_size (stype))
return true;
return false;
}
@@ -816,8 +815,8 @@ gen_address_calculation (tree exp, hsa_bb *hbb, vec <hsa_op_reg_p> ssa_map,
hsa_op_immed *imm = hsa_alloc_immed_op (exp);
if (addrtype != imm->type)
{
- gcc_assert (bittype_for_type (addrtype)
- > bittype_for_type (imm->type));
+ gcc_assert (hsa_type_bit_size (addrtype)
+ > hsa_type_bit_size (imm->type));
imm->type = addrtype;
}
return imm;
@@ -1181,12 +1180,13 @@ hsa_build_append_simple_mov (hsa_op_reg *dest, hsa_op_base *src, hsa_bb *hbb)
insn->operands[1] = src;
if (hsa_op_reg *sreg = dyn_cast <hsa_op_reg *> (src))
{
- gcc_assert (bittype_for_type (dest->type) == bittype_for_type (sreg->type));
+ gcc_assert (hsa_type_bit_size (dest->type)
+ == hsa_type_bit_size (sreg->type));
sreg->uses.safe_push (insn);
}
else
- gcc_assert (bittype_for_type (dest->type)
- == bittype_for_type (as_a <hsa_op_immed *> (src)->type));
+ gcc_assert (hsa_type_bit_size (dest->type)
+ == hsa_type_bit_size (as_a <hsa_op_immed *> (src)->type));
set_reg_def (dest, insn);
hsa_append_insn (hbb, insn);
}
@@ -1280,17 +1280,17 @@ gen_hsa_insns_for_store (tree lhs, hsa_op_base *src, hsa_bb *hbb,
{
/* ...and all vector immediates apparently need to be vectors of
unsigned bytes. */
- BrigType16_t bt = bittype_for_type (imm->type);
- gcc_assert (bt == bittype_for_type (mem->type));
- switch (bt)
+ unsigned bs = hsa_type_bit_size (imm->type);
+ gcc_assert (bs == hsa_type_bit_size (mem->type));
+ switch (bs)
{
- case BRIG_TYPE_B32:
+ case 32:
imm->type = BRIG_TYPE_U8X4;
break;
- case BRIG_TYPE_B64:
+ case 64:
imm->type = BRIG_TYPE_U8X8;
break;
- case BRIG_TYPE_B128:
+ case 128:
imm->type = BRIG_TYPE_U8X16;
break;
default:
@@ -1954,7 +1954,8 @@ specialop:
atominsn->opcode = BRIG_OPCODE_ATOMIC;
/* Should check what the memory scope is */
atominsn->memoryscope = BRIG_MEMORY_SCOPE_WORKGROUP;
- atominsn->type = bittype_for_type (hsa_type_for_scalar_tree_type (TREE_TYPE (lhs), false));
+ atominsn->type = hsa_bittype_for_type
+ (hsa_type_for_scalar_tree_type (TREE_TYPE (lhs), false));
atominsn->operands[0] = dest;
atominsn->operands[1] = addr;
atominsn->operands[2]
@@ -156,6 +156,97 @@ hsa_opcode_op_output_p (BrigOpcode16_t opcode, int opnum)
}
}
+/* Return size of HSA type T in bits. */
+
+unsigned
+hsa_type_bit_size (BrigType16_t t)
+{
+ switch (t)
+ {
+ case BRIG_TYPE_B1:
+ return 1;
+
+ case BRIG_TYPE_U8:
+ case BRIG_TYPE_S8:
+ case BRIG_TYPE_B8:
+ return 8;
+
+ case BRIG_TYPE_U16:
+ case BRIG_TYPE_S16:
+ case BRIG_TYPE_B16:
+ case BRIG_TYPE_F16:
+ return 16;
+
+ case BRIG_TYPE_U32:
+ case BRIG_TYPE_S32:
+ case BRIG_TYPE_B32:
+ case BRIG_TYPE_F32:
+ case BRIG_TYPE_U8X4:
+ case BRIG_TYPE_U16X2:
+ case BRIG_TYPE_S8X4:
+ case BRIG_TYPE_S16X2:
+ case BRIG_TYPE_F16X2:
+ return 32;
+
+ case BRIG_TYPE_U64:
+ case BRIG_TYPE_S64:
+ case BRIG_TYPE_F64:
+ case BRIG_TYPE_B64:
+ case BRIG_TYPE_U8X8:
+ case BRIG_TYPE_U16X4:
+ case BRIG_TYPE_U32X2:
+ case BRIG_TYPE_S8X8:
+ case BRIG_TYPE_S16X4:
+ case BRIG_TYPE_S32X2:
+ case BRIG_TYPE_F16X4:
+ case BRIG_TYPE_F32X2:
+
+ return 64;
+
+ case BRIG_TYPE_B128:
+ case BRIG_TYPE_U8X16:
+ case BRIG_TYPE_U16X8:
+ case BRIG_TYPE_U32X4:
+ case BRIG_TYPE_U64X2:
+ case BRIG_TYPE_S8X16:
+ case BRIG_TYPE_S16X8:
+ case BRIG_TYPE_S32X4:
+ case BRIG_TYPE_S64X2:
+ case BRIG_TYPE_F16X8:
+ case BRIG_TYPE_F32X4:
+ case BRIG_TYPE_F64X2:
+ return 128;
+
+ default:
+ gcc_assert (seen_error ());
+ return t;
+ }
+}
+
+/* Return HSA bit-type with the same size as the type T. */
+
+BrigType16_t
+hsa_bittype_for_type (BrigType16_t t)
+{
+ switch (hsa_type_bit_size (t))
+ {
+ case 1:
+ return BRIG_TYPE_B1;
+ case 8:
+ return BRIG_TYPE_B8;
+ case 16:
+ return BRIG_TYPE_B16;
+ case 32:
+ return BRIG_TYPE_B32;
+ case 64:
+ return BRIG_TYPE_B64;
+ case 128:
+ return BRIG_TYPE_B128;
+ default:
+ return t;
+ }
+}
+
/* Create a mapping between the original function DECL and kernel name NAME. */
void
@@ -612,6 +612,8 @@ void hsa_deinit_compilation_unit_data (void);
bool hsa_machine_large_p (void);
bool hsa_full_profile_p (void);
bool hsa_opcode_op_output_p (BrigOpcode16_t, int);
+unsigned hsa_type_bit_size (BrigType16_t t);
+BrigType16_t hsa_bittype_for_type (BrigType16_t t);
void hsa_add_kern_decl_mapping (tree decl, char *name);
unsigned hsa_get_number_decl_kernel_mappings (void);
tree hsa_get_decl_kernel_mapping_decl (unsigned i);