From: Jan Dubiec <jdx@o2.pl>
To: gdb-patches@sourceware.org
Cc: Jan Dubiec <jdx@o2.pl>, Jeffrey Law <jeffrey.law@oss.qualcomm.com>
Subject: [PATCH] H8/300: sim: Fix simulator hang caused by qsort on Windows/MinGW.
Date: Sat, 22 Aug 2026 13:02:50 +0200 [thread overview]
Message-ID: <20260822110423.1569154-1-jdx@o2.pl> (raw)
See the comment below. I don't know why qsort behaves so strangely. It
could be a bug, or simply a consequence of its being an unstable sort.
Unfortunately, I don't have time to investigate the root cause.
Signed-off-by: Jan Dubiec <jdx@o2.pl>
---
sim/h8300/compile.c | 35 +++++++++++++++++++++++++++++++++++
1 file changed, 35 insertions(+)
diff --git a/sim/h8300/compile.c b/sim/h8300/compile.c
index 06988095228..c08f7704ef3 100644
--- a/sim/h8300/compile.c
+++ b/sim/h8300/compile.c
@@ -1568,6 +1568,41 @@ store2 (SIM_DESC sd, ea_type *arg, int n)
return store_1 (sd, arg, n, 1);
}
+#ifdef __MINGW32__
+/* On Windows/MinGW, qsort for some reason produces a "shuffled" opcode
+table instead of a sorted one, causing the entire simulator to hang.
+
+This is a simple insertion sort implementation, but it has virtually
+no impact on simulator performance. */
+
+#define qsort opcode_insertion_sort
+
+static void
+opcode_insertion_sort(void *base, size_t nmemb, size_t size,
+ int (*compar)(const void *, const void *))
+{
+ unsigned char *a = base;
+ struct h8_opcode tmp;
+ size_t i, j;
+
+ if (nmemb < 2 || size == 0)
+ return;
+
+ for (i = 1; i < nmemb; ++i) {
+ memcpy(&tmp, a + i * size, size);
+
+ j = i;
+ while (j > 0 && compar(&tmp, a + (j - 1) * size) < 0) {
+ memcpy(a + j * size, a + (j - 1) * size, size);
+ --j;
+ }
+
+ memcpy(a + j * size, &tmp, size);
+ }
+
+}
+#endif /* #ifdef __MINGW32__ */
+
/* Callback for qsort. We sort first based on availability
(available instructions sort lower). When availability state
is the same, then we use the first 4 bit nibble as a secondary
--
2.55.0
next reply other threads:[~2026-08-22 11:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-22 11:02 Jan Dubiec [this message]
2026-08-23 20:50 ` Jan Dubiec
2026-08-27 15:19 ` Tom Tromey
2026-08-30 1:40 ` Jan Dubiec
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260822110423.1569154-1-jdx@o2.pl \
--to=jdx@o2.pl \
--cc=gdb-patches@sourceware.org \
--cc=jeffrey.law@oss.qualcomm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox