Skip to contentSkip to conversation

OpenRISC orfpx64a32 support

PATCH Superseded Stafford Horne 1 participant 8 messages Mar 31, 2019 – Apr 9, 2019

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover OpenRISC orfpx64a32 support

Hello,

This is a set of patches to the OpenRISC assembler and simulator to support 64-bit floating point operations on 32-bit cores using register pairs, see orfpx64a32 [0].

The original patches were written by Andrey Bacherov and I have made some updates to get the simulator working and to match ABI updates from GCC 9. The main GCC 9 ABI change is to have r16 and above pair with an n+2 register rather than n+1. This is done because openrisc callee saved registers are r14-r30 (even). If a 64-bit value was stored in {r16,r17}, it would always need to be spilled across function calls as r17 is volatile. Therefore, values of 64-bits and greater are stored in even reg pairs, such as {r16,r18}.

Example of orfpx64a32 operations:

	lf.add.d r4, r6, r8    ; {r3,r4}   <= {r5,r6} + {r7,r8}
	lf.add.d r16, r20, r24 ; {r16,r18} <= {r20,r22} + {r24,r26}

These binutil patches have been used along with the GCC FPU patches [1] on the OpenRISC GCC 9 toolchain to test single and double precision floating point support. The main 'real' implementation of this hardware is Andrey's or1k_marocchino [2] core implementation which we have been using along with simulators for verification.

This whole patch series can be found on my github repo [3] as well.

[0] https://openrisc.io/proposals/orfpx64a32
[1] git at github.com:stffrdhrn/gcc.git or1k-fpu-1
[2] https://github.com/openrisc/or1k_marocchino
[3] [email protected]:stffrdhrn/binutils-gdb.git orfpx64a32-1

Stafford Horne (6):
cpu: Add support for orfp64a32 spec
opcodes: Regenerate opcodes for orfp64a32 spec sim/or1k: Regenerate sim for orfp64a32 spec sim/common: Wire in df/di conversion
sim/or1k: Add test for 64-bit fpu operations sim/common: Fix issue with wrong byte order on BE targets

 cpu/or1k.cpu                      |  15 +-
 cpu/or1kcommon.cpu                | 103 ++++--
 cpu/or1korfpx.cpu                 | 113 +++++--
 opcodes/or1k-asm.c                |  19 +-
 opcodes/or1k-desc.c               | 227 +++++++++++--
 opcodes/or1k-desc.h               | 330 +++++++++----------
 opcodes/or1k-dis.c                |  19 +-
 opcodes/or1k-ibld.c               | 114 ++++++-
 opcodes/or1k-opc.c                | 166 ++++++++--
 opcodes/or1k-opc.h                |  21 +-
 opcodes/or1k-opinst.c             |  51 +++
 sim/common/cgen-accfp.c           |  24 ++
 sim/common/cgen-ops.h             |   8 +-
 sim/or1k/cpu.c                    |  60 +++-
 sim/or1k/cpu.h                    | 115 ++++++-
 sim/or1k/decode.c                 | 302 ++++++++++++++----
 sim/or1k/decode.h                 |  16 +-
 sim/or1k/model.c                  | 510 ++++++++++++++++++++++++++++++
 sim/or1k/sem-switch.c             | 296 +++++++++++++++++
 sim/or1k/sem.c                    | 326 +++++++++++++++++++
 sim/testsuite/sim/or1k/fpu64a32.S | 172 ++++++++++
 21 files changed, 2637 insertions(+), 370 deletions(-)
 create mode 100644 sim/testsuite/sim/or1k/fpu64a32.S
Signature · 1 line
2.19.1
#1 lore raw

PATCH 1/6 cpu: Add support for orfp64a32 spec

This patch adds support for OpenRISC 64-bit FPU operations on 32-bit cores by using register pairs. The functionality is being added to the OpenRISC spec as per architecture proposal 14[0].

This patch also contains a few fixes to the symantics for existing OpenRISC single and double precision FPU operations.

[0] https://openrisc.io/proposals/orfpx64a32

cpu/ChangeLog:

yyyy-mm-dd Andrey Bacherov <[email protected]>
Stafford Horne <[email protected]>

* or1k.cpu (ORFPX64A32-MACHS): New pmacro.
(ORFPX-MACHS): Removed pmacro.
* or1kcommon.cpu (h-spr, spr-shift, spr-address, h-gpr): Reorder and add comments.
(h-fdr): Update comment to indicate or64. (reg-pair-offset): New hardware for 64-bit or32 register pair. (h-fd32r): New hardware for 64-bit fpu registers. (h-i64r): New hardware for 64-bit int registers.
* or1korfpx.cpu (rDSF, rASF, rBSF): Update attribute to ORFPX32-MACHS. (rDDF, rADF, rBDF): Update operand comment to indicate or64. (rDD32F, rAD32F, rBD32F, rDDI, rADI): New operands. (float-regreg-insn): Update single precision generator to MACH ORFPX32-MACHS. Add generator for or32 64-bit instructions. (float-setflag-insn): Update single precision generator to MACH ORFPX32-MACHS. Fix double instructions from single to double precision. Add generator for or32 64-bit instructions. (float-cust-insn cust-num): Update single precision generator to MACH ORFPX32-MACHS. Add generator for or32 64-bit instructions. (lf-rem-s, lf-itof-s, lf-ftoi-s, lf-madd-s): Update MACH to ORFPX32-MACHS.
(lf-rem-d): Fix operation from mod to rem.
(lf-rem-d32, lf-itof-d32, lf-ftoi-d32, lf-madd-d32): New instruction. (lf-itof-d): Fix operands from single to double. (lf-ftoi-d): Update operand mode from DI to WI.

