Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3965290
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T03:26:36+00:00 2026-05-20T03:26:36+00:00

I have a header file containing a lot of small inline functions. Most of

  • 0

I have a header file containing a lot of small inline functions. Most of them happen to have constant data. Since these functions are performance critical, the way they handle constants becomes important. AFAIK there are two ways to refer to constants:

1) Define them in a separate source file that is later linked with the application.

2) Define the constants in-place.

I would choose the latter way because it’s more maintainable. However, the it might be slower if the compiler doesn’t optimize thousands of equal constants that are created by inlining.

The question:

Will the compiler combine these equal constants? In particular, which of the following methods will be utilized?

1) Combining of equal constants across the compilation unit.
2) Combining of equal constants across the linking module (whole program or library)
3) Combining the constants with any static constant data that happens to have the same bit pattern and fulfills the alignment requirements across the compilation unit or whole program.

I use a modern compiler (GCC4.5).

I’m not an expert in assembler, thus I couldn’t answer this question myself using several simple tests 🙂

EDIT:

The constants are quite big (most of them at least 16 bytes), so the compiler can’t make them immediate values.

EDIT2:

EXAMPLE of the code

This one uses the constant in-place:

float_4 sign(float_4 a)
{
    const __attribute__((aligned(16))) float mask[4] = { //I use a macro for this line
        0x80000000, 0x80000000, 0x80000000, 0x80000000};
    const int128 mask = load(mask);
    return b_and(a, mask);
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T03:26:36+00:00Added an answer on May 20, 2026 at 3:26 am

    According to the GCC the following option does what you want:

    -fmerge-constants

    Attempt to merge identical constants (string constants and floating point constants) across compilation units.
    This option is the default for optimized compilation if the assembler and linker support it. Use -fno-merge-constants to inhibit this behavior.
    Enabled at levels -O, -O2, -O3, -Os.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have C header file containing the following type definition: // example.h typedef struct
I have a c++ header file containing a class. I want to use this
i have shared the header file containing class definition of a Context Free grammar
I have two sources: an xml-file containing definitions of several hundred data structures, basically
I have a situation. I have some functions in a header file that are
I have a structure defined in a header file called data.h. I am including
I have a file where a data structure containing 6 columns is stored side
I have a header file like this: #ifndef __GEN_NOTE_MARKERS_TO_DEVELOPERS_HPP__ #define __GEN_NOTE_MARKERS_TO_DEVELOPERS_HPP__ #ifdef _DEBUG //
I have a header file, lets say Common.h, that is included in all of
I have a header file variable.h where i declare all my global variable.Then i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.