
(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}
Sampling outcomes in binary32 precision:
Herbie found 15 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(log1p(Float32(Float32(-4.0) * u)) * Float32(-s)) end
\begin{array}{l}
\\
\mathsf{log1p}\left(-4 \cdot u\right) \cdot \left(-s\right)
\end{array}
Initial program 63.9%
Applied rewrites99.3%
Final simplification99.3%
(FPCore (s u) :precision binary32 (* (fma (fma (* s (fma 64.0 u 21.333333333333332)) u (* 8.0 s)) u (* 4.0 s)) u))
float code(float s, float u) {
return fmaf(fmaf((s * fmaf(64.0f, u, 21.333333333333332f)), u, (8.0f * s)), u, (4.0f * s)) * u;
}
function code(s, u) return Float32(fma(fma(Float32(s * fma(Float32(64.0), u, Float32(21.333333333333332))), u, Float32(Float32(8.0) * s)), u, Float32(Float32(4.0) * s)) * u) end
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(s \cdot \mathsf{fma}\left(64, u, 21.333333333333332\right), u, 8 \cdot s\right), u, 4 \cdot s\right) \cdot u
\end{array}
Initial program 63.9%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
Applied rewrites92.9%
(FPCore (s u) :precision binary32 (* (fma (* (fma (fma 64.0 u 21.333333333333332) u 8.0) u) u (* 4.0 u)) s))
float code(float s, float u) {
return fmaf((fmaf(fmaf(64.0f, u, 21.333333333333332f), u, 8.0f) * u), u, (4.0f * u)) * s;
}
function code(s, u) return Float32(fma(Float32(fma(fma(Float32(64.0), u, Float32(21.333333333333332)), u, Float32(8.0)) * u), u, Float32(Float32(4.0) * u)) * s) end
\begin{array}{l}
\\
\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(64, u, 21.333333333333332\right), u, 8\right) \cdot u, u, 4 \cdot u\right) \cdot s
\end{array}
Initial program 63.9%
Applied rewrites99.3%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f3292.7
Applied rewrites92.7%
Applied rewrites92.9%
(FPCore (s u) :precision binary32 (* (* (+ (* (fma (fma 64.0 u 21.333333333333332) u 8.0) u) 4.0) u) s))
float code(float s, float u) {
return (((fmaf(fmaf(64.0f, u, 21.333333333333332f), u, 8.0f) * u) + 4.0f) * u) * s;
}
function code(s, u) return Float32(Float32(Float32(Float32(fma(fma(Float32(64.0), u, Float32(21.333333333333332)), u, Float32(8.0)) * u) + Float32(4.0)) * u) * s) end
\begin{array}{l}
\\
\left(\left(\mathsf{fma}\left(\mathsf{fma}\left(64, u, 21.333333333333332\right), u, 8\right) \cdot u + 4\right) \cdot u\right) \cdot s
\end{array}
Initial program 63.9%
Applied rewrites99.3%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f3292.7
Applied rewrites92.7%
Applied rewrites92.7%
(FPCore (s u) :precision binary32 (* s (* (fma (fma (fma 64.0 u 21.333333333333332) u 8.0) u 4.0) u)))
float code(float s, float u) {
return s * (fmaf(fmaf(fmaf(64.0f, u, 21.333333333333332f), u, 8.0f), u, 4.0f) * u);
}
function code(s, u) return Float32(s * Float32(fma(fma(fma(Float32(64.0), u, Float32(21.333333333333332)), u, Float32(8.0)), u, Float32(4.0)) * u)) end
\begin{array}{l}
\\
s \cdot \left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{fma}\left(64, u, 21.333333333333332\right), u, 8\right), u, 4\right) \cdot u\right)
\end{array}
Initial program 63.9%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
distribute-rgt-inN/A
distribute-rgt-inN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f3292.7
Applied rewrites92.7%
(FPCore (s u) :precision binary32 (* (fma (* s (fma 21.333333333333332 u 8.0)) u (* 4.0 s)) u))
float code(float s, float u) {
return fmaf((s * fmaf(21.333333333333332f, u, 8.0f)), u, (4.0f * s)) * u;
}
function code(s, u) return Float32(fma(Float32(s * fma(Float32(21.333333333333332), u, Float32(8.0))), u, Float32(Float32(4.0) * s)) * u) end
\begin{array}{l}
\\
\mathsf{fma}\left(s \cdot \mathsf{fma}\left(21.333333333333332, u, 8\right), u, 4 \cdot s\right) \cdot u
\end{array}
Initial program 63.9%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
*-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f32N/A
lower-*.f3290.5
Applied rewrites90.5%
(FPCore (s u) :precision binary32 (* (fma s 4.0 (* (* (fma 21.333333333333332 u 8.0) s) u)) u))
float code(float s, float u) {
return fmaf(s, 4.0f, ((fmaf(21.333333333333332f, u, 8.0f) * s) * u)) * u;
}
function code(s, u) return Float32(fma(s, Float32(4.0), Float32(Float32(fma(Float32(21.333333333333332), u, Float32(8.0)) * s) * u)) * u) end
\begin{array}{l}
\\
\mathsf{fma}\left(s, 4, \left(\mathsf{fma}\left(21.333333333333332, u, 8\right) \cdot s\right) \cdot u\right) \cdot u
\end{array}
Initial program 63.9%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
*-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f32N/A
lower-*.f3290.5
Applied rewrites90.5%
Applied rewrites90.5%
(FPCore (s u) :precision binary32 (* (* (+ (* (fma 21.333333333333332 u 8.0) u) 4.0) u) s))
float code(float s, float u) {
return (((fmaf(21.333333333333332f, u, 8.0f) * u) + 4.0f) * u) * s;
}
function code(s, u) return Float32(Float32(Float32(Float32(fma(Float32(21.333333333333332), u, Float32(8.0)) * u) + Float32(4.0)) * u) * s) end
\begin{array}{l}
\\
\left(\left(\mathsf{fma}\left(21.333333333333332, u, 8\right) \cdot u + 4\right) \cdot u\right) \cdot s
\end{array}
Initial program 63.9%
Applied rewrites99.3%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f3290.3
Applied rewrites90.3%
Applied rewrites90.3%
(FPCore (s u) :precision binary32 (* s (* (fma (fma 21.333333333333332 u 8.0) u 4.0) u)))
float code(float s, float u) {
return s * (fmaf(fmaf(21.333333333333332f, u, 8.0f), u, 4.0f) * u);
}
function code(s, u) return Float32(s * Float32(fma(fma(Float32(21.333333333333332), u, Float32(8.0)), u, Float32(4.0)) * u)) end
\begin{array}{l}
\\
s \cdot \left(\mathsf{fma}\left(\mathsf{fma}\left(21.333333333333332, u, 8\right), u, 4\right) \cdot u\right)
\end{array}
Initial program 63.9%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f3290.3
Applied rewrites90.3%
(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 63.9%
Applied rewrites99.3%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
distribute-rgt-inN/A
+-commutativeN/A
*-commutativeN/A
associate-*l*N/A
distribute-rgt-inN/A
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
+-commutativeN/A
lower-fma.f3290.2
Applied rewrites90.2%
(FPCore (s u) :precision binary32 (* (fma (* s u) 8.0 (* 4.0 s)) u))
float code(float s, float u) {
return fmaf((s * u), 8.0f, (4.0f * s)) * u;
}
function code(s, u) return Float32(fma(Float32(s * u), Float32(8.0), Float32(Float32(4.0) * s)) * u) end
\begin{array}{l}
\\
\mathsf{fma}\left(s \cdot u, 8, 4 \cdot s\right) \cdot u
\end{array}
Initial program 63.9%
Applied rewrites99.3%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower-*.f32N/A
lower-*.f3285.7
Applied rewrites85.7%
(FPCore (s u) :precision binary32 (* s (* (fma 8.0 u 4.0) u)))
float code(float s, float u) {
return s * (fmaf(8.0f, u, 4.0f) * u);
}
function code(s, u) return Float32(s * Float32(fma(Float32(8.0), u, Float32(4.0)) * u)) end
\begin{array}{l}
\\
s \cdot \left(\mathsf{fma}\left(8, u, 4\right) \cdot u\right)
\end{array}
Initial program 63.9%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3285.6
Applied rewrites85.6%
(FPCore (s u) :precision binary32 (* (* s (fma 8.0 u 4.0)) u))
float code(float s, float u) {
return (s * fmaf(8.0f, u, 4.0f)) * u;
}
function code(s, u) return Float32(Float32(s * fma(Float32(8.0), u, Float32(4.0))) * u) end
\begin{array}{l}
\\
\left(s \cdot \mathsf{fma}\left(8, u, 4\right)\right) \cdot u
\end{array}
Initial program 63.9%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3285.5
Applied rewrites85.5%
(FPCore (s u) :precision binary32 (* s (* 4.0 u)))
float code(float s, float u) {
return s * (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 * (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 63.9%
Taylor expanded in u around 0
lower-*.f3271.4
Applied rewrites71.4%
(FPCore (s u) :precision binary32 (* 4.0 (* s u)))
float code(float s, float u) {
return 4.0f * (s * 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 = 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
\begin{array}{l}
\\
4 \cdot \left(s \cdot u\right)
\end{array}
Initial program 63.9%
Taylor expanded in u around 0
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
associate-*r*N/A
distribute-rgt-outN/A
lower-*.f32N/A
+-commutativeN/A
lower-fma.f3285.5
Applied rewrites85.5%
Applied rewrites85.5%
Taylor expanded in u around 0
Applied rewrites71.3%
herbie shell --seed 2025006
(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))))))