---
 cpu/or1k.cpu       |  15 +++---
 cpu/or1kcommon.cpu | 103 +++++++++++++++++++++++++++++++++--------
 cpu/or1korfpx.cpu  | 113 +++++++++++++++++++++++++++++++++++++--------
 3 files changed, 186 insertions(+), 45 deletions(-)
cpu/or1k.cpu +8 -7
index 3a932bcb90..e1ae1b8c88 100644
@@ -1,8 +1,9 @@
 ; OpenRISC 1000 architecture.  -*- Scheme -*-
-; Copyright 2000-2014 Free Software Foundation, Inc.
+; Copyright 2000-2019 Free Software Foundation, Inc.
 ; Contributed for OR32 by Johan Rydberg, jrydberg at opencores.org
 ; Modified by Julius Baxter, juliusbaxter at gmail.com
 ; Modified by Peter Gavin, pgavin at gmail.com
+; Modified by Andrey Bacherov, avbacherov at opencores.org
 ;
 ; This program is free software; you can redistribute it and/or modify
 ; it under the terms of the GNU General Public License as published by
@@ -42,12 +43,12 @@
   (base-insn-bitsize 32)
   )
 
-(define-pmacro OR32-MACHS    or32,or32nd)
-(define-pmacro OR64-MACHS    or64,or64nd)
-(define-pmacro ORBIS-MACHS   or32,or32nd,or64,or64nd)
-(define-pmacro ORFPX-MACHS   or32,or32nd,or64,or64nd)
-(define-pmacro ORFPX32-MACHS or32,or32nd,or64,or64nd)
-(define-pmacro ORFPX64-MACHS or64,or64nd)
+(define-pmacro OR32-MACHS       or32,or32nd)
+(define-pmacro OR64-MACHS       or64,or64nd)
+(define-pmacro ORBIS-MACHS      or32,or32nd,or64,or64nd)
+(define-pmacro ORFPX32-MACHS    or32,or32nd,or64,or64nd)
+(define-pmacro ORFPX64-MACHS    or64,or64nd)
+(define-pmacro ORFPX64A32-MACHS or32,or32nd) ; float64 for 32-bit machs
 
 (define-attr
   (for model)
cpu/or1kcommon.cpu +85 -18

133 lines not on this page · raw message

cpu/or1korfpx.cpu +93 -20

220 lines not on this page · raw message

Signature · 1 line
2.19.1
#2 lore raw

PATCH 2/6 opcodes: Regenerate opcodes for orfp64a32 spec

In reply to Stafford Horne

opcodes/ChangeLog:

* or1k-asm.c: Regenerated.
* or1k-desc.c: Regenerated.
* or1k-desc.h: Regenerated.
* or1k-dis.c: Regenerated.
* or1k-ibld.c: Regenerated.
* or1k-opc.c: Regenerated.
* or1k-opc.h: Regenerated.
* or1k-opinst.c: Regenerated.

---
 opcodes/or1k-asm.c    |  19 ++-
 opcodes/or1k-desc.c   | 227 ++++++++++++++++++++++++++---
 opcodes/or1k-desc.h   | 330 +++++++++++++++++++++---------------------
 opcodes/or1k-dis.c    |  19 ++-
 opcodes/or1k-ibld.c   | 114 +++++++++++++--
 opcodes/or1k-opc.c    | 166 ++++++++++++++++++---
 opcodes/or1k-opc.h    |  21 +--
 opcodes/or1k-opinst.c |  51 +++++++
 8 files changed, 716 insertions(+), 231 deletions(-)
opcodes/or1k-asm.c +17 -2
index 7d058d03f5..f1e20e4ebc 100644
@@ -466,8 +466,14 @@ or1k_cgen_parse_operand (CGEN_CPU_DESC cd,
     case OR1K_OPERAND_RA :
       errmsg = cgen_parse_keyword (cd, strp, & or1k_cgen_opval_h_gpr, & fields->f_r2);
       break;
+    case OR1K_OPERAND_RAD32F :
+      errmsg = cgen_parse_keyword (cd, strp, & or1k_cgen_opval_h_fd32r, & fields->f_r2);
+      break;
     case OR1K_OPERAND_RADF :
-      errmsg = cgen_parse_keyword (cd, strp, & or1k_cgen_opval_h_fdr, & fields->f_r1);
+      errmsg = cgen_parse_keyword (cd, strp, & or1k_cgen_opval_h_fdr, & fields->f_r2);
+      break;
+    case OR1K_OPERAND_RADI :
+      errmsg = cgen_parse_keyword (cd, strp, & or1k_cgen_opval_h_i64r, & fields->f_r2);
       break;
     case OR1K_OPERAND_RASF :
       errmsg = cgen_parse_keyword (cd, strp, & or1k_cgen_opval_h_fsr, & fields->f_r2);
@@ -475,8 +481,11 @@ or1k_cgen_parse_operand (CGEN_CPU_DESC cd,
     case OR1K_OPERAND_RB :
       errmsg = cgen_parse_keyword (cd, strp, & or1k_cgen_opval_h_gpr, & fields->f_r3);
       break;
+    case OR1K_OPERAND_RBD32F :
+      errmsg = cgen_parse_keyword (cd, strp, & or1k_cgen_opval_h_fd32r, & fields->f_r3);
+      break;
     case OR1K_OPERAND_RBDF :
-      errmsg = cgen_parse_keyword (cd, strp, & or1k_cgen_opval_h_fdr, & fields->f_r1);
+      errmsg = cgen_parse_keyword (cd, strp, & or1k_cgen_opval_h_fdr, & fields->f_r3);
       break;
     case OR1K_OPERAND_RBSF :
       errmsg = cgen_parse_keyword (cd, strp, & or1k_cgen_opval_h_fsr, & fields->f_r3);
@@ -484,9 +493,15 @@ or1k_cgen_parse_operand (CGEN_CPU_DESC cd,
     case OR1K_OPERAND_RD :
       errmsg = cgen_parse_keyword (cd, strp, & or1k_cgen_opval_h_gpr, & fields->f_r1);
       break;
+    case OR1K_OPERAND_RDD32F :
+      errmsg = cgen_parse_keyword (cd, strp, & or1k_cgen_opval_h_fd32r, & fields->f_r1);
+      break;
     case OR1K_OPERAND_RDDF :
       errmsg = cgen_parse_keyword (cd, strp, & or1k_cgen_opval_h_fdr, & fields->f_r1);
       break;
+    case OR1K_OPERAND_RDDI :
+      errmsg = cgen_parse_keyword (cd, strp, & or1k_cgen_opval_h_i64r, & fields->f_r1);
+      break;
     case OR1K_OPERAND_RDSF :
       errmsg = cgen_parse_keyword (cd, strp, & or1k_cgen_opval_h_fsr, & fields->f_r1);
       break;
opcodes/or1k-desc.c +208 -19

376 lines not on this page · raw message

opcodes/or1k-desc.h +167 -163

353 lines not on this page · raw message

opcodes/or1k-dis.c +17 -2
index f14c56fec4..c7a80ba4c9 100644
@@ -99,8 +99,14 @@ or1k_cgen_print_operand (CGEN_CPU_DESC cd,
     case OR1K_OPERAND_RA :
       print_keyword (cd, info, & or1k_cgen_opval_h_gpr, fields->f_r2, 0);
       break;
+    case OR1K_OPERAND_RAD32F :
+      print_keyword (cd, info, & or1k_cgen_opval_h_fd32r, fields->f_r2, 0);
+      break;
     case OR1K_OPERAND_RADF :
-      print_keyword (cd, info, & or1k_cgen_opval_h_fdr, fields->f_r1, 0);
+      print_keyword (cd, info, & or1k_cgen_opval_h_fdr, fields->f_r2, 0);
+      break;
+    case OR1K_OPERAND_RADI :
+      print_keyword (cd, info, & or1k_cgen_opval_h_i64r, fields->f_r2, 0);
       break;
     case OR1K_OPERAND_RASF :
       print_keyword (cd, info, & or1k_cgen_opval_h_fsr, fields->f_r2, 0);
@@ -108,8 +114,11 @@ or1k_cgen_print_operand (CGEN_CPU_DESC cd,
     case OR1K_OPERAND_RB :
       print_keyword (cd, info, & or1k_cgen_opval_h_gpr, fields->f_r3, 0);
       break;
+    case OR1K_OPERAND_RBD32F :
+      print_keyword (cd, info, & or1k_cgen_opval_h_fd32r, fields->f_r3, 0);
+      break;
     case OR1K_OPERAND_RBDF :
-      print_keyword (cd, info, & or1k_cgen_opval_h_fdr, fields->f_r1, 0);
+      print_keyword (cd, info, & or1k_cgen_opval_h_fdr, fields->f_r3, 0);
       break;
     case OR1K_OPERAND_RBSF :
       print_keyword (cd, info, & or1k_cgen_opval_h_fsr, fields->f_r3, 0);
@@ -117,9 +126,15 @@ or1k_cgen_print_operand (CGEN_CPU_DESC cd,
     case OR1K_OPERAND_RD :
       print_keyword (cd, info, & or1k_cgen_opval_h_gpr, fields->f_r1, 0);
       break;
+    case OR1K_OPERAND_RDD32F :
+      print_keyword (cd, info, & or1k_cgen_opval_h_fd32r, fields->f_r1, 0);
+      break;
     case OR1K_OPERAND_RDDF :
       print_keyword (cd, info, & or1k_cgen_opval_h_fdr, fields->f_r1, 0);
       break;
+    case OR1K_OPERAND_RDDI :
+      print_keyword (cd, info, & or1k_cgen_opval_h_i64r, fields->f_r1, 0);
+      break;
     case OR1K_OPERAND_RDSF :
       print_keyword (cd, info, & or1k_cgen_opval_h_fsr, fields->f_r1, 0);
       break;
opcodes/or1k-ibld.c +102 -12

252 lines not on this page · raw message

opcodes/or1k-opc.c +142 -24

298 lines not on this page · raw message

opcodes/or1k-opc.h +12 -9
index 78ed425332..54fc31fabc 100644
@@ -65,21 +65,24 @@ typedef enum cgen_insn_type {
  , OR1K_INSN_L_MACU, OR1K_INSN_L_MSB, OR1K_INSN_L_MSBU, OR1K_INSN_L_CUST1
  , OR1K_INSN_L_CUST2, OR1K_INSN_L_CUST3, OR1K_INSN_L_CUST4, OR1K_INSN_L_CUST5
  , OR1K_INSN_L_CUST6, OR1K_INSN_L_CUST7, OR1K_INSN_L_CUST8, OR1K_INSN_LF_ADD_S
- , OR1K_INSN_LF_ADD_D, OR1K_INSN_LF_SUB_S, OR1K_INSN_LF_SUB_D, OR1K_INSN_LF_MUL_S
- , OR1K_INSN_LF_MUL_D, OR1K_INSN_LF_DIV_S, OR1K_INSN_LF_DIV_D, OR1K_INSN_LF_REM_S
- , OR1K_INSN_LF_REM_D, OR1K_INSN_LF_ITOF_S, OR1K_INSN_LF_ITOF_D, OR1K_INSN_LF_FTOI_S
- , OR1K_INSN_LF_FTOI_D, OR1K_INSN_LF_EQ_S, OR1K_INSN_LF_EQ_D, OR1K_INSN_LF_NE_S
- , OR1K_INSN_LF_NE_D, OR1K_INSN_LF_GE_S, OR1K_INSN_LF_GE_D, OR1K_INSN_LF_GT_S
- , OR1K_INSN_LF_GT_D, OR1K_INSN_LF_LT_S, OR1K_INSN_LF_LT_D, OR1K_INSN_LF_LE_S
- , OR1K_INSN_LF_LE_D, OR1K_INSN_LF_MADD_S, OR1K_INSN_LF_MADD_D, OR1K_INSN_LF_CUST1_S
- , OR1K_INSN_LF_CUST1_D
+ , OR1K_INSN_LF_ADD_D, OR1K_INSN_LF_ADD_D32, OR1K_INSN_LF_SUB_S, OR1K_INSN_LF_SUB_D
+ , OR1K_INSN_LF_SUB_D32, OR1K_INSN_LF_MUL_S, OR1K_INSN_LF_MUL_D, OR1K_INSN_LF_MUL_D32
+ , OR1K_INSN_LF_DIV_S, OR1K_INSN_LF_DIV_D, OR1K_INSN_LF_DIV_D32, OR1K_INSN_LF_REM_S
+ , OR1K_INSN_LF_REM_D, OR1K_INSN_LF_REM_D32, OR1K_INSN_LF_ITOF_S, OR1K_INSN_LF_ITOF_D
+ , OR1K_INSN_LF_ITOF_D32, OR1K_INSN_LF_FTOI_S, OR1K_INSN_LF_FTOI_D, OR1K_INSN_LF_FTOI_D32
+ , OR1K_INSN_LF_EQ_S, OR1K_INSN_LF_EQ_D, OR1K_INSN_LF_EQ_D32, OR1K_INSN_LF_NE_S
+ , OR1K_INSN_LF_NE_D, OR1K_INSN_LF_NE_D32, OR1K_INSN_LF_GE_S, OR1K_INSN_LF_GE_D
+ , OR1K_INSN_LF_GE_D32, OR1K_INSN_LF_GT_S, OR1K_INSN_LF_GT_D, OR1K_INSN_LF_GT_D32
+ , OR1K_INSN_LF_LT_S, OR1K_INSN_LF_LT_D, OR1K_INSN_LF_LT_D32, OR1K_INSN_LF_LE_S
+ , OR1K_INSN_LF_LE_D, OR1K_INSN_LF_LE_D32, OR1K_INSN_LF_MADD_S, OR1K_INSN_LF_MADD_D
+ , OR1K_INSN_LF_MADD_D32, OR1K_INSN_LF_CUST1_S, OR1K_INSN_LF_CUST1_D, OR1K_INSN_LF_CUST1_D32
 } CGEN_INSN_TYPE;
 
 /* Index of `invalid' insn place holder.  */
 #define CGEN_INSN_INVALID OR1K_INSN_INVALID
 
 /* Total number of insns in table.  */
-#define MAX_INSNS ((int) OR1K_INSN_LF_CUST1_D + 1)
+#define MAX_INSNS ((int) OR1K_INSN_LF_CUST1_D32 + 1)
 
 /* This struct records data prior to insertion or after extraction.  */
 struct cgen_fields
opcodes/or1k-opinst.c +51 -0

113 lines not on this page · raw message

Signature · 1 line
2.19.1
#3 lore raw

PATCH 3/6 sim/or1k: Regenerate sim for orfp64a32 spec

In reply to Stafford Horne

sim/ChangeLog:

* or1k/cpu.c: Regenerate.
* or1k/cpu.h: Regenerate.
* or1k/decode.c: Regenerate.
* or1k/decode.h: Regenerate.
* or1k/model.c: Regenerate.
* or1k/sem-switch.c: Regenerate.
* or1k/sem.c: Regenerate.

---
 sim/or1k/cpu.c        |  60 +++--
 sim/or1k/cpu.h        | 115 +++++++++-
 sim/or1k/decode.c     | 302 +++++++++++++++++++------
 sim/or1k/decode.h     |  16 +-
 sim/or1k/model.c      | 510 ++++++++++++++++++++++++++++++++++++++++++
 sim/or1k/sem-switch.c | 296 ++++++++++++++++++++++++
 sim/or1k/sem.c        | 326 +++++++++++++++++++++++++++
 7 files changed, 1537 insertions(+), 88 deletions(-)
sim/or1k/cpu.c +46 -14
index f93b51276e..a0ee763813 100644
@@ -44,6 +44,38 @@ or1k32bf_h_pc_set (SIM_CPU *current_cpu, USI newval)
   SET_H_PC (newval);
 }
 
+/* Get the value of h-spr.  */
+
+USI
+or1k32bf_h_spr_get (SIM_CPU *current_cpu, UINT regno)
+{
+  return GET_H_SPR (regno);
+}
+
+/* Set a value for h-spr.  */
+
+void
+or1k32bf_h_spr_set (SIM_CPU *current_cpu, UINT regno, USI newval)
+{
+  SET_H_SPR (regno, newval);
+}
+
+/* Get the value of h-gpr.  */
+
+USI
+or1k32bf_h_gpr_get (SIM_CPU *current_cpu, UINT regno)
+{
+  return GET_H_GPR (regno);
+}
+
+/* Set a value for h-gpr.  */
+
+void
+or1k32bf_h_gpr_set (SIM_CPU *current_cpu, UINT regno, USI newval)
+{
+  SET_H_GPR (regno, newval);
+}
+
 /* Get the value of h-fsr.  */
 
 SF
@@ -60,36 +92,36 @@ or1k32bf_h_fsr_set (SIM_CPU *current_cpu, UINT regno, SF newval)
   SET_H_FSR (regno, newval);
 }
 
-/* Get the value of h-spr.  */
+/* Get the value of h-fd32r.  */
 
-USI
-or1k32bf_h_spr_get (SIM_CPU *current_cpu, UINT regno)
+DF
+or1k32bf_h_fd32r_get (SIM_CPU *current_cpu, UINT regno)
 {
-  return GET_H_SPR (regno);
+  return GET_H_FD32R (regno);
 }
 
-/* Set a value for h-spr.  */
+/* Set a value for h-fd32r.  */
 
 void
-or1k32bf_h_spr_set (SIM_CPU *current_cpu, UINT regno, USI newval)
+or1k32bf_h_fd32r_set (SIM_CPU *current_cpu, UINT regno, DF newval)
 {
-  SET_H_SPR (regno, newval);
+  SET_H_FD32R (regno, newval);
 }
 
-/* Get the value of h-gpr.  */
+/* Get the value of h-i64r.  */
 
-USI
-or1k32bf_h_gpr_get (SIM_CPU *current_cpu, UINT regno)
+DI
+or1k32bf_h_i64r_get (SIM_CPU *current_cpu, UINT regno)
 {
-  return GET_H_GPR (regno);
+  return GET_H_I64R (regno);
 }
 
-/* Set a value for h-gpr.  */
+/* Set a value for h-i64r.  */
 
 void
-or1k32bf_h_gpr_set (SIM_CPU *current_cpu, UINT regno, USI newval)
+or1k32bf_h_i64r_set (SIM_CPU *current_cpu, UINT regno, DI newval)
 {
-  SET_H_GPR (regno, newval);
+  SET_H_I64R (regno, newval);
 }
 
 /* Get the value of h-sys-vr.  */
sim/or1k/cpu.h +110 -5

167 lines not on this page · raw message

sim/or1k/decode.c +238 -64

435 lines not on this page · raw message

sim/or1k/decode.h +11 -5
index 8650bdfa0e..76c2c667ac 100644
@@ -60,10 +60,14 @@ typedef enum or1k32bf_insn_type {
  , OR1K32BF_INSN_L_MACU, OR1K32BF_INSN_L_MSB, OR1K32BF_INSN_L_MSBU, OR1K32BF_INSN_L_CUST1
  , OR1K32BF_INSN_L_CUST2, OR1K32BF_INSN_L_CUST3, OR1K32BF_INSN_L_CUST4, OR1K32BF_INSN_L_CUST5
  , OR1K32BF_INSN_L_CUST6, OR1K32BF_INSN_L_CUST7, OR1K32BF_INSN_L_CUST8, OR1K32BF_INSN_LF_ADD_S
- , OR1K32BF_INSN_LF_SUB_S, OR1K32BF_INSN_LF_MUL_S, OR1K32BF_INSN_LF_DIV_S, OR1K32BF_INSN_LF_REM_S
- , OR1K32BF_INSN_LF_ITOF_S, OR1K32BF_INSN_LF_FTOI_S, OR1K32BF_INSN_LF_EQ_S, OR1K32BF_INSN_LF_NE_S
- , OR1K32BF_INSN_LF_GE_S, OR1K32BF_INSN_LF_GT_S, OR1K32BF_INSN_LF_LT_S, OR1K32BF_INSN_LF_LE_S
- , OR1K32BF_INSN_LF_MADD_S, OR1K32BF_INSN_LF_CUST1_S, OR1K32BF_INSN__MAX
+ , OR1K32BF_INSN_LF_ADD_D32, OR1K32BF_INSN_LF_SUB_S, OR1K32BF_INSN_LF_SUB_D32, OR1K32BF_INSN_LF_MUL_S
+ , OR1K32BF_INSN_LF_MUL_D32, OR1K32BF_INSN_LF_DIV_S, OR1K32BF_INSN_LF_DIV_D32, OR1K32BF_INSN_LF_REM_S
+ , OR1K32BF_INSN_LF_REM_D32, OR1K32BF_INSN_LF_ITOF_S, OR1K32BF_INSN_LF_ITOF_D32, OR1K32BF_INSN_LF_FTOI_S
+ , OR1K32BF_INSN_LF_FTOI_D32, OR1K32BF_INSN_LF_EQ_S, OR1K32BF_INSN_LF_EQ_D32, OR1K32BF_INSN_LF_NE_S
+ , OR1K32BF_INSN_LF_NE_D32, OR1K32BF_INSN_LF_GE_S, OR1K32BF_INSN_LF_GE_D32, OR1K32BF_INSN_LF_GT_S
+ , OR1K32BF_INSN_LF_GT_D32, OR1K32BF_INSN_LF_LT_S, OR1K32BF_INSN_LF_LT_D32, OR1K32BF_INSN_LF_LE_S
+ , OR1K32BF_INSN_LF_LE_D32, OR1K32BF_INSN_LF_MADD_S, OR1K32BF_INSN_LF_MADD_D32, OR1K32BF_INSN_LF_CUST1_S
+ , OR1K32BF_INSN_LF_CUST1_D32, OR1K32BF_INSN__MAX
 } OR1K32BF_INSN_TYPE;
 
 /* Enum declaration for semantic formats in cpu family or1k32bf.  */
@@ -80,7 +84,9 @@ typedef enum or1k32bf_sfmt_type {
  , OR1K32BF_SFMT_L_XORI, OR1K32BF_SFMT_L_ADDI, OR1K32BF_SFMT_L_ADDIC, OR1K32BF_SFMT_L_MULI
  , OR1K32BF_SFMT_L_EXTHS, OR1K32BF_SFMT_L_CMOV, OR1K32BF_SFMT_L_SFGTS, OR1K32BF_SFMT_L_SFGTSI
  , OR1K32BF_SFMT_L_MAC, OR1K32BF_SFMT_L_MACI, OR1K32BF_SFMT_L_MACU, OR1K32BF_SFMT_LF_ADD_S
- , OR1K32BF_SFMT_LF_ITOF_S, OR1K32BF_SFMT_LF_FTOI_S, OR1K32BF_SFMT_LF_EQ_S, OR1K32BF_SFMT_LF_MADD_S
+ , OR1K32BF_SFMT_LF_ADD_D32, OR1K32BF_SFMT_LF_ITOF_S, OR1K32BF_SFMT_LF_ITOF_D32, OR1K32BF_SFMT_LF_FTOI_S
+ , OR1K32BF_SFMT_LF_FTOI_D32, OR1K32BF_SFMT_LF_EQ_S, OR1K32BF_SFMT_LF_EQ_D32, OR1K32BF_SFMT_LF_MADD_S
+ , OR1K32BF_SFMT_LF_MADD_D32
 } OR1K32BF_SFMT_TYPE;
 
 /* Function unit handlers (user written).  */
sim/or1k/model.c +510 -0

730 lines not on this page · raw message

sim/or1k/sem-switch.c +296 -0

406 lines not on this page · raw message

sim/or1k/sem.c +326 -0

436 lines not on this page · raw message

Signature · 1 line
2.19.1
#4 lore raw

PATCH 4/6 sim/common: Wire in df/di conversion

In reply to Stafford Horne

Up until now these have not been used in any CGEN targets, add them as they are now used by OpenRISC.

sim/common/ChangeLog:

* cgen-accfp.c (floatdidf, fixdfdi): New functions. (cgen_init_accurate_fpu): Add floatdidf and fixdfdi.

---
 sim/common/cgen-accfp.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
sim/common/cgen-accfp.c +24 -0
index 5d600c6e41..51f5a29fe2 100644
@@ -349,6 +349,17 @@ floatsidf (CGEN_FPU* fpu, int how UNUSED, SI x)
   return res;
 }
 
+static DF
+floatdidf (CGEN_FPU* fpu, int how UNUSED, DI x)
+{
+  sim_fpu ans;
+  unsigned64 res;
+
+  sim_fpu_i64to (&ans, x, sim_fpu_round_near);
+  sim_fpu_to64 (&res, &ans);
+  return res;
+}
+
 static SF
 ufloatsisf (CGEN_FPU* fpu, int how UNUSED, USI x)
 {
@@ -382,6 +393,17 @@ fixdfsi (CGEN_FPU* fpu, int how UNUSED, DF x)
   return res;
 }
 
+static DI
+fixdfdi (CGEN_FPU* fpu, int how UNUSED, DF x)
+{
+  sim_fpu op1;
+  unsigned64 res;
+
+  sim_fpu_64to (&op1, x);
+  sim_fpu_to64i (&res, &op1, sim_fpu_round_near);
+  return res;
+}
+
 static USI
 ufixsfsi (CGEN_FPU* fpu, int how UNUSED, SF x)
 {
@@ -739,8 +761,10 @@ cgen_init_accurate_fpu (SIM_CPU* cpu, CGEN_FPU* fpu, CGEN_FPU_ERROR_FN* error)
   o->ftruncdfsf = ftruncdfsf;
   o->floatsisf = floatsisf;
   o->floatsidf = floatsidf;
+  o->floatdidf = floatdidf;
   o->ufloatsisf = ufloatsisf;
   o->fixsfsi = fixsfsi;
   o->fixdfsi = fixdfsi;
+  o->fixdfdi = fixdfdi;
   o->ufixsfsi = ufixsfsi;
 }
Signature · 1 line
2.19.1
#5 lore raw

PATCH 5/6 sim/or1k: Add test for 64-bit fpu operations

In reply to Stafford Horne

This is a very basic test but it ensure the machine is wired up correctly and that the assembler works.

sim/testsuite/sim/or1k/ChangeLog:

* fpu64a32.S: New file.

---
 sim/testsuite/sim/or1k/fpu64a32.S | 172 ++++++++++++++++++++++++++++++
 1 file changed, 172 insertions(+)
 create mode 100644 sim/testsuite/sim/or1k/fpu64a32.S
sim/testsuite/sim/or1k/fpu64a32.S new file +172 -0
new file mode 100644
index 0000000000..6c40170854
@@ -0,0 +1,172 @@
+/* Tests some basic fpu instructions.
+
+   Copyright (C) 2017-2019 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+# mach: or1k
+# output: report(0x400921f9);\n
+# output: report(0xf01b866e);\n
+# output: report(0x4005bf09);\n
+# output: report(0x95aaf790);\n
+# output: report(0x00000000);\n
+# output: report(0x00001234);\n
+# output: \n
+# output: report(0x40b23400);\n
+# output: report(0x00000000);\n
+# output: report(0x40b23400);\n
+# output: report(0x00000000);\n
+# output: \n
+# output: report(0x40177081);\n
+# output: report(0xc2e33eff);\n
+# output: report(0x400921f9);\n
+# output: report(0xf01b866e);\n
+# output: \n
+# output: report(0x40211456);\n
+# output: report(0x587dfabf);\n
+# output: report(0x400921f9);\n
+# output: report(0xf01b866d);\n
+# output: \n
+# output: report(0x00000001);\n
+# output: \n
+# output: WARNING: ignoring fpu error caught in fast mode.\n
+# output: report(0x00000000);\n
+# output: \n
+# output: exit(0)\n
+
+#include "or1k-asm-test-helpers.h"
+
+	STANDARD_TEST_ENVIRONMENT
+
+	.section .exception_vectors
+
+	/* Floating point exception.  */
+	.org	0xd00
+
+	/* The handling is a bit dubious at present.  We just patch the
+	   instruction with l.nop and restart.  This will go wrong in branch
+	   delay slots.  But we don't have those in this test.  */
+	l.addi r1, r1, -EXCEPTION_STACK_SKIP_SIZE
+	PUSH r2
+	PUSH r3
+	/* Save the address of the instruction that caused the problem.  */
+	MOVE_FROM_SPR r2, SPR_EPCR_BASE
+	LOAD_IMMEDIATE r3, 0x15000000 /* Opcode for l.nop  */
+	l.sw	-4(r2), r3
+	POP r3
+	POP r2
+	l.addi r1, r1, EXCEPTION_STACK_SKIP_SIZE
+	l.rfe
+
+	.section .data
+	.align 4
+	.type   pi, @object
+	.size   pi, 8
+anchor:
+pi:
+	.double  3.14159
+
+	.type   e, @object
+	.size   e, 8
+e:
+	.double  2.71828
+
+	.type   large, @object
+	.size   large, 8
+large:
+	.long  0
+	.long  0x1234
+
+	.section .text
+start_tests:
+	PUSH LINK_REGISTER_R9
+
+	/* Test lf.itof.d int to double conversion.  Setting up:
+	 *  r11      pointer to data
+	 *  r12,r13  pi as double
+	 *  r14,r15  e  as double
+	 *  r16,r17  a long long
+	 */
+	l.ori	r11, r0, ha(anchor)
+	l.addi	r11, r11, lo(anchor)
+	l.lwz	r12, 0(r11)
+	l.lwz	r13, 4(r11)
+
+	l.lwz	r14, 8(r11)
+	l.lwz	r15, 12(r11)
+
+	l.lwz	r16, 16(r11)
+	l.lwz	r18, 20(r11)
+
+	/* Output to ensure we loaded it correctly.  */
+	REPORT_REG_TO_CONSOLE r12
+	REPORT_REG_TO_CONSOLE r13
+
+	REPORT_REG_TO_CONSOLE r14
+	REPORT_REG_TO_CONSOLE r15
+
+	REPORT_REG_TO_CONSOLE r16
+	REPORT_REG_TO_CONSOLE r18
+	PRINT_NEWLINE_TO_CONSOLE
+
+	/* Convert the big long to a double. */
+	lf.itof.d r16, r16
+	REPORT_REG_TO_CONSOLE r16
+	REPORT_REG_TO_CONSOLE r18
+
+	/* Convert the double back to a long, it should match before. */
+	lf.ftoi.d r16, r16
+	lf.itof.d r16, r16
+
+	REPORT_REG_TO_CONSOLE r16
+	REPORT_REG_TO_CONSOLE r18
+
+	PRINT_NEWLINE_TO_CONSOLE
+
+	/* Add and subtract some double values.  */
+	lf.add.d r12, r12, r14
+	REPORT_REG_TO_CONSOLE r12
+	REPORT_REG_TO_CONSOLE r13
+
+	lf.sub.d r12, r12, r14
+	REPORT_REG_TO_CONSOLE r12
+	REPORT_REG_TO_CONSOLE r13
+	PRINT_NEWLINE_TO_CONSOLE
+
+	/* Multiply and divide double values.  */
+	lf.mul.d r12, r12, r14
+	REPORT_REG_TO_CONSOLE r12
+	REPORT_REG_TO_CONSOLE r13
+
+	lf.div.d r12, r12, r14
+	REPORT_REG_TO_CONSOLE r12
+	REPORT_REG_TO_CONSOLE r13
+	PRINT_NEWLINE_TO_CONSOLE
+
+	/* Test lf.sfge.s set flag if r6 >= r10.  */
+	lf.sfge.d r12, r14
+	MOVE_FROM_SPR r2, SPR_SR
+	REPORT_BIT_TO_CONSOLE r2, SPR_SR_F
+	PRINT_NEWLINE_TO_CONSOLE
+
+	/* Test raising an exception by dividing by 0.  */
+	MOVE_FROM_SPR r2, SPR_FPCSR
+	l.ori	r2, r2, 0x1
+	MOVE_TO_SPR SPR_FPCSR, r2
+div0:	lf.div.d r2, r12, r0
+	REPORT_EXCEPTION div0
+	PRINT_NEWLINE_TO_CONSOLE
+
+	POP LINK_REGISTER_R9
+	RETURN_TO_LINK_REGISTER_R9
Signature · 1 line
2.19.1
#6 lore raw

PATCH 6/6 sim/common: Fix issue with wrong byte order on BE targets

In reply to Stafford Horne

Currently only the OpenRISC sim uses this JOINSIDF() function to compose a double float from 2 registers. The old code doesn't seem to work as the work order gets swapped when running on a x86_64 host. This change fixes that, but I am not sure if its the best thing to do.

On mips they do similar reg pair floating point operations composing doubles from 2 32-bit registers in sim/mips/cp1.c value_fpr().

sim/common/ChangeLog:

* cgen-ops.h (JOINSIDF): Fix big endian check.

---
 sim/common/cgen-ops.h | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)
sim/common/cgen-ops.h +2 -6
index 841552066f..d718394723 100644
@@ -431,12 +431,8 @@ JOINSIDI (SI x0, SI x1)
 SEMOPS_INLINE DF
 JOINSIDF (SI x0, SI x1)
 {
-  union { SI in[2]; DF out; } x;
-  if (CURRENT_TARGET_BYTE_ORDER == BFD_ENDIAN_BIG)
-    x.in[0] = x0, x.in[1] = x1;
-  else
-    x.in[1] = x0, x.in[0] = x1;
-  return x.out;
+  /* Making doubles is the same as making long longs.  */
+  return MAKEDI (x0, x1);
 }
 
 SEMOPS_INLINE XF
Signature · 1 line
2.19.1
#7 lore raw

cover OpenRISC orfpx64a32 support

In reply to Stafford Horne

FYI, I have resent this series properly CCing binutils.

-Stafford

Quoted 69 lines · Stafford Horne

Hello,

This is a set of patches to the OpenRISC assembler and simulator to support 64-bit floating point operations on 32-bit cores using register pairs, see orfpx64a32 [0].

The original patches were written by Andrey Bacherov and I have made some updates to get the simulator working and to match ABI updates from GCC 9. The main GCC 9 ABI change is to have r16 and above pair with an n+2 register rather than n+1. This is done because openrisc callee saved registers are r14-r30 (even). If a 64-bit value was stored in {r16,r17}, it would always need to be spilled across function calls as r17 is volatile. Therefore, values of 64-bits and greater are stored in even reg pairs, such as {r16,r18}.

Example of orfpx64a32 operations:

	lf.add.d r4, r6, r8    ; {r3,r4}   <= {r5,r6} + {r7,r8}
	lf.add.d r16, r20, r24 ; {r16,r18} <= {r20,r22} + {r24,r26}

These binutil patches have been used along with the GCC FPU patches [1] on the OpenRISC GCC 9 toolchain to test single and double precision floating point support. The main 'real' implementation of this hardware is Andrey's or1k_marocchino [2] core implementation which we have been using along with simulators for verification.

This whole patch series can be found on my github repo [3] as well.

[0] https://openrisc.io/proposals/orfpx64a32
[1] git at github.com:stffrdhrn/gcc.git or1k-fpu-1
[2] https://github.com/openrisc/or1k_marocchino
[3] git at github.com:stffrdhrn/binutils-gdb.git orfpx64a32-1

Stafford Horne (6):
cpu: Add support for orfp64a32 spec
opcodes: Regenerate opcodes for orfp64a32 spec sim/or1k: Regenerate sim for orfp64a32 spec sim/common: Wire in df/di conversion
sim/or1k: Add test for 64-bit fpu operations sim/common: Fix issue with wrong byte order on BE targets

 cpu/or1k.cpu                      |  15 +-
 cpu/or1kcommon.cpu                | 103 ++++--
 cpu/or1korfpx.cpu                 | 113 +++++--
 opcodes/or1k-asm.c                |  19 +-
 opcodes/or1k-desc.c               | 227 +++++++++++--
 opcodes/or1k-desc.h               | 330 +++++++++----------
 opcodes/or1k-dis.c                |  19 +-
 opcodes/or1k-ibld.c               | 114 ++++++-
 opcodes/or1k-opc.c                | 166 ++++++++--
 opcodes/or1k-opc.h                |  21 +-
 opcodes/or1k-opinst.c             |  51 +++
 sim/common/cgen-accfp.c           |  24 ++
 sim/common/cgen-ops.h             |   8 +-
 sim/or1k/cpu.c                    |  60 +++-
 sim/or1k/cpu.h                    | 115 ++++++-
 sim/or1k/decode.c                 | 302 ++++++++++++++----
 sim/or1k/decode.h                 |  16 +-
 sim/or1k/model.c                  | 510 ++++++++++++++++++++++++++++++
 sim/or1k/sem-switch.c             | 296 +++++++++++++++++
 sim/or1k/sem.c                    | 326 +++++++++++++++++++
 sim/testsuite/sim/or1k/fpu64a32.S | 172 ++++++++++
 21 files changed, 2637 insertions(+), 370 deletions(-)
 create mode 100644 sim/testsuite/sim/or1k/fpu64a32.S
Signature · 1 line
2.19.1