[flac-dev] Two questions about RG in flac

Robert Kausch robert.kausch at freac.org
Tue Jun 3 10:19:14 PDT 2014

Am 03.06.2014 16:45, schrieb lvqcl:
> 2) to ALL:
> I attached a small program. Compile and run it.
> * Does it work correctly when compiled with -O3 -msse2 options?
> * If yes, does it work correctly when compiled with -O3 -funroll-loops 
> -msse2 options?
>   ( and what is the version of your GCC? )
I further reduced the testcase (attached).

The bug only occurs if N >= 64; presumably the second loop is only SSE2 
optimized if that's the case.

The problem seems to be that sum is interpreted as a 64 bit value if 
SSE2 was used in the loop (the lower 32 bits of the result give the 
expected value). If sum is evaluated another time before or after (!) 
the printf, the problem goes away. For example, changing the last line 
to "return sum + 1;" lets the problem disappear.

I confirmed the bug with GCC 4.6.3 on Ubuntu. As on Windows, only 32 bit 
code generation is affected.

You should file a bug report with the GCC team.
-------------- next part --------------
#include <stdio.h>

#define N 64 /* problem is triggered only if N >= 64 */
unsigned A[N];

int main()
	unsigned i, sum = 0; /* both sum and A[] need to be unsigned for the bug to happen */

	for (i = 0; i < N; i++) A[i] = 1;
	for (i = 0; i < N; i++) sum += A[i];

	printf("Sum = %f (should be equal to %i)\n", (float) sum, N);

	return 0;

More information about the flac-dev mailing list