跳至主要內容
Knowledgebase
Home
Renesas Electronics Taiwan - Knowledgebase

Is FPSCR registration required for using SH compiler?

Latest Updated:11/17/2014

Question:

I'm using the SH compiler. Although there is no statement that might use floating point, code for setting the precision mode (PR bit) in the FPSCR register is generated.

Answer:

If the following options set to the default values have been used, code for setting the PR bit in the FPSCR register will be generated even if you are not using floating point.

  • -fpu option (default: not specified (displayed as Mix on the High-performance Embedded Workshop))
  • -fpscr option (default: -fpscr=aggressive)

When -fpscr=aggressive is specified, single precision is always guaranteed as the precision mode at the head of a function, however, the precision mode on return from a function call is not guaranteed. Accordingly, the example below will lead to the generation of code for setting the PR bit.

Example of C source code

------------------------------
int x,y;   
 void func1(int a){       //Single precision mode is guaranteed at the head of this function.
               …  
 }                     // The precision mode is not guaranteed at the end of this function.
 void func2(int b){  
               …  
 }   
 void main(void)  
 {   
  func1(x);  
  func2(y);             //The precision mode is not guaranteed at the head of func2(). }

 } 

Result of compiling of main() above (when -cpu=2afpu is specified)
Since the precision mode is not guaranteed at the head of func2() 
after returning from the call of func1(), 
the compiler will generate code for setting the PR bit(*).

_main:    
  STS.L PR,@-R15  
  MOV.L L13,R1 ; _x 
  BSR _func1  
  MOV.L @R1,R4 ; x 
  STS FPSCR,R5 ; * 
  MOVI20S #-1572864,R6; H'FFE80 ; * 
  MOV.L L13+4,R7 ; _y 
  ADD #-1,R6 ; * 
  MOV.L @R7,R4 ; y 
  AND R6,R5 ; * 
  LDS R5,FPSCR ; * 
  BRA _func2  
  LDS.L @R15+,PR 
------------------------------

When -fpscr=safe is specified, code for setting the PR bit is only generated when a double-precision floating-point calculation is used. This is to guarantee that the precision always becomes single precision after a function call. When -fpu=single or -fpu=double is specified, code for setting the PR bit is not generated because the precision always becomes single or double.

Document for reference: SH Compiler Application Note 2-Compiler use guide: Coding Guide (Using FPU)

Suitable Products
C/C++ Compiler Package for SuperH Family