Skip to content

Commit e0102a6

Browse files
committed
Stabilize DWA LUT test half-distance compare on i686
Add `ieeeFloatAbsDiffHalf()` using volatile float steps so each half→float conversion and subtraction rounds to IEEE binary32 before fabs. Without this, i686 387 FPU extended precision can pick a different closest candidate than `dwaQuantTables.h` (built with typical SSE float math), breaking `testLutHeader`. Made with Cursor Signed-off-by: Cary Phillips <cary@ilm.com>
1 parent f5bf7c2 commit e0102a6

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

src/test/OpenEXRCoreTest/compressionTables.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "IlmThreadSemaphore.h"
3333

3434
#include <cstddef>
35+
#include <cmath>
3536
#include <math.h>
3637
#include <stdio.h>
3738
#include <stdlib.h>
@@ -68,6 +69,19 @@ using namespace OPENEXR_IMF_NAMESPACE;
6869
namespace
6970
{
7071

72+
// Absolute |float(a)-float(b)| for half values, using volatile intermediates so
73+
// each step rounds to IEEE binary32. Without this, i686 defaults (387 stack) can
74+
// keep extra precision and change which candidate "wins" vs tables built with
75+
// SSE float math — no special compile flags required for users running tests.
76+
static inline float
77+
ieeeFloatAbsDiffHalf (const half& a, const half& b)
78+
{
79+
volatile float af = static_cast<float> (a);
80+
volatile float bf = static_cast<float> (b);
81+
volatile float d = af - bf;
82+
return std::fabs (static_cast<float> (d));
83+
}
84+
7185
class LutHeaderWorker
7286
{
7387
public:
@@ -160,8 +174,8 @@ class LutHeaderWorker
160174

161175
tmpHalf.setBits (i);
162176

163-
if (fabs ((float) inputHalf - (float) tmpHalf) <
164-
fabs ((float) inputHalf - (float) closestHalf))
177+
if (ieeeFloatAbsDiffHalf (inputHalf, tmpHalf) <
178+
ieeeFloatAbsDiffHalf (inputHalf, closestHalf))
165179
{
166180
closestHalf = tmpHalf;
167181
}

0 commit comments

Comments
 (0)