
(FPCore (s u)
: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))))))float code(float s, float u) {
return s * logf((1.0f / (1.0f - (4.0f * u))));
}
real(4) function code(s, u)
use fmin_fmax_functions
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
s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right)
Herbie found 15 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (s u)
: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))))))float code(float s, float u) {
return s * logf((1.0f / (1.0f - (4.0f * u))));
}
real(4) function code(s, u)
use fmin_fmax_functions
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
s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right)
(FPCore (s u)
:precision binary32
:pre (and (and (<= 0.0 s) (<= s 256.0))
(and (<= 2.328306437e-10 u) (<= u 0.25)))
(* -1.0 (* s (log1p (* -4.0 u)))))float code(float s, float u) {
return -1.0f * (s * log1pf((-4.0f * u)));
}
function code(s, u) return Float32(Float32(-1.0) * Float32(s * log1p(Float32(Float32(-4.0) * u)))) end
-1 \cdot \left(s \cdot \mathsf{log1p}\left(-4 \cdot u\right)\right)
Initial program 61.5%
Taylor expanded in u around 0
Applied rewrites91.1%
Applied rewrites91.1%
Taylor expanded in s around 0
Applied rewrites63.9%
Applied rewrites99.3%
(FPCore (s u)
:precision binary32
:pre (and (and (<= 0.0 s) (<= s 256.0))
(and (<= 2.328306437e-10 u) (<= u 0.25)))
(if (<= (* 4.0 u) 0.014499999582767487)
(* s (fma (* u u) (fma u 21.333333333333332 8.0) (* u 4.0)))
(* (log (fma u -4.0 1.0)) (- s))))float code(float s, float u) {
float tmp;
if ((4.0f * u) <= 0.014499999582767487f) {
tmp = s * fmaf((u * u), fmaf(u, 21.333333333333332f, 8.0f), (u * 4.0f));
} else {
tmp = logf(fmaf(u, -4.0f, 1.0f)) * -s;
}
return tmp;
}
function code(s, u) tmp = Float32(0.0) if (Float32(Float32(4.0) * u) <= Float32(0.014499999582767487)) tmp = Float32(s * fma(Float32(u * u), fma(u, Float32(21.333333333333332), Float32(8.0)), Float32(u * Float32(4.0)))); else tmp = Float32(log(fma(u, Float32(-4.0), Float32(1.0))) * Float32(-s)); end return tmp end
\begin{array}{l}
\mathbf{if}\;4 \cdot u \leq 0.014499999582767487:\\
\;\;\;\;s \cdot \mathsf{fma}\left(u \cdot u, \mathsf{fma}\left(u, 21.333333333333332, 8\right), u \cdot 4\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(\mathsf{fma}\left(u, -4, 1\right)\right) \cdot \left(-s\right)\\
\end{array}
if (*.f32 #s(literal 4 binary32) u) < 0.0144999996Initial program 61.5%
Taylor expanded in u around 0
Applied rewrites91.1%
Applied rewrites91.3%
if 0.0144999996 < (*.f32 #s(literal 4 binary32) u) Initial program 61.5%
Taylor expanded in u around 0
Applied rewrites91.1%
Applied rewrites91.1%
Taylor expanded in s around 0
Applied rewrites63.9%
Applied rewrites63.9%
(FPCore (s u)
:precision binary32
:pre (and (and (<= 0.0 s) (<= s 256.0))
(and (<= 2.328306437e-10 u) (<= u 0.25)))
(if (<= (* 4.0 u) 0.014499999582767487)
(* u (fma 4.0 s (* u (* s (fma u 21.333333333333332 8.0)))))
(* (log (fma u -4.0 1.0)) (- s))))float code(float s, float u) {
float tmp;
if ((4.0f * u) <= 0.014499999582767487f) {
tmp = u * fmaf(4.0f, s, (u * (s * fmaf(u, 21.333333333333332f, 8.0f))));
} else {
tmp = logf(fmaf(u, -4.0f, 1.0f)) * -s;
}
return tmp;
}
function code(s, u) tmp = Float32(0.0) if (Float32(Float32(4.0) * u) <= Float32(0.014499999582767487)) tmp = Float32(u * fma(Float32(4.0), s, Float32(u * Float32(s * fma(u, Float32(21.333333333333332), Float32(8.0)))))); else tmp = Float32(log(fma(u, Float32(-4.0), Float32(1.0))) * Float32(-s)); end return tmp end
\begin{array}{l}
\mathbf{if}\;4 \cdot u \leq 0.014499999582767487:\\
\;\;\;\;u \cdot \mathsf{fma}\left(4, s, u \cdot \left(s \cdot \mathsf{fma}\left(u, 21.333333333333332, 8\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(\mathsf{fma}\left(u, -4, 1\right)\right) \cdot \left(-s\right)\\
\end{array}
if (*.f32 #s(literal 4 binary32) u) < 0.0144999996Initial program 61.5%
Taylor expanded in u around 0
Applied rewrites91.3%
Taylor expanded in s around 0
Applied rewrites91.3%
Applied rewrites91.3%
if 0.0144999996 < (*.f32 #s(literal 4 binary32) u) Initial program 61.5%
Taylor expanded in u around 0
Applied rewrites91.1%
Applied rewrites91.1%
Taylor expanded in s around 0
Applied rewrites63.9%
Applied rewrites63.9%
(FPCore (s u)
:precision binary32
:pre (and (and (<= 0.0 s) (<= s 256.0))
(and (<= 2.328306437e-10 u) (<= u 0.25)))
(if (<= (* 4.0 u) 0.014499999582767487)
(* (* s (fma (fma u 21.333333333333332 8.0) u 4.0)) u)
(* (log (fma u -4.0 1.0)) (- s))))float code(float s, float u) {
float tmp;
if ((4.0f * u) <= 0.014499999582767487f) {
tmp = (s * fmaf(fmaf(u, 21.333333333333332f, 8.0f), u, 4.0f)) * u;
} else {
tmp = logf(fmaf(u, -4.0f, 1.0f)) * -s;
}
return tmp;
}
function code(s, u) tmp = Float32(0.0) if (Float32(Float32(4.0) * u) <= Float32(0.014499999582767487)) tmp = Float32(Float32(s * fma(fma(u, Float32(21.333333333333332), Float32(8.0)), u, Float32(4.0))) * u); else tmp = Float32(log(fma(u, Float32(-4.0), Float32(1.0))) * Float32(-s)); end return tmp end
\begin{array}{l}
\mathbf{if}\;4 \cdot u \leq 0.014499999582767487:\\
\;\;\;\;\left(s \cdot \mathsf{fma}\left(\mathsf{fma}\left(u, 21.333333333333332, 8\right), u, 4\right)\right) \cdot u\\
\mathbf{else}:\\
\;\;\;\;\log \left(\mathsf{fma}\left(u, -4, 1\right)\right) \cdot \left(-s\right)\\
\end{array}
if (*.f32 #s(literal 4 binary32) u) < 0.0144999996Initial program 61.5%
Taylor expanded in u around 0
Applied rewrites91.3%
Applied rewrites91.0%
Applied rewrites91.1%
if 0.0144999996 < (*.f32 #s(literal 4 binary32) u) Initial program 61.5%
Taylor expanded in u around 0
Applied rewrites91.1%
Applied rewrites91.1%
Taylor expanded in s around 0
Applied rewrites63.9%
Applied rewrites63.9%
(FPCore (s u)
:precision binary32
:pre (and (and (<= 0.0 s) (<= s 256.0))
(and (<= 2.328306437e-10 u) (<= u 0.25)))
(if (<= (* 4.0 u) 0.014499999582767487)
(* (* s u) (fma (fma u 21.333333333333332 8.0) u 4.0))
(* (log (fma u -4.0 1.0)) (- s))))float code(float s, float u) {
float tmp;
if ((4.0f * u) <= 0.014499999582767487f) {
tmp = (s * u) * fmaf(fmaf(u, 21.333333333333332f, 8.0f), u, 4.0f);
} else {
tmp = logf(fmaf(u, -4.0f, 1.0f)) * -s;
}
return tmp;
}
function code(s, u) tmp = Float32(0.0) if (Float32(Float32(4.0) * u) <= Float32(0.014499999582767487)) tmp = Float32(Float32(s * u) * fma(fma(u, Float32(21.333333333333332), Float32(8.0)), u, Float32(4.0))); else tmp = Float32(log(fma(u, Float32(-4.0), Float32(1.0))) * Float32(-s)); end return tmp end
\begin{array}{l}
\mathbf{if}\;4 \cdot u \leq 0.014499999582767487:\\
\;\;\;\;\left(s \cdot u\right) \cdot \mathsf{fma}\left(\mathsf{fma}\left(u, 21.333333333333332, 8\right), u, 4\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(\mathsf{fma}\left(u, -4, 1\right)\right) \cdot \left(-s\right)\\
\end{array}
if (*.f32 #s(literal 4 binary32) u) < 0.0144999996Initial program 61.5%
Taylor expanded in u around 0
Applied rewrites91.3%
Applied rewrites91.0%
Applied rewrites91.1%
Applied rewrites90.8%
if 0.0144999996 < (*.f32 #s(literal 4 binary32) u) Initial program 61.5%
Taylor expanded in u around 0
Applied rewrites91.1%
Applied rewrites91.1%
Taylor expanded in s around 0
Applied rewrites63.9%
Applied rewrites63.9%
(FPCore (s u)
:precision binary32
:pre (and (and (<= 0.0 s) (<= s 256.0))
(and (<= 2.328306437e-10 u) (<= u 0.25)))
(if (<= (* 4.0 u) 0.004000000189989805)
(* u (fma 4.0 s (* 8.0 (* s u))))
(* (log (fma u -4.0 1.0)) (- s))))float code(float s, float u) {
float tmp;
if ((4.0f * u) <= 0.004000000189989805f) {
tmp = u * fmaf(4.0f, s, (8.0f * (s * u)));
} else {
tmp = logf(fmaf(u, -4.0f, 1.0f)) * -s;
}
return tmp;
}
function code(s, u) tmp = Float32(0.0) if (Float32(Float32(4.0) * u) <= Float32(0.004000000189989805)) tmp = Float32(u * fma(Float32(4.0), s, Float32(Float32(8.0) * Float32(s * u)))); else tmp = Float32(log(fma(u, Float32(-4.0), Float32(1.0))) * Float32(-s)); end return tmp end
\begin{array}{l}
\mathbf{if}\;4 \cdot u \leq 0.004000000189989805:\\
\;\;\;\;u \cdot \mathsf{fma}\left(4, s, 8 \cdot \left(s \cdot u\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\log \left(\mathsf{fma}\left(u, -4, 1\right)\right) \cdot \left(-s\right)\\
\end{array}
if (*.f32 #s(literal 4 binary32) u) < 0.00400000019Initial program 61.5%
Taylor expanded in u around 0
Applied rewrites86.9%
if 0.00400000019 < (*.f32 #s(literal 4 binary32) u) Initial program 61.5%
Taylor expanded in u around 0
Applied rewrites91.1%
Applied rewrites91.1%
Taylor expanded in s around 0
Applied rewrites63.9%
Applied rewrites63.9%
(FPCore (s u)
:precision binary32
:pre (and (and (<= 0.0 s) (<= s 256.0))
(and (<= 2.328306437e-10 u) (<= u 0.25)))
(* u (fma 4.0 s (* 8.0 (* s u)))))float code(float s, float u) {
return u * fmaf(4.0f, s, (8.0f * (s * u)));
}
function code(s, u) return Float32(u * fma(Float32(4.0), s, Float32(Float32(8.0) * Float32(s * u)))) end
u \cdot \mathsf{fma}\left(4, s, 8 \cdot \left(s \cdot u\right)\right)
Initial program 61.5%
Taylor expanded in u around 0
Applied rewrites86.9%
(FPCore (s u)
:precision binary32
:pre (and (and (<= 0.0 s) (<= s 256.0))
(and (<= 2.328306437e-10 u) (<= u 0.25)))
(* (* s (fma u 8.0 4.0)) u))float code(float s, float u) {
return (s * fmaf(u, 8.0f, 4.0f)) * u;
}
function code(s, u) return Float32(Float32(s * fma(u, Float32(8.0), Float32(4.0))) * u) end
\left(s \cdot \mathsf{fma}\left(u, 8, 4\right)\right) \cdot u
Initial program 61.5%
Taylor expanded in u around 0
Applied rewrites86.9%
Applied rewrites87.2%
Applied rewrites86.7%
(FPCore (s u)
:precision binary32
:pre (and (and (<= 0.0 s) (<= s 256.0))
(and (<= 2.328306437e-10 u) (<= u 0.25)))
(* (* s u) (fma u 8.0 4.0)))float code(float s, float u) {
return (s * u) * fmaf(u, 8.0f, 4.0f);
}
function code(s, u) return Float32(Float32(s * u) * fma(u, Float32(8.0), Float32(4.0))) end
\left(s \cdot u\right) \cdot \mathsf{fma}\left(u, 8, 4\right)
Initial program 61.5%
Taylor expanded in u around 0
Applied rewrites86.9%
Applied rewrites87.2%
Applied rewrites86.7%
Applied rewrites86.4%
(FPCore (s u)
:precision binary32
:pre (and (and (<= 0.0 s) (<= s 256.0))
(and (<= 2.328306437e-10 u) (<= u 0.25)))
(* s (* u 4.0)))float code(float s, float u) {
return s * (u * 4.0f);
}
real(4) function code(s, u)
use fmin_fmax_functions
real(4), intent (in) :: s
real(4), intent (in) :: u
code = s * (u * 4.0e0)
end function
function code(s, u) return Float32(s * Float32(u * Float32(4.0))) end
function tmp = code(s, u) tmp = s * (u * single(4.0)); end
s \cdot \left(u \cdot 4\right)
Initial program 61.5%
Taylor expanded in u around 0
Applied rewrites86.7%
Taylor expanded in u around 0
Applied rewrites73.8%
(FPCore (s u)
:precision binary32
:pre (and (and (<= 0.0 s) (<= s 256.0))
(and (<= 2.328306437e-10 u) (<= u 0.25)))
(* 4.0 (* s u)))float code(float s, float u) {
return 4.0f * (s * u);
}
real(4) function code(s, u)
use fmin_fmax_functions
real(4), intent (in) :: s
real(4), intent (in) :: u
code = 4.0e0 * (s * u)
end function
function code(s, u) return Float32(Float32(4.0) * Float32(s * u)) end
function tmp = code(s, u) tmp = single(4.0) * (s * u); end
4 \cdot \left(s \cdot u\right)
Initial program 61.5%
Taylor expanded in u around 0
Applied rewrites73.6%
(FPCore (s u)
:precision binary32
:pre (and (and (<= 0.0 s) (<= s 256.0))
(and (<= 2.328306437e-10 u) (<= u 0.25)))
(if (<= s 4.307599612825561e-29) 0.0 (+ s s)))float code(float s, float u) {
float tmp;
if (s <= 4.307599612825561e-29f) {
tmp = 0.0f;
} else {
tmp = s + s;
}
return tmp;
}
real(4) function code(s, u)
use fmin_fmax_functions
real(4), intent (in) :: s
real(4), intent (in) :: u
real(4) :: tmp
if (s <= 4.307599612825561e-29) then
tmp = 0.0e0
else
tmp = s + s
end if
code = tmp
end function
function code(s, u) tmp = Float32(0.0) if (s <= Float32(4.307599612825561e-29)) tmp = Float32(0.0); else tmp = Float32(s + s); end return tmp end
function tmp_2 = code(s, u) tmp = single(0.0); if (s <= single(4.307599612825561e-29)) tmp = single(0.0); else tmp = s + s; end tmp_2 = tmp; end
\begin{array}{l}
\mathbf{if}\;s \leq 4.307599612825561 \cdot 10^{-29}:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;s + s\\
\end{array}
if s < 4.30759961e-29Initial program 61.5%
Applied rewrites16.5%
if 4.30759961e-29 < s Initial program 61.5%
Applied rewrites17.3%
Applied rewrites17.3%
(FPCore (s u)
:precision binary32
:pre (and (and (<= 0.0 s) (<= s 256.0))
(and (<= 2.328306437e-10 u) (<= u 0.25)))
(* s 0.015625))float code(float s, float u) {
return s * 0.015625f;
}
real(4) function code(s, u)
use fmin_fmax_functions
real(4), intent (in) :: s
real(4), intent (in) :: u
code = s * 0.015625e0
end function
function code(s, u) return Float32(s * Float32(0.015625)) end
function tmp = code(s, u) tmp = s * single(0.015625); end
s \cdot 0.015625
Initial program 61.5%
Applied rewrites20.8%
(FPCore (s u)
:precision binary32
:pre (and (and (<= 0.0 s) (<= s 256.0))
(and (<= 2.328306437e-10 u) (<= u 0.25)))
(if (<= s 1.235573164014442e-17) 0.0 u))float code(float s, float u) {
float tmp;
if (s <= 1.235573164014442e-17f) {
tmp = 0.0f;
} else {
tmp = u;
}
return tmp;
}
real(4) function code(s, u)
use fmin_fmax_functions
real(4), intent (in) :: s
real(4), intent (in) :: u
real(4) :: tmp
if (s <= 1.235573164014442e-17) then
tmp = 0.0e0
else
tmp = u
end if
code = tmp
end function
function code(s, u) tmp = Float32(0.0) if (s <= Float32(1.235573164014442e-17)) tmp = Float32(0.0); else tmp = u; end return tmp end
function tmp_2 = code(s, u) tmp = single(0.0); if (s <= single(1.235573164014442e-17)) tmp = single(0.0); else tmp = u; end tmp_2 = tmp; end
\begin{array}{l}
\mathbf{if}\;s \leq 1.235573164014442 \cdot 10^{-17}:\\
\;\;\;\;0\\
\mathbf{else}:\\
\;\;\;\;u\\
\end{array}
if s < 1.23557316e-17Initial program 61.5%
Applied rewrites16.5%
if 1.23557316e-17 < s Initial program 61.5%
Applied rewrites11.9%
Applied rewrites11.9%
(FPCore (s u)
:precision binary32
:pre (and (and (<= 0.0 s) (<= s 256.0))
(and (<= 2.328306437e-10 u) (<= u 0.25)))
0.0)float code(float s, float u) {
return 0.0f;
}
real(4) function code(s, u)
use fmin_fmax_functions
real(4), intent (in) :: s
real(4), intent (in) :: u
code = 0.0e0
end function
function code(s, u) return Float32(0.0) end
function tmp = code(s, u) tmp = single(0.0); end
0
Initial program 61.5%
Applied rewrites16.5%
herbie shell --seed 2026089 +o generate:egglog
(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))))))