Rev 874 | Rev 1653 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 874 | Rev 1031 | ||
---|---|---|---|
Line 54... | Line 54... | ||
54 | /** Take fraction shifted by 10 bits to left, round it, normalize it and detect exceptions |
54 | /** Take fraction shifted by 10 bits to left, round it, normalize it and detect exceptions |
55 | * @param exp exponent with bias |
55 | * @param exp exponent with bias |
56 | * @param cfrac fraction shifted 10 places left with added hidden bit |
56 | * @param cfrac fraction shifted 10 places left with added hidden bit |
57 | * @return valied float64 |
57 | * @return valied float64 |
58 | */ |
58 | */ |
59 | float64 finishFloat64(__s32 cexp, __u64 cfrac, char sign) |
59 | float64 finishFloat64(int32_t cexp, uint64_t cfrac, char sign) |
60 | { |
60 | { |
61 | float64 result; |
61 | float64 result; |
62 | 62 | ||
63 | result.parts.sign = sign; |
63 | result.parts.sign = sign; |
64 | 64 | ||
Line 106... | Line 106... | ||
106 | result.parts.exp = FLOAT64_MAX_EXPONENT; |
106 | result.parts.exp = FLOAT64_MAX_EXPONENT; |
107 | result.parts.fraction = 0; |
107 | result.parts.fraction = 0; |
108 | return result; |
108 | return result; |
109 | } |
109 | } |
110 | 110 | ||
111 | result.parts.exp = (__u32)cexp; |
111 | result.parts.exp = (uint32_t)cexp; |
112 | 112 | ||
113 | result.parts.fraction = ((cfrac >>(64 - FLOAT64_FRACTION_SIZE - 2 ) ) & (~FLOAT64_HIDDEN_BIT_MASK)); |
113 | result.parts.fraction = ((cfrac >>(64 - FLOAT64_FRACTION_SIZE - 2 ) ) & (~FLOAT64_HIDDEN_BIT_MASK)); |
114 | 114 | ||
115 | return result; |
115 | return result; |
116 | } |
116 | } |
117 | 117 | ||
118 | /** Counts leading zeroes in 64bit unsigned integer |
118 | /** Counts leading zeroes in 64bit unsigned integer |
119 | * @param i |
119 | * @param i |
120 | */ |
120 | */ |
121 | int countZeroes64(__u64 i) |
121 | int countZeroes64(uint64_t i) |
122 | { |
122 | { |
123 | int j; |
123 | int j; |
124 | for (j =0; j < 64; j += 8) { |
124 | for (j =0; j < 64; j += 8) { |
125 | if ( i & (0xFFll << (56 - j))) { |
125 | if ( i & (0xFFll << (56 - j))) { |
126 | return (j + countZeroes8(i >> (56 - j))); |
126 | return (j + countZeroes8(i >> (56 - j))); |
Line 131... | Line 131... | ||
131 | } |
131 | } |
132 | 132 | ||
133 | /** Counts leading zeroes in 32bit unsigned integer |
133 | /** Counts leading zeroes in 32bit unsigned integer |
134 | * @param i |
134 | * @param i |
135 | */ |
135 | */ |
136 | int countZeroes32(__u32 i) |
136 | int countZeroes32(uint32_t i) |
137 | { |
137 | { |
138 | int j; |
138 | int j; |
139 | for (j =0; j < 32; j += 8) { |
139 | for (j =0; j < 32; j += 8) { |
140 | if ( i & (0xFF << (24 - j))) { |
140 | if ( i & (0xFF << (24 - j))) { |
141 | return (j + countZeroes8(i >> (24 - j))); |
141 | return (j + countZeroes8(i >> (24 - j))); |
Line 146... | Line 146... | ||
146 | } |
146 | } |
147 | 147 | ||
148 | /** Counts leading zeroes in byte |
148 | /** Counts leading zeroes in byte |
149 | * @param i |
149 | * @param i |
150 | */ |
150 | */ |
151 | int countZeroes8(__u8 i) |
151 | int countZeroes8(uint8_t i) |
152 | { |
152 | { |
153 | return zeroTable[i]; |
153 | return zeroTable[i]; |
154 | } |
154 | } |
155 | 155 | ||
156 | /** Round and normalize number expressed by exponent and fraction with first bit (equal to hidden bit) at 30. bit |
156 | /** Round and normalize number expressed by exponent and fraction with first bit (equal to hidden bit) at 30. bit |
157 | * @param exp exponent |
157 | * @param exp exponent |
158 | * @param fraction part with hidden bit shifted to 30. bit |
158 | * @param fraction part with hidden bit shifted to 30. bit |
159 | */ |
159 | */ |
160 | void roundFloat32(__s32 *exp, __u32 *fraction) |
160 | void roundFloat32(int32_t *exp, uint32_t *fraction) |
161 | { |
161 | { |
162 | /* rounding - if first bit after fraction is set then round up */ |
162 | /* rounding - if first bit after fraction is set then round up */ |
163 | (*fraction) += (0x1 << 6); |
163 | (*fraction) += (0x1 << 6); |
164 | 164 | ||
165 | if ((*fraction) & (FLOAT32_HIDDEN_BIT_MASK << 8)) { |
165 | if ((*fraction) & (FLOAT32_HIDDEN_BIT_MASK << 8)) { |
Line 180... | Line 180... | ||
180 | 180 | ||
181 | /** Round and normalize number expressed by exponent and fraction with first bit (equal to hidden bit) at 62. bit |
181 | /** Round and normalize number expressed by exponent and fraction with first bit (equal to hidden bit) at 62. bit |
182 | * @param exp exponent |
182 | * @param exp exponent |
183 | * @param fraction part with hidden bit shifted to 62. bit |
183 | * @param fraction part with hidden bit shifted to 62. bit |
184 | */ |
184 | */ |
185 | void roundFloat64(__s32 *exp, __u64 *fraction) |
185 | void roundFloat64(int32_t *exp, uint64_t *fraction) |
186 | { |
186 | { |
187 | /* rounding - if first bit after fraction is set then round up */ |
187 | /* rounding - if first bit after fraction is set then round up */ |
188 | (*fraction) += (0x1 << 9); |
188 | (*fraction) += (0x1 << 9); |
189 | 189 | ||
190 | if ((*fraction) & (FLOAT64_HIDDEN_BIT_MASK << 11)) { |
190 | if ((*fraction) & (FLOAT64_HIDDEN_BIT_MASK << 11)) { |