Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® Software > Using sprint without including floating point library code

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



Using sprint without including floating point library code
Moderator:
JFMD

Post Reply
Follow this topic



Using sprint without including floating point library code

PeterT posted on 25 Apr 2012 3:31 PM PST
Member
10 Forum Posts

 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?




Re: Using sprint without including floating point library code

Bob Marlowe posted on 26 Apr 2012 05:59 AM PST
Top Contributor
1768 Forum Posts

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



Re: Using sprintf without including floating point library code

PeterT posted on 26 Apr 2012 08:29 AM PST
Member
10 Forum Posts

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?



Re: Using sprintf without including floating point library code

PeterT posted on 26 Apr 2012 10:09 AM PST
Member
10 Forum Posts

 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

       ...

 

 



Re: Using sprint without including floating point library code

Bob Marlowe posted on 26 Apr 2012 10:48 AM PST
Top Contributor
1768 Forum Posts

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



Re: Using sprint without including floating point library code

PeterT posted on 27 Apr 2012 10:06 AM PST
Member
10 Forum Posts

 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?






ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.

Spec No: None; Sunset Owner: GRAA; Secondary Owner: RAIK; Sunset Date: 01/01/20