loops in fadd and fdiv

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

loops in fadd and fdiv

763 次查看
mabdelrahman
Contributor I

Hello,
we are currently evaluating a tool to calculate the worst-case execution time of our code (tasks and ISRs to be exact).
This analyzes the machine instructions in the elf file.
However, it has issues finding out how often the loops in fadd and fdiv (S12Z target, CodeWarrior 10.5) are getting executed.
Can anyone tell me where I find this in the documentation?

Thanks

0 项奖励
回复
1 回复

700 次查看
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi Mohamed Abdelrahman

fadd and fdiv are CW system library functions, normally they are called when application executes floating orations.Thus the frequency of execution these functions depends on user applications. I don't think we have document about these functions.

What do you mean "loops in fadd and fdiv" ? For example, fdiv function is like this:

Is your question about the maximal execution time of this __fdiv(void) function?

_EXTERNC_ void __fdiv(void){
    __asm{        
        SAVE_REGISTERS_TO_BE_USED_BY_FP_ROUTINES
        JSR     unpack_operands
        
#ifdef __HANDLE_SPECIAL_OPERATIONS__        
        /* any operation with a NaN yields a NaN result */
        BRSET     D4, #NAN, return_Nan
        BRSET     D5, #NAN, return_Nan
        
        /* Infinity / Infinity             = NaN */
        /* n / Infinity                     = zero */
        /* (+/-)Infinity / (+/-)valid_op     = (+/-)Infinity        */
        BRSET     D4, #INFINITY, left_inf
        BRSET     D5, #INFINITY, return_Zero
        BRA        check_for_zero_op    
    left_inf:        
        BRCLR    D5, #INFINITY, second_op_not_inf
    /* invalid exception for inf / inf */
    #ifdef __FP_EXCEPTIONS__
        BSET.B    exceptions, #EINVALID
    #endif
        BRA        return_Nan
    second_op_not_inf:
    
        BRSET     D5, #INFINITY, return_Nan
        TBEQ    D1, return_left_op        
        LD        D0, left_op_unpacked
        BTGL    D0, #7
        ST        D0, left_op_unpacked
        BRA        return_left_op    
    check_for_zero_op:
#endif    
        /* 0 / 0                 = Nan */
        /* (+/-)non_zero / 0     = (+/-)Infinity */
        BRSET     D4, #ZERO, left_zero
        BRCLR     D5, #ZERO, compute_exponent
    #ifdef __FP_EXCEPTIONS__
        BSET.B    exceptions, #EDIVZERO
    #endif
        JMP        return_infinity
    left_zero:
        BRCLR    D5, #ZERO, return_Zero
    /* invalid exception for 0 / 0 */
    #ifdef __FP_EXCEPTIONS__
        BSET.B    exceptions, #EINVALID
    #endif
        BRA        return_Nan
        
    compute_exponent:            
        EOR        D0, D1        
        SUB        D2, D3        
        ADD        D2, #127
        
        /* allocate space for the quotient */
        LEA        S, (-4,S) 
        CLR.L    (0,SP)        
        LD        D4, #31
    /* normalize subnormal values */
        CLR        D5
        INC        D5
        JSR        normalize_subnormals

    mantissa_division:        
        CMP        D7, D6
        BHI        shift_mantissa
        SUB        D6, D7
        LSL        D6, D6, #1
        BSET.L    (0,SP), D4
        DBPL    D4,    mantissa_division
        BRA        quotient
    shift_mantissa:
        LSL        D6, D6, #1    
        DBPL    D4,    mantissa_division            
                
    quotient:
    #ifdef __FP_ROUNDING__
    /* special sticky bit */
        TBEQ    D6, END_CMP
    SET_STICKY:
        BSET.L    (0,S), #5
    END_CMP:
    #endif
        PUL        D6            /* pul the quotient in D6 register */
    /* special underflow case for subnormal result with exponent 1 */
    /* because of simple 0x7F bias value (unlike softfloat's 0x7D) */
    /* result exponent is not <= 0 so normalize_d_mantissa doesn't catch this case */
    #ifdef __FP_EXCEPTIONS__
        CMP        D2, #1
        BNE        NO_UNDERFLOW
        BRSET    D6, #31, NO_UNDERFLOW
        BIT        D6, #0x000000E0
        BEQ        NO_UNDERFLOW
        BSET.B    exceptions, #EUNDERFLOW
        BSET.B    exceptions, #EINEXACT
    NO_UNDERFLOW:
    #endif
        JMP        normalize_mantissa
    
    return_left_op:
        JMP        return_operand
    return_right_op:
        MOV.L    right_op_unpacked, left_op_unpacked        
        JMP        return_operand
    return_Nan:
    #ifdef __FP_EXCEPTIONS__
    /* invalid exception for operation with a signaling nan */
        BRSET    D4, #SNAN, IS_EINVALID2
        BRSET    D5, #SNAN, IS_EINVALID2
        BRA        NO_EINVALID2
    IS_EINVALID2:
        BSET.B    exceptions, #EINVALID
    NO_EINVALID2:
    #endif
        MOV.L    #NAN_ENCODING, left_op_unpacked        
        JMP        return_operand
    return_Zero:
        MOV.L    #PLUS_ZERO_ENCODING, left_op_unpacked        
        EOR     D0, D1
        BFINS.L    left_op_unpacked, D0, #1:31
        JMP        return_operand    
    }
}

Have a nice day,

Jun Zhang

0 项奖励
回复