summaryrefslogtreecommitdiffstats
path: root/lldb/source/Core/DataExtractor.cpp
diff options
context:
space:
mode:
authorEnrico Granata <egranata@apple.com>2013-06-11 00:18:18 +0000
committerEnrico Granata <egranata@apple.com>2013-06-11 00:18:18 +0000
commit97fe23e00a88957494bf2c993c998907b894206a (patch)
tree7471248c6db7b1200748a4243718fba33d51ced2 /lldb/source/Core/DataExtractor.cpp
parent864dd750935f5cb3f69a8049180b2d618ad2737c (diff)
downloadbcm5719-llvm-97fe23e00a88957494bf2c993c998907b894206a.tar.gz
bcm5719-llvm-97fe23e00a88957494bf2c993c998907b894206a.zip
<rdar://problem/12783351>
Add support for half-floats, as specified by IEEE-754-2008 With this checkin, you can now say: (lldb) x/7hf foo to read 7 half-floats at address foo llvm-svn: 183716
Diffstat (limited to 'lldb/source/Core/DataExtractor.cpp')
-rw-r--r--lldb/source/Core/DataExtractor.cpp34
1 files changed, 34 insertions, 0 deletions
diff --git a/lldb/source/Core/DataExtractor.cpp b/lldb/source/Core/DataExtractor.cpp
index aa567f8f339..64d2929f119 100644
--- a/lldb/source/Core/DataExtractor.cpp
+++ b/lldb/source/Core/DataExtractor.cpp
@@ -1302,6 +1302,22 @@ DumpAPInt (Stream *s, const DataExtractor &data, lldb::offset_t offset, lldb::of
return offset;
}
+static float half2float (uint16_t half)
+{
+ union{ float f; uint32_t u;}u;
+ int32_t v = (int16_t) half;
+
+ if( 0 == (v & 0x7c00))
+ {
+ u.u = v & 0x80007FFFU;
+ return u.f * 0x1.0p125f;
+ }
+
+ v <<= 13;
+ u.u = v | 0x70000000U;
+ return u.f * 0x1.0p-112f;
+}
+
lldb::offset_t
DataExtractor::Dump (Stream *s,
offset_t start_offset,
@@ -1712,6 +1728,24 @@ DataExtractor::Dump (Stream *s,
}
break;
+ case eFormatHalfFloat:
+ {
+ std::ostringstream ss;
+ if (item_byte_size == 2)
+ {
+ uint16_t half = this->GetU16(&offset);
+ float half_converted = half2float(half);
+ ss << half_converted;
+ }
+ else
+ {
+ s->Printf("error: unsupported byte size (%zu) for half-float format", item_byte_size);
+ return offset;
+ }
+ ss.flush();
+ s->Printf("%s", ss.str().c_str());
+ }
+ break;
case eFormatUnicode16:
s->Printf("U+%4.4x", GetU16 (&offset));
break;
OpenPOWER on IntegriCloud