Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we initialize the global variables? #95

Open
huyubiao opened this issue Apr 2, 2024 · 2 comments
Open

Can we initialize the global variables? #95

huyubiao opened this issue Apr 2, 2024 · 2 comments

Comments

@huyubiao
Copy link

huyubiao commented Apr 2, 2024

In GCC 10, the default option -fcommon is changed to -fno-common, see: PR85678. As a result, the uninitialized non-static global variables are moved from the COMMON block to the .bss. As a result, the performance tested in the same environment but different GCC versions is different.
Can we initialize the global variable to eliminate this difference? (Global variables are also usually recommended to be initialized.)

@gstrauss
Copy link
Collaborator

gstrauss commented Apr 2, 2024

Is there a measurable difference in the performance tests if the global variables are in the .data section or the .bss section?

The latest gcc stable release is gcc 13.2 (https://gcc.gnu.org/releases.html)

@huyubiao
Copy link
Author

huyubiao commented Apr 2, 2024

Is there a measurable difference in the performance tests if the global variables are in the .data section or the .bss section?

The latest gcc stable release is gcc 13.2 (https://gcc.gnu.org/releases.html)

  • I tried to test with dhry_1.c and dhry_2.c in 13.2: when using -fno-common the performance is around 9200, but with -fcommon the performance is above 9500. After the global non-static variables in dhry_1.c are initialized and -fcommon is used, the performance returns to 9200. On gcc 10.3 the difference in performance is sometimes greater than 10%.
  • By the way: I was using Intel Sapphire Rapids when it comes to the CPU architecture. This problem may not exist on other architectures.
  • I mean, is it possible to unify here: 1. Initialize global non-static variables; 2. Explicitly use -fno-common during compilation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants