Using sprint without including floating point library code

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

 I have noticed that Keil includes the full (not the small, not the compact, but the large) library of floating point routines when you use printf/sprinf even if the float type parameter is never used.  Is there a relatively clean and simple way to prevent the fp routines from being loaded?

0 Likes
5 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

I always thought that unused parts of a program are optimized-out when in Project -> Build settings -> Keil 8051 -> Linker the option "Remove unused Segments" is set to true.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Unused code is typically optimized out.  I can look at my MAP file and see all the API functions that are deleted.  However, that doesn't seem to be the case with the library functions.  My understanding is that since I use the sprintf library routine, it calls the same routine no matter what the actual parameters I send are.  That sprintf routine has calls to FP routines which may or may not be used based on the parameters I send to it.  The compiler can't be sure that I'm not sending it FP parameters so it cannot optimize those out automatically.  I read on the Keil website that perhaps there are two versions of the sprintf routines and that one of them does not support FP parameters.  I have been unable, however, to find any description of how to select that smaller sprintf routine.  Perhaps it has something to do with what the "memory model" is set to, which for PSoC is defaulted to LARGE.  I'm not at all sure that has anything to do with it though.  I am quite certain that it is the sprintf usage that is including the FP routines as I can see in the MAP file how the "modules" are linked.  I wonder if my only option is to use the NODEFAULTLIB directive for the linker and then manually select the library files to include.  Anyone have some thoughts on the issue?

0 Likes
Anonymous
Not applicable

 Here's a new twist.  I commented out all of my sprintf calls to see how much space the FP routines were actually using.  The code size dropped by about 1k, but I noticed in the MAP file that the FP modules were still being linked.  The only other place that uses any FP is the ADC which has two functions that use floats, but those functions are optimized out as they are not being used.  I verified by cross referencing the LST and MAP files that all occurences of a FP routine call in the LST file were in functions that were shown as being deleted in the MAP file.  Also, right near the top of the MAP file it states the following: "MEMORY MODEL: LARGE WITH FLOATING POINT ARITHMETIC".

   

 

   

Here are another copy and paste from the MAP file:

   

 PUBLIC SYMBOLS OF MODULE:  .\DP8051_Keil_903\Release\(project).omf (LCD)

   

      VALUE       CLASS    TYPE      PUBLIC SYMBOL NAME

   

      =================================================

   

     ...

   

      01000243H   CODE     ---       ?C?FCASTC

   

      0100023EH   CODE     ---       ?C?FCASTI

   

      01000239H   CODE     ---       ?C?FCASTL

   

      010001C2H   CODE     ---       ?C?FPCMP

   

      010001C0H   CODE     ---       ?C?FPCMP3

   

      01000123H   CODE     ---       ?C?FPDIV

   

      010002AEH   CODE     ---       ?C?FPGETOPN2

   

      0100001AH   CODE     ---       ?C?FPMUL

   

      010002E3H   CODE     ---       ?C?FPNANRESULT

   

      010002EDH   CODE     ---       ?C?FPOVERFLOW

   

      010002C5H   CODE     ---       ?C?FPRESULT

   

      010002D9H   CODE     ---       ?C?FPRESULT2

   

      010002EAH   CODE     ---       ?C?FPUNDERFLOW

   

       ...

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

I just created a new empty project. There was no float in the map-file. When I inserted a float and assigned it a value, I got the same header as you in the .Map-file, the resulting file was just 12 bits larger in code.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

 I tried the NODEFAULTLIBRARY linker directive and then added the C51L.LIB, but it wouldn't link because of the FP usage in the ADC API.  I guess the linking happens prior to the optimization and deletion of unused segments.  It would be nice if that optimization was extended to the library routines as well as the APIs.  It looks like I'm stuck with the FP routines whether I use them or not.  Anyone else have any experience with this issue?

0 Likes