From c9b7962cd345d3f8e9619e15fb7dbc02c579c190 Mon Sep 17 00:00:00 2001 From: Eyck-Alexander Jentzsch Date: Mon, 17 Feb 2025 15:07:14 +0100 Subject: [PATCH] adds Vector Integer Divide Instructions --- src/vm/vector_functions.hpp | 38 +++++++++++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 4 deletions(-) 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;