diff --git a/.build_number b/.build_number index 00e37d62b..4f6811f46 100644 --- a/.build_number +++ b/.build_number @@ -1 +1 @@ -1596 +1597 diff --git a/src/libtriton/arch/arm/aarch64/aarch64Cpu.cpp b/src/libtriton/arch/arm/aarch64/aarch64Cpu.cpp index e42f2c610..da9f2093c 100644 --- a/src/libtriton/arch/arm/aarch64/aarch64Cpu.cpp +++ b/src/libtriton/arch/arm/aarch64/aarch64Cpu.cpp @@ -543,8 +543,8 @@ namespace triton { imm.setShiftValue(op->shift.value); inst.operands.push_back(triton::arch::OperandWrapper(imm)); - } break; + } default: /* NOTE: CIMM, and missing one are not supported yet. */ diff --git a/src/libtriton/arch/immediate.cpp b/src/libtriton/arch/immediate.cpp index a3493d2cc..40616e0f3 100644 --- a/src/libtriton/arch/immediate.cpp +++ b/src/libtriton/arch/immediate.cpp @@ -30,35 +30,33 @@ namespace triton { this->setValue(value, size); } + Immediate::Immediate(double value, triton::uint32 size /* bytes */, triton::arch::endianness_e platform_endianness) { triton::uint64 imm_value; - auto need_swap = sys_endianness != platform_endianness; - if (size == sizeof(double)) { - static_assert(sizeof(double) == sizeof(triton::uint64), - "Unexpected double type size"); + if (size == sizeof(double)) { + static_assert(sizeof(double) == sizeof(triton::uint64), "Unexpected double type size"); std::memcpy(&imm_value, &value, sizeof(double)); if (need_swap) { imm_value = utils::byteswap(imm_value); } } + else if (size == sizeof(float)) { // single-precision float fvalue = static_cast(value); triton::uint32 repr; - static_assert(sizeof(float) == sizeof(uint32_t), - "Unexpected float type size"); + static_assert(sizeof(float) == sizeof(uint32_t), "Unexpected float type size"); std::memcpy(&repr, &fvalue, sizeof(float)); - - imm_value = need_swap ? static_cast(utils::byteswap(repr)) - : static_cast(repr); - } else if (size == 2) { // half-precision + imm_value = need_swap ? static_cast(utils::byteswap(repr)) : static_cast(repr); + } + + else if (size == 2) { // half-precision float fvalue = static_cast(value); - triton::uint16 repr = sf::f32_to_f16(fvalue); - imm_value = need_swap ? static_cast(utils::byteswap(repr)) - : static_cast(repr); - + triton::uint16 repr = triton::sf::f32_to_f16(fvalue); + imm_value = need_swap ? static_cast(utils::byteswap(repr)) : static_cast(repr); } + else { throw triton::exceptions::Immediate("Immediate::Immediate(double): Invalid encoding size."); } diff --git a/src/libtriton/includes/triton/coreUtils.hpp b/src/libtriton/includes/triton/coreUtils.hpp index 660523cb9..b9aaf1579 100644 --- a/src/libtriton/includes/triton/coreUtils.hpp +++ b/src/libtriton/includes/triton/coreUtils.hpp @@ -83,10 +83,7 @@ namespace triton { template <> TRITON_EXPORT triton::uint512 cast(const triton::uint80& value); template - std::enable_if_t< - std::is_unsigned_v, - T> - byteswap(T value) { + std::enable_if_t, T> byteswap(T value) { std::array repr; std::memcpy(&repr, &value, sizeof(value)); std::reverse(repr.begin(), repr.end()); diff --git a/src/libtriton/includes/triton/softfloat.hpp b/src/libtriton/includes/triton/softfloat.hpp index 6c47fa127..fc2df6abf 100644 --- a/src/libtriton/includes/triton/softfloat.hpp +++ b/src/libtriton/includes/triton/softfloat.hpp @@ -23,12 +23,13 @@ namespace triton { * \addtogroup softfloat * @{ */ - - //! Cast 32-bit floating point value to 16-bit according to IEEE-754 - auto f32_to_f16(float value) -> uint16_t; - } + //! Cast 32-bit floating point value to 16-bit according to IEEE-754 + auto f32_to_f16(float value) -> uint16_t; -} + /*! @} End of softfloat namespace */ + }; +/*! @} End of triton namespace */ +}; -#endif /* TRITON_SOFTFLOAT_HPP */ \ No newline at end of file +#endif /* TRITON_SOFTFLOAT_HPP */ diff --git a/src/libtriton/utils/softfloat.cpp b/src/libtriton/utils/softfloat.cpp index 8781b5d4a..be02c0cbd 100644 --- a/src/libtriton/utils/softfloat.cpp +++ b/src/libtriton/utils/softfloat.cpp @@ -12,31 +12,38 @@ namespace triton { namespace sf { - auto f32_to_f16(float value) -> uint16_t { + uint16_t f32_to_f16(float value) { uint32_t f; - static_assert(sizeof(float) == sizeof(uint32_t), - "Unexpected float type size"); + + static_assert(sizeof(float) == sizeof(uint32_t), "Unexpected float type size"); std::memcpy(&f, &value, sizeof(uint32_t)); - uint16_t sign = (f >> 16) & 0x8000; - int16_t exponent = ((f >> 23) & 0xff) - 127 + 15; - uint16_t mantissa = (f >> 13) & 0x3ff; + + uint16_t sign = ((f >> 16) & 0x8000); + int16_t exponent = ((f >> 23) & 0xff) - 127 + 15; + uint16_t mantissa = ((f >> 13) & 0x3ff); + if (exponent <= 0) { if (exponent < -10) { return sign; } mantissa = (mantissa | 0x400) >> (1 - exponent); return sign | mantissa; - } else if (exponent == 0xff - (127 - 15)) { + } + + else if (exponent == 0xff - (127 - 15)) { if (mantissa) { return sign | 0x7fff; } else { return sign | 0x7c00; } - } else if (exponent > 30) { + } + + else if (exponent > 30) { return sign | 0x7c00; } + return sign | (exponent << 10) | mantissa; } - } /* sf namespace */ -} /* triton namespace */ \ No newline at end of file + }; /* sf namespace */ +}; /* triton namespace */