From: Stefan Markovic <smarkovic@wavecomp.com>
To: Aleksandar Markovic <aleksandar.markovic@rt-rk.com>,
"qemu-devel@nongnu.org" <qemu-devel@nongnu.org>,
"jancraig@amazon.com" <jancraig@amazon.com>,
Aleksandar Markovic <amarkovic@wavecomp.com>
Subject: Re: [Qemu-devel] [PATCH 5/6] target/mips: MXU: Add handlers for max/min instructions
Date: Tue, 18 Dec 2018 15:05:05 +0000 [thread overview]
Message-ID: <3d59f696-be48-d274-0995-33836eca552a@wavecomp.com> (raw)
In-Reply-To: <20181217200444.14812-6-aleksandar.markovic@rt-rk.com>
On 17.12.18. 21:04, Aleksandar Markovic wrote:
> From: Aleksandar Markovic <amarkovic@wavecomp.com>
>
> Add translation handlers for max/min MXU instructions.
>
> Signed-off-by: Aleksandar Markovic <amarkovic@wavecomp.com>
> ---
> target/mips/translate.c | 356 +++++++++++++++++++++++++++++++++++++---
> 1 file changed, 335 insertions(+), 21 deletions(-)
Reviewed-by: Stefan Markovic <smarkovic@wavecomp.com>
> diff --git a/target/mips/translate.c b/target/mips/translate.c
> index c74a831a17..339de8c32b 100644
> --- a/target/mips/translate.c
> +++ b/target/mips/translate.c
> @@ -24815,6 +24815,338 @@ static void gen_mxu_S32XOR(DisasContext *ctx)
> }
>
>
> +/*
> + * MXU instruction category max/min
> + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> + *
> + * S32MAX D16MAX Q8MAX
> + * S32MIN D16MIN Q8MIN
> + */
> +
> +/*
> + * S32MAX XRa, XRb, XRc
> + * Update XRa with the maximum of signed 32-bit integers contained
> + * in XRb and XRc.
> + *
> + * S32MIN XRa, XRb, XRc
> + * Update XRa with the minimum of signed 32-bit integers contained
> + * in XRb and XRc.
> + *
> + * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
> + * +-----------+---------+-----+-------+-------+-------+-----------+
> + * | SPECIAL2 |0 0 0 0 0| opc | XRc | XRb | XRa |MXU__POOL00|
> + * +-----------+---------+-----+-------+-------+-------+-----------+
> + */
> +static void gen_mxu_S32MAX_S32MIN(DisasContext *ctx)
> +{
> + uint32_t pad, opc, XRc, XRb, XRa;
> +
> + pad = extract32(ctx->opcode, 21, 5);
> + opc = extract32(ctx->opcode, 18, 3);
> + XRc = extract32(ctx->opcode, 14, 4);
> + XRb = extract32(ctx->opcode, 10, 4);
> + XRa = extract32(ctx->opcode, 6, 4);
> +
> + if (unlikely(pad != 0)) {
> + /* opcode padding incorrect -> do nothing */
> + } else if (unlikely(XRa == 0)) {
> + /* destination is zero register -> do nothing */
> + } else if (unlikely((XRb == 0) && (XRc == 0))) {
> + /* both operands zero registers -> just set destination to zero */
> + tcg_gen_movi_i32(mxu_gpr[XRa - 1], 0);
> + } else if (unlikely((XRb == 0) || (XRc == 0))) {
> + /* exactly one operand is zero register - find which one is not...*/
> + uint32_t XRx = XRb ? XRb : XRc;
> + /* ...and do max/min operation with one operand 0 */
> + if (opc == OPC_MXU_S32MAX) {
> + tcg_gen_smax_i32(mxu_gpr[XRa - 1], mxu_gpr[XRx - 1], 0);
> + } else {
> + tcg_gen_smin_i32(mxu_gpr[XRa - 1], mxu_gpr[XRx - 1], 0);
> + }
> + } else if (unlikely(XRb == XRc)) {
> + /* both operands same -> just set destination to one of them */
> + tcg_gen_mov_i32(mxu_gpr[XRa - 1], mxu_gpr[XRb - 1]);
> + } else {
> + /* the most general case */
> + if (opc == OPC_MXU_S32MAX) {
> + tcg_gen_smax_i32(mxu_gpr[XRa - 1], mxu_gpr[XRb - 1],
> + mxu_gpr[XRc - 1]);
> + } else {
> + tcg_gen_smin_i32(mxu_gpr[XRa - 1], mxu_gpr[XRb - 1],
> + mxu_gpr[XRc - 1]);
> + }
> + }
> +}
> +
> +/*
> + * D16MAX
> + * Update XRa with the 16-bit-wise maximums of signed integers
> + * contained in XRb and XRc.
> + *
> + * D16MIN
> + * Update XRa with the 16-bit-wise minimums of signed integers
> + * contained in XRb and XRc.
> + *
> + * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
> + * +-----------+---------+-----+-------+-------+-------+-----------+
> + * | SPECIAL2 |0 0 0 0 0| opc | XRc | XRb | XRa |MXU__POOL00|
> + * +-----------+---------+-----+-------+-------+-------+-----------+
> + */
> +static void gen_mxu_D16MAX_D16MIN(DisasContext *ctx)
> +{
> + uint32_t pad, opc, XRc, XRb, XRa;
> +
> + pad = extract32(ctx->opcode, 21, 5);
> + opc = extract32(ctx->opcode, 18, 3);
> + XRc = extract32(ctx->opcode, 14, 4);
> + XRb = extract32(ctx->opcode, 10, 4);
> + XRa = extract32(ctx->opcode, 6, 4);
> +
> + if (unlikely(pad != 0)) {
> + /* opcode padding incorrect -> do nothing */
> + } else if (unlikely(XRc == 0)) {
> + /* destination is zero register -> do nothing */
> + } else if (unlikely((XRb == 0) && (XRa == 0))) {
> + /* both operands zero registers -> just set destination to zero */
> + tcg_gen_movi_i32(mxu_gpr[XRc - 1], 0);
> + } else if (unlikely((XRb == 0) || (XRa == 0))) {
> + /* exactly one operand is zero register - find which one is not...*/
> + uint32_t XRx = XRb ? XRb : XRc;
> + /* ...and do half-word-wise max/min with one operand 0 */
> + TCGv_i32 t0 = tcg_temp_new();
> + TCGv_i32 t1 = tcg_const_i32(0);
> +
> + /* the left half-word first */
> + tcg_gen_andi_i32(t0, mxu_gpr[XRx - 1], 0xFFFF0000);
> + if (opc == OPC_MXU_D16MAX) {
> + tcg_gen_smax_i32(mxu_gpr[XRa - 1], t0, t1);
> + } else {
> + tcg_gen_smin_i32(mxu_gpr[XRa - 1], t0, t1);
> + }
> +
> + /* the right half-word */
> + tcg_gen_andi_i32(t0, mxu_gpr[XRx - 1], 0x0000FFFF);
> + /* move half-words to the leftmost position */
> + tcg_gen_shli_i32(t0, t0, 16);
> + /* t0 will be max/min of t0 and t1 */
> + if (opc == OPC_MXU_D16MAX) {
> + tcg_gen_smax_i32(t0, t0, t1);
> + } else {
> + tcg_gen_smin_i32(t0, t0, t1);
> + }
> + /* return resulting half-words to its original position */
> + tcg_gen_shri_i32(t0, t0, 16);
> + /* finaly update the destination */
> + tcg_gen_or_i32(mxu_gpr[XRa - 1], mxu_gpr[XRa - 1], t0);
> +
> + tcg_temp_free(t1);
> + tcg_temp_free(t0);
> + } else if (unlikely(XRb == XRc)) {
> + /* both operands same -> just set destination to one of them */
> + tcg_gen_mov_i32(mxu_gpr[XRa - 1], mxu_gpr[XRb - 1]);
> + } else {
> + /* the most general case */
> + TCGv_i32 t0 = tcg_temp_new();
> + TCGv_i32 t1 = tcg_temp_new();
> +
> + /* the left half-word first */
> + tcg_gen_andi_i32(t0, mxu_gpr[XRb - 1], 0xFFFF0000);
> + tcg_gen_andi_i32(t1, mxu_gpr[XRc - 1], 0xFFFF0000);
> + if (opc == OPC_MXU_D16MAX) {
> + tcg_gen_smax_i32(mxu_gpr[XRa - 1], t0, t1);
> + } else {
> + tcg_gen_smin_i32(mxu_gpr[XRa - 1], t0, t1);
> + }
> +
> + /* the right half-word */
> + tcg_gen_andi_i32(t0, mxu_gpr[XRb - 1], 0x0000FFFF);
> + tcg_gen_andi_i32(t1, mxu_gpr[XRc - 1], 0x0000FFFF);
> + /* move half-words to the leftmost position */
> + tcg_gen_shli_i32(t0, t0, 16);
> + tcg_gen_shli_i32(t1, t1, 16);
> + /* t0 will be max/min of t0 and t1 */
> + if (opc == OPC_MXU_D16MAX) {
> + tcg_gen_smax_i32(t0, t0, t1);
> + } else {
> + tcg_gen_smin_i32(t0, t0, t1);
> + }
> + /* return resulting half-words to its original position */
> + tcg_gen_shri_i32(t0, t0, 16);
> + /* finaly update the destination */
> + tcg_gen_or_i32(mxu_gpr[XRa - 1], mxu_gpr[XRa - 1], t0);
> +
> + tcg_temp_free(t1);
> + tcg_temp_free(t0);
> + }
> +}
> +
> +/*
> + * Q8MAX
> + * Update XRa with the 8-bit-wise maximums of signed integers
> + * contained in XRb and XRc.
> + *
> + * Q8MIN
> + * Update XRa with the 8-bit-wise minimums of signed integers
> + * contained in XRb and XRc.
> + *
> + * 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0 9 8 7 6 5 4 3 2 1 0
> + * +-----------+---------+-----+-------+-------+-------+-----------+
> + * | SPECIAL2 |0 0 0 0 0| opc | XRc | XRb | XRa |MXU__POOL00|
> + * +-----------+---------+-----+-------+-------+-------+-----------+
> + */
> +static void gen_mxu_Q8MAX_Q8MIN(DisasContext *ctx)
> +{
> + uint32_t pad, opc, XRc, XRb, XRa;
> +
> + pad = extract32(ctx->opcode, 21, 5);
> + opc = extract32(ctx->opcode, 18, 3);
> + XRc = extract32(ctx->opcode, 14, 4);
> + XRb = extract32(ctx->opcode, 10, 4);
> + XRa = extract32(ctx->opcode, 6, 4);
> +
> + if (unlikely(pad != 0)) {
> + /* opcode padding incorrect -> do nothing */
> + } else if (unlikely(XRa == 0)) {
> + /* destination is zero register -> do nothing */
> + } else if (unlikely((XRb == 0) && (XRc == 0))) {
> + /* both operands zero registers -> just set destination to zero */
> + tcg_gen_movi_i32(mxu_gpr[XRa - 1], 0);
> + } else if (unlikely((XRb == 0) || (XRc == 0))) {
> + /* exactly one operand is zero register - make it be the first...*/
> + uint32_t XRx = XRb ? XRb : XRc;
> + /* ...and do byte-wise max/min with one operand 0 */
> + TCGv_i32 t0 = tcg_temp_new();
> + TCGv_i32 t1 = tcg_const_i32(0);
> +
> + /* the leftmost byte (byte 3) first */
> + tcg_gen_andi_i32(t0, mxu_gpr[XRx - 1], 0xFF000000);
> + if (opc == OPC_MXU_Q8MAX) {
> + tcg_gen_smax_i32(mxu_gpr[XRa - 1], t0, t1);
> + } else {
> + tcg_gen_smin_i32(mxu_gpr[XRa - 1], t0, t1);
> + }
> +
> + /* byte 2 */
> + tcg_gen_andi_i32(t0, mxu_gpr[XRx - 1], 0x00FF0000);
> + /* move half-words to the leftmost position */
> + tcg_gen_shli_i32(t0, t0, 8);
> + /* t0 will be max/min of t0 and t1 */
> + if (opc == OPC_MXU_Q8MAX) {
> + tcg_gen_smax_i32(t0, t0, t1);
> + } else {
> + tcg_gen_smin_i32(t0, t0, t1);
> + }
> + /* return resulting byte to its original position */
> + tcg_gen_shri_i32(t0, t0, 8);
> + /* finaly update the destination */
> + tcg_gen_or_i32(mxu_gpr[XRa - 1], mxu_gpr[XRa - 1], t0);
> +
> + /* byte 1 */
> + tcg_gen_andi_i32(t0, mxu_gpr[XRx - 1], 0x0000FF00);
> + /* move half-words to the leftmost position */
> + tcg_gen_shli_i32(t0, t0, 16);
> + /* t0 will be max/min of t0 and t1 */
> + if (opc == OPC_MXU_Q8MAX) {
> + tcg_gen_smax_i32(t0, t0, t1);
> + } else {
> + tcg_gen_smin_i32(t0, t0, t1);
> + }
> + /* return resulting byte to its original position */
> + tcg_gen_shri_i32(t0, t0, 24);
> + /* finaly update the destination */
> + tcg_gen_or_i32(mxu_gpr[XRa - 1], mxu_gpr[XRa - 1], t0);
> +
> + /* byte 0 */
> + tcg_gen_andi_i32(t0, mxu_gpr[XRx - 1], 0x000000FF);
> + /* move half-words to the leftmost position */
> + tcg_gen_shli_i32(t0, t0, 24);
> + /* t0 will be max/min of t0 and t1 */
> + if (opc == OPC_MXU_Q8MAX) {
> + tcg_gen_smax_i32(t0, t0, t1);
> + } else {
> + tcg_gen_smin_i32(t0, t0, t1);
> + }
> + /* return resulting byte to its original position */
> + tcg_gen_shri_i32(t0, t0, 8);
> + /* finaly update the destination */
> + tcg_gen_or_i32(mxu_gpr[XRa - 1], mxu_gpr[XRa - 1], t0);
> +
> + tcg_temp_free(t1);
> + tcg_temp_free(t0);
> + } else if (unlikely(XRb == XRc)) {
> + /* both operands same -> just set destination to one of them */
> + tcg_gen_mov_i32(mxu_gpr[XRa - 1], mxu_gpr[XRb - 1]);
> + } else {
> + /* the most general case */
> + TCGv_i32 t0 = tcg_temp_new();
> + TCGv_i32 t1 = tcg_temp_new();
> +
> + /* the leftmost byte (byte 3) first */
> + tcg_gen_andi_i32(t0, mxu_gpr[XRb - 1], 0xFF000000);
> + tcg_gen_andi_i32(t1, mxu_gpr[XRc - 1], 0xFF000000);
> + if (opc == OPC_MXU_Q8MAX) {
> + tcg_gen_smax_i32(mxu_gpr[XRa - 1], t0, t1);
> + } else {
> + tcg_gen_smin_i32(mxu_gpr[XRa - 1], t0, t1);
> + }
> +
> + /* byte 2 */
> + tcg_gen_andi_i32(t0, mxu_gpr[XRb - 1], 0x00FF0000);
> + tcg_gen_andi_i32(t1, mxu_gpr[XRc - 1], 0x00FF0000);
> + /* move half-words to the leftmost position */
> + tcg_gen_shli_i32(t0, t0, 8);
> + tcg_gen_shli_i32(t1, t1, 8);
> + /* t0 will be max/min of t0 and t1 */
> + if (opc == OPC_MXU_Q8MAX) {
> + tcg_gen_smax_i32(t0, t0, t1);
> + } else {
> + tcg_gen_smin_i32(t0, t0, t1);
> + }
> + /* return resulting byte to its original position */
> + tcg_gen_shri_i32(t0, t0, 8);
> + /* finaly update the destination */
> + tcg_gen_or_i32(mxu_gpr[XRa - 1], mxu_gpr[XRa - 1], t0);
> +
> + /* byte 1 */
> + tcg_gen_andi_i32(t0, mxu_gpr[XRb - 1], 0x0000FF00);
> + tcg_gen_andi_i32(t1, mxu_gpr[XRc - 1], 0x0000FF00);
> + /* move half-words to the leftmost position */
> + tcg_gen_shli_i32(t0, t0, 16);
> + tcg_gen_shli_i32(t1, t1, 16);
> + /* t0 will be max/min of t0 and t1 */
> + if (opc == OPC_MXU_Q8MAX) {
> + tcg_gen_smax_i32(t0, t0, t1);
> + } else {
> + tcg_gen_smin_i32(t0, t0, t1);
> + }
> + /* return resulting byte to its original position */
> + tcg_gen_shri_i32(t0, t0, 24);
> + /* finaly update the destination */
> + tcg_gen_or_i32(mxu_gpr[XRa - 1], mxu_gpr[XRa - 1], t0);
> +
> + /* byte 0 */
> + tcg_gen_andi_i32(t0, mxu_gpr[XRb - 1], 0x000000FF);
> + tcg_gen_andi_i32(t1, mxu_gpr[XRc - 1], 0x000000FF);
> + /* move half-words to the leftmost position */
> + tcg_gen_shli_i32(t0, t0, 24);
> + tcg_gen_shli_i32(t1, t1, 24);
> + /* t0 will be max/min of t0 and t1 */
> + if (opc == OPC_MXU_Q8MAX) {
> + tcg_gen_smax_i32(t0, t0, t1);
> + } else {
> + tcg_gen_smin_i32(t0, t0, t1);
> + }
> + /* return resulting byte to its original position */
> + tcg_gen_shri_i32(t0, t0, 8);
> + /* finaly update the destination */
> + tcg_gen_or_i32(mxu_gpr[XRa - 1], mxu_gpr[XRa - 1], t0);
> +
> + tcg_temp_free(t1);
> + tcg_temp_free(t0);
> + }
> +}
> +
> +
> /*
> * Decoding engine for MXU
> * =======================
> @@ -24836,34 +25168,16 @@ static void decode_opc_mxu__pool00(CPUMIPSState *env, DisasContext *ctx)
>
> switch (opcode) {
> case OPC_MXU_S32MAX:
> - /* TODO: Implement emulation of S32MAX instruction. */
> - MIPS_INVAL("OPC_MXU_S32MAX");
> - generate_exception_end(ctx, EXCP_RI);
> - break;
> case OPC_MXU_S32MIN:
> - /* TODO: Implement emulation of S32MIN instruction. */
> - MIPS_INVAL("OPC_MXU_S32MIN");
> - generate_exception_end(ctx, EXCP_RI);
> + gen_mxu_S32MAX_S32MIN(ctx);
> break;
> case OPC_MXU_D16MAX:
> - /* TODO: Implement emulation of D16MAX instruction. */
> - MIPS_INVAL("OPC_MXU_D16MAX");
> - generate_exception_end(ctx, EXCP_RI);
> - break;
> case OPC_MXU_D16MIN:
> - /* TODO: Implement emulation of D16MIN instruction. */
> - MIPS_INVAL("OPC_MXU_D16MIN");
> - generate_exception_end(ctx, EXCP_RI);
> + gen_mxu_D16MAX_D16MIN(ctx);
> break;
> case OPC_MXU_Q8MAX:
> - /* TODO: Implement emulation of Q8MAX instruction. */
> - MIPS_INVAL("OPC_MXU_Q8MAX");
> - generate_exception_end(ctx, EXCP_RI);
> - break;
> case OPC_MXU_Q8MIN:
> - /* TODO: Implement emulation of Q8MIN instruction. */
> - MIPS_INVAL("OPC_MXU_Q8MIN");
> - generate_exception_end(ctx, EXCP_RI);
> + gen_mxu_Q8MAX_Q8MIN(ctx);
> break;
> case OPC_MXU_Q8SLT:
> /* TODO: Implement emulation of Q8SLT instruction. */
next prev parent reply other threads:[~2018-12-18 15:05 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-17 20:04 [Qemu-devel] [PATCH 0/6] target/mips: Amend MXU support Aleksandar Markovic
2018-12-17 20:04 ` [Qemu-devel] [PATCH 1/6] target/mips: MXU: Add missing opcodes/decoding for LX* instructions Aleksandar Markovic
2018-12-18 14:21 ` Stefan Markovic
2018-12-27 17:15 ` Janeczek, Craig
2018-12-27 18:44 ` Aleksandar Markovic
2018-12-27 18:50 ` Janeczek, Craig
2018-12-27 19:23 ` Aleksandar Markovic
2018-12-27 19:37 ` Janeczek, Craig
2018-12-27 20:12 ` Aleksandar Markovic
2018-12-17 20:04 ` [Qemu-devel] [PATCH 2/6] target/mips: MXU: Add generic naming for optn2 constants Aleksandar Markovic
2018-12-17 20:04 ` [Qemu-devel] [PATCH 3/6] target/mips: MXU: Improve textual description Aleksandar Markovic
2018-12-18 14:30 ` Stefan Markovic
2018-12-17 20:04 ` [Qemu-devel] [PATCH 4/6] target/mips: MXU: Add handlers for logic instructions Aleksandar Markovic
2018-12-18 14:39 ` Stefan Markovic
2018-12-17 20:04 ` [Qemu-devel] [PATCH 5/6] target/mips: MXU: Add handlers for max/min instructions Aleksandar Markovic
2018-12-18 15:05 ` Stefan Markovic [this message]
2018-12-27 17:18 ` Janeczek, Craig
2018-12-27 20:14 ` Aleksandar Markovic
2018-12-23 17:22 ` Aleksandar Markovic
2018-12-25 19:34 ` Richard Henderson
2021-03-15 21:26 ` Philippe Mathieu-Daudé
2018-12-17 20:04 ` [Qemu-devel] [PATCH 6/6] target/mips: MXU: Add handlers for an align instruction Aleksandar Markovic
2018-12-18 15:19 ` Stefan Markovic
2018-12-27 21:27 ` [Qemu-devel] [PATCH 0/6] target/mips: Amend MXU support Aleksandar Markovic
2018-12-31 14:40 ` Aleksandar Markovic
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3d59f696-be48-d274-0995-33836eca552a@wavecomp.com \
--to=smarkovic@wavecomp.com \
--cc=aleksandar.markovic@rt-rk.com \
--cc=amarkovic@wavecomp.com \
--cc=jancraig@amazon.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).