Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove dead code from half #179

Merged
merged 2 commits into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/Imath/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ imath_define_library(Imath
ImathFun.cpp
ImathMatrixAlgo.cpp
toFloat.h
eLut.h
half.cpp
HEADERS
ImathBoxAlgo.h
Expand Down
82 changes: 0 additions & 82 deletions src/Imath/eLut.cpp

This file was deleted.

164 changes: 0 additions & 164 deletions src/Imath/half.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,178 +37,14 @@ using namespace std;
const imath_half_uif_t imath_half_to_float_table_data[1 << 16] =
#include "toFloat.h"

const uint16_t imath_float_half_exp_table_data[1 << 9] =
#include "eLut.h"

extern "C" {
EXPORT_CONST const imath_half_uif_t *imath_half_to_float_table = imath_half_to_float_table_data;
EXPORT_CONST const uint16_t *imath_float_half_exp_table = imath_float_half_exp_table_data;
} // extern "C"

#endif

// clang-format on

//#ifdef IMATH_USE_ORIGINAL_HALF_IMPLEMENTATION
//-----------------------------------------------
// Overflow handler for float-to-half conversion;
// generates a hardware floating-point overflow,
// which may be trapped by the operating system.
//-----------------------------------------------

static float
half_overflow() IMATH_NOEXCEPT
{
float f = 1e10;

for (int i = 0; i < 10; i++)
f *= f; // this will overflow before the for loop terminates

return f;
}

//-----------------------------------------------------
// Float-to-half conversion -- general case, including
// zeroes, denormalized numbers and exponent overflows.
//-----------------------------------------------------

IMATH_EXPORT uint16_t
half::long_convert (int i) IMATH_NOEXCEPT
{
//
// Our floating point number, f, is represented by the bit
// pattern in integer i. Disassemble that bit pattern into
// the sign, s, the exponent, e, and the significand, m.
// Shift s into the position where it will go in in the
// resulting half number.
// Adjust e, accounting for the different exponent bias
// of float and half (127 versus 15).
//

int s = (i >> 16) & 0x00008000;
int e = ((i >> 23) & 0x000000ff) - (127 - 15);
int m = i & 0x007fffff;

//
// Now reassemble s, e and m into a half:
//

if (e <= 0)
{
if (e < -10)
{
//
// E is less than -10. The absolute value of f is
// less than HALF_DENORM_MIN (f may be a small normalized
// float, a denormalized float or a zero).
//
// We convert f to a half zero with the same sign as f.
//

return s;
}

//
// E is between -10 and 0. F is a normalized float
// whose magnitude is less than HALF_NRM_MIN.
//
// We convert f to a denormalized half.
//

//
// Add an explicit leading 1 to the significand.
//

m = m | 0x00800000;

//
// Round to m to the nearest (10+e)-bit value (with e between
// -10 and 0); in case of a tie, round to the nearest even value.
//
// Rounding may cause the significand to overflow and make
// our number normalized. Because of the way a half's bits
// are laid out, we don't have to treat this case separately;
// the code below will handle it correctly.
//

int t = 14 - e;
int a = (1 << (t - 1)) - 1;
int b = (m >> t) & 1;

m = (m + a + b) >> t;

//
// Assemble the half from s, e (zero) and m.
//

return s | m;
}
else if (e == 0xff - (127 - 15))
{
if (m == 0)
{
//
// F is an infinity; convert f to a half
// infinity with the same sign as f.
//

return s | 0x7c00;
}
else
{
//
// F is a NAN; we produce a half NAN that preserves
// the sign bit and the 10 leftmost bits of the
// significand of f, with one exception: If the 10
// leftmost bits are all zero, the NAN would turn
// into an infinity, so we have to set at least one
// bit in the significand.
//

m >>= 13;
return s | 0x7c00 | m | (m == 0);
}
}
else
{
//
// E is greater than zero. F is a normalized float.
// We try to convert f to a normalized half.
//

//
// Round to m to the nearest 10-bit value. In case of
// a tie, round to the nearest even value.
//

m = m + 0x00000fff + ((m >> 13) & 1);

if (m & 0x00800000)
{
m = 0; // overflow in significand,
e += 1; // adjust exponent
}

//
// Handle exponent overflow
//

if (e > 30)
{
half_overflow (); // Cause a hardware floating point overflow;
return s | 0x7c00; // if this returns, the half becomes an
} // infinity with the same sign as f.

//
// Assemble the half from s, e and m.
//

return s | (e << 10) | (m >> 13);
}
}

//#endif

//---------------------
// Stream I/O operators
//---------------------
Expand Down
13 changes: 0 additions & 13 deletions src/Imath/half.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,15 +144,6 @@ extern
# endif
IMATH_EXPORT const imath_half_uif_t* imath_half_to_float_table;

// This is still exposed as a symbol, but is no longer actively used
// other than within the performance test @sa half_perf_test.cpp
// TODO: consider deprecating and removing it
# if defined(__cplusplus)
extern "C"
# else
extern
# endif
IMATH_EXPORT const uint16_t* imath_float_half_exp_table;
#endif

////////////////////////////////////////
Expand Down Expand Up @@ -180,8 +171,6 @@ imath_half_to_float (imath_half_bits_t h)
// (1.06 vs 1.08 ns/call) to avoid the constants and just do 4
// shifts.
//
//uint32_t hexpmant = (h & ~0x8000) << 13;
//v.i = (h & 0x8000) << 16;
uint32_t hexpmant = ( (uint32_t)(h) << 17 ) >> 4;
v.i = ((uint32_t)(h >> 15)) << 31;

cary-ilm marked this conversation as resolved.
Show resolved Hide resolved
Expand Down Expand Up @@ -505,8 +494,6 @@ class IMATH_EXPORT_TYPE half
"Assumption about the size of floats correct");
using uif = imath_half_uif;

// preserved for legacy conversion
IMATH_EXPORT static uint16_t long_convert ( int i ) IMATH_NOEXCEPT;
private:

constexpr uint16_t mantissa() const IMATH_NOEXCEPT;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/ImathTest/half_c_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static const c_half_uif half_to_float[1 << 16] =
#include "../Imath/toFloat.h"

static const unsigned short half_eLut[1 << 9] =
#include "../Imath/eLut.h"
#include "eLut.h"

static short exp_long_convert (int i)
{
Expand Down
Loading