34 #ifndef __ARCH_VEGA_OPERAND_HH__
35 #define __ARCH_VEGA_OPERAND_HH__
81 virtual void read() = 0;
82 virtual void write() = 0;
98 template<
typename DataType,
bool Const,
size_t NumDwords>
101 template<
typename DataType,
bool Const,
102 size_t NumDwords =
sizeof(DataType) /
sizeof(
VecElemU32)>
106 "Incorrect number of DWORDS for VEGA operand.");
136 ->reservedScalarRegs);
156 for (
auto i = 0;
i < NumDwords; ++
i) {
160 DPRINTF(GPUVRF,
"Read v[%d]\n", vgprIdx);
161 cu->
vrf[wf->
simdId]->printReg(wf, vgprIdx);
164 if (NumDwords == 1) {
166 auto vgpr =
vecReg.template as<DataType>();
167 auto reg_file_vgpr =
vrfData[0]->template as<VecElemU32>();
169 std::memcpy((
void*)&vgpr[lane],
170 (
void*)®_file_vgpr[lane],
sizeof(DataType));
172 }
else if (NumDwords == 2) {
175 auto vgpr =
vecReg.template as<VecElemU64>();
176 auto reg_file_vgpr0 =
vrfData[0]->template as<VecElemU32>();
177 auto reg_file_vgpr1 =
vrfData[1]->template as<VecElemU32>();
181 ((
VecElemU32*)&tmp_val)[0] = reg_file_vgpr0[lane];
182 ((
VecElemU32*)&tmp_val)[1] = reg_file_vgpr1[lane];
183 vgpr[lane] = tmp_val;
210 if (NumDwords == 1) {
214 auto reg_file_vgpr =
vrfData[0]->template as<VecElemU32>();
215 auto vgpr =
vecReg.template as<DataType>();
218 if (exec_mask[lane] ||
_gpuDynInst->ignoreExec()) {
219 std::memcpy((
void*)®_file_vgpr[lane],
220 (
void*)&vgpr[lane],
sizeof(DataType));
224 DPRINTF(GPUVRF,
"Write v[%d]\n", vgprIdx);
225 cu->
vrf[wf->
simdId]->printReg(wf, vgprIdx);
226 }
else if (NumDwords == 2) {
233 auto reg_file_vgpr0 =
vrfData[0]->template as<VecElemU32>();
234 auto reg_file_vgpr1 =
vrfData[1]->template as<VecElemU32>();
235 auto vgpr =
vecReg.template as<VecElemU64>();
238 if (exec_mask[lane] ||
_gpuDynInst->ignoreExec()) {
239 reg_file_vgpr0[lane] = ((
VecElemU32*)&vgpr[lane])[0];
240 reg_file_vgpr1[lane] = ((
VecElemU32*)&vgpr[lane])[1];
244 DPRINTF(GPUVRF,
"Write v[%d:%d]\n", vgprIdx0, vgprIdx1);
245 cu->
vrf[wf->
simdId]->printReg(wf, vgprIdx0);
246 cu->
vrf[wf->
simdId]->printReg(wf, vgprIdx1);
267 template<
bool Condition = (NumDwords == 1 || NumDwords == 2) && Const>
277 assert(std::is_floating_point<DataType>::value);
278 ret_val = std::fabs(ret_val);
282 assert(std::is_floating_point<DataType>::value);
288 auto vgpr =
vecReg.template as<DataType>();
289 DataType ret_val = vgpr[idx];
292 assert(std::is_floating_point<DataType>::value);
293 ret_val = std::fabs(ret_val);
297 assert(std::is_floating_point<DataType>::value);
310 template<
bool Condition = (NumDwords == 1 || NumDwords == 2) && !Const>
317 return vecReg.template as<DataType>()[idx];
362 std::array<VecRegContainerU32*, NumDwords>
vrfData;
365 template<
typename DataType,
bool Const,
366 size_t NumDwords =
sizeof(DataType) /
sizeof(
ScalarRegU32)>
370 "Incorrect number of DWORDS for VEGA operand.");
391 template<
bool Condition = NumDwords == 1 || NumDwords == 2>
395 assert(
sizeof(DataType) <=
sizeof(
srfData));
396 DataType raw_data((DataType)0);
397 std::memcpy((
void*)&raw_data, (
void*)
srfData.data(),
412 Wavefront *wf = _gpuDynInst->wavefront();
418 for (
auto i = 0;
i < NumDwords; ++
i) {
421 DPRINTF(GPUSRF,
"Read s[%d]\n", sgprIdx);
422 cu->
srf[wf->
simdId]->printReg(wf, sgprIdx);
430 Wavefront *wf = _gpuDynInst->wavefront();
437 if (NumDwords == 1) {
438 std::memcpy((
void*)&new_exec_mask_val,
440 }
else if (NumDwords == 2) {
441 std::memcpy((
void*)&new_exec_mask_val,
444 panic(
"Trying to write more than 2 DWORDS to EXEC\n");
448 DPRINTF(GPUSRF,
"Write EXEC\n");
449 DPRINTF(GPUSRF,
"EXEC = %#x\n", new_exec_mask_val);
455 assert(NumDwords == 1);
459 std::memcpy((
void*)&new_exec_mask_hi_val,
460 (
void*)
srfData.data(),
sizeof(new_exec_mask_hi_val));
462 new_exec_mask_hi_val);
465 DPRINTF(GPUSRF,
"Write EXEC\n");
466 DPRINTF(GPUSRF,
"EXEC = %#x\n", new_exec_mask_val);
468 _gpuDynInst->writeMiscReg(_opIdx,
srfData[0]);
471 for (
auto i = 0;
i < NumDwords; ++
i) {
473 auto &sgpr = cu->
srf[wf->
simdId]->readWriteable(sgprIdx);
474 if (_gpuDynInst->isLoad()) {
477 _gpuDynInst->scalar_data)[
i];
481 DPRINTF(GPUSRF,
"Write s[%d]\n", sgprIdx);
482 cu->
srf[wf->
simdId]->printReg(wf, sgprIdx);
490 template<
bool Condition = NumDwords == 1 || NumDwords == 2>
494 DataType &sgpr = *((DataType*)
srfData.data());
498 template<
bool Condition = (NumDwords == 1 || NumDwords == 2) && !Const>
502 std::memcpy((
void*)
srfData.data(), (
void*)&rhs,
sizeof(DataType));
516 assert(NumDwords == 1 || NumDwords == 2);
522 execMask().to_ullong();
523 std::memcpy((
void*)
srfData.data(), (
void*)&exec_mask,
525 DPRINTF(GPUSRF,
"Read EXEC\n");
526 DPRINTF(GPUSRF,
"EXEC = %#x\n", exec_mask);
535 assert(NumDwords == 1);
537 ->execMask().to_ullong();
540 std::memcpy((
void*)
srfData.data(), (
void*)&exec_mask_hi,
542 DPRINTF(GPUSRF,
"Read EXEC_HI\n");
543 DPRINTF(GPUSRF,
"EXEC_HI = %#x\n", exec_mask_hi);
549 assert(NumDwords == 1);
550 srfData[0] = _gpuDynInst->srcLiteral();
555 std::memcpy((
void*)
srfData.data(), (
void*)&pos_half,
563 std::memcpy((
void*)
srfData.data(), (
void*)&neg_half,
600 std::memcpy((
void*)
srfData.data(), (
void*)&neg_four ,
613 std::memcpy((
void*)
srfData.data(),
614 (
void*)&pi_u64,
sizeof(
srfData));
616 std::memcpy((
void*)
srfData.data(),
617 (
void*)&pi_u32,
sizeof(
srfData));
623 assert(
sizeof(DataType) <=
sizeof(
srfData));
624 DataType misc_val(0);
626 misc_val = (DataType)_gpuDynInst
627 ->readConstVal<DataType>(_opIdx);
629 misc_val = (DataType)_gpuDynInst->readMiscReg(_opIdx);
631 std::memcpy((
void*)
srfData.data(), (
void*)&misc_val,
645 Wavefront *wf = _gpuDynInst->wavefront();
656 assert(NumDwords == 1);
663 assert(sgprIdx > -1);
741 #endif // __ARCH_VEGA_OPERAND_HH__