36 #ifndef __ARCH_HSAIL_OPERAND_HH__ 37 #define __ARCH_HSAIL_OPERAND_HH__ 51 #include "debug/GPUReg.hh" 52 #include "enums/RegisterType.hh" 68 BaseOperand() { registerType = Enums::RT_NONE; regOperandSize = 0; }
86 : kind(_kind), regKind(_regKind)
91 : kind(_kind), type(_type)
110 unsigned &maxRegIdx,
char _regFileChar);
112 bool init_from_vect(
unsigned opOffset,
const BrigObject *obj,
int at,
113 unsigned &maxRegIdx,
char _regFileChar);
115 void initWithStrOffset(
unsigned strOffset,
const BrigObject *obj,
116 unsigned &maxRegIdx,
char _regFileChar);
154 template<
typename OperandType>
158 assert(
sizeof(OperandType) <=
sizeof(uint32_t));
159 assert(regIdx < w->maxSpVgprs);
164 switch (
sizeof(OperandType)) {
166 vgprIdx = w->
remap(regIdx, 1, 1);
168 read<uint32_t>(vgprIdx, lane)) & 0xff;
171 vgprIdx = w->
remap(regIdx, 2, 1);
173 read<uint32_t>(vgprIdx, lane)) & 0xffff;
176 vgprIdx = w->
remap(regIdx,
sizeof(OperandType), 1);
178 read<OperandType>(vgprIdx, lane);
181 panic(
"Bad OperandType\n");
185 return (OperandType)ret;
192 return get<uint32_t>(
w, lane);
195 template<
typename OperandType>
197 std::string disassemble();
200 template<
typename OperandType>
204 DPRINTF(GPUReg,
"CU%d, WF[%d][%d], lane %d: $s%d <- %d\n",
207 assert(
sizeof(OperandType) ==
sizeof(uint32_t));
208 assert(regIdx < w->maxSpVgprs);
209 uint32_t vgprIdx = w->
remap(regIdx,
sizeof(OperandType), 1);
217 DPRINTF(GPUReg,
"CU%d, WF[%d][%d], lane %d: $s%d <- %d\n",
220 assert(regIdx < w->maxSpVgprs);
221 uint32_t vgprIdx = w->
remap(regIdx,
sizeof(uint32_t), 1);
259 template<
typename OperandType>
263 assert(
sizeof(OperandType) <=
sizeof(uint64_t));
265 assert(regIdx < w->maxDpVgprs);
266 uint32_t vgprIdx = w->
remap(regIdx,
sizeof(OperandType), 1);
271 template<
typename OperandType>
275 DPRINTF(GPUReg,
"CU%d, WF[%d][%d], lane %d: $d%d <- %d\n",
279 assert(
sizeof(OperandType) <=
sizeof(uint64_t));
281 assert(regIdx < w->maxDpVgprs);
282 uint32_t vgprIdx = w->
remap(regIdx,
sizeof(OperandType), 1);
286 std::string disassemble();
323 template<
typename OperandType>
327 assert(regIdx < w->condRegState->numRegs());
332 template<
typename OperandType>
336 DPRINTF(GPUReg,
"CU%d, WF[%d][%d], lane %d: $c%d <- %d\n",
340 assert(regIdx < w->condRegState->numRegs());
344 std::string disassemble();
356 bool init_from_vect(
unsigned opOffset,
const BrigObject *obj,
int at);
357 std::string disassemble();
359 template<
typename OperandType>
363 assert(
sizeof(OperandType) <=
sizeof(T));
364 panic_if(
w ==
nullptr,
"WF pointer needs to be set");
369 return (OperandType)
w->computeUnit->wfSize();
373 return *(OperandType*)&bits;
380 template<
typename OperandType>
384 return get<OperandType>(
w);
394 switch (brigOp->
kind) {
398 DPRINTF(GPUReg,
"sizeof(T): %lu, byteCount: %d\n",
sizeof(T),
411 bits = std::numeric_limits<unsigned long long>::digits;
420 template <
typename T>
435 unsigned *data_offset =
446 return init(*data_offset, obj);
455 template<
typename RegOperand,
typename T>
462 void setImm(
const bool value) { is_imm = value; }
469 void init_from_vect(
unsigned opOffset,
const BrigObject *obj,
int at);
470 std::string disassemble();
472 template<
typename OperandType>
476 return is_imm ? imm_op.template get<OperandType>(
w) :
477 reg_op.template get<OperandType>(w, lane);
484 return reg_op.opSize();
494 return reg_op.registerType == Enums::RT_VECTOR;
503 return reg_op.registerType == Enums::RT_CONDITION;
513 return reg_op.registerType == Enums::RT_SCALAR;
523 return reg_op.regIndex();
529 template<
typename RegOperand,
typename T>
535 if (reg_op.init(opOffset, obj)) {
539 if (imm_op.init(opOffset, obj)) {
544 fatal(
"RegOrImmOperand::init(): bad operand kind %d\n",
548 template<
typename RegOperand,
typename T>
553 if (reg_op.init_from_vect(opOffset, obj, at)) {
559 if (imm_op.init_from_vect(opOffset, obj, at)) {
565 fatal(
"RegOrImmOperand::init(): bad operand kind %d\n",
569 template<
typename RegOperand,
typename T>
573 return is_imm ? imm_op.disassemble() : reg_op.disassemble();
587 std::string disassemble(std::string reg_disassembly);
588 uint64_t calcUniformBase();
592 virtual uint64_t calcLane(
Wavefront *w,
int lane=0) = 0;
599 template<
typename RegOperandType>
605 uint64_t calcUniform();
608 uint32_t
opSize() {
return reg.opSize(); }
613 std::string disassemble();
616 template<
typename RegOperandType>
620 using namespace Brig;
624 switch (baseOp->
kind) {
628 storageElement =
nullptr;
632 if (
reg.regFileChar ==
's') {
642 reg.regOperandSize =
sizeof(uint32_t);
645 else if (
reg.regFileChar ==
'd') {
648 reg.regOperandSize =
sizeof(uint64_t);
655 fatal(
"RegAddrOperand: bad operand kind %d\n", baseOp->
kind);
660 template<
typename RegOperandType>
664 fatal(
"can't do calcUniform() on register-based address\n");
669 template<
typename RegOperandType>
674 Addr address = calcUniformBase();
678 if (
reg.regFileChar ==
's') {
679 addrVec[lane] = address +
reg.template get<uint32_t>(
w, lane);
681 addrVec[lane] = address +
reg.template get<Addr>(
w, lane);
687 template<
typename RegOperandType>
691 Addr address = calcUniformBase();
693 return address +
reg.template get<Addr>(
w, lane);
696 template<
typename RegOperandType>
710 uint64_t calcUniform();
712 uint64_t calcLane(
Wavefront *w,
int lane=0);
713 std::string disassemble();
725 return calcUniform();
731 uint64_t address = calcUniformBase();
734 addrVec[lane] = address;
743 std::string disassemble();
759 DPRINTF(GPUReg,
"getSrcOperand, idx: %d, sz_args: %d\n", idx,
762 return callArgs.at(idx)->offset;
767 std::string disassemble();
769 template<
typename OperandType>
773 return w->
readCallArgMem<OperandType>(lane, getSrcOperand(arg_idx));
776 template<
typename OperandType>
781 DPRINTF(GPUReg,
"CU%d, WF[%d][%d], lane %d: arg[%d] <- %d\n",
783 getSrcOperand(0),
val);
793 std::string disassemble();
796 #endif // __ARCH_HSAIL_OPERAND_HH__ bool init(unsigned opOffset, const BrigObject *obj)
#define panic(...)
This implements a cprintf based panic() function.
#define fatal(...)
This implements a cprintf based fatal() function.
const std::string & name()
void write(int regIdx, int threadId, T value)
std::string disassemble(std::string reg_disassembly)
BrigRegOperandInfo(Brig::BrigKind16_t _kind, Brig::BrigRegisterKind _regKind)
void calcVector(Wavefront *w, std::vector< Addr > &addrVec)
RegOrImmOperand< SRegOperand, uint32_t > SRegOrImmOperand
void setImm(const bool value)
RegAddrOperand< SRegOperand > SRegAddrOperand
StorageElement * storageElement
bool init_from_vect(unsigned opOffset, const BrigObject *obj, int at)
T read(int regIdx, int threadId)
class ConditionRegisterState * condRegState
static unsigned maxRegIdx
void init(unsigned opOffset, const BrigObject *obj)
int getSrcOperand(int idx)
static unsigned maxRegIdx
bool init_from_vect(unsigned opOffset, const BrigObject *obj, int at)
bool init(unsigned opOffset, const BrigObject *obj)
void calcVector(Wavefront *w, std::vector< Addr > &addrVec)
bool init_from_vect(unsigned opOffset, const BrigObject *obj, int at)
std::string csprintf(const char *format, const Args &...args)
void init_from_vect(unsigned opOffset, const BrigObject *obj, int at)
void init(unsigned opOffset, const BrigObject *obj)
void writeCallArgMem(int lane, int addr, CType val)
Enums::RegisterType registerType
const uint8_t * getData(int offs) const
BrigRegOperandInfo(Brig::BrigKind16_t _kind, Brig::BrigType _type)
CType readCallArgMem(int lane, int addr)
std::vector< StorageElement * > callArgs
ComputeUnit * computeUnit
std::string disassemble()
Defines global host-dependent types: Counter, Tick, and (indirectly) {int,uint}{8,16,32,64}_t.
uint64_t Addr
Address type This will probably be moved somewhere else in the near future.
void initWithStrOffset(unsigned strOffset, const BrigObject *obj)
uint64_t calcLane(Wavefront *w, int lane=0)
RegAddrOperand< DRegOperand > DRegAddrOperand
const Brig::BrigOperand * getOperand(int offs) const
static unsigned maxRegIdx
std::vector< VectorRegisterFile * > vrf
BrigDataOffsetOperandList32_t elements
std::string disassemble()
BrigRegOperandInfo findRegDataType(unsigned opOffset, const BrigObject *obj)
VectorMask execMask() const
bool init(unsigned opOffset, const BrigObject *obj)
void initWithStrOffset(unsigned strOffset, const BrigObject *obj, unsigned &maxRegIdx, char _regFileChar)
Brig::BrigRegisterKind regKind
bool init(unsigned opOffset, const BrigObject *obj, unsigned &maxRegIdx, char _regFileChar)
bool init_from_vect(unsigned opOffset, const BrigObject *obj, int at)
uint64_t calcUniformBase()
uint32_t remap(uint32_t vgprIndex, uint32_t size, uint8_t mode=0)
T bits(T val, int first, int last)
Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it...
uint32_t getTarget(Wavefront *w, int lane)
uint64_t calcLane(Wavefront *w, int lane=0)
bool init_from_vect(unsigned opOffset, const BrigObject *obj, int at, unsigned &maxRegIdx, char _regFileChar)
#define panic_if(cond,...)
Conditional panic macro that checks the supplied condition and only panics if the condition is true a...
bool init(unsigned opOffset, const BrigObject *obj)
RegOrImmOperand< CRegOperand, bool > CRegOrImmOperand
void set(Wavefront *w, int lane, OperandType &val)
const FlagsType init
This Stat is Initialized.
void initWithStrOffset(unsigned strOffset, const BrigObject *obj)
RegOrImmOperand< DRegOperand, uint64_t > DRegOrImmOperand
std::string disassemble()
BrigOperandOffset32_t reg
void initWithStrOffset(unsigned strOffset, const BrigObject *obj)