qemu-ppc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 1/4] tests/libqtest: Introduce qtest_get_arch_bits()


From: Philippe Mathieu-Daudé
Subject: Re: [PATCH 1/4] tests/libqtest: Introduce qtest_get_arch_bits()
Date: Tue, 10 Oct 2023 11:48:27 +0200
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.15.1

On 10/10/23 11:46, Thomas Huth wrote:
On 10/10/2023 09.49, Philippe Mathieu-Daudé wrote:
Add a method to return the architecture bits (currently 8/32/64).

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
---
  tests/qtest/libqtest.h |  8 ++++++++
  tests/qtest/libqtest.c | 21 +++++++++++++++++++++
  2 files changed, 29 insertions(+)

+unsigned qtest_get_arch_bits(void)
+{
+    static const char *const arch64[] = {
+        "aarch64", "hppa", "x86_64", "loongarch64", "mips64",
+        "mips64el", "ppc64", "riscv64", "s390x", "sparc64",
+    };
+    const char *arch = qtest_get_arch();
+
+    if (!strcmp(arch, "avr")) {

Just a matter of taste, but I prefer g_str_equal(), that's easier to read.

+        return 8;
+    }
+
+    for (unsigned i = 0; i < ARRAY_SIZE(arch64); i++) {
+        if (!strcmp(arch, arch64[i])) {
+            return 64;
+        }
+    }
+
+    return 32;
+}

Since this function might get called multiple times, would it make sense to cache the value? I.e.:

   static const unsigned bits;

   if (!bits) {
       ... do all the magic to find out the right bits ...
   }

   return bits;

?

Fine by me, I'll do as suggested in v2.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]