Yet another fix for mcore-sim

Message ID 6de3406e-b76a-4599-b946-10e431a2dd75@gmail.com
State New
Headers
Series Yet another fix for mcore-sim |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gdb_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gdb_check--master-arm success Testing passed

Commit Message

Jeff Law Dec. 17, 2023, 4:54 a.m. UTC
  Someday I'll type "sourceware.org" correctly on a consistent basis.



-------- Forwarded Message --------
Subject: Yet another fix for mcore-sim
Date: Sat, 16 Dec 2023 21:52:12 -0700
From: Jeff Law <jeffreyalaw@gmail.com>
To: gdb-patches@sourcware.org


This came up testing the CRC optimization work from Mariam@RAU. 
Basically to optimize some CRC loops into table lookups or carryless 
multiplies, we may need to do a bit reflection, which on the mcore 
processor is done using a rotate instruction.

Unfortunately the simulator implementation of rotates has the exact same 
problem as we saw with right shifts.  The input value may have been sign 
extended from 32 to 64 bits.  When we rotate the extended value, we get 
those sign extension bits and thus the wrong result.

The fix is the same.  Rather than using a "long", use a uint32_t for the 
type of the temporary.  This fixes a handful of tests in the GCC testsuite:

> mcore-sim: gcc.c-torture/execute/20100805-1.c   -O0  execution test
> mcore-sim: gcc.c-torture/execute/20100805-1.c   -O1  execution test
> mcore-sim: gcc.c-torture/execute/20100805-1.c   -O2  execution test
> mcore-sim: gcc.c-torture/execute/20100805-1.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  execution test
> mcore-sim: gcc.c-torture/execute/20100805-1.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  execution test
> mcore-sim: gcc.c-torture/execute/20100805-1.c   -O3 -g  execution test
> mcore-sim: gcc.c-torture/execute/20100805-1.c   -Os  execution test
> mcore-sim: gcc.c-torture/execute/20180112-1.c   -O0  execution test
> mcore-sim: gcc.c-torture/execute/20180112-1.c   -O1  execution test
> mcore-sim: gcc.c-torture/execute/20180112-1.c   -O2  execution test
> mcore-sim: gcc.c-torture/execute/20180112-1.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  execution test
> mcore-sim: gcc.c-torture/execute/20180112-1.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  execution test
> mcore-sim: gcc.c-torture/execute/20180112-1.c   -O3 -g  execution test
> mcore-sim: gcc.c-torture/execute/20180112-1.c   -Os  execution test
> mcore-sim: gcc.dg/20050922-1.c execution test
> mcore-sim: gcc.dg/crc-25.c execution test
> mcore-sim: gcc.dg/crc-26.c execution test
> mcore-sim: gcc.dg/crc-8.c execution test
> mcore-sim: gcc.dg/pr57233.c execution test


The crc-* tests are Mariam's CRC optimizer tests.  The rest are 
regression tests already in the GCC testsuite.

OK for the trunk?

Jeff
  

Comments

Andrew Burgess Dec. 18, 2023, 12:54 p.m. UTC | #1
Jeff Law <jeffreyalaw@gmail.com> writes:

> Someday I'll type "sourceware.org" correctly on a consistent basis.
>
>
>
> -------- Forwarded Message --------
> Subject: Yet another fix for mcore-sim
> Date: Sat, 16 Dec 2023 21:52:12 -0700
> From: Jeff Law <jeffreyalaw@gmail.com>
> To: gdb-patches@sourcware.org
>
>
> This came up testing the CRC optimization work from Mariam@RAU. 
> Basically to optimize some CRC loops into table lookups or carryless 
> multiplies, we may need to do a bit reflection, which on the mcore 
> processor is done using a rotate instruction.
>
> Unfortunately the simulator implementation of rotates has the exact same 
> problem as we saw with right shifts.  The input value may have been sign 
> extended from 32 to 64 bits.  When we rotate the extended value, we get 
> those sign extension bits and thus the wrong result.
>
> The fix is the same.  Rather than using a "long", use a uint32_t for the 
> type of the temporary.  This fixes a handful of tests in the GCC testsuite:
>
>> mcore-sim: gcc.c-torture/execute/20100805-1.c   -O0  execution test
>> mcore-sim: gcc.c-torture/execute/20100805-1.c   -O1  execution test
>> mcore-sim: gcc.c-torture/execute/20100805-1.c   -O2  execution test
>> mcore-sim: gcc.c-torture/execute/20100805-1.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  execution test
>> mcore-sim: gcc.c-torture/execute/20100805-1.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  execution test
>> mcore-sim: gcc.c-torture/execute/20100805-1.c   -O3 -g  execution test
>> mcore-sim: gcc.c-torture/execute/20100805-1.c   -Os  execution test
>> mcore-sim: gcc.c-torture/execute/20180112-1.c   -O0  execution test
>> mcore-sim: gcc.c-torture/execute/20180112-1.c   -O1  execution test
>> mcore-sim: gcc.c-torture/execute/20180112-1.c   -O2  execution test
>> mcore-sim: gcc.c-torture/execute/20180112-1.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  execution test
>> mcore-sim: gcc.c-torture/execute/20180112-1.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  execution test
>> mcore-sim: gcc.c-torture/execute/20180112-1.c   -O3 -g  execution test
>> mcore-sim: gcc.c-torture/execute/20180112-1.c   -Os  execution test
>> mcore-sim: gcc.dg/20050922-1.c execution test
>> mcore-sim: gcc.dg/crc-25.c execution test
>> mcore-sim: gcc.dg/crc-26.c execution test
>> mcore-sim: gcc.dg/crc-8.c execution test
>> mcore-sim: gcc.dg/pr57233.c execution test
>
>
> The crc-* tests are Mariam's CRC optimizer tests.  The rest are 
> regression tests already in the GCC testsuite.
>
> OK for the trunk?

