Problem with returning a float32 number to the calling function

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

Problem with returning a float32 number to the calling function

跳至解决方案
3,021 次查看
johna123
Contributor II

I am currently using codewarrior V2.5 for PowerPC with the MPC5607B which has a Z0 core with no hardware floating point support.

I am using the software floating point option and I am able to calculate correctly floating point math operations with no problem.  The issue is when I send the calculated result back to the calling function the variable in the calling function that is expected to be equated to the return result is not getting set to the value calculated.  I have included the following libraries in my project:

MSL_C.PPCEABI.bar.VS.UC.a

Runtime.PPCEABI.VS.UC.a

 

It is like the GPR register assignment is not looking at the right register for the return parameter. 

I have converted the function to return UINT32 and it does return the parameter appropriately but I need to be able to return floating point numbers.  Thank you!

标签 (1)
标记 (1)
0 项奖励
回复
1 解答
1,991 次查看
johna123
Contributor II

Thanks for the reply.  I did try what you suggested and it did work.  Then I looked carefully at at the header files that I am including in my main and noticed that I had forgotten to add the header file that defines the function that I am using to the main.c.  I am guessing that the compiler was redifining the function call since it did not have the appropriate header file included.  Once I did that my float return did work so thank you for help and time.  It did help point me in the right direction.

 

But this raises another question.  Why did the compiler not warn me of the redefinition.  I have used codewarrior before and it has in the past warn me of redefinitions.  I tried excluding another file and it did not warn me of that either.  Is there a setting that I need to enable to turn on warnings?

 

Thanks again!

 

 

在原帖中查看解决方案

0 项奖励
回复
5 回复数
1,991 次查看
CrasyCat
Specialist III

Hello

 

Are you sure the library files you are using matches your project settings?

 

Please refer to "{Install}\Help\PDF\Power Architecture Build Tools Reference.pdf" chapter "Libraries and Support Code", section "Main Standard Libraries" -> "Choosing an MSL library" for information on encoding used for library names.

 

Make sure the library you are selecting matches your actual compilation option... 

 

CrasyCat

0 项奖励
回复
1,991 次查看
johna123
Contributor II

I have looked at this and the libraries that I am using are the default ones that came in when I set up the project based on the option that I chose.  Also, it has been my experience that if I choose a library that does not conform to the project settings I get warnings from the compiler.

 

Either way, I have tried different libraries based on the table that you referenced in your reply with no success.  I have been able to pass the result by passing the address of the float variable thru the parameter list which is a possible work around but I would need to change a number of function calls that use the return at the end of the function to pass a result back.

 

Any other ideas?  Thank you for you help!

johna123

0 项奖励
回复
1,991 次查看
stanish
NXP Employee
NXP Employee

Hi Johana123,

 

I've tested this using software floating point sum (MPC5604P):

 

1) created new project using ProjectWizard, enable software floating point.Default libs (Runtime.PPCEABI.VS.UC.a, MSL_C.PPCEABI.bare.VS.UC.a)

 

2) add fsum() into main.c: 

 

volatile float x,y,f; 

 

float fsum(float a, float b)

{

   return a+b;

int main(void) {

  volatile int i = 0;

  x = 3.14;

  y = 2.5; 

  f = fsum(x,y);

 

3) compile and check in the P&E debugger.

 

It works as expected.

 

Could you possibly try the same example on your side.

If it works then please post your code here to review.

 

Stanish 

0 项奖励
回复
1,992 次查看
johna123
Contributor II

Thanks for the reply.  I did try what you suggested and it did work.  Then I looked carefully at at the header files that I am including in my main and noticed that I had forgotten to add the header file that defines the function that I am using to the main.c.  I am guessing that the compiler was redifining the function call since it did not have the appropriate header file included.  Once I did that my float return did work so thank you for help and time.  It did help point me in the right direction.

 

But this raises another question.  Why did the compiler not warn me of the redefinition.  I have used codewarrior before and it has in the past warn me of redefinitions.  I tried excluding another file and it did not warn me of that either.  Is there a setting that I need to enable to turn on warnings?

 

Thanks again!

 

 

0 项奖励
回复
1,991 次查看
johna123
Contributor II
OK,  I found the warnings check boxes and now they are enabled.  Thanks for you help.  I think I am good now.
0 项奖励
回复