On Mon, 18 Feb 2013, Daniel Michalik wrote: > When comparing the asm outputs I see that the first example does not call > ___fs2uint, why does it not need to do this to cast the value of x?
> void main(void) { > float x = 6116.0; > debug = x; > //debug is 6116. > } > unsigned int debug = 1234; > float julianday = 6116.0; > > void main(void) { > float x = 6116.0; > > debug = julianday; > // expect 6116, obtain a vastly different (arbitrary?) number > } I can't answer most of your questions because I do use pic and so I am not very familiar with that part of SDCC. However, I can answer why SDCC does not need to call __fs2uint in the first example. SDCC's optimizations are all at the function level. It can see that x is assigned the float value 6116.0 and then debug is assigned a value from x. It sees that there are no intervening instructions that could modify x's value, therefor debug is assigned the value 6116.0 cast to unsigned int. This cast is being applied to a known constant, so the compiler performs this cast during compilation to avoid the overhead of calling __fs2uint during run-time. This does not happen in the second example because julianday is assigned the value 6116.0 outside of the function. When optimizing the function, the compiler only considers the code within the function and so does not assume any variable still has its globally initialized value. Since the compiler is not certain of the value of julianday, it cannot compute the cast at compile-time and so inserts a call to __fs2uint to perform the cast at run-time. Give this version a try: void main(void) { volatile float x = 6116.0; debug = x; //debug is 6116. } The "volatile" keyword should disable most optimizion related to the variable x and force the cast to be performed at run-time. If this leaves the correct value in debug, the problem is with initialization of global variables. However, if this also fails, then there is likely a problem with the function implementing the run-time cast. Erik ------------------------------------------------------------------------------ Everyone hates slow websites. So do we. Make your web apps faster with AppDynamics Download AppDynamics Lite for free today: http://p.sf.net/sfu/appdyn_d2d_feb _______________________________________________ Sdcc-user mailing list Sdcc-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/sdcc-user