It would be nice if there were some tests added to the simulator tree.
Could you create one similar to sim/testsuite/mcore/lsr.s maybe?

(Pre-)Approved with a test:

Approved-By: Andrew Burgess <aburgess@redhat.com>

Thanks,
Andrew

>
> Jeff
> diff --git a/sim/mcore/interp.c b/sim/mcore/interp.c
> index 8bfb745a11f..94e0a1675be 100644
> --- a/sim/mcore/interp.c
> +++ b/sim/mcore/interp.c
> @@ -1015,7 +1015,7 @@ step_once (SIM_DESC sd, SIM_CPU *cpu)
>  	case 0x38: case 0x39:				/* xsr, rotli */
>  	  {
>  	    unsigned imm = IMM5;
> -	    unsigned long tmp = gr[RD];
> +	    uint32_t tmp = gr[RD];
>  	    if (imm == 0)
>  	      {
>  		int32_t cbit;
  
Jeff Law Dec. 19, 2023, 5:09 a.m. UTC | #2
On 12/18/23 05:54, Andrew Burgess wrote:
> Jeff Law <jeffreyalaw@gmail.com> writes:
> 
>> Someday I'll type "sourceware.org" correctly on a consistent basis.
>>
>>
>>
>> -------- Forwarded Message --------
>> Subject: Yet another fix for mcore-sim
>> Date: Sat, 16 Dec 2023 21:52:12 -0700
>> From: Jeff Law <jeffreyalaw@gmail.com>
>> To: gdb-patches@sourcware.org
>>
>>
>> This came up testing the CRC optimization work from Mariam@RAU.
>> Basically to optimize some CRC loops into table lookups or carryless
>> multiplies, we may need to do a bit reflection, which on the mcore
>> processor is done using a rotate instruction.
>>
>> Unfortunately the simulator implementation of rotates has the exact same
>> problem as we saw with right shifts.  The input value may have been sign
>> extended from 32 to 64 bits.  When we rotate the extended value, we get
>> those sign extension bits and thus the wrong result.
>>
>> The fix is the same.  Rather than using a "long", use a uint32_t for the
>> type of the temporary.  This fixes a handful of tests in the GCC testsuite:
>>
>>> mcore-sim: gcc.c-torture/execute/20100805-1.c   -O0  execution test
>>> mcore-sim: gcc.c-torture/execute/20100805-1.c   -O1  execution test
>>> mcore-sim: gcc.c-torture/execute/20100805-1.c   -O2  execution test
>>> mcore-sim: gcc.c-torture/execute/20100805-1.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  execution test
>>> mcore-sim: gcc.c-torture/execute/20100805-1.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  execution test
>>> mcore-sim: gcc.c-torture/execute/20100805-1.c   -O3 -g  execution test
>>> mcore-sim: gcc.c-torture/execute/20100805-1.c   -Os  execution test
>>> mcore-sim: gcc.c-torture/execute/20180112-1.c   -O0  execution test
>>> mcore-sim: gcc.c-torture/execute/20180112-1.c   -O1  execution test
>>> mcore-sim: gcc.c-torture/execute/20180112-1.c   -O2  execution test
>>> mcore-sim: gcc.c-torture/execute/20180112-1.c   -O2 -flto -fno-use-linker-plugin -flto-partition=none  execution test
>>> mcore-sim: gcc.c-torture/execute/20180112-1.c   -O2 -flto -fuse-linker-plugin -fno-fat-lto-objects  execution test
>>> mcore-sim: gcc.c-torture/execute/20180112-1.c   -O3 -g  execution test
>>> mcore-sim: gcc.c-torture/execute/20180112-1.c   -Os  execution test
>>> mcore-sim: gcc.dg/20050922-1.c execution test
>>> mcore-sim: gcc.dg/crc-25.c execution test
>>> mcore-sim: gcc.dg/crc-26.c execution test
>>> mcore-sim: gcc.dg/crc-8.c execution test
>>> mcore-sim: gcc.dg/pr57233.c execution test
>>
>>
>> The crc-* tests are Mariam's CRC optimizer tests.  The rest are
>> regression tests already in the GCC testsuite.
>>
>> OK for the trunk?
> 
> It would be nice if there were some tests added to the simulator tree.
> Could you create one similar to sim/testsuite/mcore/lsr.s maybe?
> 
> (Pre-)Approved with a test:

Test added.  Fix and test pushed to the trunk.

Thanks,
jeff

ps.  Hadn't realized you'd moved to Red Hat.  Looks like we missed each 
other by about ~6 months.
  

Patch

diff --git a/sim/mcore/interp.c b/sim/mcore/interp.c
index 8bfb745a11f..94e0a1675be 100644
--- a/sim/mcore/interp.c
+++ b/sim/mcore/interp.c
@@ -1015,7 +1015,7 @@  step_once (SIM_DESC sd, SIM_CPU *cpu)
 	case 0x38: case 0x39:				/* xsr, rotli */
 	  {
 	    unsigned imm = IMM5;
-	    unsigned long tmp = gr[RD];
+	    uint32_t tmp = gr[RD];
 	    if (imm == 0)
 	      {
 		int32_t cbit;