• Aucun résultat trouvé

Floating-Point Support

Dans le document TMS34010 C Compiler (Page 66-71)

C Compiler Operation

Section 5 Runtime Environment

5.7 Floating-Point Support

The TMS34010 C compiler supports floating-point functions for both sin-gle-precision (32-bit) and double-precision (64-bit) values. All floating-point arguments are passed on the stack; floating-floating-point return values are returned on the stack. Single-precision values are converted to doubles when they are passed to functions. Operations between two single-precision oper-ands are performed in single-precision. Operations between a single-precision operand and a double-precision operand are performed in double-precision.

A custom package of floating-point routines is included with the C compiler;

these functions do not follow standard C calling conventions. The calling conventions for these routines follow a classic operand stack:

• The compiler pushes the floating-point arguments onto the argument stack, then generates a call to a floating-point function.

• The floating-point function pops the arguments off the stack, performs the operation, and pushes the results back onto the stack.

Some floating-point functions expect integer arguments or return integer val-ues; all integers are passed and returned in register A8.

Section 5.7.1 describes the floating-point formats used for these routines;

Section 5.7.2 through Section 5.7.5 list the floating-point routines.

5.7.1 Floating-Point Formats

The compiler is unaware of the internal floating-point format; the only re-striction the compiler places on a floating-point number is the representation of the number. This allows you to customize a floating-point package for your environment. Section 5.7.1.1 and Section 5.7.2 describe the floating-point format used by the floating-point routines that are included with the C com-piler.

Runtime Environment - Floating-Point Support

5.7.1.1 Single-Precision Floating-Point Format

31 32

MSB

Figure 5-3 illustrates the single-precision floating-point format. Single-precision values are represented in 32 bits: a sign bit (bit 31 ), an 8-bit biased exponent (bits 23-30), and a 23-bit mantissa (bits 0-22).

23 22

o

LSB Figure 5-3. Single-Precision Format

Given a sign bit s, an exponent e, and a mantissa f, the value V of the float-ing-point number X= (s,e,f) is:

If s=O, e=255, and f=O, the V =

+

00

If s=1, e=255, and f=O, the V = -00

If 0<e<255 and f:l:O, then V = (-1)S x 2e-127(.f); V is not valid if X= (s,e,f) is not a normalized floating-point number

If s=O, e=O, and f=O, the V = 0

• For all other cases, V = not valid

Precision of single-precision values is greater than six decimal digits; the range includes:

Positive values: 5.87747 x 10-39 to 1.70141 x 1038

Negative values: -1.70141 x 1038 to -5.87747 x 10-39

• 0

• ±oo

5.7.1.2 Double-Precision Floating-Point Format

63 62

Figure 5-4 illustrates the double-precision floating-point format. Double-precision values are represented in 64 bits: a sign bit (bit 63) an 11-bit biased exponent (bits 52-62), and a 52-bit mantissa (bits 0-51).

52 51

o

.!~'... ~:'. ,"

MSB

5-18

LSB Figure 5-4. Double-Precision Format

Given a sign bit s, an exponent e, and a mantissa f, the value V of the float-ing-point number X= (s,e,f) is:

If s=O, e=2047, and f=O, the V = +00

If s=1, e=2047, and f=O, the V

=

-00

Runtime Environment - Floating-Point Support

If 0<e<2047 and f#:O, then V

=

(-1)S x 2e-1023(.f): V is not valid if X= (s,e,f) is not a normalized floating-point number

If s=O, e=O, and f=O, the V = 0

5.7.2 Double-Precision Functions

Assume that dl and d2 are double-precision floating-point values on the

Runtime Environment - Floating-Point Support

5.7.3 Single-Precision Functions

5-20

Assume that f1 and f2 are single-precision floating-point values on the stack;

f 1 is pushed first.

Runtime Environment - Floating-Point Support

5.7.4 Conversion Functions Assume that:

f and d are single-precision or double-precision floating-point values on the stack,

• i is an integer that is passed in AS, and

• u is an unsigned integer that is passed in AS.

Function FD$DTOF FD$DTOI FD$DTOU FD$FTOD FD$FTOI FD$FTOU FD$UTOD FD$ITOD FO$UTOF FD$ITOF

Action

Convert d to single precision and return on stack.

Convert d to a signed integer and return in AS.

Convert d to an unsigned integer and return in AS.

Convert f to double precision and return on stack.

Convert f to a signed integer and return in AS.

Convert f to an unsigned integer and return in AS.

Convert u to double precision and return on stack.

Convert i to double precision and return on stack.

Convert u to single precision and return on the stack.

Convert i to single precision and return on the stack.

5.7.5 Floating-Point Errors

You can customize this function in any way you wish; write your own function and use the archiver to include the function into the floating-point library.

Function Action

-fp-error Called whenever a floating-point exception occurs.

Runtime Environment - System Initialization system. The boot. obj module must be combined with the C object modules at link time; this occurs by default when you use the -c or -cr linker options

2) Autoinitializes global variables by copying the data from the initialization tables in .cinit to the storage allocated for the variables in .bss. (Note that in the RAM initialization model, a loader performs this step before the program runs - it is not performed by the boot routine.)

3) Calls the function main to begin running the C program.

You can replace or modify the boot routine to meet your system requirements.

However, the boot routine must perform the three operations listed above in order to correctly initialize the C environment.

5.8.1 Initializing the Stack

5-22

C code uses two stacks to manage the runtim6 environment:

• The system stack is used to save the status of a calling function or of an interrupted function. The system stack starts at the highest address in the stack space and grows toward lower addresses.

The SP register is a dedicated register that points to the system stack.

The TMS34010 instruction set supports several instructions for manip-ulating the system stack, including:

MMTM (save registers) MMFM (restore registers) CALLA or CALL (call a function)

RETS or RETI (return from a function or interrupt)

• The program stack is used for local frame generation during a function call; it is used for passing arguments to functions and for allocating local (temporary) variables for a called function. The program stack is con-trolled entirely through software. The TMS34010 does not dedicate a register to point to the program stack; however, the C compiler uses re-gister A 14 (STK) as the program-stack pointer.

Dans le document TMS34010 C Compiler (Page 66-71)

Documents relatifs