[2/2] RISC-V: NaN-box FP values smaller than an FP register.

Message ID 20181019214953.9010-1-jimw@sifive.com
State New, archived
Headers

Commit Message

Jim Wilson Oct. 19, 2018, 9:49 p.m. UTC
  The hardware requires that values in FP registers be NaN-boxed, so we must
extend them with 1's instead of 0's as we do for integer values.

	gdb/
	* riscv-tdep.c (riscv_push_dummy_call) <in_reg>: Check for value in
	FP reg smaller than FP reg size, and fill with -1 instead of 0.
---
 gdb/riscv-tdep.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
  

Comments

Kevin Buettner Oct. 20, 2018, 9:39 p.m. UTC | #1
On Fri, 19 Oct 2018 14:49:53 -0700
Jim Wilson <jimw@sifive.com> wrote:

> The hardware requires that values in FP registers be NaN-boxed, so we must
> extend them with 1's instead of 0's as we do for integer values.
> 
> 	gdb/
> 	* riscv-tdep.c (riscv_push_dummy_call) <in_reg>: Check for value in
> 	FP reg smaller than FP reg size, and fill with -1 instead of 0.

Okay.

Kevin
  
Jim Wilson Oct. 22, 2018, 9:21 p.m. UTC | #2
On Sat, Oct 20, 2018 at 2:39 PM Kevin Buettner <kevinb@redhat.com> wrote:
> On Fri, 19 Oct 2018 14:49:53 -0700
> Jim Wilson <jimw@sifive.com> wrote:
>
> > The hardware requires that values in FP registers be NaN-boxed, so we must
> > extend them with 1's instead of 0's as we do for integer values.
> >
> >       gdb/
> >       * riscv-tdep.c (riscv_push_dummy_call) <in_reg>: Check for value in
> >       FP reg smaller than FP reg size, and fill with -1 instead of 0.
>
> Okay.

Committed.

Jim
  

Patch

diff --git a/gdb/riscv-tdep.c b/gdb/riscv-tdep.c
index a4d732f6f9..5be889d300 100644
--- a/gdb/riscv-tdep.c
+++ b/gdb/riscv-tdep.c
@@ -2408,7 +2408,12 @@  riscv_push_dummy_call (struct gdbarch *gdbarch,
 	    gdb_byte tmp [sizeof (ULONGEST)];
 
 	    gdb_assert (info->argloc[0].c_length <= info->length);
-	    memset (tmp, 0, sizeof (tmp));
+	    /* FP values in FP registers must be NaN-boxed.  */
+	    if (riscv_is_fp_regno_p (info->argloc[0].loc_data.regno)
+		&& info->argloc[0].c_length < call_info.flen)
+	      memset (tmp, -1, sizeof (tmp));
+	    else
+	      memset (tmp, 0, sizeof (tmp));
 	    memcpy (tmp, info->contents, info->argloc[0].c_length);
 	    regcache->cooked_write (info->argloc[0].loc_data.regno, tmp);
 	    second_arg_length =
@@ -2447,7 +2452,12 @@  riscv_push_dummy_call (struct gdbarch *gdbarch,
 		gdb_assert ((riscv_is_fp_regno_p (info->argloc[1].loc_data.regno)
 			     && second_arg_length <= call_info.flen)
 			    || second_arg_length <= call_info.xlen);
-		memset (tmp, 0, sizeof (tmp));
+		/* FP values in FP registers must be NaN-boxed.  */
+		if (riscv_is_fp_regno_p (info->argloc[1].loc_data.regno)
+		    && second_arg_length < call_info.flen)
+		  memset (tmp, -1, sizeof (tmp));
+		else
+		  memset (tmp, 0, sizeof (tmp));
 		memcpy (tmp, second_arg_data, second_arg_length);
 		regcache->cooked_write (info->argloc[1].loc_data.regno, tmp);
 	      }