--- nono/m680x0/testacc.cpp 2026/04/29 17:04:28 1.1.1.1 +++ nono/m680x0/testacc.cpp 2026/04/29 17:04:29 1.1.1.2 @@ -25,6 +25,27 @@ volatile int perf_signaled; // パフォ struct timeval perf_start; // パフォーマンス測定開始時刻 uint64 perf_count; // パフォーマンス測定用。処理回数 +// value を16進数で指定のビット数分の文字列にする +std::string +hex(uint32 value, int sz) +{ + char buf[32]; + + switch (sz) { + case 8: + snprintf(buf, sizeof(buf), "%02x", value); + break; + case 16: + snprintf(buf, sizeof(buf), "%04x", value); + break; + case 32: + default: + snprintf(buf, sizeof(buf), "%08x", value); + break; + } + return std::string(buf); +} + // 整数(32bitまで)を検査する void xp_equal(uint32 expected, uint32 actual, const char *name) @@ -274,8 +295,8 @@ test_add(int sz) uint64 tmp = src + dst; uint64 res = tmp & MASK(sz); - sprintf(where, "%0*" PRIx64 " + %0*" PRIx64, - (sz / 4), src, (sz / 4), dst); + std::string w = hex(src, sz) + " + " + hex(dst, sz); + strlcpy(where, w.c_str(), sizeof(where)); bool C = tmp & BIT(sz); bool V = ((res ^ src) & (res ^ dst)) & BIT(sz - 1); @@ -335,8 +356,8 @@ test_sub(int sz) tmp = (uint64)dst - (uint64)src; } uint64 res = tmp & MASK(sz); - sprintf(where, "%0*" PRIx64 " - %0*" PRIx64, - (sz / 4), dst, (sz / 4), src); + std::string w = hex(dst, sz) + " - " + hex(src, sz); + strlcpy(where, w.c_str(), sizeof(where)); bool C = tmp & BIT(sz); bool V = ((src ^ dst) & (res ^ dst)) & BIT(sz - 1);