Skip to content
Snippets Groups Projects
Verified Commit e7aa3861 authored by Recolic Keghart's avatar Recolic Keghart
Browse files

> Manual commit: Implemented more instructions for bit-test. Now passing most tests except 2.

U201614531
recolic
Linux RECOLICPC 5.4.6-arch3-1 #1 SMP PREEMPT Tue, 24 Dec 2019 04:36:53 +0000 x86_64 GNU/Linux
 22:49:38 up  4:23,  1 user,  load average: 0.44, 0.78, 0.65
e61ade3efdb6b2a065905e25e190ebb73554f4d1
parent 80f8c13f
No related branches found
No related tags found
No related merge requests found
...@@ -42,7 +42,7 @@ namespace EHelperImpl { ...@@ -42,7 +42,7 @@ namespace EHelperImpl {
make_EHelper(cmp) { make_EHelper(cmp) {
rlib::println("debug: cmp: id_dest=", *id_dest, ", id_src=", *id_src); // rlib::println("debug: cmp: id_dest=", *id_dest, ", id_src=", *id_src);
rtl_sext(&t1, &id_dest->val, id_dest->width); rtl_sext(&t1, &id_dest->val, id_dest->width);
rtl_sext(&t2, &id_src->val, id_src->width); rtl_sext(&t2, &id_src->val, id_src->width);
......
...@@ -62,11 +62,13 @@ namespace EHelperImpl { ...@@ -62,11 +62,13 @@ namespace EHelperImpl {
} }
make_EHelper(cltd) { make_EHelper(cltd) {
// r: dbt
if (decoding.is_operand_size_16) { if (decoding.is_operand_size_16) {
TODO(); rtl_sext(&t0, &reg_l(R_EAX), 2);
rtl_shri(&reg_l(R_EDX), &t0, 16);
} }
else { else {
TODO(); rtl_sari(&reg_l(R_EDX), &reg_l(R_EAX), 31);
} }
print_asm(decoding.is_operand_size_16 ? "cwtl" : "cltd"); print_asm(decoding.is_operand_size_16 ? "cwtl" : "cltd");
......
...@@ -4,14 +4,11 @@ ...@@ -4,14 +4,11 @@
void sign_extend_if_required(const Operand &dest, Operand &src) { void sign_extend_if_required(const Operand &dest, Operand &src) {
if(dest.width > src.width) { if(dest.width > src.width) {
rtl_sext(&src.val, &src.val, src.width); rtl_sext(&src.val, &src.val, src.width);
src.imm = src.val;
src.width = dest.width; src.width = dest.width;
} }
} }
namespace EHelperImpl { namespace EHelperImpl {
using vaddr_t = uint32_t;
make_EHelper(test) { make_EHelper(test) {
// `and` without write_back. // `and` without write_back.
sign_extend_if_required(*id_dest, *id_src); sign_extend_if_required(*id_dest, *id_src);
...@@ -24,9 +21,9 @@ namespace EHelperImpl { ...@@ -24,9 +21,9 @@ namespace EHelperImpl {
} }
make_EHelper(and_) { make_EHelper(and_) {
rlib::printfln("before test, id_dest={}, src={}", *id_dest, *id_src); // rlib::printfln("debug: before test, id_dest={}, src={}", *id_dest, *id_src);
sign_extend_if_required(*id_dest, *id_src); sign_extend_if_required(*id_dest, *id_src);
rlib::printfln("after test, id_dest={}, src={}", *id_dest, *id_src); // rlib::printfln("debug: after test, id_dest={}, src={}", *id_dest, *id_src);
rtl_and(&id_dest->val, &id_dest->val, &id_src->val); rtl_and(&id_dest->val, &id_dest->val, &id_src->val);
operand_write(id_dest, &id_dest->val); operand_write(id_dest, &id_dest->val);
...@@ -50,28 +47,49 @@ namespace EHelperImpl { ...@@ -50,28 +47,49 @@ namespace EHelperImpl {
} }
make_EHelper(or_) { make_EHelper(or_) {
TODO(); sign_extend_if_required(*id_dest, *id_src);
rtl_or(&id_dest->val, &id_dest->val, &id_src->val);
operand_write(id_dest, &id_dest->val);
rtl_update_ZFSF(&id_dest->val, id_dest->width);
cpu_eflags::get<cpu_eflags::CF>() = cpu_eflags::get<cpu_eflags::OF>() = false;
print_asm_template2(or); print_asm_template2(or);
} }
make_EHelper(sar) { make_EHelper(sar) {
TODO(); // r: dbt
// unnecessary to update CF and OF in NEMU // warning: unnecessary to update CF and OF in NEMU
if (id_dest->width == 1) {
id_dest->val = (int8_t)id_dest->val;
}
else if (id_dest->width == 2) {
id_dest->val = (int16_t)id_dest->val;
}
rtl_sar(&t2, &id_dest->val, &id_src->val);
operand_write(id_dest, &t2);
rtl_update_ZFSF(&t2, id_dest->width);
print_asm_template2(sar); print_asm_template2(sar);
} }
make_EHelper(shl) { make_EHelper(shl) {
TODO(); // r: dbt
// unnecessary to update CF and OF in NEMU // unnecessary to update CF and OF in NEMU
rtl_shl(&t2, &id_dest->val, &id_src->val);
operand_write(id_dest, &t2);
rtl_update_ZFSF(&t2, id_dest->width);
print_asm_template2(shl); print_asm_template2(shl);
} }
make_EHelper(shr) { make_EHelper(shr) {
TODO(); // r: dbt
// unnecessary to update CF and OF in NEMU // unnecessary to update CF and OF in NEMU
rtl_shr(&t2, &id_dest->val, &id_src->val);
operand_write(id_dest, &t2);
rtl_update_ZFSF(&t2, id_dest->width);
print_asm_template2(shr); print_asm_template2(shr);
} }
...@@ -86,13 +104,31 @@ namespace EHelperImpl { ...@@ -86,13 +104,31 @@ namespace EHelperImpl {
} }
make_EHelper(not_) { make_EHelper(not_) {
TODO(); rtl_not(&id_dest->val, &id_dest->val);
operand_write(id_dest, &id_dest->val);
print_asm_template1(not); print_asm_template1(not);
} }
make_EHelper(rol) { make_EHelper(rol) {
TODO(); // r: dbt
rtl_shl(&t0, &id_dest->val, &id_src->val);
if (decoding.is_operand_size_16) {
t3 = 0;
rtl_addi(&t1, &t3, 16);
rtl_sub(&t1, &t1, &id_src->val);
rtl_shr(&t2, &id_dest->val, &t1);
} else {
t3 = 0;
rtl_addi(&t1, &t3, 32);
rtl_sub(&t1, &t1, &id_src->val);
rtl_shr(&t2, &id_dest->val, &t1);
}
rtl_or(&t0, &t0, &t2);
operand_write(id_dest, &t0);
// unnecessary to update CF and OF in NEMU
rtl_update_ZFSF(&t0, id_dest->width);
print_asm_template1(rol); print_asm_template1(rol);
} }
......
#include "trap.h"
int min3(int x, int y, int z) {
int m;
if(x < y) { m = x; }
else { m = y; }
if(z < m) m = z;
return m;
}
//int test_data[] = {0, 0x7fffffff, 0x80000000, 0xffffffff};
//int ans [] = {0, 0, -2147483648, -1, 0, 0, -2147483648, -1, -2147483648, -2147483648, -2147483648, -2147483648, -1, -1, -2147483648, -1, 0, 0, -2147483648, -1, 0, 2147483647, -2147483648, -1, -2147483648, -2147483648, -2147483648, -2147483648, -1, -1, -2147483648, -1, -2147483648, -2147483648, -2147483648, -2147483648, -2147483648, -2147483648, -2147483648, -2147483648, -2147483648, -2147483648, -2147483648, -2147483648, -2147483648, -2147483648, -2147483648, -2147483648, -1, -1, -2147483648, -1, -1, -1, -2147483648, -1, -2147483648, -2147483648, -2147483648, -2147483648, -1, -1, -2147483648, -1};
int test_data[] = {1,2};
int ans [] = {1,1,1, 1,1,1, 1,1,2};
#define NR_DATA (sizeof(test_data) / sizeof(test_data[0]))
int main() {
int rmax = 0;
if(test_data[0] < test_data[1])
rmax = test_data[1];
else
rmax = test_data[0];
nemu_assert(rmax == test_data[1]);
return 0;
int i, j, k, ans_idx = 0;
//nemu_assert(min3(4,6,8) == 4);
for(i = 0; i < NR_DATA; i ++) {
for(j = 0; j < NR_DATA; j ++) {
for(k = 0; k < NR_DATA; k ++) {
nemu_assert(min3(test_data[i], test_data[j], test_data[k]) == ans[ans_idx ++]);
}
//nemu_assert(k == NR_DATA);
}
//nemu_assert(j == NR_DATA);
}
//nemu_assert(i == NR_DATA);
return 0;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment