qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Philippe Mathieu-Daudé" <philmd@linaro.org>
To: Pierrick Bouvier <pierrick.bouvier@linaro.org>,
	Thomas Huth <thuth@redhat.com>,
	qemu-devel@nongnu.org
Cc: "Mahmoud Mandour" <ma.mandourr@gmail.com>,
	"Marcel Apfelbaum" <marcel.apfelbaum@gmail.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Alexandre Iooss" <erdnaxe@crans.org>,
	"Jason Wang" <jasowang@redhat.com>,
	"Aleksandar Rikalo" <arikalo@gmail.com>,
	"Anton Johansson" <anjo@rev.ng>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Huacai Chen" <chenhuacai@kernel.org>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"Sven Schnelle" <svens@stackframe.org>,
	"Jiaxun Yang" <jiaxun.yang@flygoat.com>,
	qemu-arm@nongnu.org, "Aurelien Jarno" <aurelien@aurel32.net>,
	"Max Filippov" <jcmvbkbc@gmail.com>,
	"Paul Burton" <paulburton@kernel.org>
Subject: Re: [PATCH 08/13] hw/xtensa/xtfpga: Replace memcpy()+tswap32() by stl_endian_p()
Date: Thu, 3 Oct 2024 23:40:42 +0200	[thread overview]
Message-ID: <a1a67f7c-553c-42d4-b852-2cc26e7181a0@linaro.org> (raw)
In-Reply-To: <46ea20fd-c6bc-411a-b8e2-ab7179c00185@linaro.org>

On 3/10/24 23:34, Pierrick Bouvier wrote:
> On 10/3/24 14:31, Pierrick Bouvier wrote:
>> On 10/3/24 13:48, Philippe Mathieu-Daudé wrote:
>>> On 3/10/24 18:04, Pierrick Bouvier wrote:
>>>> On 10/3/24 09:02, Philippe Mathieu-Daudé wrote:
>>>>> On 30/9/24 16:32, Thomas Huth wrote:
>>>>>> On 30/09/2024 09.34, Philippe Mathieu-Daudé wrote:
>>>>>>> Replace a pair of memcpy() + tswap32() by stl_endian_p(),
>>>>>>> which also swap the value using target endianness.
>>>>>>>
>>>>>>> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
>>>>>>> ---
>>>>>>>      hw/xtensa/xtfpga.c | 6 ++----
>>>>>>>      1 file changed, 2 insertions(+), 4 deletions(-)
>>>>>>>
>>>>>>> diff --git a/hw/xtensa/xtfpga.c b/hw/xtensa/xtfpga.c
>>>>>>> index 228f00b045..521fe84b01 100644
>>>>>>> --- a/hw/xtensa/xtfpga.c
>>>>>>> +++ b/hw/xtensa/xtfpga.c
>>>>>>> @@ -438,11 +438,9 @@ static void xtfpga_init(const XtfpgaBoardDesc
>>>>>>> *board, MachineState *machine)
>>>>>>>                  const size_t boot_sz = TARGET_BIG_ENDIAN ?
>>>>>>> sizeof(boot_be)
>>>>>>>                                                           :
>>>>>>> sizeof(boot_le);
>>>>>>>                  uint8_t *boot = TARGET_BIG_ENDIAN ? boot_be : 
>>>>>>> boot_le;
>>>>>>> -            uint32_t entry_pc = tswap32(entry_point);
>>>>>>> -            uint32_t entry_a2 = tswap32(tagptr);
>>>>>>> -            memcpy(boot + 4, &entry_pc, sizeof(entry_pc));
>>>>>>> -            memcpy(boot + 8, &entry_a2, sizeof(entry_a2));
>>>>>>> +            stl_endian_p(TARGET_BIG_ENDIAN, boot + 4, entry_point);
>>>>>>> +            stl_endian_p(TARGET_BIG_ENDIAN, boot + 8, tagptr);
>>>>>>
>>>>>> Why don't you simply use stl_p() here?
>>>>>
>>>>> We want to remove the tswap32() calls...
>>>>>
>>>>
>>>> I think is point is that you could directly use stl_be_p, instead of
>>>> stl_endian_p(TARGET_BIT_ENDIAN, ...).
>>>
>>> TARGET_BIG_ENDIAN is defined as 0 on little endian, and 1 on big one.
>>>
>>> The following change isn't worth it:
>>>
>>>      if (TARGET_BIG_ENDIAN) {
>>>        stl_be_p(boot + 8, tagptr);
>>>      } else {
>>>        stl_le_p(boot + 8, tagptr);
>>>      }
>>>
>>> Maybe I'm missing Thomas point, as the xtfpga machines are available
>>> for both xtensa-softmmu (LE) and xtensaeb-softmmu (BE).
>>>
>>>> I don't know if your intent is to make be/le variant "private" and
>>>> relies only on endian_p though.
>>>
>>> My intent is to enforce endian agnostic API uses when possible, and
>>> use LE/BE specific variant when it is known at build time.
>>
>> Oh ok, it's me who missed your point then.
>> For some reason, I thought we were always calling big endian variant.
>>
>> Thus, your implementation makes totally sense.
>>
>> Let's see if Thomas meant something different.
>> Else,
>> Reviewed-by: Pierrick Bouvier <pierrick.bouvier@linaro.org>
> 
> Looking more closely,
> stl_p is already correctly defined when you know at compile time your 
> target endianness. So Thomas was referring to this.
> 
> https://gitlab.com/qemu-project/qemu/-/blame/master/include/exec/cpu-all.h?ref_type=heads#L49

OK I guess I'm seeing Thomas point now; this series cover was not clear
enough. The goal is to remove TARGET_BIG_ENDIAN so we can build half
objects and do a little step toward the single binary.

Maybe I need to kill the stl_p & Co functions first, or do it while
suggesting this target agnostic replacement API.


  reply	other threads:[~2024-10-03 21:41 UTC|newest]

Thread overview: 48+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-09-30  7:34 [PATCH 00/13] hw: Add ld/st_endian() APIs Philippe Mathieu-Daudé
2024-09-30  7:34 ` [PATCH 01/13] qemu/bswap: Introduce ld/st_endian_p() API Philippe Mathieu-Daudé
2024-10-01 16:45   ` Pierrick Bouvier
2024-10-03 20:50   ` Philippe Mathieu-Daudé
2024-10-03 21:28     ` Richard Henderson
2024-10-03 21:34       ` Philippe Mathieu-Daudé
2024-10-03 21:37         ` Richard Henderson
2024-10-03 21:46           ` Philippe Mathieu-Daudé
2024-09-30  7:34 ` [PATCH 02/13] hw/virtio/virtio-access: Use the " Philippe Mathieu-Daudé
2024-10-01 16:46   ` Pierrick Bouvier
2024-09-30  7:34 ` [PATCH 03/13] target/arm/ptw: " Philippe Mathieu-Daudé
2024-10-01 16:46   ` Pierrick Bouvier
2024-09-30  7:34 ` [PATCH 04/13] hw/mips: Pass BlCpuCfg argument to bootloader API Philippe Mathieu-Daudé
2024-10-01 16:49   ` Pierrick Bouvier
2024-09-30  7:34 ` [PATCH 05/13] hw/mips: Add cpu_is_bigendian field to BlCpuCfg structure Philippe Mathieu-Daudé
2024-10-01 16:50   ` Pierrick Bouvier
2024-09-30  7:34 ` [PATCH 06/13] tests/tcg/plugins: Use the ld/st_endian_p() API Philippe Mathieu-Daudé
2024-10-01 16:50   ` Pierrick Bouvier
2024-10-02 12:18   ` Alex Bennée
2024-09-30  7:34 ` [PATCH 07/13] hw/xtensa/xtfpga: Remove TARGET_BIG_ENDIAN #ifdef'ry Philippe Mathieu-Daudé
2024-09-30 14:28   ` Thomas Huth
2024-10-01 16:51   ` Pierrick Bouvier
2024-10-03 21:35   ` Richard Henderson
2024-10-10 18:08     ` Philippe Mathieu-Daudé
2024-09-30  7:34 ` [PATCH 08/13] hw/xtensa/xtfpga: Replace memcpy()+tswap32() by stl_endian_p() Philippe Mathieu-Daudé
2024-09-30 14:32   ` Thomas Huth
2024-10-03 16:02     ` Philippe Mathieu-Daudé
2024-10-03 16:04       ` Pierrick Bouvier
2024-10-03 20:48         ` Philippe Mathieu-Daudé
2024-10-03 21:31           ` Pierrick Bouvier
2024-10-03 21:34             ` Pierrick Bouvier
2024-10-03 21:40               ` Philippe Mathieu-Daudé [this message]
2024-10-04  6:44                 ` Thomas Huth
2024-10-04 14:08                   ` Richard Henderson
2024-09-30  7:34 ` [PATCH 09/13] exec/memory_ldst_phys: Introduce ld/st_endian_phys() API Philippe Mathieu-Daudé
2024-10-01 16:54   ` Pierrick Bouvier
2024-10-03 21:39   ` Richard Henderson
2024-10-03 21:47   ` Richard Henderson
2024-09-30  7:34 ` [PATCH 10/13] hw/virtio/virtio-access: Use " Philippe Mathieu-Daudé
2024-10-01 16:54   ` Pierrick Bouvier
2024-09-30  7:34 ` [PATCH 11/13] hw/pci/pci_device: Add PCI_DMA_DEFINE_LDST_END() macro Philippe Mathieu-Daudé
2024-10-01 16:56   ` Pierrick Bouvier
2024-09-30  7:34 ` [PATCH 12/13] hw/pci/pci_device: Introduce ld/st_endian_pci_dma() API Philippe Mathieu-Daudé
2024-10-01 16:57   ` Pierrick Bouvier
2024-10-03 22:04   ` Richard Henderson
2024-09-30  7:34 ` [PATCH 13/13] hw/net/tulip: Use " Philippe Mathieu-Daudé
2024-10-01 16:57   ` Pierrick Bouvier
2024-10-03 22:10   ` 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=a1a67f7c-553c-42d4-b852-2cc26e7181a0@linaro.org \
    --to=philmd@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=anjo@rev.ng \
    --cc=arikalo@gmail.com \
    --cc=aurelien@aurel32.net \
    --cc=chenhuacai@kernel.org \
    --cc=erdnaxe@crans.org \
    --cc=jasowang@redhat.com \
    --cc=jcmvbkbc@gmail.com \
    --cc=jiaxun.yang@flygoat.com \
    --cc=ma.mandourr@gmail.com \
    --cc=marcel.apfelbaum@gmail.com \
    --cc=mst@redhat.com \
    --cc=paulburton@kernel.org \
    --cc=peter.maydell@linaro.org \
    --cc=pierrick.bouvier@linaro.org \
    --cc=qemu-arm@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=svens@stackframe.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).