Skip to content

Commit

Permalink
Manually hoist loop invariants in Imf::bytesPerDeepLineTable.
Browse files Browse the repository at this point in the history
This is primarily done to avoid a call to pixelTypeSize within the inner loop.
In particular, gcc makes the call to pixelTypeSize via PLT indirection so it
may have arbitrary side-effects (i.e. ELF symbol interposition strikes again)
and may not be moved out of the loop by the compiler.
  • Loading branch information
John Loy authored and nickrasmussen committed Aug 8, 2018
1 parent 5aa0afd commit 71b8109
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions OpenEXR/IlmImf/ImfMisc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,14 +147,18 @@ bytesPerDeepLineTable (const Header &header,
c != channels.end();
++c)
{
const int ySampling = c.channel().ySampling;
const int xSampling = c.channel().xSampling;
const int pixelSize = pixelTypeSize (c.channel().type);

for (int y = minY; y <= maxY; ++y)
if (modp (y, c.channel().ySampling) == 0)
if (modp (y, ySampling) == 0)
{
int nBytes = 0;
for (int x = dataWindow.min.x; x <= dataWindow.max.x; x++)
{
if (modp (x, c.channel().xSampling) == 0)
nBytes += pixelTypeSize (c.channel().type) *
if (modp (x, xSampling) == 0)
nBytes += pixelSize *
sampleCount(base, xStride, yStride, x, y);
}
bytesPerLine[y - dataWindow.min.y] += nBytes;
Expand Down

0 comments on commit 71b8109

Please sign in to comment.