[前][次][番号順一覧][スレッド一覧]

ruby-changes:69130

From: Kevin <ko1@a...>
Date: Thu, 21 Oct 2021 08:20:57 +0900 (JST)
Subject: [ruby-changes:69130] a0bb731f4f (master): Add some YJIT runtime tests

https://git.ruby-lang.org/ruby.git/commit/?id=a0bb731f4f

From a0bb731f4f71ad3e57be57fb0a1a7347107dbf0d Mon Sep 17 00:00:00 2001
From: Kevin Newton <kddnewton@g...>
Date: Mon, 19 Jul 2021 11:26:34 -0400
Subject: Add some YJIT runtime tests

This is just for helping my own understanding, but could be useful for others as well.
---
 yjit_asm_tests.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 57 insertions(+), 2 deletions(-)

diff --git a/yjit_asm_tests.c b/yjit_asm_tests.c
index 3d948d38f4..ccda979437 100644
--- a/yjit_asm_tests.c
+++ b/yjit_asm_tests.c
@@ -58,7 +58,7 @@ void check_bytes(codeblock_t* cb, const char* bytes) https://github.com/ruby/ruby/blob/trunk/yjit_asm_tests.c#L58
     }
 }
 
-void run_tests()
+void run_assembler_tests()
 {
     printf("Running assembler tests\n");
 
@@ -353,9 +353,64 @@ void run_tests() https://github.com/ruby/ruby/blob/trunk/yjit_asm_tests.c#L353
     printf("Assembler tests done\n");
 }
 
+void assert_equal(expected, actual)
+{
+    if (expected != actual) {
+        fprintf(stderr, "expected %d, got %d\n", expected, actual);
+        exit(-1);
+    }
+}
+
+void run_runtime_tests()
+{
+    printf("Running runtime tests\n");
+
+    codeblock_t codeblock;
+    codeblock_t* cb = &codeblock;
+
+    uint8_t* mem_block = alloc_exec_mem(4096);
+    cb_init(cb, mem_block, 4096);
+
+    int (*function)(void);
+    function = (int (*)(void))mem_block;
+
+    #define TEST(BODY) cb_set_pos(cb, 0); BODY ret(cb); assert_equal(7, function());
+
+    // add
+    TEST({ mov(cb, RAX, imm_opnd(0)); add(cb, RAX, imm_opnd(7)); })
+    TEST({ mov(cb, RAX, imm_opnd(0)); mov(cb, RCX, imm_opnd(7)); add(cb, RAX, RCX); })
+
+    // and
+    TEST({ mov(cb, RAX, imm_opnd(31)); and(cb, RAX, imm_opnd(7)); })
+    TEST({ mov(cb, RAX, imm_opnd(31)); mov(cb, RCX, imm_opnd(7)); and(cb, RAX, RCX); })
+
+    // or
+    TEST({ mov(cb, RAX, imm_opnd(3)); or(cb, RAX, imm_opnd(4)); })
+    TEST({ mov(cb, RAX, imm_opnd(3)); mov(cb, RCX, imm_opnd(4)); or(cb, RAX, RCX); })
+
+    // push/pop
+    TEST({ mov(cb, RCX, imm_opnd(7)); push(cb, RCX); pop(cb, RAX); })
+
+    // shr
+    TEST({ mov(cb, RAX, imm_opnd(31)); shr(cb, RAX, imm_opnd(2)); })
+
+    // sub
+    TEST({ mov(cb, RAX, imm_opnd(12)); sub(cb, RAX, imm_opnd(5)); })
+    TEST({ mov(cb, RAX, imm_opnd(12)); mov(cb, RCX, imm_opnd(5)); sub(cb, RAX, RCX); })
+
+    // xor
+    TEST({ mov(cb, RAX, imm_opnd(13)); xor(cb, RAX, imm_opnd(10)); })
+    TEST({ mov(cb, RAX, imm_opnd(13)); mov(cb, RCX, imm_opnd(10)); xor(cb, RAX, RCX); })
+
+    #undef TEST
+
+    printf("Runtime tests done\n");
+}
+
 int main(int argc, char** argv)
 {
-    run_tests();
+    run_assembler_tests();
+    run_runtime_tests();
 
     return 0;
 }
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]