1 /*----------------------------------------------------------------------------*/
2 /**
3  *	This confidential and proprietary software may be used only as
4  *	authorised by a licensing agreement from ARM Limited
5  *	(C) COPYRIGHT 2011-2012 ARM Limited
6  *	ALL RIGHTS RESERVED
7  *
8  *	The entire notice above must be reproduced on all authorised
9  *	copies and copies may only be made to the extent permitted
10  *	by a licensing agreement from ARM Limited.
11  *
12  *	@brief	Soft IEEE-754 floating point library.
13  */
14 /*----------------------------------------------------------------------------*/
15 
16 #ifndef SOFTFLOAT_H_INCLUDED
17 
18 #define SOFTFLOAT_H_INCLUDED
19 
20 #if defined __cplusplus
21 extern "C"
22 {
23 #endif
24 
25 #if defined __cplusplus && !defined(_MSC_VER)
26 
27 	/* if compiling as C++, we need to define these macros in order to obtain all the macros in stdint.h . */
28 	#define __STDC_LIMIT_MACROS
29 	#define __STDC_CONSTANT_MACROS
30 	#include <stdint.h>
31 
32 #else
33 
34 	typedef unsigned char uint8_t;
35 	typedef signed char int8_t;
36 	typedef unsigned short uint16_t;
37 	typedef signed short int16_t;
38 	typedef unsigned int uint32_t;
39 	typedef signed int int32_t;
40 
41 #endif
42 
43 
44 uint32_t clz32(uint32_t p);
45 
46 
47 /* targets that don't have UINT32_C probably don't have the rest of C99s stdint.h */
48 #ifndef UINT32_C
49 
50 	#define PASTE(a) a
51 	#define UINT64_C(a) PASTE(a##ULL)
52 	#define UINT32_C(a) PASTE(a##U)
53 	#define INT64_C(a) PASTE(a##LL)
54 	#define INT32_C(a) a
55 
56 	#define PRIX32 "X"
57 	#define PRId32 "d"
58 	#define PRIu32 "u"
59 	#define PRIX64 "LX"
60 	#define PRId64 "Ld"
61 	#define PRIu64 "Lu"
62 
63 #endif
64 
65 	/*	sized soft-float types. These are mapped to the sized integer types of C99, instead of C's
66 		floating-point types; this is because the library needs to maintain exact, bit-level control on all
67 		operations on these data types. */
68 	typedef uint16_t sf16;
69 	typedef uint32_t sf32;
70 
71 	/* the five rounding modes that IEEE-754r defines */
72 	typedef enum
73 	{
74 		SF_UP = 0,				/* round towards positive infinity */
75 		SF_DOWN = 1,			/* round towards negative infinity */
76 		SF_TOZERO = 2,			/* round towards zero */
77 		SF_NEARESTEVEN = 3,		/* round toward nearest value; if mid-between, round to even value */
78 		SF_NEARESTAWAY = 4		/* round toward nearest value; if mid-between, round away from zero */
79 	} roundmode;
80 
81 	/* narrowing float->float conversions */
82 	sf16 sf32_to_sf16(sf32, roundmode);
83 
84 	/* widening float->float conversions */
85 	sf32 sf16_to_sf32(sf16);
86 
87 	sf16 float_to_sf16(float, roundmode);
88 	float sf16_to_float(sf16);
89 
90 
91 #if defined __cplusplus
92 }
93 #endif
94 
95 #endif
96