Skip to content

Commit

Permalink
Add support for gdtoa-desktop to generate shortest representations fo…
Browse files Browse the repository at this point in the history
…r 80-bit long doubles
  • Loading branch information
10110111 committed Sep 1, 2018
1 parent d7b676d commit 872c9c1
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 2 deletions.
15 changes: 14 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ else()
add_definitions("-DHAVE_DOUBLE_CONVERSION")
endif()


find_package(Qt5Core)

include_directories("include")
Expand All @@ -79,6 +78,7 @@ else()
endif()

if((${CMAKE_SYSTEM_PROCESSOR} MATCHES "i[3456]86") OR (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x86_64") OR (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "AMD64"))
set(CPU_TYPE "x86")
if(${CMAKE_SIZEOF_VOID_P} EQUAL 4)
add_definitions(-DEDB_X86)
elseif(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
Expand All @@ -88,6 +88,7 @@ if((${CMAKE_SYSTEM_PROCESSOR} MATCHES "i[3456]86") OR (${CMAKE_SYSTEM_PROCESSOR}
endif()

if((${CMAKE_SYSTEM_PROCESSOR} MATCHES "armv[0-9]+"))
set(CPU_TYPE "arm")
if(${CMAKE_SIZEOF_VOID_P} EQUAL 4)
add_definitions(-DEDB_ARM32)
elseif(${CMAKE_SIZEOF_VOID_P} EQUAL 8)
Expand All @@ -96,6 +97,18 @@ if((${CMAKE_SYSTEM_PROCESSOR} MATCHES "armv[0-9]+"))
include_directories("include/arch/arm-generic")
endif()

if(${CPU_TYPE} STREQUAL "x86")
pkg_check_modules(GDTOA gdtoa-desktop)
if(NOT GDTOA_FOUND)
message(WARNING "gdtoa-desktop package wasn't found. 80-bit floating-point values will be showed with max_digits10 digits of precision instead of shortest representation.")
else()
add_definitions("-DHAVE_GDTOA")
include_directories(${GDTOA_INCLUDE_DIRS})
link_directories(${GDTOA_LIBRARY_DIRS})
endif()
endif()


if ((${CMAKE_CXX_COMPILER_ID} STREQUAL "Clang") OR (${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU"))
if(ENABLE_ASAN)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=address") # -fsanitize-address-use-after-scope
Expand Down
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ set_property(TARGET edb PROPERTY CXX_EXTENSIONS OFF)
set_property(TARGET edb PROPERTY CXX_STANDARD 14)
set_target_properties(edb PROPERTIES ENABLE_EXPORTS 1)

target_link_libraries(edb ${CAPSTONE_LIBRARIES} Qt5::Widgets Qt5::Xml Qt5::XmlPatterns Qt5::Svg ${GRAPHVIZ_LIBRARIES} ${DOUBLE_CONVERSION_LIBRARIES})
target_link_libraries(edb ${CAPSTONE_LIBRARIES} Qt5::Widgets Qt5::Xml Qt5::XmlPatterns Qt5::Svg ${GRAPHVIZ_LIBRARIES} ${DOUBLE_CONVERSION_LIBRARIES} ${GDTOA_LIBRARIES})

target_include_directories (edb PRIVATE
"capstone-edb"
Expand Down
14 changes: 14 additions & 0 deletions src/FloatX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifdef HAVE_DOUBLE_CONVERSION
#include <double-conversion/double-conversion.h>
#endif
#ifdef HAVE_GDTOA
#include <gdtoa-desktop.h>
#endif

template<typename T>
struct SpecialValues;
Expand Down Expand Up @@ -331,6 +334,17 @@ QString formatFloat(Float value)
return result;
}
}
#endif
#ifdef HAVE_GDTOA
if(std::is_same<Float, edb::value80>::value)
{
char buffer[64]={};
gdtoa_g_xfmt(buffer, &value, -1, sizeof buffer);
const QString result=buffer;
if(result.size()==1 && result[0].isDigit())
return result+".0"; // avoid printing small whole numbers as integers
return result;
}
#endif
std::ostringstream ss;
ss << std::setprecision(std::numeric_limits<decltype(toFloatValue(value))>::max_digits10) << toFloatValue(value);
Expand Down

0 comments on commit 872c9c1

Please sign in to comment.