From a2845cee7058589f906640597b6e9c3c640f1df7 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Mon, 6 Jan 2014 10:34:07 -0800 Subject: [PATCH] Update %pow instructions to use vec4 stack. --- vvp/compile.cc | 6 ++--- vvp/vthread.cc | 70 +++++++++++++++++++++++--------------------------- 2 files changed, 35 insertions(+), 41 deletions(-) diff --git a/vvp/compile.cc b/vvp/compile.cc index e77409afb..1a4f9df08 100644 --- a/vvp/compile.cc +++ b/vvp/compile.cc @@ -227,9 +227,9 @@ static const struct opcode_table_s opcode_table[] = { { "%pop/real",of_POP_REAL,1, {OA_NUMBER, OA_NONE, OA_NONE} }, { "%pop/str", of_POP_STR, 1, {OA_NUMBER, OA_NONE, OA_NONE} }, { "%pop/vec4",of_POP_VEC4,1, {OA_NUMBER, OA_NONE, OA_NONE} }, - { "%pow", of_POW, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} }, - { "%pow/s", of_POW_S, 3, {OA_BIT1, OA_BIT2, OA_NUMBER} }, - { "%pow/wr", of_POW_WR, 0, {OA_NONE, OA_NONE, OA_NONE} }, + { "%pow", of_POW, 0, {OA_NONE, OA_NONE, OA_NONE} }, + { "%pow/s", of_POW_S, 0, {OA_NONE, OA_NONE, OA_NONE} }, + { "%pow/wr", of_POW_WR, 0, {OA_NONE, OA_NONE, OA_NONE} }, { "%prop/obj",of_PROP_OBJ,1, {OA_NUMBER, OA_NONE, OA_NONE} }, { "%prop/r", of_PROP_R, 1, {OA_NUMBER, OA_NONE, OA_NONE} }, { "%prop/str",of_PROP_STR,1, {OA_NUMBER, OA_NONE, OA_NONE} }, diff --git a/vvp/vthread.cc b/vvp/vthread.cc index 7c4b292d9..4f62e3bfa 100644 --- a/vvp/vthread.cc +++ b/vvp/vthread.cc @@ -4886,21 +4886,24 @@ bool of_POP_VEC4(vthread_t thr, vvp_code_t cp) return true; } -bool of_POW(vthread_t thr, vvp_code_t cp) +/* + * %pow + */ +bool of_POW(vthread_t thr, vvp_code_t) { -#if 0 - assert(cp->bit_idx[0] >= 4); + vvp_vector4_t valb = thr->pop_vec4(); + vvp_vector4_t vala = thr->pop_vec4(); - unsigned idx = cp->bit_idx[0]; - unsigned idy = cp->bit_idx[1]; - unsigned wid = cp->number; - vvp_vector2_t xv2 = vvp_vector2_t(vthread_bits_to_vector(thr, idx, wid)); - vvp_vector2_t yv2 = vvp_vector2_t(vthread_bits_to_vector(thr, idy, wid)); + assert(vala.size()==valb.size()); + unsigned wid = vala.size(); + + vvp_vector2_t xv2 = vvp_vector2_t(vala); + vvp_vector2_t yv2 = vvp_vector2_t(valb); /* If we have an X or Z in the arguments return X. */ if (xv2.is_NaN() || yv2.is_NaN()) { - for (unsigned jdx = 0 ; jdx < wid ; jdx += 1) - thr_put_bit(thr, cp->bit_idx[0]+jdx, BIT4_X); + vvp_vector4_t tmp (wid, BIT4_X); + thr->push_vec4(tmp); return true; } @@ -4910,38 +4913,34 @@ bool of_POW(vthread_t thr, vvp_code_t cp) vvp_vector2_t result = pow(xv2, yv2); - /* If the result is too small zero pad it. */ - if (result.size() < wid) { - for (unsigned jdx = wid-1; jdx >= result.size(); jdx -= 1) - thr_put_bit(thr, cp->bit_idx[0]+jdx, BIT4_0); - wid = result.size(); + /* Copy only what we need of the result. If the result is too + small, zero-pad it. */ + for (unsigned jdx = 0; jdx < wid; jdx += 1) { + if (jdx >= result.size()) + vala.set_bit(jdx, BIT4_0); + else + vala.set_bit(jdx, result.value(jdx) ? BIT4_1 : BIT4_0); } + thr->push_vec4(vala); - /* Copy only what we need of the result. */ - for (unsigned jdx = 0; jdx < wid; jdx += 1) - thr_put_bit(thr, cp->bit_idx[0]+jdx, - result.value(jdx) ? BIT4_1 : BIT4_0); -#else - fprintf(stderr, "XXXX NOT IMPLEMENTED: %%pow ...\n"); -#endif return true; } -bool of_POW_S(vthread_t thr, vvp_code_t cp) +/* + * %pow/s + */ +bool of_POW_S(vthread_t thr, vvp_code_t) { -#if 0 - assert(cp->bit_idx[0] >= 4); + vvp_vector4_t yv = thr->pop_vec4(); + vvp_vector4_t xv = thr->pop_vec4(); - unsigned idx = cp->bit_idx[0]; - unsigned idy = cp->bit_idx[1]; - unsigned wid = cp->number; - vvp_vector4_t xv = vthread_bits_to_vector(thr, idx, wid); - vvp_vector4_t yv = vthread_bits_to_vector(thr, idy, wid); + assert(xv.size()==yv.size()); + unsigned wid = xv.size(); /* If we have an X or Z in the arguments return X. */ if (xv.has_xz() || yv.has_xz()) { - for (unsigned jdx = 0 ; jdx < wid ; jdx += 1) - thr_put_bit(thr, cp->bit_idx[0]+jdx, BIT4_X); + vvp_vector4_t tmp (wid, BIT4_X); + thr->push_vec4(tmp); return true; } @@ -4954,12 +4953,7 @@ bool of_POW_S(vthread_t thr, vvp_code_t cp) else resd = pow(xd, yd); vvp_vector4_t res = vvp_vector4_t(wid, resd); - /* Copy the result. */ - for (unsigned jdx = 0; jdx < wid; jdx += 1) - thr_put_bit(thr, cp->bit_idx[0]+jdx, res.value(jdx)); -#else - fprintf(stderr, "XXXX NOT IMPLEMENTED: %%pow/s ...\n"); -#endif + thr->push_vec4(res); return true; }