From: Ilya Leoshkevich <iii@linux.ibm.com>
To: "Alex Bennée" <alex.bennee@linaro.org>,
"Richard Henderson" <richard.henderson@linaro.org>,
"David Hildenbrand" <david@redhat.com>
Cc: qemu-devel@nongnu.org, qemu-s390x@nongnu.org,
"Thomas Weißschuh" <thomas@t-8ch.de>,
"Peter Maydell" <peter.maydell@linaro.org>,
"Ilya Leoshkevich" <iii@linux.ibm.com>
Subject: [PATCH v3 1/2] tests/tcg/multiarch: Make the system memory test work on big-endian
Date: Wed, 26 Apr 2023 00:48:49 +0200 [thread overview]
Message-ID: <20230425224850.2116064-2-iii@linux.ibm.com> (raw)
In-Reply-To: <20230425224850.2116064-1-iii@linux.ibm.com>
Store the bytes in descending order on big-endian.
Invert the logic in the multi-byte signed tests on big-endian.
Make the checks in the multi-byte signed tests stricter.
Signed-off-by: Ilya Leoshkevich <iii@linux.ibm.com>
---
tests/tcg/multiarch/system/memory.c | 64 +++++++++++++++++++----------
1 file changed, 42 insertions(+), 22 deletions(-)
diff --git a/tests/tcg/multiarch/system/memory.c b/tests/tcg/multiarch/system/memory.c
index 214f7d4f54b..eaae6929cb3 100644
--- a/tests/tcg/multiarch/system/memory.c
+++ b/tests/tcg/multiarch/system/memory.c
@@ -40,18 +40,21 @@ static void pdot(int count)
}
/*
- * Helper macros for shift/extract so we can keep our endian handling
- * in one place.
+ * Helper macros for endian handling.
*/
-#define BYTE_SHIFT(b, pos) ((uint64_t)b << (pos * 8))
-#define BYTE_EXTRACT(b, pos) ((b >> (pos * 8)) & 0xff)
+#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
+#define BYTE_SHIFT(b, pos) (b << (pos * 8))
+#define BYTE_NEXT(b) ((b)++)
+#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+#define BYTE_SHIFT(b, pos) (b << ((sizeof(b) - 1 - (pos)) * 8))
+#define BYTE_NEXT(b) ((b)--)
+#else
+#error Unsupported __BYTE_ORDER__
+#endif
/*
- * Fill the data with ascending value bytes.
- *
- * Currently we only support Little Endian machines so write in
- * ascending address order. When we read higher address bytes should
- * either be zero or higher than the lower bytes.
+ * Fill the data with ascending (for little-endian) or descending (for
+ * big-endian) value bytes.
*/
static void init_test_data_u8(int unused_offset)
@@ -62,14 +65,14 @@ static void init_test_data_u8(int unused_offset)
ml_printf("Filling test area with u8:");
for (i = 0; i < TEST_SIZE; i++) {
- *ptr++ = count++;
+ *ptr++ = BYTE_NEXT(count);
pdot(i);
}
ml_printf("done\n");
}
/*
- * Full the data with alternating positive and negative bytes. This
+ * Fill the data with alternating positive and negative bytes. This
* should mean for reads larger than a byte all subsequent reads will
* stay either negative or positive. We never write 0.
*/
@@ -119,7 +122,7 @@ static void init_test_data_u16(int offset)
reset_start_data(offset);
for (i = 0; i < max; i++) {
- uint8_t low = count++, high = count++;
+ uint16_t low = BYTE_NEXT(count), high = BYTE_NEXT(count);
word = BYTE_SHIFT(high, 1) | BYTE_SHIFT(low, 0);
*ptr++ = word;
pdot(i);
@@ -139,9 +142,10 @@ static void init_test_data_u32(int offset)
reset_start_data(offset);
for (i = 0; i < max; i++) {
- uint8_t b4 = count++, b3 = count++;
- uint8_t b2 = count++, b1 = count++;
- word = BYTE_SHIFT(b1, 3) | BYTE_SHIFT(b2, 2) | BYTE_SHIFT(b3, 1) | b4;
+ uint32_t b4 = BYTE_NEXT(count), b3 = BYTE_NEXT(count);
+ uint32_t b2 = BYTE_NEXT(count), b1 = BYTE_NEXT(count);
+ word = BYTE_SHIFT(b1, 3) | BYTE_SHIFT(b2, 2) | BYTE_SHIFT(b3, 1) |
+ BYTE_SHIFT(b4, 0);
*ptr++ = word;
pdot(i);
}
@@ -160,13 +164,13 @@ static void init_test_data_u64(int offset)
reset_start_data(offset);
for (i = 0; i < max; i++) {
- uint8_t b8 = count++, b7 = count++;
- uint8_t b6 = count++, b5 = count++;
- uint8_t b4 = count++, b3 = count++;
- uint8_t b2 = count++, b1 = count++;
+ uint64_t b8 = BYTE_NEXT(count), b7 = BYTE_NEXT(count);
+ uint64_t b6 = BYTE_NEXT(count), b5 = BYTE_NEXT(count);
+ uint64_t b4 = BYTE_NEXT(count), b3 = BYTE_NEXT(count);
+ uint64_t b2 = BYTE_NEXT(count), b1 = BYTE_NEXT(count);
word = BYTE_SHIFT(b1, 7) | BYTE_SHIFT(b2, 6) | BYTE_SHIFT(b3, 5) |
BYTE_SHIFT(b4, 4) | BYTE_SHIFT(b5, 3) | BYTE_SHIFT(b6, 2) |
- BYTE_SHIFT(b7, 1) | b8;
+ BYTE_SHIFT(b7, 1) | BYTE_SHIFT(b8, 0);
*ptr++ = word;
pdot(i);
}
@@ -374,12 +378,20 @@ static bool read_test_data_s16(int offset, bool neg_first)
ml_printf("Reading s16 from %#lx (offset %d, %s):", ptr,
offset, neg_first ? "neg" : "pos");
+ /*
+ * If the first byte is negative, then the last byte is positive.
+ * Therefore the logic below must be flipped for big-endian.
+ */
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+ neg_first = !neg_first;
+#endif
+
for (i = 0; i < max; i++) {
int32_t data = *ptr++;
if (neg_first && data < 0) {
pdot(i);
- } else if (data > 0) {
+ } else if (!neg_first && data > 0) {
pdot(i);
} else {
ml_printf("Error %d %c 0\n", data, neg_first ? '<' : '>');
@@ -399,12 +411,20 @@ static bool read_test_data_s32(int offset, bool neg_first)
ml_printf("Reading s32 from %#lx (offset %d, %s):",
ptr, offset, neg_first ? "neg" : "pos");
+ /*
+ * If the first byte is negative, then the last byte is positive.
+ * Therefore the logic below must be flipped for big-endian.
+ */
+#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
+ neg_first = !neg_first;
+#endif
+
for (i = 0; i < max; i++) {
int64_t data = *ptr++;
if (neg_first && data < 0) {
pdot(i);
- } else if (data > 0) {
+ } else if (!neg_first && data > 0) {
pdot(i);
} else {
ml_printf("Error %d %c 0\n", data, neg_first ? '<' : '>');
--
2.39.2
next prev parent reply other threads:[~2023-04-25 22:50 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-04-25 22:48 [PATCH v3 0/2] tests/tcg/s390x: Enable the multiarch system tests Ilya Leoshkevich
2023-04-25 22:48 ` Ilya Leoshkevich [this message]
2023-05-11 11:20 ` [PATCH v3 1/2] tests/tcg/multiarch: Make the system memory test work on big-endian Alex Bennée
2023-04-25 22:48 ` [PATCH v3 2/2] tests/tcg/s390x: Enable the multiarch system tests Ilya Leoshkevich
2023-04-26 15:18 ` Richard Henderson
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=20230425224850.2116064-2-iii@linux.ibm.com \
--to=iii@linux.ibm.com \
--cc=alex.bennee@linaro.org \
--cc=david@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=richard.henderson@linaro.org \
--cc=thomas@t-8ch.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.