diff mbox series

[v3,05/40] target/mips: Add nanoMIPS decoding and extraction utilities

Message ID 1532004912-13899-6-git-send-email-stefan.markovic@rt-rk.com
State New
Headers show
Series Add nanoMIPS support to QEMU | expand

Commit Message

Stefan Markovic July 19, 2018, 12:54 p.m. UTC
From: Yongbok Kim <yongbok.kim@mips.com>

Add some basic utility functions and macros for nanoMIPS decoding
engine.

Signed-off-by: Yongbok Kim <yongbok.kim@mips.com>
Signed-off-by: Aleksandar Markovic <amarkovic@wavecomp.com>
Signed-off-by: Stefan Markovic <smarkovic@wavecomp.com>
---
 target/mips/translate.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

Comments

Richard Henderson July 19, 2018, 4:57 p.m. UTC | #1
On 07/19/2018 05:54 AM, Stefan Markovic wrote:
> +static int decode_gpr_gpr3(int r)
> +{
> +    static const int map[] = { 16, 17, 18, 19, 4, 5, 6, 7 };
> +
> +    return map[r & 0x7];
> +}
> +
> +static int decode_gpr_gpr4(int r)
> +{
> +    static const int map[] = { 8, 9, 10, 11, 4, 5, 6, 7,
> +                            16, 17, 18, 19, 20, 21, 22, 23 };
> +
> +    return map[r & 0xf];
> +}
> +
> +/* Used for 16-bit store instructions.  */
> +static int decode_gpr_gpr4_zero(int r)

I think it's worth spending one line to document the pseudocode function from
which each of these come.  E.g.

/* Implement nanoMIPS pseudocode decode_gpr(encoded_gpr, 'gpr4.zero').  */

Which is certainly more accurate than the comment that is there currently.

Otherwise,
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>


r~
Aleksandar Markovic July 24, 2018, 11 a.m. UTC | #2
> From: Richard Henderson <richard.henderson@linaro.org>
> Sent: Thursday, July 19, 2018 6:57 PM
>
> I think it's worth spending one line to document the pseudocode function from
> which each of these come.  E.g.
>
> /* Implement nanoMIPS pseudocode decode_gpr(encoded_gpr, 'gpr4.zero').  */
>
> Which is certainly more accurate than the comment that is there currently.
>
> Otherwise,
> Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
>
>
> r~

Hello, Richard

The comments will be fixed in v4. Also, the fourth decode_gpr_XXX function will be moved to this patch (from one of remaining patches with decoding logic). These functions will be all marked inline. This also means that the compiler will not complain about "unused functions".

Aleksandar
diff mbox series

Patch

diff --git a/target/mips/translate.c b/target/mips/translate.c
index 67a0f70..4e6ae1f 100644
--- a/target/mips/translate.c
+++ b/target/mips/translate.c
@@ -16465,6 +16465,41 @@  enum {
  *
  */
 
+static int decode_gpr_gpr3(int r)
+{
+    static const int map[] = { 16, 17, 18, 19, 4, 5, 6, 7 };
+
+    return map[r & 0x7];
+}
+
+static int decode_gpr_gpr4(int r)
+{
+    static const int map[] = { 8, 9, 10, 11, 4, 5, 6, 7,
+                            16, 17, 18, 19, 20, 21, 22, 23 };
+
+    return map[r & 0xf];
+}
+
+/* Used for 16-bit store instructions.  */
+static int decode_gpr_gpr4_zero(int r)
+{
+    static const int map[] = { 8, 9, 10, 0, 4, 5, 6, 7,
+                            16, 17, 18, 19, 20, 21, 22, 23 };
+
+    return map[r & 0xf];
+}
+
+
+/* extraction utilities */
+
+#define NANOMIPS_EXTRACT_RD(op) ((op >> 7) & 0x7)
+#define NANOMIPS_EXTRACT_RS(op) ((op >> 4) & 0x7)
+#define NANOMIPS_EXTRACT_RS2(op) uMIPS_RS(op)
+#define NANOMIPS_EXTRACT_RS1(op) ((op >> 1) & 0x7)
+#define NANOMIPS_EXTRACT_RD5(op) ((op >> 5) & 0x1f)
+#define NANOMIPS_EXTRACT_RS5(op) (op & 0x1f)
+
+
 static int decode_nanomips_opc(CPUMIPSState *env, DisasContext *ctx)
 {
     return 2;