2007-12-17 17:43:24

by Johannes Berg

[permalink] [raw]
Subject: Re: [patch 3/9] mac80211: Add PID controller based rate control algorithm


> + /* We need to do an arithmetic right shift. ISO C says this is
> + * implementation defined for negative left operands. Hence, be
> + * careful to get it right, also for negative values. */
> + adj = (adj < 0) ? -((-adj) >> (2 * RC_PID_ARITH_SHIFT)) :
> + adj >> (2 * RC_PID_ARITH_SHIFT);

That looks... weird.

As far as I know all compilers the kernel can use will do an arithmetic
right shift if the data type is signed.

johannes


Attachments:
signature.asc (828.00 B)
This is a digitally signed message part

2007-12-17 21:08:54

by Mattias Nissler

[permalink] [raw]
Subject: Re: [patch 3/9] mac80211: Add PID controller based rate control algorithm


On Mon, 2007-12-17 at 12:50 +0100, Johannes Berg wrote:
> > + /* We need to do an arithmetic right shift. ISO C says this is
> > + * implementation defined for negative left operands. Hence, be
> > + * careful to get it right, also for negative values. */
> > + adj = (adj < 0) ? -((-adj) >> (2 * RC_PID_ARITH_SHIFT)) :
> > + adj >> (2 * RC_PID_ARITH_SHIFT);
>
> That looks... weird.
>
> As far as I know all compilers the kernel can use will do an arithmetic
> right shift if the data type is signed.

Where is your information from? I actually had some misbehaviour that
was fixed after I introduced this. I'll check the assembly gcc produces
to shed some light on this.

Mattias


2007-12-18 12:50:40

by Johannes Berg

[permalink] [raw]
Subject: Re: [patch 3/9] mac80211: Add PID controller based rate control algorithm


> > As far as I know all compilers the kernel can use will do an arithmetic
> > right shift if the data type is signed.
>
> Where is your information from?

Just empirically :)

> I actually had some misbehaviour that
> was fixed after I introduced this. I'll check the assembly gcc produces
> to shed some light on this.

Ok. I like the macro that stefano introduced better than inlining this
code and I can live with that. I know gcc can emit arithmetic right
shifts.

johannes


Attachments:
signature.asc (828.00 B)
This is a digitally signed message part