Performace problems with gcc 3.0.4
Joe Buck
Joe.Buck@synopsys.com
Tue Mar 19 09:46:00 GMT 2002
> According to [a friend], the following code is about
> 50% slower than the version without structs.
>
> He was tried the ICC (Intel compiler) and it
> generates the same code for the two cases but
> gcc does not. He played with all optimization
> flags that affect numeric code but to no avail.
>
> Does anyone know what might be the problem ?
Yes, it's a well-known problem with gcc. Structs get committed to memory
too early. Some compilers are able to split apart structs and treat their
members as independent scalar variables; gcc can only do this for structs
or classes with a single member.
> /* Code with structs */
> #include <stdio.h>
> int main()
> {
> typedef struct {
> double a;
> double b;
> } twodoubles;
>
> twodoubles x;
> int i;
>
> x.a = 0.0;
> x.b = 0.0;
> for (i = 0; i < 100000000; i++) {
> x.a = x.b + 1.0;
> x.b = x.a - x.b + 1.0;
> }
>
> printf("a: %g\nb: %g\n", x.a, x.b);
> return 0;
> }
>
> -------------------------------------------------------
> /* Code without structs */
> #include <stdio.h>
>
> int main()
> {
> double a, b;
> int i;
>
> a = 0.0;
> b = 0.0;
> for (i = 0; i < 100000000; i++) {
> a = b + 1.0;
> b = a - b + 1.0;
> }
>
> printf("a: %g\nb: %g\n", a, b);
> return 0;
> }
>
>
More information about the Gcc
mailing list