
(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 6 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.004000000189989805) (* (- s) (* (- (* (- (* -21.333333333333332 u) 8.0) u) 4.0) u)) (* s (log (/ 1.0 (- 1.0 (* 4.0 u)))))))
float code(float s, float u) {
float tmp;
if (u <= 0.004000000189989805f) {
tmp = -s * (((((-21.333333333333332f * u) - 8.0f) * u) - 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.004000000189989805e0) then
tmp = -s * ((((((-21.333333333333332e0) * u) - 8.0e0) * u) - 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.004000000189989805)) tmp = Float32(Float32(-s) * Float32(Float32(Float32(Float32(Float32(Float32(-21.333333333333332) * u) - Float32(8.0)) * u) - 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.004000000189989805)) tmp = -s * (((((single(-21.333333333333332) * u) - single(8.0)) * u) - 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.004000000189989805:\\
\;\;\;\;\left(-s\right) \cdot \left(\left(\left(-21.333333333333332 \cdot u - 8\right) \cdot u - 4\right) \cdot u\right)\\
\mathbf{else}:\\
\;\;\;\;s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right)\\
\end{array}
\end{array}
if u < 0.00400000019Initial program 53.3%
Taylor expanded in u around 0
lower-*.f3281.5
Applied rewrites81.5%
Applied rewrites81.1%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f32N/A
lower-*.f32N/A
lower-*.f32N/A
lower-*.f3281.5
Applied rewrites81.3%
Taylor expanded in s around -inf
Applied rewrites98.8%
if 0.00400000019 < u Initial program 94.3%
(FPCore (s u) :precision binary32 (* (- s) (* (- (* (- (* -21.333333333333332 u) 8.0) u) 4.0) u)))
float code(float s, float u) {
return -s * (((((-21.333333333333332f * u) - 8.0f) * u) - 4.0f) * u);
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = -s * ((((((-21.333333333333332e0) * u) - 8.0e0) * u) - 4.0e0) * u)
end function
function code(s, u) return Float32(Float32(-s) * Float32(Float32(Float32(Float32(Float32(Float32(-21.333333333333332) * u) - Float32(8.0)) * u) - Float32(4.0)) * u)) end
function tmp = code(s, u) tmp = -s * (((((single(-21.333333333333332) * u) - single(8.0)) * u) - single(4.0)) * u); end
\begin{array}{l}
\\
\left(-s\right) \cdot \left(\left(\left(-21.333333333333332 \cdot u - 8\right) \cdot u - 4\right) \cdot u\right)
\end{array}
Initial program 61.3%
Taylor expanded in u around 0
lower-*.f3273.1
Applied rewrites73.1%
Applied rewrites72.8%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f32N/A
lower-*.f32N/A
lower-*.f32N/A
lower-*.f3273.1
Applied rewrites72.9%
Taylor expanded in s around -inf
Applied rewrites91.2%
(FPCore (s u) :precision binary32 (* s (+ (* (* 8.0 u) u) (* 4.0 u))))
float code(float s, float u) {
return s * (((8.0f * u) * u) + (4.0f * u));
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = s * (((8.0e0 * u) * u) + (4.0e0 * u))
end function
function code(s, u) return Float32(s * Float32(Float32(Float32(Float32(8.0) * u) * u) + Float32(Float32(4.0) * u))) end
function tmp = code(s, u) tmp = s * (((single(8.0) * u) * u) + (single(4.0) * u)); end
\begin{array}{l}
\\
s \cdot \left(\left(8 \cdot u\right) \cdot u + 4 \cdot u\right)
\end{array}
Initial program 61.3%
Taylor expanded in u around 0
lower-*.f3273.1
Applied rewrites73.1%
Applied rewrites72.8%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3273.1
Applied rewrites72.9%
Applied rewrites86.7%
(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 61.3%
Taylor expanded in u around 0
lower-*.f3273.1
Applied rewrites73.1%
Applied rewrites72.8%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3273.1
Applied rewrites72.9%
Applied rewrites86.6%
(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 61.3%
Taylor expanded in u around 0
lower-*.f3273.1
Applied rewrites73.1%
(FPCore (s u) :precision binary32 (* (* u s) 4.0))
float code(float s, float u) {
return (u * s) * 4.0f;
}
real(4) function code(s, u)
real(4), intent (in) :: s
real(4), intent (in) :: u
code = (u * s) * 4.0e0
end function
function code(s, u) return Float32(Float32(u * s) * Float32(4.0)) end
function tmp = code(s, u) tmp = (u * s) * single(4.0); end
\begin{array}{l}
\\
\left(u \cdot s\right) \cdot 4
\end{array}
Initial program 61.3%
Taylor expanded in u around 0
lower-*.f3273.1
Applied rewrites73.1%
Applied rewrites72.8%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f32N/A
lower-*.f32N/A
lower-*.f32N/A
lower-*.f3273.1
Applied rewrites72.9%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lower-*.f3272.8
Applied rewrites72.8%
herbie shell --seed 2024337
(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))))))