upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/runtime/test/cpu_emulation_test.cpp
diff options
context:
space:
mode:
authoroscarlosu-lab <251827664+oscarlosu-lab@users.noreply.github.com>2026-11-24 05:54:10 +0100
committeroscarlosu-lab <251827664+oscarlosu-lab@users.noreply.github.com>2026-11-24 05:54:10 +0100
commit361e8455a20aa6606fb542d86e39b552da2e60e6 (patch)
treecc0812f1e3b090bf7c7f50f51d9e37343f3fd74b /runtime/test/cpu_emulation_test.cpp
parentd2cd6c0d970083eee4d7b40daabb2480a77b1790 (diff)
cpu_emulation: run a whole CLZERO zeroing loop in one emulated step
Diffstat (limited to 'runtime/test/cpu_emulation_test.cpp')
-rw-r--r--runtime/test/cpu_emulation_test.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/runtime/test/cpu_emulation_test.cpp b/runtime/test/cpu_emulation_test.cpp
index 4e1ef3cdb..b25ecb69d 100644
--- a/runtime/test/cpu_emulation_test.cpp
+++ b/runtime/test/cpu_emulation_test.cpp
@@ -244,6 +244,33 @@ void test_live(const ce::Host& host) {
244 "clzero with 66 emulated"); 244 "clzero with 66 emulated");
245 } 245 }
246 246
247 // clzero loop fast-path: mov rax, rcx; clzero; add rax, 0x40; cmp rax, rdx; jb -12; ret
248 {
249 alignas(64) static uint8_t buf[512];
250 std::memset(buf, 0xA5, sizeof buf);
251 Code clz_loop({0x48, 0x89, 0xC8, 0x0F, 0x01, 0xFC, 0x48, 0x83, 0xC0, 0x40, 0x48, 0x39, 0xD0, 0x72, 0xF4, 0xC3});
252 check(run(clz_loop, buf + 64, buf + 320, &ex), "clzero loop ran");
253 bool loop_ok = true;
254 for (int i = 0; i < 512; ++i) loop_ok &= buf[i] == ((i >= 64 && i < 320) ? 0 : 0xA5);
255 check(loop_ok, "clzero loop zeroed exact span [64, 320)");
256
257 // REX.R limit register (r8): mov rax, rcx; mov r8, rdx; clzero; add rax, 0x40; cmp rax, r8; jb -12; ret
258 std::memset(buf, 0xA5, sizeof buf);
259 Code clz_r8({0x48, 0x89, 0xC8, 0x49, 0x89, 0xD0, 0x0F, 0x01, 0xFC, 0x48, 0x83, 0xC0, 0x40, 0x4C, 0x39, 0xC0,
260 0x72, 0xF4, 0xC3});
261 check(run(clz_r8, buf + 64, buf + 320, &ex), "clzero loop (r8) ran");
262 bool r8_ok = true;
263 for (int i = 0; i < 512; ++i) r8_ok &= buf[i] == ((i >= 64 && i < 320) ? 0 : 0xA5);
264 check(r8_ok, "clzero loop (r8) zeroed exact span [64, 320)");
265
266 // Non-multiple-of-64 limit (300): rounds up to 320, matching native do-while `cmp rax, limit; jb`.
267 std::memset(buf, 0xA5, sizeof buf);
268 check(run(clz_loop, buf + 64, buf + 300, &ex), "clzero loop (unaligned limit) ran");
269 bool unaligned_ok = true;
270 for (int i = 0; i < 512; ++i) unaligned_ok &= buf[i] == ((i >= 64 && i < 320) ? 0 : 0xA5);
271 check(unaligned_ok, "clzero loop (unaligned limit 300) zeroed span [64, 320)");
272 }
273
247 // mov rax,rcx; xor ecx,ecx; xor edx,edx; monitorx; xor eax,eax; xor ecx,ecx; mwaitx; ret 274 // mov rax,rcx; xor ecx,ecx; xor edx,edx; monitorx; xor eax,eax; xor ecx,ecx; mwaitx; ret
248 // (no timer: an interrupt or a store ends a native wait; the emulated one returns at once) 275 // (no timer: an interrupt or a store ends a native wait; the emulated one returns at once)
249 Code mon({0x48, 0x89, 0xC8, 0x31, 0xC9, 0x31, 0xD2, 0x0F, 0x01, 0xFA, 0x31, 0xC0, 0x31, 0xC9, 0x0F, 0x01, 0xFB, 276 Code mon({0x48, 0x89, 0xC8, 0x31, 0xC9, 0x31, 0xD2, 0x0F, 0x01, 0xFA, 0x31, 0xC0, 0x31, 0xC9, 0x0F, 0x01, 0xFB,