hsail: add popcount type and generate popcount instructions
This commit is contained in:
parent
3bb3db6194
commit
86b375f2f3
3 changed files with 27 additions and 2 deletions
|
@ -1455,6 +1455,8 @@ struct BrigInstSourceType {
|
|||
uint16_t reserved; //.defValue=0
|
||||
};
|
||||
|
||||
typedef BrigInstSourceType BrigInstPopcount;
|
||||
|
||||
struct BrigOperandAddress {
|
||||
BrigBase base;
|
||||
BrigCodeOffset32_t symbol; //.wtype=ItemRef<DirectiveVariable>
|
||||
|
|
|
@ -211,6 +211,7 @@ header_templates = {
|
|||
'ExtractInsertInst': header_template_1dt,
|
||||
'CmpInst': header_template_2dt,
|
||||
'CvtInst': header_template_2dt,
|
||||
'PopcountInst': header_template_2dt,
|
||||
'LdInst': '',
|
||||
'StInst': '',
|
||||
'SpecialInstNoSrc': header_template_nodt,
|
||||
|
@ -426,6 +427,7 @@ exec_templates = {
|
|||
'ClassInst': exec_template_1dt_2src_1dest,
|
||||
'CmpInst': exec_template_2dt,
|
||||
'CvtInst': exec_template_2dt,
|
||||
'PopcountInst': exec_template_2dt,
|
||||
'LdInst': '',
|
||||
'StInst': '',
|
||||
'SpecialInstNoSrc': exec_template_nodt_nosrc,
|
||||
|
@ -555,7 +557,7 @@ def gen(brig_opcode, types=None, expr=None, base_class='ArithInst',
|
|||
dest_is_src_flag = str(dest_is_src).lower() # for C++
|
||||
if base_class in ['ShiftInst']:
|
||||
expr = re.sub(r'\bsrc(\d)\b', r'src_val\1', expr)
|
||||
elif base_class in ['ArithInst', 'CmpInst', 'CvtInst']:
|
||||
elif base_class in ['ArithInst', 'CmpInst', 'CvtInst', 'PopcountInst']:
|
||||
expr = re.sub(r'\bsrc(\d)\b', r'src_val[\1]', expr)
|
||||
else:
|
||||
expr = re.sub(r'\bsrc(\d)\b', r'src_val\1', expr)
|
||||
|
@ -674,7 +676,8 @@ gen('Xor', bit_types, 'src0 ^ src1')
|
|||
|
||||
gen('Bitselect', bit_types, '(src1 & src0) | (src2 & ~src0)')
|
||||
gen('Firstbit',bit_types, 'firstbit(src0)')
|
||||
gen('Popcount', ('B32', 'B64'), '__builtin_popcount(src0)')
|
||||
gen('Popcount', ('U32',), '__builtin_popcount(src0)', 'PopcountInst', \
|
||||
('sourceType', ('B32', 'B64')))
|
||||
|
||||
gen('Shl', arith_int_types, 'src0 << (unsigned)src1', 'ShiftInst')
|
||||
gen('Shr', arith_int_types, 'src0 >> (unsigned)src1', 'ShiftInst')
|
||||
|
|
|
@ -725,6 +725,26 @@ namespace HsailISA
|
|||
}
|
||||
};
|
||||
|
||||
template<typename DestDataType, typename SrcDataType>
|
||||
class PopcountInst :
|
||||
public CommonInstBase<typename DestDataType::OperandType,
|
||||
typename SrcDataType::OperandType, 1>
|
||||
{
|
||||
public:
|
||||
std::string opcode_suffix()
|
||||
{
|
||||
return csprintf("_%s_%s", DestDataType::label, SrcDataType::label);
|
||||
}
|
||||
|
||||
PopcountInst(const Brig::BrigInstBase *ib, const BrigObject *obj,
|
||||
const char *_opcode)
|
||||
: CommonInstBase<typename DestDataType::OperandType,
|
||||
typename SrcDataType::OperandType,
|
||||
1>(ib, obj, _opcode)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
class SpecialInstNoSrcNoDest : public HsailGPUStaticInst
|
||||
{
|
||||
public:
|
||||
|
|
Loading…
Reference in a new issue