diff options
| author | ptitSeb <sebastien.chev@gmail.com> | 2021-07-02 10:17:28 +0200 |
|---|---|---|
| committer | ptitSeb <sebastien.chev@gmail.com> | 2021-07-02 10:17:28 +0200 |
| commit | 140254f311eead840969229040c807ad3da3f177 (patch) | |
| tree | 9aa0454f457504de7967c3d3522ad29ed580264a /tests | |
| parent | 56401f667525063eac16081d19395527d3403e60 (diff) | |
| download | box64-140254f311eead840969229040c807ad3da3f177.tar.gz box64-140254f311eead840969229040c807ad3da3f177.zip | |
[DYNAREC] Fixed DIV opcode, and added test17 about div/idiv
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ref17.txt | 12 | ||||
| -rwxr-xr-x | tests/test17 | bin | 0 -> 19976 bytes | |||
| -rw-r--r-- | tests/test17.c | 50 |
3 files changed, 62 insertions, 0 deletions
diff --git a/tests/ref17.txt b/tests/ref17.txt new file mode 100644 index 00000000..349d50d0 --- /dev/null +++ b/tests/ref17.txt @@ -0,0 +1,12 @@ +div 1, 1 => 1 / 0 +div 10, 5 => 2 / 0 +div 10, 3 => 3 / 1 +div 1, 18446744073709551615 => 0 / 1 +div 10, 18446744073709551613 => 0 / 10 +div 18446744073709551606, 18446744073709551613 => 0 / 18446744073709551606 +idiv 1, 1 => 1 / 0 +idiv 10, 5 => 2 / 0 +idiv 10, 3 => 3 / 1 +idiv 1, -1 => -1 / 0 +idiv 10, -3 => -3 / 1 +idiv -10, -3 => 3 / -1 diff --git a/tests/test17 b/tests/test17 new file mode 100755 index 00000000..bcfd74f8 --- /dev/null +++ b/tests/test17 Binary files differdiff --git a/tests/test17.c b/tests/test17.c new file mode 100644 index 00000000..799c1368 --- /dev/null +++ b/tests/test17.c @@ -0,0 +1,50 @@ +#include <string.h> +#include <stdio.h> +#include <stddef.h> +#include <stdlib.h> +#include <stdint.h> +#include <math.h> + +#if defined(__x86_64__) +uint64_t _div_(uint64_t a, uint64_t b, uint64_t *r) +{ + uint64_t ret, rem; + asm volatile ( + "xor %%rdx, %%rdx\n" + "div %%rcx\n" + "mov %%rdx, %%rbx\n" + :"=a" (ret), "=b" (rem):"a" (a), "c" (b):"rdx","cc"); + *r = rem; + return ret; +} +uint64_t _idiv_(uint64_t a, uint64_t b, uint64_t *r) +{ + uint64_t ret, rem; + asm volatile ( + "cqo\n" + "idiv %%rcx\n" + "mov %%rdx, %%rbx\n" + :"=a" (ret), "=b" (rem):"a" (a), "c" (b):"rdx","cc"); + *r = rem; + return ret; +} +#else +#endif + +int main(int argc, const char** argv) +{ + uint64_t datas[][2] = {{1,1},{10,5},{10,3},{1, (uint64_t)-1}, {10, (uint64_t)-3}, {(uint64_t)-10, (uint64_t)-3}}; + + int sz = sizeof(datas)/sizeof(datas[0]); + for(int i=0; i<sz; ++i) { + uint64_t rem = 0; + uint64_t d = _div_(datas[i][0], datas[i][1], &rem); + printf("div %llu, %llu => %llu / %llu\n", datas[i][0], datas[i][1], d, rem); + } + for(int i=0; i<sz; ++i) { + uint64_t rem = 0; + uint64_t d = _idiv_(datas[i][0], datas[i][1], &rem); + printf("idiv %lld, %lld => %lld / %lld\n", datas[i][0], datas[i][1], d, rem); + } + return 0; +} |