[Lldb-commits] [lldb] r183716 - <rdar://problem/12783351>
Enrico Granata
egranata at apple.com
Mon Jun 10 17:18:18 PDT 2013
Author: enrico
Date: Mon Jun 10 19:18:18 2013
New Revision: 183716
URL: http://llvm.org/viewvc/llvm-project?rev=183716&view=rev
Log:
<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
Modified:
lldb/trunk/include/lldb/lldb-enumerations.h
lldb/trunk/source/Commands/CommandObjectMemory.cpp
lldb/trunk/source/Core/DataExtractor.cpp
lldb/trunk/source/DataFormatters/FormatManager.cpp
Modified: lldb/trunk/include/lldb/lldb-enumerations.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/lldb-enumerations.h?rev=183716&r1=183715&r2=183716&view=diff
==============================================================================
--- lldb/trunk/include/lldb/lldb-enumerations.h (original)
+++ lldb/trunk/include/lldb/lldb-enumerations.h Mon Jun 10 19:18:18 2013
@@ -125,6 +125,7 @@ namespace lldb {
eFormatAddressInfo, // Describe what an address points to (func + offset with file/line, symbol + offset, data, etc)
eFormatHexFloat, // ISO C99 hex float string
eFormatInstruction, // Disassemble an opcode
+ eFormatHalfFloat, // Half-floats (IEEE-754-2008 binary16 interchange format)
eFormatVoid, // Do not print this
kNumFormats
} Format;
Modified: lldb/trunk/source/Commands/CommandObjectMemory.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Commands/CommandObjectMemory.cpp?rev=183716&r1=183715&r2=183716&view=diff
==============================================================================
--- lldb/trunk/source/Commands/CommandObjectMemory.cpp (original)
+++ lldb/trunk/source/Commands/CommandObjectMemory.cpp Mon Jun 10 19:18:18 2013
@@ -180,12 +180,15 @@ public:
case eFormatUnicode32:
case eFormatUnsigned:
case eFormatHexFloat:
+ case eFormatHalfFloat:
if (!byte_size_option_set)
byte_size_value = 4;
if (!num_per_line_option_set)
m_num_per_line = 1;
if (!count_option_set)
format_options.GetCountValue() = 8;
+ if (format_options.GetFormat() == eFormatFloat && byte_size_option_set && byte_size_value == 2)
+ format_options.GetFormatValue().SetCurrentValue(eFormatHalfFloat);
break;
case eFormatBytes:
@@ -1170,6 +1173,7 @@ protected:
case eFormatComplexInteger:
case eFormatAddressInfo:
case eFormatHexFloat:
+ case eFormatHalfFloat:
case eFormatInstruction:
case eFormatVoid:
result.AppendError("unsupported format for writing memory");
Modified: lldb/trunk/source/Core/DataExtractor.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Core/DataExtractor.cpp?rev=183716&r1=183715&r2=183716&view=diff
==============================================================================
--- lldb/trunk/source/Core/DataExtractor.cpp (original)
+++ lldb/trunk/source/Core/DataExtractor.cpp Mon Jun 10 19:18:18 2013
@@ -1302,6 +1302,22 @@ DumpAPInt (Stream *s, const DataExtracto
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;
Modified: lldb/trunk/source/DataFormatters/FormatManager.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/DataFormatters/FormatManager.cpp?rev=183716&r1=183715&r2=183716&view=diff
==============================================================================
--- lldb/trunk/source/DataFormatters/FormatManager.cpp (original)
+++ lldb/trunk/source/DataFormatters/FormatManager.cpp Mon Jun 10 19:18:18 2013
@@ -72,6 +72,7 @@ g_format_infos[] =
{ eFormatCharArray , 'a' , "character array" },
{ eFormatAddressInfo , 'A' , "address" },
{ eFormatHexFloat , '\0' , "hex float" },
+ { eFormatHalfFloat , '\0' , "half float" },
{ eFormatInstruction , 'i' , "instruction" },
{ eFormatVoid , 'v' , "void" }
};
More information about the lldb-commits
mailing list