#include <cstdint>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>

#include <ipu_arch_info/ipuArchInfo.h>

namespace {
void decode(const ArchInfo::Register &reg, std::uint32_t value) {
  std::cout << reg.name << " offset=0x" << std::hex << reg.getOffset()
            << " value=0x" << value << std::dec << '\n';
  for (const auto *field : reg) {
    std::cout << "  " << field->name << " shift=" << field->shift
              << " width=" << field->size << " value="
              << field->getFrom(value) << '\n';
  }
}
} // namespace

int main(int argc, char **argv) {
  if (argc != 2) {
    std::cerr << "usage: gsp_config_decode VALUE\n";
    return 2;
  }
  const auto value = static_cast<std::uint32_t>(std::strtoul(argv[1], nullptr, 0));
  const auto &arch = ipuArchInfoByName("ipu21");
  decode(arch.SS.GSPCR, value);
  return 0;
}
