Messages in this thread | | | Date | Sun, 4 Nov 2012 16:52:04 +0100 | From | Oleg Nesterov <> | Subject | Re: [PATCH 1/1] percpu_rw_semaphore: reimplement to not block the readers unnecessarily |
| |
On 11/04, George Spelvin wrote: > > Grand poo-bah Linus wrote: > > Now, I doubt you'll find an architecture or C compiler where this will > > actually ever make a difference, but the fact remains that you > > shouldn't use signed integers for counters like this. You should use > > unsigned, and you should rely on the well-defined modulo-2**n > > semantics. > > Actually, this is another C standard undefined case that recent versions of > GCC exploit for optimization. ^^^^^^^^^^^^
This is another thing,
> For example, the loop: > for (i = 1; i; i++) > /* Code */ > will never terminate! Feed the following to gcc -O2 and see for yourself:
Yes, because ...
> Notice the lack of test in the "jmp .L2" loop.
Exactly.
But if we have like
int A, B;
int sum(void) { return A + B; }
then I doubt there is any architecture (at least supported by linux) which can generate the different code if you do s/int/unsigned/.
Anyway I agree, unsigned makes more sense, and I changed this patch accordingly..
Oleg.
| |