From 409f8c582308910a13bd62ad479c11175568b5a9 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Fri, 5 Dec 2014 09:45:29 -0800 Subject: [PATCH] Add the vec4 %subi instruction --- tgt-vvp/eval_vec4.c | 3 +++ vvp/codes.h | 1 + vvp/compile.cc | 1 + vvp/vthread.cc | 24 ++++++++++++++++++++++++ 4 files changed, 29 insertions(+) diff --git a/tgt-vvp/eval_vec4.c b/tgt-vvp/eval_vec4.c index ac3c974b0..2b1a62cf5 100644 --- a/tgt-vvp/eval_vec4.c +++ b/tgt-vvp/eval_vec4.c @@ -138,6 +138,9 @@ static void draw_binary_vec4_arith(ivl_expr_t expr) case '+': draw_immediate_vec4(re, "%addi"); return; + case '-': + draw_immediate_vec4(re, "%subi"); + return; case '*': draw_immediate_vec4(re, "%muli"); return; diff --git a/vvp/codes.h b/vvp/codes.h index e31dd9cae..68b0755c3 100644 --- a/vvp/codes.h +++ b/vvp/codes.h @@ -226,6 +226,7 @@ extern bool of_STORE_STRA(vthread_t thr, vvp_code_t code); extern bool of_STORE_VEC4(vthread_t thr, vvp_code_t code); extern bool of_STORE_VEC4A(vthread_t thr, vvp_code_t code); extern bool of_SUB(vthread_t thr, vvp_code_t code); +extern bool of_SUBI(vthread_t thr, vvp_code_t code); extern bool of_SUB_WR(vthread_t thr, vvp_code_t code); extern bool of_SUBSTR(vthread_t thr, vvp_code_t code); extern bool of_SUBSTR_VEC4(vthread_t thr, vvp_code_t code); diff --git a/vvp/compile.cc b/vvp/compile.cc index ea71009a8..eb74b8be4 100644 --- a/vvp/compile.cc +++ b/vvp/compile.cc @@ -274,6 +274,7 @@ static const struct opcode_table_s opcode_table[] = { { "%store/vec4a", of_STORE_VEC4A, 3, {OA_ARR_PTR, OA_BIT1, OA_BIT2} }, { "%sub", of_SUB, 0, {OA_NONE, OA_NONE, OA_NONE} }, { "%sub/wr", of_SUB_WR, 0, {OA_NONE, OA_NONE, OA_NONE} }, + { "%subi", of_SUBI, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} }, { "%substr", of_SUBSTR, 2,{OA_BIT1, OA_BIT2, OA_NONE} }, { "%substr/vec4",of_SUBSTR_VEC4,2,{OA_BIT1, OA_BIT2, OA_NONE} }, { "%test_nul", of_TEST_NUL, 1,{OA_FUNC_PTR,OA_NONE, OA_NONE} }, diff --git a/vvp/vthread.cc b/vvp/vthread.cc index 671cbcfbb..a6bfe8b3c 100644 --- a/vvp/vthread.cc +++ b/vvp/vthread.cc @@ -5464,6 +5464,30 @@ bool of_SUB(vthread_t thr, vvp_code_t) return true; } +/* + * %subi , , + * + * Pop1 operand, get the other operand from the arguments, and push + * the result. + */ +bool of_SUBI(vthread_t thr, vvp_code_t cp) +{ + unsigned wid = cp->number; + + vvp_vector4_t&l = thr->peek_vec4(); + + // I expect that most of the bits of an immediate value are + // going to be zero, so start the result vector with all zero + // bits. Then we only need to replace the bits that are different. + vvp_vector4_t r (wid, BIT4_0); + get_immediate_rval (cp, r); + + l.sub(r); + + return true; + +} + bool of_SUB_WR(vthread_t thr, vvp_code_t) { double r = thr->pop_real();