summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDmitry Grinberg <dmitrygr@google.com>2016-01-13 18:49:25 +0000
committerandroid-build-merger <android-build-merger@google.com>2016-01-13 18:49:25 +0000
commit19b72822e0b4472dd156113ac50b505d0e70a9bb (patch)
treea19fcf4a9c20772fabd6c976d530d67d04a86ec2
parent8cef81634cfb33487332df5f1c898b77bc286db7 (diff)
parent5d62888f53a0f3153e381a319f1fb2f947bd78fc (diff)
downloadcontexthub-19b72822e0b4472dd156113ac50b505d0e70a9bb.tar.gz
floatRt: even faster floatFromi[U]int64
am: fa93eb7f3a * commit 'fa93eb7f3a2940f0cc7255a344658f4a57aedb85': floatRt: even faster floatFromi[U]int64
-rw-r--r--firmware/src/floatRt.c27
1 files changed, 1 insertions, 26 deletions
diff --git a/firmware/src/floatRt.c b/firmware/src/floatRt.c
index 16459c3f..15a27be9 100644
--- a/firmware/src/floatRt.c
+++ b/firmware/src/floatRt.c
@@ -126,37 +126,12 @@ int64_t floatToInt64(float f)
float floatFromUint64(uint64_t v)
{
uint32_t hi = v >> 32, lo = v;
- int32_t exp;
if (!hi) //this is very fast for cases where we fit into a uint32_t
return(float)lo;
else {
- exp = 63 - __builtin_clz(hi);
- if (exp > MANTISSA_BITS) {
-
- //when we shift bits out, we must round, so we shift by one less, then add rounding bit, then shift out
- lo = v >> (exp - MANTISSA_BITS - 1);
- lo++;
- lo >>= 1;
-
- //we could have overflowed into more bits - handle it. Here we cannot overflow again since low bits are sure to be all zeroes
- if (lo >> (MANTISSA_BITS + 1)) {
- lo >>= 1;
- exp++;
- }
- }
- else
- lo = v << (MANTISSA_BITS - exp);
-
- //remove the implied one
- lo &=~ (1 << MANTISSA_BITS);
-
- //write in the exponent
- exp += EXP_ADJUST;
- lo |= exp << MANTISSA_BITS;
+ return ((float)hi) * 4294967296.0f + (float)lo;
}
-
- return *(float*)&lo;
}
float floatFromInt64(int64_t v)