diff --git a/src/vm/vector_functions.hpp b/src/vm/vector_functions.hpp index ae902af..c82462d 100644 --- a/src/vm/vector_functions.hpp +++ b/src/vm/vector_functions.hpp @@ -184,10 +184,40 @@ std::function get_funct(unsigned funct6, // case 0b011101: // VMNAND // case 0b011110: // VMNOR // case 0b011111: // VMXNOR - // case 0b100000: // VDIVU - // case 0b100001: // VDIV - // case 0b100010: // VREMU - // case 0b100011: // VREM + case 0b100000: // VDIVU + return [](src2_elem_t vs2, src1_elem_t vs1) -> dest_elem_t { + if(vs1 == 0) + return -1; + else + return vs2 / vs1; + }; + case 0b100001: // VDIV + return [](src2_elem_t vs2, src1_elem_t vs1) -> dest_elem_t { + if(vs1 == 0) + return -1; + else if(vs2 == std::numeric_limits>::min() && + static_cast>(vs1) == -1) + return vs2; + else + return static_cast>(vs2) / static_cast>(vs1); + }; + case 0b100010: // VREMU + return [](src2_elem_t vs2, src1_elem_t vs1) -> dest_elem_t { + if(vs1 == 0) + return vs2; + else + return vs2 % vs1; + }; + case 0b100011: // VREM + return [](src2_elem_t vs2, src1_elem_t vs1) -> dest_elem_t { + if(vs1 == 0) + return vs2; + else if(vs2 == std::numeric_limits>::min() && + static_cast>(vs1) == -1) + return 0; + else + return static_cast>(vs2) % static_cast>(vs1); + }; case 0b100100: // VMULHU return [](src2_elem_t vs2, src1_elem_t vs1) { return (static_cast>(vs2) * static_cast>(vs1)) >> sizeof(dest_elem_t) * 8;