From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Thomas Huth <thuth@redhat.com>, qemu-devel@nongnu.org
Cc: "Paolo Bonzini" <pbonzini@redhat.com>,
qemu-ppc@nongnu.org, "Alex Bennée" <alex.bennee@linaro.org>,
qemu-arm@nongnu.org, qemu-block@nongnu.org,
"Laurent Vivier" <lvivier@redhat.com>
Subject: Re: [PATCH 1/4] tests/libqtest: Introduce qtest_get_arch_bits()
Date: Tue, 10 Oct 2023 11:48:27 +0200 [thread overview]
Message-ID: <6fcc827a-02fb-7fad-a853-5bcdf9aaa7a1@linaro.org> (raw)
In-Reply-To: <e108d282-5eec-4430-1a10-8cf3170bb18c@redhat.com>
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.
next prev parent reply other threads:[~2023-10-10 9:48 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-10 7:49 [PATCH 0/4] tests/qtest: Introduce qtest_get_base_arch() and qtest_get_arch_bits() Philippe Mathieu-Daudé
2023-10-10 7:49 ` [PATCH 1/4] tests/libqtest: Introduce qtest_get_arch_bits() Philippe Mathieu-Daudé
2023-10-10 9:46 ` Thomas Huth
2023-10-10 9:48 ` Philippe Mathieu-Daudé [this message]
2023-10-10 7:49 ` [PATCH 2/4] tests/qtest: Use qtest_get_arch_bits() Philippe Mathieu-Daudé
2023-10-10 9:49 ` Thomas Huth
2023-10-10 10:03 ` Ani Sinha
2023-10-10 7:49 ` [PATCH 3/4] tests/libqtest: Introduce qtest_get_base_arch() Philippe Mathieu-Daudé
2023-10-10 8:42 ` Philippe Mathieu-Daudé
2023-10-10 9:50 ` Thomas Huth
2023-10-10 7:49 ` [PATCH 4/4] tests/qtest: Use qtest_get_base_arch() Philippe Mathieu-Daudé
2023-10-10 9:38 ` Akihiko Odaki
2023-10-10 9:58 ` Thomas Huth
2023-10-10 10:37 ` Philippe Mathieu-Daudé
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=6fcc827a-02fb-7fad-a853-5bcdf9aaa7a1@linaro.org \
--to=philmd@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=lvivier@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-arm@nongnu.org \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=thuth@redhat.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;
as well as URLs for NNTP newsgroup(s).