Memory allocation for float constant

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Memory allocation for float constant

4,035 Views
SSK
Contributor I

I am using Codewarrior 4.6 build 6350 for MC9S12A128. I am using float constant’s arrays in my code as:

 

const float c_POL_0[4] = {-5.78917222e-06, +2.50809493e-03, +2.22793687e+00, -2.42091388e+02};

const float c_POL_1[4] = {+1.01890899e-06, +6.30461601e-04, +2.40305016e+00, -2.47634281e+02};

const float c_POL_2[4] = {+2.14757889e-06, -2.76439182e-04, +2.64911809e+00, -2.70148753e+02};

 

const float c_LIN[3] =

     {     100.000,

             260.785,

          LIMIT_MAX  };

 

While debugging the code, I found that compiler generates the memory addresses for c_POL_0 and c_LIN only. It does not generate memory addresses for c_POL_1 and c_POL_2. I checked this in .map file generated by the compiler. I am not using any optimizations for the compiler. What could be the reason? Please clarify.

 

Thanks in advance.

Labels (1)
Tags (1)
0 Kudos
11 Replies

896 Views
CrasyCat
Specialist III
Hello
 
Are you accessing the constants from  c_POL_1 and c_POL_2 in your application?
If you are using constants from these tables only in the module, where the variables are defined, the compiler might replace the constant variable by the constant value.
 
You can disable that optimization specifying option -OnCstVar in your compiler command line arguments.
 
If this does not help It is probably better to submit a Service request through our on line support web site and provide the whole project to the support team for an accurate analysis,.
 
Click here to submit a service request.

Make sure to attach a reproducible project and installed product information to the service request.
To generate the required information:
- Start CodeWarrior
- Open the project
- Select "Help" -> "Pack and Go" and follow instructions on the screen.

Attach the generated .zip file to the SR.
CrasyCat
0 Kudos

896 Views
SSK
Contributor I
Hello,
 
Yes, I am accessing c_POL1 and c_POL2 as well but it depends on some input value. The input value is checked for limits from c_LIN array. If input value falls within 0 and 100 then c_POL_0 is accessed, if it falls within 101 to 260 then c_POL_1 is accessed and if it falls within 261 to 5000 then c_POL_2 is accessed.
 
I tried disabling the CONST variable by constant replacement (-OnCstVar) but does not solve the problem.
 
Thanks in advance.
0 Kudos

896 Views
SSK
Contributor I
Hello,
 
As the c_POL_x is reffered indirectly depending on some input value, if I use dummy access for c_POL_1 and c_POL_2, compiler generates the address for these in the map file. Is there any compiler option required to enable/disable the generation of address for indirectly addressed variables? Is Codewarrior using any default optimization(s) that is/are not available to enable/disable? Is there any dead code/ dead variable optimization implemented in Codewarrior?
 
Thanks in advance.
0 Kudos

896 Views
J2MEJediMaster
Specialist I
I think that the "unaccessed" constants are being dead-stripped. Check in the HC12 Compiler setting panel to make sure that the optimization setting, Optimized Dead Assignments, is unchecked.

---Tom

0 Kudos

896 Views
SSK
Contributor I
Hello TOM,
 
I checked the option Optimized Dead Assignments. It is unchecked but still the address is not generated for c_POL_1 and c_POL_2. What other optimization setting(s) do I need to check? I even checked for constant folding (-Onca) and tree optimizer (-Ont) with disable address optimization. Still the problem exists. Please guide me. Your earliest help in this regard will be highly appreciated.
 
Thanks in advance.
0 Kudos

896 Views
CompilerGuru
NXP Employee
NXP Employee
I would suggest that you post how the constants are accessed, that appears to behave differently than you expect.
Some simple things like constant folding always takes place, for example:

Code:
if (sizeof(int) == 2) {  ptr = array_with_2_byte_elements;} else if (sizeof(int) == 4) {  ptr = array_with_4_byte_elements;} else {....

is always accessing either of the arrays, I don't think there is a way to generate code for basically a if (0).
Maybe it is also something else, but I really think we need more information before we can help.

If you cannot provide the source code, I would suggest to create a new project and to try to reproduce the issue there. That could also help as often the issue is not where we think it is...

Also look at the generated code, see what the compiler does (usually I use -onf for debugging such cases, the generated code is more straight forward and that should not affect this issue)

Daniel


0 Kudos

896 Views
SSK
Contributor I
Hello Daniel,
 
Please find the following how I access my variables:
 
#define LIMIT_MAX 5000
#define SIZE_LIN 3
 
volatile const float c_POLPTIEC00_0[4] = {-5.78917222e-06, +2.50809493e-03, +2.22793687e+00, -2.42091388e+02};
volatile const float c_POLPTIEC00_1[4] = {+1.01890899e-06, +6.30461601e-04, +2.40305016e+00, -2.47634281e+02};
volatile const float c_POLPTIEC00_2[4] = {+2.14757889e-06, -2.76439182e-04, +2.64911809e+00, -2.70148753e+02};
 
const float c_LIN9[3] =
  { 100.000,
   260.785,
   LIMIT_MAX};
 
const float * const cp_LIN [SIZE_LIN] =
{
      &c_LIN9[0]
};
 
const float * const cp_POL [SIZE_LIN] =
{
      &c_POLPTIEC00_0[0],
      //&c_POLPTIEC00_1[0], //if declared, compiler generates the code for this
      //&c_POLPTIEC00_2[0] //if declared, compiler generates the code for this
};
 
main {
float *p_pol_tbl;
float *p_lin_tbl;
 
 asm_main(); /* call the assembly function */
 Init_CPU();
 init_sys();
 
 p_lin_tbl = cp_LIN[0];
 p_pol_tbl = cp_POL[0];
 
}
 
The map file shows, these two variables in the Unused-Objects section
 
 STT25x.c.o:
  c_POLPTIEC00_1 c_POLPTIEC00_2
 
Please clarify. Thanks in advance.
0 Kudos

896 Views
CompilerGuru
NXP Employee
NXP Employee
Not sure what to clarify. Not used variables are not linked, not allocated.
If you have a particular issue, please let us know, so far it just looks to be as I would have expected it....

Daniel
0 Kudos

896 Views
SSK
Contributor I
Do you mean, I must refer these variable in order to generate the code/address for these......!!
 
I have various such constant arrays in my code. In this case, I need to declare all these variables though at run time, any one of them may/will come into picture actually. The same code initially was on HC11 processor. There we had used IAR workbench. This was not happening with IAR. Whether any default optimization is applied by Codewarrior?
0 Kudos

896 Views
CrasyCat
Specialist III
Hello
 
Variables, which are ot used inside of the code does not get allocated in the CPU memory.
 
If you want to allocate variables which are not referenced in the application you can specify them in the ENTRIES block within the linker .prm file.
 
To add variables  c_POLPTIEC00_1 and c_POLPTIEC00_2, the ENTRIES block should look like:
 
ENTRIES
 c_POLPTIEC00_1 c_POLPTIEC00_2
END
 
CrasyCat
0 Kudos

896 Views
CrasyCat
Specialist III
Hello
 
If this did not help, I would recommend you to submit a service request for that.

Click here to submit a service request.

Make sure to attach a reproducible project and installed product information to the service request.
To generate the required information:
- Start CodeWarrior
- Open the project
- Select "Help" -> "Pack and Go" and follow instructions on the screen.

Attach the generated .zip file to the SR.
 
CrasyCat
0 Kudos