|
From: | Paolo Bonzini |
Subject: | Re: FW: New Defects reported by Coverity Scan for QEMU |
Date: | Fri, 5 Nov 2021 16:59:19 +0100 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 |
On 11/5/21 16:31, Peter Maydell wrote:
The loop nest in question is (the index must be < 128) for (int offset = 1; offset < 128; offset <<= 1) { for (int k = 0; k < 128; k++) { if (!(k & offset)) { swap(vector1.ub[k], vector0.ub[k + offset]); } } } Basically, it's looking for elements to swap, and the "if (!(k & offset))" prevents "k + offset" from overflowing.
It would still be slightly more efficient however to change the loop to k < 128 - offset.
Another possibility is to change the inner loop to for (int k = offset; k < 128; k = (k + 1) | offset) swap(vector1.ub[k-offset], vector0.ub[k]); Paolo
[Prev in Thread] | Current Thread | [Next in Thread] |