qemu-trivial
[Top][All Lists]
Advanced

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

Re: [Qemu-trivial] [Qemu-devel] [PATCH 19/29] disas: use QEMU_IS_ALIGNED


From: Paolo Bonzini
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH 19/29] disas: use QEMU_IS_ALIGNED macro
Date: Sun, 23 Jul 2017 16:52:05 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.2.1

On 18/07/2017 16:43, Thomas Huth wrote:
> On 18.07.2017 13:07, Marc-André Lureau wrote:
>> Hi
>>
>> On Mon, Jul 17, 2017 at 11:09 PM, Philippe Mathieu-Daudé
>> <address@hidden> wrote:
>>> Applied using the Coccinelle semantic patch 
>>> scripts/coccinelle/use_osdep.cocci
> [...]
>>> diff --git a/disas.c b/disas.c
>>> index d335c55bbf..8b59448286 100644
>>> --- a/disas.c
>>> +++ b/disas.c
>>> @@ -151,7 +151,7 @@ static int print_insn_objdump(bfd_vma pc, 
>>> disassemble_info *info,
>>>      info->read_memory_func(pc, buf, n, info);
>>>
>>>      for (i = 0; i < n; ++i) {
>>> -        if (i % 32 == 0) {
>>> +        if (QEMU_IS_ALIGNED(i, 32)) {
>>>              info->fprintf_func(info->stream, "\n%s: ", prefix);
>>>          }
>>>          info->fprintf_func(info->stream, "%02x", buf[i]);
> 
> This looks wrong to me. QEMU_IS_ALIGNED should be used for addresses and
> similar things. This part here is about pretty printing a hex dump.
> 
> The code should likely be converted to use qemu_hexdump() instead, I guess.

qemu_hexdump only works with FILE*.

But I agree that QEMU_IS_ALIGNED looks weird here.  I think it should
mostly be used when the argument is a pointer, to hide the cast.  Uses
for non-pointer arguments should be decided on a one-by-one basis; "is
the first argument an address" is definitely a good thing to consider.
Another might be "is the second argument a variable", because "i % n ==
0" is less efficient than "(i & (n - 1)) == 0".

Paolo


Paolo



reply via email to

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