
(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))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
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
\begin{array}{l}
\\
s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right)
\end{array}
Herbie found 9 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))));
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
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
\begin{array}{l}
\\
s \cdot \log \left(\frac{1}{1 - 4 \cdot u}\right)
\end{array}
(FPCore (s u) :precision binary32 (* (- (log1p (* -4.0 u))) s))
float code(float s, float u) {
return -log1pf((-4.0f * u)) * s;
}
function code(s, u) return Float32(Float32(-log1p(Float32(Float32(-4.0) * u))) * s) end
\begin{array}{l}
\\
\left(-\mathsf{log1p}\left(-4 \cdot u\right)\right) \cdot s
\end{array}
Initial program 61.0%
lift-*.f32N/A
lift-log.f32N/A
lift-/.f32N/A
lift--.f32N/A
lift-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
log-recN/A
lower-neg.f32N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower-log1p.f32N/A
lower-*.f3299.4
Applied rewrites99.4%
(FPCore (s u) :precision binary32 (* (fma (* (fma (fma 64.0 u 21.333333333333332) u 8.0) s) u (* 4.0 s)) u))
float code(float s, float u) {
return fmaf((fmaf(fmaf(64.0f, u, 21.333333333333332f), u, 8.0f) * s), u, (4.0f * s)) * u;
}
function code(s, u) return Float32(fma(Float32(fma(fma(Float32(64.0), u, Float32(21.333333333333332)), u, Float32(8.0)) * s), u, Float32(Float32(4.0) * s)) * u) end
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(64, u, 21.333333333333332\right), u, 8\right) \cdot s, u, 4 \cdot s\right) \cdot u
\end{array}
Initial program 61.0%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
Applied rewrites93.4%
Taylor expanded in s around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
+-commutativeN/A
lower-*.f32N/A
lift-fma.f32N/A
lift-fma.f3293.4
Applied rewrites93.4%
(FPCore (s u) :precision binary32 (* (* (fma (fma (fma 64.0 u 21.333333333333332) u 8.0) u 4.0) s) u))
float code(float s, float u) {
return (fmaf(fmaf(fmaf(64.0f, u, 21.333333333333332f), u, 8.0f), u, 4.0f) * s) * u;
}
function code(s, u) return Float32(Float32(fma(fma(fma(Float32(64.0), u, Float32(21.333333333333332)), u, Float32(8.0)), u, Float32(4.0)) * s) * u) end
\begin{array}{l}
\\
\left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(64, u, 21.333333333333332\right), u, 8\right), u, 4\right) \cdot s\right) \cdot u
\end{array}
Initial program 61.0%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
Applied rewrites93.4%
Taylor expanded in s around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
+-commutativeN/A
lower-*.f32N/A
lift-fma.f32N/A
lift-fma.f32N/A
lift-fma.f3293.1
Applied rewrites93.1%
(FPCore (s u) :precision binary32 (* (fma (* (fma 21.333333333333332 u 8.0) s) u (* 4.0 s)) u))
float code(float s, float u) {
return fmaf((fmaf(21.333333333333332f, u, 8.0f) * s), u, (4.0f * s)) * u;
}
function code(s, u) return Float32(fma(Float32(fma(Float32(21.333333333333332), u, Float32(8.0)) * s), u, Float32(Float32(4.0) * s)) * u) end
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(21.333333333333332, u, 8\right) \cdot s, u, 4 \cdot s\right) \cdot u
\end{array}
Initial program 61.0%
lift-*.f32N/A
lift-log.f32N/A
lift-/.f32N/A
lift--.f32N/A
lift-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
log-recN/A
lower-neg.f32N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower-log1p.f32N/A
lower-*.f3299.4
Applied rewrites99.4%
Taylor expanded in u around 0
*-commutativeN/A
neg-logN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-*.f3291.2
Applied rewrites91.2%
Taylor expanded in s around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3291.2
Applied rewrites91.2%
(FPCore (s u) :precision binary32 (* (* (fma (fma 21.333333333333332 u 8.0) u 4.0) s) u))
float code(float s, float u) {
return (fmaf(fmaf(21.333333333333332f, u, 8.0f), u, 4.0f) * s) * u;
}
function code(s, u) return Float32(Float32(fma(fma(Float32(21.333333333333332), u, Float32(8.0)), u, Float32(4.0)) * s) * u) end
\begin{array}{l}
\\
\left(\mathsf{fma}\left(\mathsf{fma}\left(21.333333333333332, u, 8\right), u, 4\right) \cdot s\right) \cdot u
\end{array}
Initial program 61.0%
lift-*.f32N/A
lift-log.f32N/A
lift-/.f32N/A
lift--.f32N/A
lift-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
log-recN/A
lower-neg.f32N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower-log1p.f32N/A
lower-*.f3299.4
Applied rewrites99.4%
Taylor expanded in u around 0
*-commutativeN/A
neg-logN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
associate-*r*N/A
lower-fma.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-*.f3291.2
Applied rewrites91.2%
Taylor expanded in s around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f3291.0
Applied rewrites91.0%
(FPCore (s u) :precision binary32 (* (fma (* u u) 8.0 (* 4.0 u)) s))
float code(float s, float u) {
return fmaf((u * u), 8.0f, (4.0f * u)) * s;
}
function code(s, u) return Float32(fma(Float32(u * u), Float32(8.0), Float32(Float32(4.0) * u)) * s) end
\begin{array}{l}
\\
\mathsf{fma}\left(u \cdot u, 8, 4 \cdot u\right) \cdot s
\end{array}
Initial program 61.0%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-*.f3286.9
Applied rewrites86.9%
lift-*.f32N/A
lift-*.f32N/A
*-commutativeN/A
lift-*.f32N/A
lower-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
distribute-rgt-inN/A
lower-fma.f32N/A
lift-*.f32N/A
lower-*.f32N/A
associate-*r*N/A
lower-*.f32N/A
lift-*.f3287.2
Applied rewrites87.2%
Taylor expanded in s around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
pow2N/A
lift-*.f32N/A
lower-*.f3286.9
Applied rewrites86.9%
(FPCore (s u) :precision binary32 (* (* (fma 8.0 u 4.0) s) u))
float code(float s, float u) {
return (fmaf(8.0f, u, 4.0f) * s) * u;
}
function code(s, u) return Float32(Float32(fma(Float32(8.0), u, Float32(4.0)) * s) * u) end
\begin{array}{l}
\\
\left(\mathsf{fma}\left(8, u, 4\right) \cdot s\right) \cdot u
\end{array}
Initial program 61.0%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f32N/A
*-commutativeN/A
lower-*.f32N/A
lower-*.f3286.9
Applied rewrites86.9%
lift-*.f32N/A
lift-*.f32N/A
lift-fma.f32N/A
+-commutativeN/A
associate-*r*N/A
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3286.8
Applied rewrites86.8%
(FPCore (s u) :precision binary32 (* s (* u 4.0)))
float code(float s, float u) {
return s * (u * 4.0f);
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
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
\begin{array}{l}
\\
s \cdot \left(u \cdot 4\right)
\end{array}
Initial program 61.0%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f3274.0
Applied rewrites74.0%
(FPCore (s u) :precision binary32 (* (* s u) 4.0))
float code(float s, float u) {
return (s * u) * 4.0f;
}
module fmin_fmax_functions
implicit none
private
public fmax
public fmin
interface fmax
module procedure fmax88
module procedure fmax44
module procedure fmax84
module procedure fmax48
end interface
interface fmin
module procedure fmin88
module procedure fmin44
module procedure fmin84
module procedure fmin48
end interface
contains
real(8) function fmax88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(4) function fmax44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, max(x, y), y /= y), x /= x)
end function
real(8) function fmax84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, max(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmax48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), max(dble(x), y), y /= y), x /= x)
end function
real(8) function fmin88(x, y) result (res)
real(8), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(4) function fmin44(x, y) result (res)
real(4), intent (in) :: x
real(4), intent (in) :: y
res = merge(y, merge(x, min(x, y), y /= y), x /= x)
end function
real(8) function fmin84(x, y) result(res)
real(8), intent (in) :: x
real(4), intent (in) :: y
res = merge(dble(y), merge(x, min(x, dble(y)), y /= y), x /= x)
end function
real(8) function fmin48(x, y) result(res)
real(4), intent (in) :: x
real(8), intent (in) :: y
res = merge(y, merge(dble(x), min(dble(x), y), y /= y), x /= x)
end function
end module
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(Float32(s * u) * Float32(4.0)) end
function tmp = code(s, u) tmp = (s * u) * single(4.0); end
\begin{array}{l}
\\
\left(s \cdot u\right) \cdot 4
\end{array}
Initial program 61.0%
lift-*.f32N/A
lift-log.f32N/A
lift-/.f32N/A
lift--.f32N/A
lift-*.f32N/A
*-commutativeN/A
lower-*.f32N/A
log-recN/A
lower-neg.f32N/A
metadata-evalN/A
fp-cancel-sign-sub-invN/A
lower-log1p.f32N/A
lower-*.f3299.4
Applied rewrites99.4%
Taylor expanded in u around 0
*-commutativeN/A
neg-logN/A
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-commutativeN/A
lower-*.f32N/A
lower-*.f3273.8
Applied rewrites73.8%
herbie shell --seed 2025107
(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))))))