public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] fix for aarch64 sim tbnz bug
@ 2016-12-02  4:49 Jim Wilson
  2016-12-02  9:32 ` Mike Frysinger
  2016-12-02 12:03 ` Nick Clifton
  0 siblings, 2 replies; 11+ messages in thread
From: Jim Wilson @ 2016-12-02  4:49 UTC (permalink / raw)
  To: gdb-patches; +Cc: Nick Clifton

[-- Attachment #1: Type: text/plain, Size: 366 bytes --]

Debugged another gcc testsuite failure, and found that tbnz/tbz are
broken when the bit position to test is greater than 31.  There are
two problems.  The high bit of the bit position is shifted left by the
wrong amount.  And we need to use (uint64_t)1 to get a 64-bit shift
result.

Tested with a gcc C testsuite run.  This reduces failures from 2856 to 2710.

Jim

[-- Attachment #2: aarch64-sim-tbnz.patch --]
[-- Type: text/x-patch, Size: 1367 bytes --]

	sim/aarch64
	* simulator.c (tbnz, tbz): Cast 1 to uint64_t before shifting.
	(dexTestBranchImmediate): Shift high bit of pos by 5 not 4.

diff --git a/sim/aarch64/simulator.c b/sim/aarch64/simulator.c
index 4fa5dc1..34fd17d 100644
--- a/sim/aarch64/simulator.c
+++ b/sim/aarch64/simulator.c
@@ -13353,7 +13353,7 @@ tbnz (sim_cpu *cpu, uint32_t  pos, int32_t offset)
   unsigned rt = INSTR (4, 0);
 
   TRACE_DECODE (cpu, "emulated at line %d", __LINE__);
-  if (aarch64_get_reg_u64 (cpu, rt, NO_SP) & (1 << pos))
+  if (aarch64_get_reg_u64 (cpu, rt, NO_SP) & (((uint64_t) 1) << pos))
     aarch64_set_next_PC_by_offset (cpu, offset);
 }
 
@@ -13364,7 +13364,7 @@ tbz (sim_cpu *cpu, uint32_t  pos, int32_t offset)
   unsigned rt = INSTR (4, 0);
 
   TRACE_DECODE (cpu, "emulated at line %d", __LINE__);
-  if (!(aarch64_get_reg_u64 (cpu, rt, NO_SP) & (1 << pos)))
+  if (!(aarch64_get_reg_u64 (cpu, rt, NO_SP) & (((uint64_t) 1) << pos)))
     aarch64_set_next_PC_by_offset (cpu, offset);
 }
 
@@ -13407,7 +13407,7 @@ dexTestBranchImmediate (sim_cpu *cpu)
      instr[18,5]  = simm14 : signed offset counted in words
      instr[4,0]   = uimm5  */
 
-  uint32_t pos = ((INSTR (31, 31) << 4) | INSTR (23, 19));
+  uint32_t pos = ((INSTR (31, 31) << 5) | INSTR (23, 19));
   int32_t offset = simm32 (aarch64_get_instr (cpu), 18, 5) << 2;
 
   NYI_assert (30, 25, 0x1b);

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2016-12-13 10:45 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-02  4:49 [PATCH] fix for aarch64 sim tbnz bug Jim Wilson
2016-12-02  9:32 ` Mike Frysinger
2016-12-05  3:45   ` Jim Wilson
2016-12-12 18:38     ` Jim Wilson
2016-12-12 18:42     ` Mike Frysinger
2016-12-13  0:33       ` Jim Wilson
2016-12-13  6:38         ` Mike Frysinger
2016-12-13 10:45         ` Nick Clifton
2016-12-02 12:03 ` Nick Clifton
2016-12-02 13:34   ` Andreas Schwab
2016-12-02 15:59   ` Jim Wilson

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 read-only IMAP folder(s) and NNTP newsgroup(s).