
(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 6 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)))
(* s (- (log1p (* -4.0 u)))))float code(float s, float u) {
return s * -log1pf((-4.0f * u));
}
function code(s, u) return Float32(s * Float32(-log1p(Float32(Float32(-4.0) * u)))) end
s \cdot \left(-\mathsf{log1p}\left(-4 \cdot u\right)\right)
Initial program 61.4%
Applied rewrites63.9%
Applied rewrites99.4%
(FPCore (s u)
:precision binary32
:pre (and (and (<= 0.0 s) (<= s 256.0))
(and (<= 2.328306437e-10 u) (<= u 0.25)))
(if (<= (- 1.0 (* 4.0 u)) 0.9819999933242798)
(* s (- (log (fma -4.0 u 1.0))))
(/ s (+ (fma -0.3333333333333333 u -0.5) (/ 0.25 u)))))float code(float s, float u) {
float tmp;
if ((1.0f - (4.0f * u)) <= 0.9819999933242798f) {
tmp = s * -logf(fmaf(-4.0f, u, 1.0f));
} else {
tmp = s / (fmaf(-0.3333333333333333f, u, -0.5f) + (0.25f / u));
}
return tmp;
}
function code(s, u) tmp = Float32(0.0) if (Float32(Float32(1.0) - Float32(Float32(4.0) * u)) <= Float32(0.9819999933242798)) tmp = Float32(s * Float32(-log(fma(Float32(-4.0), u, Float32(1.0))))); else tmp = Float32(s / Float32(fma(Float32(-0.3333333333333333), u, Float32(-0.5)) + Float32(Float32(0.25) / u))); end return tmp end
\begin{array}{l}
\mathbf{if}\;1 - 4 \cdot u \leq 0.9819999933242798:\\
\;\;\;\;s \cdot \left(-\log \left(\mathsf{fma}\left(-4, u, 1\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{s}{\mathsf{fma}\left(-0.3333333333333333, u, -0.5\right) + \frac{0.25}{u}}\\
\end{array}
if (-.f32 #s(literal 1 binary32) (*.f32 #s(literal 4 binary32) u)) < 0.981999993Initial program 61.4%
Applied rewrites63.9%
if 0.981999993 < (-.f32 #s(literal 1 binary32) (*.f32 #s(literal 4 binary32) u)) Initial program 61.4%
Applied rewrites62.1%
Applied rewrites62.1%
Taylor expanded in u around 0
Applied rewrites88.9%
Applied rewrites92.6%
(FPCore (s u)
:precision binary32
:pre (and (and (<= 0.0 s) (<= s 256.0))
(and (<= 2.328306437e-10 u) (<= u 0.25)))
(if (<= (- 1.0 (* 4.0 u)) 0.9957000017166138)
(* s (- (log (fma -4.0 u 1.0))))
(/ s (- (/ 0.25 u) 0.5))))float code(float s, float u) {
float tmp;
if ((1.0f - (4.0f * u)) <= 0.9957000017166138f) {
tmp = s * -logf(fmaf(-4.0f, u, 1.0f));
} else {
tmp = s / ((0.25f / u) - 0.5f);
}
return tmp;
}
function code(s, u) tmp = Float32(0.0) if (Float32(Float32(1.0) - Float32(Float32(4.0) * u)) <= Float32(0.9957000017166138)) tmp = Float32(s * Float32(-log(fma(Float32(-4.0), u, Float32(1.0))))); else tmp = Float32(s / Float32(Float32(Float32(0.25) / u) - Float32(0.5))); end return tmp end
\begin{array}{l}
\mathbf{if}\;1 - 4 \cdot u \leq 0.9957000017166138:\\
\;\;\;\;s \cdot \left(-\log \left(\mathsf{fma}\left(-4, u, 1\right)\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{s}{\frac{0.25}{u} - 0.5}\\
\end{array}
if (-.f32 #s(literal 1 binary32) (*.f32 #s(literal 4 binary32) u)) < 0.995700002Initial program 61.4%
Applied rewrites63.9%
if 0.995700002 < (-.f32 #s(literal 1 binary32) (*.f32 #s(literal 4 binary32) u)) Initial program 61.4%
Applied rewrites62.1%
Applied rewrites62.1%
Taylor expanded in u around 0
Applied rewrites85.0%
Applied rewrites88.7%
(FPCore (s u)
:precision binary32
:pre (and (and (<= 0.0 s) (<= s 256.0))
(and (<= 2.328306437e-10 u) (<= u 0.25)))
(/ s (- (/ 0.25 u) 0.5)))float code(float s, float u) {
return s / ((0.25f / u) - 0.5f);
}
real(4) function code(s, u)
use fmin_fmax_functions
real(4), intent (in) :: s
real(4), intent (in) :: u
code = s / ((0.25e0 / u) - 0.5e0)
end function
function code(s, u) return Float32(s / Float32(Float32(Float32(0.25) / u) - Float32(0.5))) end
function tmp = code(s, u) tmp = s / ((single(0.25) / u) - single(0.5)); end
\frac{s}{\frac{0.25}{u} - 0.5}
Initial program 61.4%
Applied rewrites62.1%
Applied rewrites62.1%
Taylor expanded in u around 0
Applied rewrites85.0%
Applied rewrites88.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 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.4%
Taylor expanded in u around 0
Applied rewrites86.6%
Taylor expanded in u around 0
Applied rewrites73.7%
(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.4%
Taylor expanded in u around 0
Applied rewrites73.5%
herbie shell --seed 2026086
(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))))))