36 #ifndef __ARCH_HSAIL_OPERAND_HH__
37 #define __ARCH_HSAIL_OPERAND_HH__
51 #include "debug/GPUReg.hh"
52 #include "enums/RegisterType.hh"
110 unsigned &maxRegIdx,
char _regFileChar);
113 unsigned &maxRegIdx,
char _regFileChar);
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);
167 ret = (
w->computeUnit->vrf[
w->simdId]->
168 read<uint32_t>(vgprIdx, lane)) & 0xff;
171 vgprIdx =
w->remap(
regIdx, 2, 1);
172 ret = (
w->computeUnit->vrf[
w->simdId]->
173 read<uint32_t>(vgprIdx, lane)) & 0xffff;
176 vgprIdx =
w->remap(
regIdx,
sizeof(OperandType), 1);
177 ret =
w->computeUnit->vrf[
w->simdId]->
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>
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);
268 return w->computeUnit->vrf[
w->simdId]->read<OperandType>(vgprIdx,lane);
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);
323 template<
typename OperandType>
327 assert(regIdx < w->condRegState->numRegs());
329 return w->condRegState->read<OperandType>((int)
regIdx, lane);
332 template<
typename OperandType>
336 DPRINTF(GPUReg,
"CU%d, WF[%d][%d], lane %d: $c%d <- %d\n",
340 assert(regIdx < w->condRegState->numRegs());
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>
472 template<
typename OperandType>
477 reg_op.template get<OperandType>(
w, lane);
494 return reg_op.registerType == Enums::RT_VECTOR;
503 return reg_op.registerType == Enums::RT_CONDITION;
513 return reg_op.registerType == Enums::RT_SCALAR;
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);
599 template<
typename RegOperandType>
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);
643 registerType = Enums::RT_VECTOR;
645 else if (
reg.regFileChar ==
'd') {
648 reg.regOperandSize =
sizeof(uint64_t);
649 registerType = Enums::RT_VECTOR;
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>
734 addrVec[lane] = address;
759 DPRINTF(GPUReg,
"getSrcOperand, idx: %d, sz_args: %d\n", idx,
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",
796 #endif // __ARCH_HSAIL_OPERAND_HH__
bool init(unsigned opOffset, const BrigObject *obj)
void init(unsigned opOffset, const BrigObject *obj)
uint32_t getTarget(Wavefront *w, int lane)
const Brig::BrigOperand * getOperand(int offs) const
std::string disassemble()
void init(unsigned opOffset, const BrigObject *obj)
void write(int regIdx, int threadId, T value)
std::string disassemble(std::string reg_disassembly)
BrigRegOperandInfo(Brig::BrigKind16_t _kind, Brig::BrigRegisterKind _regKind)
void init(unsigned opOffset, const BrigObject *obj)
void calcVector(Wavefront *w, std::vector< Addr > &addrVec)
RegOrImmOperand< SRegOperand, uint32_t > SRegOrImmOperand
void setImm(const bool value)
std::string disassemble()
RegAddrOperand< SRegOperand > SRegAddrOperand
StorageElement * storageElement
panic_if(!root,"Invalid expression\n")
bool init_from_vect(unsigned opOffset, const BrigObject *obj, int at)
class ConditionRegisterState * condRegState
virtual uint64_t calcLane(Wavefront *w, int lane=0)=0
static unsigned maxRegIdx
void init(unsigned opOffset, const BrigObject *obj)
std::string disassemble()
std::string disassemble()
int getSrcOperand(int idx)
const uint8_t * getData(int offs) const
static unsigned maxRegIdx
std::string disassemble()
bool init_from_vect(unsigned opOffset, const BrigObject *obj, int at)
virtual void calcVector(Wavefront *w, std::vector< Addr > &addrVec)=0
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
BrigRegOperandInfo(Brig::BrigKind16_t _kind, Brig::BrigType _type)
void init(unsigned opOffset, const BrigObject *obj)
std::vector< StorageElement * > callArgs
ComputeUnit * computeUnit
std::string disassemble()
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
static unsigned maxRegIdx
void parseAddr(const Brig::BrigOperandAddress *op, const BrigObject *obj)
VectorMask execMask() const
std::vector< VectorRegisterFile * > vrf
BrigDataOffsetOperandList32_t elements
std::string disassemble()
BrigRegOperandInfo findRegDataType(unsigned opOffset, const BrigObject *obj)
bool init(unsigned opOffset, const BrigObject *obj)
std::string disassemble()
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)
void set(Wavefront *w, int lane, OperandType &val)
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)
void set(Wavefront *w, int lane, OperandType &val)
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()
void set(Wavefront *w, int lane, OperandType val)
BrigOperandOffset32_t reg
void initWithStrOffset(unsigned strOffset, const BrigObject *obj)