* [PATCH 1/2] hw/dma: sifive_pdma: Improve code readability for "!!foo & bar"
@ 2021-09-27 2:21 Bin Meng
2021-09-27 2:21 ` [PATCH 2/2] hw/dma: sifive_pdma: Don't run DMA when channel is disclaimed Bin Meng
` (2 more replies)
0 siblings, 3 replies; 12+ messages in thread
From: Bin Meng @ 2021-09-27 2:21 UTC (permalink / raw)
To: Alistair Francis, qemu-devel, qemu-riscv; +Cc: Frank Chang
GCC seems to be strict about processing pattern like "!!for & bar".
When 'bar' is not 0 or 1, it complains with -Werror=parentheses:
suggest parentheses around operand of ‘!’ or change ‘&’ to ‘&&’ or ‘!’ to ‘~’ [-Werror=parentheses]
Add a () around "foo && bar", which also improves code readability.
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
---
hw/dma/sifive_pdma.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/hw/dma/sifive_pdma.c b/hw/dma/sifive_pdma.c
index b4fd40573a..b8ec7621f3 100644
--- a/hw/dma/sifive_pdma.c
+++ b/hw/dma/sifive_pdma.c
@@ -243,7 +243,7 @@ static void sifive_pdma_write(void *opaque, hwaddr offset,
offset &= 0xfff;
switch (offset) {
case DMA_CONTROL:
- claimed = !!s->chan[ch].control & CONTROL_CLAIM;
+ claimed = !!(s->chan[ch].control & CONTROL_CLAIM);
if (!claimed && (value & CONTROL_CLAIM)) {
/* reset Next* registers */
--
2.25.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH 2/2] hw/dma: sifive_pdma: Don't run DMA when channel is disclaimed
2021-09-27 2:21 [PATCH 1/2] hw/dma: sifive_pdma: Improve code readability for "!!foo & bar" Bin Meng
@ 2021-09-27 2:21 ` Bin Meng
2021-09-27 4:47 ` [PATCH 1/2] hw/dma: sifive_pdma: Improve code readability for "!!foo & bar" Philippe Mathieu-Daudé
2021-09-27 6:51 ` Markus Armbruster
2 siblings, 0 replies; 12+ messages in thread
From: Bin Meng @ 2021-09-27 2:21 UTC (permalink / raw)
To: Alistair Francis, qemu-devel, qemu-riscv; +Cc: Frank Chang
If Control.run bit is set while not preserving the Control.claim
bit, the DMA transfer shall not be started.
The following result is PDMA tested in U-Boot on Unleashed board:
=> mw.l 0x3000000 0x0 <= Disclaim channel 0
=> mw.l 0x3000000 0x1 <= Claim channel 0
=> mw.l 0x3000004 0x55000000 <= wsize = rsize = 5 (2^5 = 32 bytes)
=> mw.q 0x3000008 0x2 <= NextBytes = 2
=> mw.q 0x3000010 0x84000000 <= NextDestination = 0x84000000
=> mw.q 0x3000018 0x84001000 <= NextSource = 0x84001000
=> mw.l 0x84000000 0x87654321 <= Fill test data to dst
=> mw.l 0x84001000 0x12345678 <= Fill test data to src
=> md.l 0x84000000 1; md.l 0x84001000 1 <= Dump src/dst memory contents
84000000: 87654321 !Ce.
84001000: 12345678 xV4.
=> md.l 0x3000000 8 <= Dump PDMA status
03000000: 00000001 55000000 00000002 00000000 .......U........
03000010: 84000000 00000000 84001000 00000000 ................
=> mw.l 0x3000000 0x2 <= Set channel 0 run bit only
=> md.l 0x3000000 8 <= Dump PDMA status
03000000: 00000000 55000000 00000002 00000000 .......U........
03000010: 84000000 00000000 84001000 00000000 ................
=> md.l 0x84000000 1; md.l 0x84001000 1 <= Dump src/dst memory contents
84000000: 87654321 !Ce.
84001000: 12345678 xV4.
Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
---
hw/dma/sifive_pdma.c | 11 +++++++++--
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/hw/dma/sifive_pdma.c b/hw/dma/sifive_pdma.c
index b8ec7621f3..85fe34f5f3 100644
--- a/hw/dma/sifive_pdma.c
+++ b/hw/dma/sifive_pdma.c
@@ -232,7 +232,7 @@ static void sifive_pdma_write(void *opaque, hwaddr offset,
{
SiFivePDMAState *s = opaque;
int ch = SIFIVE_PDMA_CHAN_NO(offset);
- bool claimed;
+ bool claimed, run;
if (ch >= SIFIVE_PDMA_CHANS) {
qemu_log_mask(LOG_GUEST_ERROR, "%s: Invalid channel no %d\n",
@@ -244,6 +244,7 @@ static void sifive_pdma_write(void *opaque, hwaddr offset,
switch (offset) {
case DMA_CONTROL:
claimed = !!(s->chan[ch].control & CONTROL_CLAIM);
+ run = !!(s->chan[ch].control & CONTROL_RUN);
if (!claimed && (value & CONTROL_CLAIM)) {
/* reset Next* registers */
@@ -254,13 +255,19 @@ static void sifive_pdma_write(void *opaque, hwaddr offset,
s->chan[ch].next_src = 0;
}
+ /* claim bit can only be cleared when run is low */
+ if (run && !(value & CONTROL_CLAIM)) {
+ value |= CONTROL_CLAIM;
+ }
+
s->chan[ch].control = value;
/*
* If channel was not claimed before run bit is set,
+ * or if the channel is disclaimed when run was low,
* DMA won't run.
*/
- if (!claimed) {
+ if (!claimed || (!run && !(value & CONTROL_CLAIM))) {
s->chan[ch].control &= ~CONTROL_RUN;
return;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] hw/dma: sifive_pdma: Improve code readability for "!!foo & bar"
2021-09-27 2:21 [PATCH 1/2] hw/dma: sifive_pdma: Improve code readability for "!!foo & bar" Bin Meng
2021-09-27 2:21 ` [PATCH 2/2] hw/dma: sifive_pdma: Don't run DMA when channel is disclaimed Bin Meng
@ 2021-09-27 4:47 ` Philippe Mathieu-Daudé
2021-09-27 5:18 ` Philippe Mathieu-Daudé
2021-09-27 6:51 ` Bin Meng
2021-09-27 6:51 ` Markus Armbruster
2 siblings, 2 replies; 12+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-27 4:47 UTC (permalink / raw)
To: Bin Meng, Alistair Francis, qemu-devel, qemu-riscv
Cc: Frank Chang, Eric Blake
On 9/27/21 04:21, Bin Meng wrote:
> GCC seems to be strict about processing pattern like "!!for & bar".
> When 'bar' is not 0 or 1, it complains with -Werror=parentheses:
>
> suggest parentheses around operand of ‘!’ or change ‘&’ to ‘&&’ or ‘!’ to ‘~’ [-Werror=parentheses]
>
> Add a () around "foo && bar", which also improves code readability.
>
> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
> ---
>
> hw/dma/sifive_pdma.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/dma/sifive_pdma.c b/hw/dma/sifive_pdma.c
> index b4fd40573a..b8ec7621f3 100644
> --- a/hw/dma/sifive_pdma.c
> +++ b/hw/dma/sifive_pdma.c
> @@ -243,7 +243,7 @@ static void sifive_pdma_write(void *opaque, hwaddr offset,
> offset &= 0xfff;
> switch (offset) {
> case DMA_CONTROL:
> - claimed = !!s->chan[ch].control & CONTROL_CLAIM;
> + claimed = !!(s->chan[ch].control & CONTROL_CLAIM);
AFAIK in C logical NOT has precedence over bitwise AND, so IIUC
compilers should read the current code as:
claimed (!!s->chan[ch].control) & CONTROL_CLAIM;
meaning this patch is doing more than "improve code readability",
this is a logical change and likely a bug fix...
BTW GCC suggestions are:
claimed (!!s->chan[ch].control) & CONTROL_CLAIM;
claimed (!!s->chan[ch].control) && CONTROL_CLAIM;
>
> if (!claimed && (value & CONTROL_CLAIM)) {
> /* reset Next* registers */
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] hw/dma: sifive_pdma: Improve code readability for "!!foo & bar"
2021-09-27 4:47 ` [PATCH 1/2] hw/dma: sifive_pdma: Improve code readability for "!!foo & bar" Philippe Mathieu-Daudé
@ 2021-09-27 5:18 ` Philippe Mathieu-Daudé
2021-09-27 6:51 ` Bin Meng
1 sibling, 0 replies; 12+ messages in thread
From: Philippe Mathieu-Daudé @ 2021-09-27 5:18 UTC (permalink / raw)
To: Bin Meng, Alistair Francis, qemu-devel, qemu-riscv
Cc: Frank Chang, Eric Blake
On 9/27/21 06:47, Philippe Mathieu-Daudé wrote:
> On 9/27/21 04:21, Bin Meng wrote:
>> GCC seems to be strict about processing pattern like "!!for & bar".
What GCC version btw?
>> When 'bar' is not 0 or 1, it complains with -Werror=parentheses:
>>
>> suggest parentheses around operand of ‘!’ or change ‘&’ to ‘&&’ or ‘!’ to ‘~’ [-Werror=parentheses]
>>
>> Add a () around "foo && bar", which also improves code readability.
>>
>> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
>> ---
>>
>> hw/dma/sifive_pdma.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/hw/dma/sifive_pdma.c b/hw/dma/sifive_pdma.c
>> index b4fd40573a..b8ec7621f3 100644
>> --- a/hw/dma/sifive_pdma.c
>> +++ b/hw/dma/sifive_pdma.c
>> @@ -243,7 +243,7 @@ static void sifive_pdma_write(void *opaque, hwaddr offset,
>> offset &= 0xfff;
>> switch (offset) {
>> case DMA_CONTROL:
>> - claimed = !!s->chan[ch].control & CONTROL_CLAIM;
>> + claimed = !!(s->chan[ch].control & CONTROL_CLAIM);
>
> AFAIK in C logical NOT has precedence over bitwise AND, so IIUC
> compilers should read the current code as:
>
> claimed (!!s->chan[ch].control) & CONTROL_CLAIM;
>
> meaning this patch is doing more than "improve code readability",
> this is a logical change and likely a bug fix...
>
> BTW GCC suggestions are:
>
> claimed (!!s->chan[ch].control) & CONTROL_CLAIM;
>
> claimed (!!s->chan[ch].control) && CONTROL_CLAIM;
>>
>> if (!claimed && (value & CONTROL_CLAIM)) {
>> /* reset Next* registers */
>>
>
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] hw/dma: sifive_pdma: Improve code readability for "!!foo & bar"
2021-09-27 4:47 ` [PATCH 1/2] hw/dma: sifive_pdma: Improve code readability for "!!foo & bar" Philippe Mathieu-Daudé
@ 2021-09-27 6:51 ` Bin Meng
2021-09-27 6:51 ` Bin Meng
1 sibling, 0 replies; 12+ messages in thread
From: Bin Meng @ 2021-09-27 6:51 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: Frank Chang, open list:RISC-V, Alistair Francis,
qemu-devel@nongnu.org Developers, Eric Blake
Hi Philippe,
On Mon, Sep 27, 2021 at 12:47 PM Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
>
> On 9/27/21 04:21, Bin Meng wrote:
> > GCC seems to be strict about processing pattern like "!!for & bar".
> > When 'bar' is not 0 or 1, it complains with -Werror=parentheses:
> >
> > suggest parentheses around operand of ‘!’ or change ‘&’ to ‘&&’ or ‘!’ to ‘~’ [-Werror=parentheses]
> >
> > Add a () around "foo && bar", which also improves code readability.
> >
> > Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
> > ---
> >
> > hw/dma/sifive_pdma.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/hw/dma/sifive_pdma.c b/hw/dma/sifive_pdma.c
> > index b4fd40573a..b8ec7621f3 100644
> > --- a/hw/dma/sifive_pdma.c
> > +++ b/hw/dma/sifive_pdma.c
> > @@ -243,7 +243,7 @@ static void sifive_pdma_write(void *opaque, hwaddr offset,
> > offset &= 0xfff;
> > switch (offset) {
> > case DMA_CONTROL:
> > - claimed = !!s->chan[ch].control & CONTROL_CLAIM;
> > + claimed = !!(s->chan[ch].control & CONTROL_CLAIM);
>
> AFAIK in C logical NOT has precedence over bitwise AND, so IIUC
> compilers should read the current code as:
>
> claimed (!!s->chan[ch].control) & CONTROL_CLAIM;
>
> meaning this patch is doing more than "improve code readability",
> this is a logical change and likely a bug fix...
Yes, you are correct. Indeed this is a bug fix. I did not dig into the
operator precedence in detail. I will reword this in v2.
>
> BTW GCC suggestions are:
>
> claimed (!!s->chan[ch].control) & CONTROL_CLAIM;
>
> claimed (!!s->chan[ch].control) && CONTROL_CLAIM;
> >
> > if (!claimed && (value & CONTROL_CLAIM)) {
> > /* reset Next* registers */
> >
I was using GCC 9.3.0 on Ubuntu 20.04.
Regards,
Bin
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] hw/dma: sifive_pdma: Improve code readability for "!!foo & bar"
@ 2021-09-27 6:51 ` Bin Meng
0 siblings, 0 replies; 12+ messages in thread
From: Bin Meng @ 2021-09-27 6:51 UTC (permalink / raw)
To: Philippe Mathieu-Daudé
Cc: Alistair Francis, qemu-devel@nongnu.org Developers,
open list:RISC-V, Frank Chang, Eric Blake
Hi Philippe,
On Mon, Sep 27, 2021 at 12:47 PM Philippe Mathieu-Daudé <f4bug@amsat.org> wrote:
>
> On 9/27/21 04:21, Bin Meng wrote:
> > GCC seems to be strict about processing pattern like "!!for & bar".
> > When 'bar' is not 0 or 1, it complains with -Werror=parentheses:
> >
> > suggest parentheses around operand of ‘!’ or change ‘&’ to ‘&&’ or ‘!’ to ‘~’ [-Werror=parentheses]
> >
> > Add a () around "foo && bar", which also improves code readability.
> >
> > Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
> > ---
> >
> > hw/dma/sifive_pdma.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/hw/dma/sifive_pdma.c b/hw/dma/sifive_pdma.c
> > index b4fd40573a..b8ec7621f3 100644
> > --- a/hw/dma/sifive_pdma.c
> > +++ b/hw/dma/sifive_pdma.c
> > @@ -243,7 +243,7 @@ static void sifive_pdma_write(void *opaque, hwaddr offset,
> > offset &= 0xfff;
> > switch (offset) {
> > case DMA_CONTROL:
> > - claimed = !!s->chan[ch].control & CONTROL_CLAIM;
> > + claimed = !!(s->chan[ch].control & CONTROL_CLAIM);
>
> AFAIK in C logical NOT has precedence over bitwise AND, so IIUC
> compilers should read the current code as:
>
> claimed (!!s->chan[ch].control) & CONTROL_CLAIM;
>
> meaning this patch is doing more than "improve code readability",
> this is a logical change and likely a bug fix...
Yes, you are correct. Indeed this is a bug fix. I did not dig into the
operator precedence in detail. I will reword this in v2.
>
> BTW GCC suggestions are:
>
> claimed (!!s->chan[ch].control) & CONTROL_CLAIM;
>
> claimed (!!s->chan[ch].control) && CONTROL_CLAIM;
> >
> > if (!claimed && (value & CONTROL_CLAIM)) {
> > /* reset Next* registers */
> >
I was using GCC 9.3.0 on Ubuntu 20.04.
Regards,
Bin
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] hw/dma: sifive_pdma: Improve code readability for "!!foo & bar"
2021-09-27 2:21 [PATCH 1/2] hw/dma: sifive_pdma: Improve code readability for "!!foo & bar" Bin Meng
@ 2021-09-27 6:51 ` Markus Armbruster
2021-09-27 4:47 ` [PATCH 1/2] hw/dma: sifive_pdma: Improve code readability for "!!foo & bar" Philippe Mathieu-Daudé
2021-09-27 6:51 ` Markus Armbruster
2 siblings, 0 replies; 12+ messages in thread
From: Markus Armbruster @ 2021-09-27 6:51 UTC (permalink / raw)
To: Bin Meng; +Cc: Frank Chang, qemu-riscv, Alistair Francis, qemu-devel
Bin Meng <bmeng.cn@gmail.com> writes:
> GCC seems to be strict about processing pattern like "!!for & bar".
> When 'bar' is not 0 or 1, it complains with -Werror=parentheses:
>
> suggest parentheses around operand of ‘!’ or change ‘&’ to ‘&&’ or ‘!’ to ‘~’ [-Werror=parentheses]
>
> Add a () around "foo && bar", which also improves code readability.
>
> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
> ---
>
> hw/dma/sifive_pdma.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/dma/sifive_pdma.c b/hw/dma/sifive_pdma.c
> index b4fd40573a..b8ec7621f3 100644
> --- a/hw/dma/sifive_pdma.c
> +++ b/hw/dma/sifive_pdma.c
> @@ -243,7 +243,7 @@ static void sifive_pdma_write(void *opaque, hwaddr offset,
> offset &= 0xfff;
> switch (offset) {
> case DMA_CONTROL:
> - claimed = !!s->chan[ch].control & CONTROL_CLAIM;
> + claimed = !!(s->chan[ch].control & CONTROL_CLAIM);
>
> if (!claimed && (value & CONTROL_CLAIM)) {
> /* reset Next* registers */
Old code
first double-negate, mapping zero to zero, non-zero to one
then mask, which does nothing, because CONTROL_CLAIM is 1
New code:
first mask, yielding 0 or 1
then double-negate, which does nothing
Looks like a bug fix to me. If I'm right, the commit message is wrong,
and the double negate is redundant.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] hw/dma: sifive_pdma: Improve code readability for "!!foo & bar"
@ 2021-09-27 6:51 ` Markus Armbruster
0 siblings, 0 replies; 12+ messages in thread
From: Markus Armbruster @ 2021-09-27 6:51 UTC (permalink / raw)
To: Bin Meng; +Cc: Alistair Francis, qemu-devel, qemu-riscv, Frank Chang
Bin Meng <bmeng.cn@gmail.com> writes:
> GCC seems to be strict about processing pattern like "!!for & bar".
> When 'bar' is not 0 or 1, it complains with -Werror=parentheses:
>
> suggest parentheses around operand of ‘!’ or change ‘&’ to ‘&&’ or ‘!’ to ‘~’ [-Werror=parentheses]
>
> Add a () around "foo && bar", which also improves code readability.
>
> Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
> ---
>
> hw/dma/sifive_pdma.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hw/dma/sifive_pdma.c b/hw/dma/sifive_pdma.c
> index b4fd40573a..b8ec7621f3 100644
> --- a/hw/dma/sifive_pdma.c
> +++ b/hw/dma/sifive_pdma.c
> @@ -243,7 +243,7 @@ static void sifive_pdma_write(void *opaque, hwaddr offset,
> offset &= 0xfff;
> switch (offset) {
> case DMA_CONTROL:
> - claimed = !!s->chan[ch].control & CONTROL_CLAIM;
> + claimed = !!(s->chan[ch].control & CONTROL_CLAIM);
>
> if (!claimed && (value & CONTROL_CLAIM)) {
> /* reset Next* registers */
Old code
first double-negate, mapping zero to zero, non-zero to one
then mask, which does nothing, because CONTROL_CLAIM is 1
New code:
first mask, yielding 0 or 1
then double-negate, which does nothing
Looks like a bug fix to me. If I'm right, the commit message is wrong,
and the double negate is redundant.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] hw/dma: sifive_pdma: Improve code readability for "!!foo & bar"
2021-09-27 6:51 ` Markus Armbruster
@ 2021-09-27 6:59 ` Bin Meng
-1 siblings, 0 replies; 12+ messages in thread
From: Bin Meng @ 2021-09-27 6:59 UTC (permalink / raw)
To: Markus Armbruster
Cc: Frank Chang, open list:RISC-V, Alistair Francis,
qemu-devel@nongnu.org Developers
Hi Markus,
On Mon, Sep 27, 2021 at 2:51 PM Markus Armbruster <armbru@redhat.com> wrote:
>
> Bin Meng <bmeng.cn@gmail.com> writes:
>
> > GCC seems to be strict about processing pattern like "!!for & bar".
> > When 'bar' is not 0 or 1, it complains with -Werror=parentheses:
> >
> > suggest parentheses around operand of ‘!’ or change ‘&’ to ‘&&’ or ‘!’ to ‘~’ [-Werror=parentheses]
> >
> > Add a () around "foo && bar", which also improves code readability.
> >
> > Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
> > ---
> >
> > hw/dma/sifive_pdma.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/hw/dma/sifive_pdma.c b/hw/dma/sifive_pdma.c
> > index b4fd40573a..b8ec7621f3 100644
> > --- a/hw/dma/sifive_pdma.c
> > +++ b/hw/dma/sifive_pdma.c
> > @@ -243,7 +243,7 @@ static void sifive_pdma_write(void *opaque, hwaddr offset,
> > offset &= 0xfff;
> > switch (offset) {
> > case DMA_CONTROL:
> > - claimed = !!s->chan[ch].control & CONTROL_CLAIM;
> > + claimed = !!(s->chan[ch].control & CONTROL_CLAIM);
> >
> > if (!claimed && (value & CONTROL_CLAIM)) {
> > /* reset Next* registers */
>
> Old code
>
> first double-negate, mapping zero to zero, non-zero to one
> then mask, which does nothing, because CONTROL_CLAIM is 1
>
> New code:
>
> first mask, yielding 0 or 1
> then double-negate, which does nothing
>
> Looks like a bug fix to me. If I'm right, the commit message is wrong,
> and the double negate is redundant.
>
Thanks for the review. The double negate is not needed with
CONTROL_CLAIM which is 1, but is needed if the bit is in another
position.
Regards,
Bin
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] hw/dma: sifive_pdma: Improve code readability for "!!foo & bar"
@ 2021-09-27 6:59 ` Bin Meng
0 siblings, 0 replies; 12+ messages in thread
From: Bin Meng @ 2021-09-27 6:59 UTC (permalink / raw)
To: Markus Armbruster
Cc: Alistair Francis, qemu-devel@nongnu.org Developers,
open list:RISC-V, Frank Chang
Hi Markus,
On Mon, Sep 27, 2021 at 2:51 PM Markus Armbruster <armbru@redhat.com> wrote:
>
> Bin Meng <bmeng.cn@gmail.com> writes:
>
> > GCC seems to be strict about processing pattern like "!!for & bar".
> > When 'bar' is not 0 or 1, it complains with -Werror=parentheses:
> >
> > suggest parentheses around operand of ‘!’ or change ‘&’ to ‘&&’ or ‘!’ to ‘~’ [-Werror=parentheses]
> >
> > Add a () around "foo && bar", which also improves code readability.
> >
> > Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
> > ---
> >
> > hw/dma/sifive_pdma.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/hw/dma/sifive_pdma.c b/hw/dma/sifive_pdma.c
> > index b4fd40573a..b8ec7621f3 100644
> > --- a/hw/dma/sifive_pdma.c
> > +++ b/hw/dma/sifive_pdma.c
> > @@ -243,7 +243,7 @@ static void sifive_pdma_write(void *opaque, hwaddr offset,
> > offset &= 0xfff;
> > switch (offset) {
> > case DMA_CONTROL:
> > - claimed = !!s->chan[ch].control & CONTROL_CLAIM;
> > + claimed = !!(s->chan[ch].control & CONTROL_CLAIM);
> >
> > if (!claimed && (value & CONTROL_CLAIM)) {
> > /* reset Next* registers */
>
> Old code
>
> first double-negate, mapping zero to zero, non-zero to one
> then mask, which does nothing, because CONTROL_CLAIM is 1
>
> New code:
>
> first mask, yielding 0 or 1
> then double-negate, which does nothing
>
> Looks like a bug fix to me. If I'm right, the commit message is wrong,
> and the double negate is redundant.
>
Thanks for the review. The double negate is not needed with
CONTROL_CLAIM which is 1, but is needed if the bit is in another
position.
Regards,
Bin
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] hw/dma: sifive_pdma: Improve code readability for "!!foo & bar"
2021-09-27 6:59 ` Bin Meng
@ 2021-09-27 7:16 ` Markus Armbruster
-1 siblings, 0 replies; 12+ messages in thread
From: Markus Armbruster @ 2021-09-27 7:16 UTC (permalink / raw)
To: Bin Meng
Cc: Frank Chang, open list:RISC-V, Alistair Francis,
qemu-devel@nongnu.org Developers
Bin Meng <bmeng.cn@gmail.com> writes:
> Hi Markus,
>
> On Mon, Sep 27, 2021 at 2:51 PM Markus Armbruster <armbru@redhat.com> wrote:
>>
>> Bin Meng <bmeng.cn@gmail.com> writes:
>>
>> > GCC seems to be strict about processing pattern like "!!for & bar".
>> > When 'bar' is not 0 or 1, it complains with -Werror=parentheses:
>> >
>> > suggest parentheses around operand of ‘!’ or change ‘&’ to ‘&&’ or ‘!’ to ‘~’ [-Werror=parentheses]
>> >
>> > Add a () around "foo && bar", which also improves code readability.
>> >
>> > Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
>> > ---
>> >
>> > hw/dma/sifive_pdma.c | 2 +-
>> > 1 file changed, 1 insertion(+), 1 deletion(-)
>> >
>> > diff --git a/hw/dma/sifive_pdma.c b/hw/dma/sifive_pdma.c
>> > index b4fd40573a..b8ec7621f3 100644
>> > --- a/hw/dma/sifive_pdma.c
>> > +++ b/hw/dma/sifive_pdma.c
>> > @@ -243,7 +243,7 @@ static void sifive_pdma_write(void *opaque, hwaddr offset,
>> > offset &= 0xfff;
>> > switch (offset) {
>> > case DMA_CONTROL:
>> > - claimed = !!s->chan[ch].control & CONTROL_CLAIM;
>> > + claimed = !!(s->chan[ch].control & CONTROL_CLAIM);
>> >
>> > if (!claimed && (value & CONTROL_CLAIM)) {
>> > /* reset Next* registers */
>>
>> Old code
>>
>> first double-negate, mapping zero to zero, non-zero to one
>> then mask, which does nothing, because CONTROL_CLAIM is 1
>>
>> New code:
>>
>> first mask, yielding 0 or 1
>> then double-negate, which does nothing
>>
>> Looks like a bug fix to me. If I'm right, the commit message is wrong,
>> and the double negate is redundant.
>>
>
> Thanks for the review. The double negate is not needed with
> CONTROL_CLAIM which is 1, but is needed if the bit is in another
> position.
It's not needed even then: conversion from integer type to bool takes
care of it. It's not wrong, though.
However, the commit message does look wrong to me.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH 1/2] hw/dma: sifive_pdma: Improve code readability for "!!foo & bar"
@ 2021-09-27 7:16 ` Markus Armbruster
0 siblings, 0 replies; 12+ messages in thread
From: Markus Armbruster @ 2021-09-27 7:16 UTC (permalink / raw)
To: Bin Meng
Cc: Alistair Francis, qemu-devel@nongnu.org Developers,
open list:RISC-V, Frank Chang
Bin Meng <bmeng.cn@gmail.com> writes:
> Hi Markus,
>
> On Mon, Sep 27, 2021 at 2:51 PM Markus Armbruster <armbru@redhat.com> wrote:
>>
>> Bin Meng <bmeng.cn@gmail.com> writes:
>>
>> > GCC seems to be strict about processing pattern like "!!for & bar".
>> > When 'bar' is not 0 or 1, it complains with -Werror=parentheses:
>> >
>> > suggest parentheses around operand of ‘!’ or change ‘&’ to ‘&&’ or ‘!’ to ‘~’ [-Werror=parentheses]
>> >
>> > Add a () around "foo && bar", which also improves code readability.
>> >
>> > Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
>> > ---
>> >
>> > hw/dma/sifive_pdma.c | 2 +-
>> > 1 file changed, 1 insertion(+), 1 deletion(-)
>> >
>> > diff --git a/hw/dma/sifive_pdma.c b/hw/dma/sifive_pdma.c
>> > index b4fd40573a..b8ec7621f3 100644
>> > --- a/hw/dma/sifive_pdma.c
>> > +++ b/hw/dma/sifive_pdma.c
>> > @@ -243,7 +243,7 @@ static void sifive_pdma_write(void *opaque, hwaddr offset,
>> > offset &= 0xfff;
>> > switch (offset) {
>> > case DMA_CONTROL:
>> > - claimed = !!s->chan[ch].control & CONTROL_CLAIM;
>> > + claimed = !!(s->chan[ch].control & CONTROL_CLAIM);
>> >
>> > if (!claimed && (value & CONTROL_CLAIM)) {
>> > /* reset Next* registers */
>>
>> Old code
>>
>> first double-negate, mapping zero to zero, non-zero to one
>> then mask, which does nothing, because CONTROL_CLAIM is 1
>>
>> New code:
>>
>> first mask, yielding 0 or 1
>> then double-negate, which does nothing
>>
>> Looks like a bug fix to me. If I'm right, the commit message is wrong,
>> and the double negate is redundant.
>>
>
> Thanks for the review. The double negate is not needed with
> CONTROL_CLAIM which is 1, but is needed if the bit is in another
> position.
It's not needed even then: conversion from integer type to bool takes
care of it. It's not wrong, though.
However, the commit message does look wrong to me.
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2021-09-27 7:17 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-27 2:21 [PATCH 1/2] hw/dma: sifive_pdma: Improve code readability for "!!foo & bar" Bin Meng
2021-09-27 2:21 ` [PATCH 2/2] hw/dma: sifive_pdma: Don't run DMA when channel is disclaimed Bin Meng
2021-09-27 4:47 ` [PATCH 1/2] hw/dma: sifive_pdma: Improve code readability for "!!foo & bar" Philippe Mathieu-Daudé
2021-09-27 5:18 ` Philippe Mathieu-Daudé
2021-09-27 6:51 ` Bin Meng
2021-09-27 6:51 ` Bin Meng
2021-09-27 6:51 ` Markus Armbruster
2021-09-27 6:51 ` Markus Armbruster
2021-09-27 6:59 ` Bin Meng
2021-09-27 6:59 ` Bin Meng
2021-09-27 7:16 ` Markus Armbruster
2021-09-27 7:16 ` Markus Armbruster
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.