Re: [Mesa-dev] [PATCH 03/10] i965: Silence loop counter overflow warning

2016-03-10 Thread Jason Ekstrand
On Mar 10, 2016 1:21 PM, "Eirik Byrkjeflot Anonsen" 
wrote:
>
> Ian Romanick  writes:
>
> > From: Ian Romanick 
> >
> > I don't understand why the old code was bad, but the new code is fine.
>
> Probably because the *loop counter* can no longer overflow. Thus the
> loop can be optimized. The fact that "i" might overflow has become
> irrelevant to the warning.

Right.  In theory, since i is incremented by 4 each time it could, in
theory, skip right over size/4 and overflow.  However, this can never
happen since size is 32 bits and is divided by 4 so it has a maximum value
of 2^30-1.  Apparently, GCC isn't quite that smart. :-)

> (And from that perspective, it isn't equivalent. If "i" overflows in the
> original code, you would get an infinite loop.)
>
> eirik
> ___
> mesa-dev mailing list
> mesa-dev@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


Re: [Mesa-dev] [PATCH 03/10] i965: Silence loop counter overflow warning

2016-03-10 Thread Eirik Byrkjeflot Anonsen
Ian Romanick  writes:

> From: Ian Romanick 
>
> I don't understand why the old code was bad, but the new code is fine.

Probably because the *loop counter* can no longer overflow. Thus the
loop can be optimized. The fact that "i" might overflow has become
irrelevant to the warning.

(And from that perspective, it isn't equivalent. If "i" overflows in the
original code, you would get an infinite loop.)

eirik
___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev


[Mesa-dev] [PATCH 03/10] i965: Silence loop counter overflow warning

2016-03-10 Thread Ian Romanick
From: Ian Romanick 

I don't understand why the old code was bad, but the new code is fine.

brw_state_dump.c: In function ‘brw_debug_batch’:
brw_state_dump.c:677:4: warning: cannot optimize loop, the loop counter may 
overflow [-Wunsafe-loop-optimizations]
for (i = 0; i < size / 4; i += 4) {
^
brw_state_dump.c:693:4: warning: cannot optimize loop, the loop counter may 
overflow [-Wunsafe-loop-optimizations]
for (i = 0; i < size / 4; i += 4) {
^

Signed-off-by: Ian Romanick 
---
 src/mesa/drivers/dri/i965/brw_state_dump.c | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_state_dump.c 
b/src/mesa/drivers/dri/i965/brw_state_dump.c
index 943b2a9..ba09537 100644
--- a/src/mesa/drivers/dri/i965/brw_state_dump.c
+++ b/src/mesa/drivers/dri/i965/brw_state_dump.c
@@ -674,7 +674,9 @@ dump_vs_constants(struct brw_context *brw, uint32_t offset, 
uint32_t size)
uint32_t *as_uint = brw->batch.bo->virtual + offset;
float *as_float = brw->batch.bo->virtual + offset;
 
-   for (unsigned i = 0; i < size / 4; i += 4) {
+   for (unsigned j = 0; j < size / 16; j++) {
+  const unsigned i = j * 4;
+
   batch_out(brw, name, offset, i, "%3d: (% f % f % f % f) (0x%08x 0x%08x 
0x%08x 0x%08x)\n",
i / 4,
as_float[i], as_float[i + 1], as_float[i + 2], as_float[i + 3],
@@ -689,7 +691,9 @@ dump_wm_constants(struct brw_context *brw, uint32_t offset, 
uint32_t size)
uint32_t *as_uint = brw->batch.bo->virtual + offset;
float *as_float = brw->batch.bo->virtual + offset;
 
-   for (unsigned i = 0; i < size / 4; i += 4) {
+   for (unsigned j = 0; j < size / 16; j++) {
+  const unsigned i = j * 4;
+
   batch_out(brw, name, offset, i, "%3d: (% f % f % f % f) (0x%08x 0x%08x 
0x%08x 0x%08x)\n",
i / 4,
as_float[i], as_float[i + 1], as_float[i + 2], as_float[i + 3],
-- 
2.5.0

___
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev