
(FPCore (s u) :precision binary32 (* s (log (/ 1.0 (- 1.0 (* 4.0 u))))))
float code(float s, float u) {
return s * logf((1.0f / (1.0f - (4.0f * u))));
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = s * log((1.0e0 / (1.0e0 - (4.0e0 * u))))
end function
function code(s, u) return Float32(s * log(Float32(Float32(1.0) / Float32(Float32(1.0) - Float32(Float32(4.0) * u))))) end
function tmp = code(s, u) tmp = s * log((single(1.0) / (single(1.0) - (single(4.0) * u)))); end
\begin{array}{l}
\\
s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right)
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (s u) :precision binary32 (* s (log (/ 1.0 (- 1.0 (* 4.0 u))))))
float code(float s, float u) {
return s * logf((1.0f / (1.0f - (4.0f * u))));
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = s * log((1.0e0 / (1.0e0 - (4.0e0 * u))))
end function
function code(s, u) return Float32(s * log(Float32(Float32(1.0) / Float32(Float32(1.0) - Float32(Float32(4.0) * u))))) end
function tmp = code(s, u) tmp = s * log((single(1.0) / (single(1.0) - (single(4.0) * u)))); end
\begin{array}{l}
\\
s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right)
\end{array}
(FPCore (s u) :precision binary32 (if (<= u 0.0007999999797903001) (* s (- (* (* u u) 8.0) (* -4.0 u))) (* s (log (/ 1.0 (- 1.0 (* 4.0 u)))))))
float code(float s, float u) {
float tmp;
if (u <= 0.0007999999797903001f) {
tmp = s * (((u * u) * 8.0f) - (-4.0f * u));
} else {
tmp = s * logf((1.0f / (1.0f - (4.0f * u))));
}
return tmp;
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
real(4) :: tmp
if (u <= 0.0007999999797903001e0) then
tmp = s * (((u * u) * 8.0e0) - ((-4.0e0) * u))
else
tmp = s * log((1.0e0 / (1.0e0 - (4.0e0 * u))))
end if
code = tmp
end function
function code(s, u) tmp = Float32(0.0) if (u <= Float32(0.0007999999797903001)) tmp = Float32(s * Float32(Float32(Float32(u * u) * Float32(8.0)) - Float32(Float32(-4.0) * u))); else tmp = Float32(s * log(Float32(Float32(1.0) / Float32(Float32(1.0) - Float32(Float32(4.0) * u))))); end return tmp end
function tmp_2 = code(s, u) tmp = single(0.0); if (u <= single(0.0007999999797903001)) tmp = s * (((u * u) * single(8.0)) - (single(-4.0) * u)); else tmp = s * log((single(1.0) / (single(1.0) - (single(4.0) * u)))); end tmp_2 = tmp; end
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;u \leq 0.0007999999797903001:\\
\;\;\;\;s \cdot \left(\left(u \cdot u\right) \cdot 8 - -4 \cdot u\right)\\
\mathbf{else}:\\
\;\;\;\;s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right)\\
\end{array}
\end{array}
if u < 7.9999998e-4Initial program 49.5%
Taylor expanded in u around 0
lower-*.f3286.1
Applied rewrites86.1%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3286.1
Applied rewrites86.1%
Applied rewrites98.2%
if 7.9999998e-4 < u Initial program 90.9%
(FPCore (s u) :precision binary32 (* s (- (* (* u u) 8.0) (* -4.0 u))))
float code(float s, float u) {
return s * (((u * u) * 8.0f) - (-4.0f * u));
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = s * (((u * u) * 8.0e0) - ((-4.0e0) * u))
end function
function code(s, u) return Float32(s * Float32(Float32(Float32(u * u) * Float32(8.0)) - Float32(Float32(-4.0) * u))) end
function tmp = code(s, u) tmp = s * (((u * u) * single(8.0)) - (single(-4.0) * u)); end
\begin{array}{l}
\\
s \cdot \left(\left(u \cdot u\right) \cdot 8 - -4 \cdot u\right)
\end{array}
Initial program 60.0%
Taylor expanded in u around 0
lower-*.f3275.0
Applied rewrites75.0%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3275.0
Applied rewrites75.0%
Applied rewrites88.0%
(FPCore (s u) :precision binary32 (* s (* (- 4.0 (* -8.0 u)) u)))
float code(float s, float u) {
return s * ((4.0f - (-8.0f * u)) * u);
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = s * ((4.0e0 - ((-8.0e0) * u)) * u)
end function
function code(s, u) return Float32(s * Float32(Float32(Float32(4.0) - Float32(Float32(-8.0) * u)) * u)) end
function tmp = code(s, u) tmp = s * ((single(4.0) - (single(-8.0) * u)) * u); end
\begin{array}{l}
\\
s \cdot \left(\left(4 - -8 \cdot u\right) \cdot u\right)
\end{array}
Initial program 60.0%
Taylor expanded in u around 0
lower-*.f3275.0
Applied rewrites75.0%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3275.0
Applied rewrites75.0%
Applied rewrites87.8%
(FPCore (s u) :precision binary32 (* s (* 4.0 u)))
float code(float s, float u) {
return s * (4.0f * u);
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = s * (4.0e0 * u)
end function
function code(s, u) return Float32(s * Float32(Float32(4.0) * u)) end
function tmp = code(s, u) tmp = s * (single(4.0) * u); end
\begin{array}{l}
\\
s \cdot \left(4 \cdot u\right)
\end{array}
Initial program 60.0%
Taylor expanded in u around 0
lower-*.f3275.0
Applied rewrites75.0%
herbie shell --seed 2024339
(FPCore (s u)
:name "Disney BSSRDF, sample scattering profile, lower"
:precision binary32
:pre (and (and (<= 0.0 s) (<= s 256.0)) (and (<= 2.328306437e-10 u) (<= u 0.25)))
(* s (log (/ 1.0 (- 1.0 (* 4.0 u))))))