
(FPCore (sinTheta_O h eta)
:precision binary32
(asin
(/
h
(sqrt
(-
(* eta eta)
(/
(* sinTheta_O sinTheta_O)
(sqrt (- 1.0 (* sinTheta_O sinTheta_O)))))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / sqrtf(((eta * eta) - ((sinTheta_O * sinTheta_O) / sqrtf((1.0f - (sinTheta_O * sinTheta_O))))))));
}
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(sintheta_o, h, eta)
use fmin_fmax_functions
real(4), intent (in) :: sintheta_o
real(4), intent (in) :: h
real(4), intent (in) :: eta
code = asin((h / sqrt(((eta * eta) - ((sintheta_o * sintheta_o) / sqrt((1.0e0 - (sintheta_o * sintheta_o))))))))
end function
function code(sinTheta_O, h, eta) return asin(Float32(h / sqrt(Float32(Float32(eta * eta) - Float32(Float32(sinTheta_O * sinTheta_O) / sqrt(Float32(Float32(1.0) - Float32(sinTheta_O * sinTheta_O)))))))) end
function tmp = code(sinTheta_O, h, eta) tmp = asin((h / sqrt(((eta * eta) - ((sinTheta_O * sinTheta_O) / sqrt((single(1.0) - (sinTheta_O * sinTheta_O)))))))); end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{\sqrt{eta \cdot eta - \frac{sinTheta\_O \cdot sinTheta\_O}{\sqrt{1 - sinTheta\_O \cdot sinTheta\_O}}}}\right)
\end{array}
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (sinTheta_O h eta)
:precision binary32
(asin
(/
h
(sqrt
(-
(* eta eta)
(/
(* sinTheta_O sinTheta_O)
(sqrt (- 1.0 (* sinTheta_O sinTheta_O)))))))))
float code(float sinTheta_O, float h, float eta) {
return asinf((h / sqrtf(((eta * eta) - ((sinTheta_O * sinTheta_O) / sqrtf((1.0f - (sinTheta_O * sinTheta_O))))))));
}
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(sintheta_o, h, eta)
use fmin_fmax_functions
real(4), intent (in) :: sintheta_o
real(4), intent (in) :: h
real(4), intent (in) :: eta
code = asin((h / sqrt(((eta * eta) - ((sintheta_o * sintheta_o) / sqrt((1.0e0 - (sintheta_o * sintheta_o))))))))
end function
function code(sinTheta_O, h, eta) return asin(Float32(h / sqrt(Float32(Float32(eta * eta) - Float32(Float32(sinTheta_O * sinTheta_O) / sqrt(Float32(Float32(1.0) - Float32(sinTheta_O * sinTheta_O)))))))) end
function tmp = code(sinTheta_O, h, eta) tmp = asin((h / sqrt(((eta * eta) - ((sinTheta_O * sinTheta_O) / sqrt((single(1.0) - (sinTheta_O * sinTheta_O)))))))); end
\begin{array}{l}
\\
\sin^{-1} \left(\frac{h}{\sqrt{eta \cdot eta - \frac{sinTheta\_O \cdot sinTheta\_O}{\sqrt{1 - sinTheta\_O \cdot sinTheta\_O}}}}\right)
\end{array}
sinTheta_O_m = (fabs.f32 sinTheta_O) (FPCore (sinTheta_O_m h eta) :precision binary32 (if (<= sinTheta_O_m 8.000000156331851e-25) (asin (/ h eta)) (asin (/ h (sqrt (fma (- sinTheta_O_m) sinTheta_O_m (* eta eta)))))))
sinTheta_O_m = fabs(sinTheta_O);
float code(float sinTheta_O_m, float h, float eta) {
float tmp;
if (sinTheta_O_m <= 8.000000156331851e-25f) {
tmp = asinf((h / eta));
} else {
tmp = asinf((h / sqrtf(fmaf(-sinTheta_O_m, sinTheta_O_m, (eta * eta)))));
}
return tmp;
}
sinTheta_O_m = abs(sinTheta_O) function code(sinTheta_O_m, h, eta) tmp = Float32(0.0) if (sinTheta_O_m <= Float32(8.000000156331851e-25)) tmp = asin(Float32(h / eta)); else tmp = asin(Float32(h / sqrt(fma(Float32(-sinTheta_O_m), sinTheta_O_m, Float32(eta * eta))))); end return tmp end
\begin{array}{l}
sinTheta_O_m = \left|sinTheta\_O\right|
\\
\begin{array}{l}
\mathbf{if}\;sinTheta\_O\_m \leq 8.000000156331851 \cdot 10^{-25}:\\
\;\;\;\;\sin^{-1} \left(\frac{h}{eta}\right)\\
\mathbf{else}:\\
\;\;\;\;\sin^{-1} \left(\frac{h}{\sqrt{\mathsf{fma}\left(-sinTheta\_O\_m, sinTheta\_O\_m, eta \cdot eta\right)}}\right)\\
\end{array}
\end{array}
if sinTheta_O < 8.00000016e-25Initial program 92.0%
Taylor expanded in eta around inf
lower-/.f3295.2
Applied rewrites95.2%
if 8.00000016e-25 < sinTheta_O Initial program 92.0%
Taylor expanded in sinTheta_O around 0
+-commutativeN/A
pow2N/A
lower-fma.f32N/A
mul-1-negN/A
lower-neg.f32N/A
pow2N/A
lift-*.f3291.8
Applied rewrites91.8%
lift-fma.f32N/A
pow2N/A
+-commutativeN/A
lift-neg.f32N/A
lift-*.f32N/A
distribute-lft-neg-inN/A
lower-fma.f32N/A
lower-neg.f32N/A
pow2N/A
lift-*.f3291.8
Applied rewrites91.8%
sinTheta_O_m = (fabs.f32 sinTheta_O) (FPCore (sinTheta_O_m h eta) :precision binary32 (if (<= sinTheta_O_m 8.000000156331851e-25) (asin (/ h eta)) (asin (/ h (sqrt (- (* eta eta) (* sinTheta_O_m sinTheta_O_m)))))))
sinTheta_O_m = fabs(sinTheta_O);
float code(float sinTheta_O_m, float h, float eta) {
float tmp;
if (sinTheta_O_m <= 8.000000156331851e-25f) {
tmp = asinf((h / eta));
} else {
tmp = asinf((h / sqrtf(((eta * eta) - (sinTheta_O_m * sinTheta_O_m)))));
}
return tmp;
}
sinTheta_O_m = private
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(sintheta_o_m, h, eta)
use fmin_fmax_functions
real(4), intent (in) :: sintheta_o_m
real(4), intent (in) :: h
real(4), intent (in) :: eta
real(4) :: tmp
if (sintheta_o_m <= 8.000000156331851e-25) then
tmp = asin((h / eta))
else
tmp = asin((h / sqrt(((eta * eta) - (sintheta_o_m * sintheta_o_m)))))
end if
code = tmp
end function
sinTheta_O_m = abs(sinTheta_O) function code(sinTheta_O_m, h, eta) tmp = Float32(0.0) if (sinTheta_O_m <= Float32(8.000000156331851e-25)) tmp = asin(Float32(h / eta)); else tmp = asin(Float32(h / sqrt(Float32(Float32(eta * eta) - Float32(sinTheta_O_m * sinTheta_O_m))))); end return tmp end
sinTheta_O_m = abs(sinTheta_O); function tmp_2 = code(sinTheta_O_m, h, eta) tmp = single(0.0); if (sinTheta_O_m <= single(8.000000156331851e-25)) tmp = asin((h / eta)); else tmp = asin((h / sqrt(((eta * eta) - (sinTheta_O_m * sinTheta_O_m))))); end tmp_2 = tmp; end
\begin{array}{l}
sinTheta_O_m = \left|sinTheta\_O\right|
\\
\begin{array}{l}
\mathbf{if}\;sinTheta\_O\_m \leq 8.000000156331851 \cdot 10^{-25}:\\
\;\;\;\;\sin^{-1} \left(\frac{h}{eta}\right)\\
\mathbf{else}:\\
\;\;\;\;\sin^{-1} \left(\frac{h}{\sqrt{eta \cdot eta - sinTheta\_O\_m \cdot sinTheta\_O\_m}}\right)\\
\end{array}
\end{array}
if sinTheta_O < 8.00000016e-25Initial program 92.0%
Taylor expanded in eta around inf
lower-/.f3295.2
Applied rewrites95.2%
if 8.00000016e-25 < sinTheta_O Initial program 92.0%
Taylor expanded in sinTheta_O around 0
pow2N/A
lift-*.f3291.8
Applied rewrites91.8%
sinTheta_O_m = (fabs.f32 sinTheta_O) (FPCore (sinTheta_O_m h eta) :precision binary32 (asin (/ h (fma (* sinTheta_O_m (/ sinTheta_O_m (fabs eta))) -0.5 (fabs eta)))))
sinTheta_O_m = fabs(sinTheta_O);
float code(float sinTheta_O_m, float h, float eta) {
return asinf((h / fmaf((sinTheta_O_m * (sinTheta_O_m / fabsf(eta))), -0.5f, fabsf(eta))));
}
sinTheta_O_m = abs(sinTheta_O) function code(sinTheta_O_m, h, eta) return asin(Float32(h / fma(Float32(sinTheta_O_m * Float32(sinTheta_O_m / abs(eta))), Float32(-0.5), abs(eta)))) end
\begin{array}{l}
sinTheta_O_m = \left|sinTheta\_O\right|
\\
\sin^{-1} \left(\frac{h}{\mathsf{fma}\left(sinTheta\_O\_m \cdot \frac{sinTheta\_O\_m}{\left|eta\right|}, -0.5, \left|eta\right|\right)}\right)
\end{array}
Initial program 92.0%
Taylor expanded in sinTheta_O around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f32N/A
lower-/.f32N/A
pow2N/A
lift-*.f32N/A
lower-sqrt.f32N/A
pow2N/A
lift-*.f32N/A
lower-sqrt.f32N/A
pow2N/A
lift-*.f3290.5
Applied rewrites90.5%
lift-*.f32N/A
lift-/.f32N/A
associate-/l*N/A
lower-*.f32N/A
lift-sqrt.f32N/A
lift-*.f32N/A
pow2N/A
lower-/.f32N/A
pow2N/A
rem-sqrt-squareN/A
lower-fabs.f3290.6
lift-sqrt.f32N/A
lift-*.f32N/A
rem-sqrt-squareN/A
lower-fabs.f3297.8
Applied rewrites97.8%
sinTheta_O_m = (fabs.f32 sinTheta_O) (FPCore (sinTheta_O_m h eta) :precision binary32 (asin (/ h eta)))
sinTheta_O_m = fabs(sinTheta_O);
float code(float sinTheta_O_m, float h, float eta) {
return asinf((h / eta));
}
sinTheta_O_m = private
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(sintheta_o_m, h, eta)
use fmin_fmax_functions
real(4), intent (in) :: sintheta_o_m
real(4), intent (in) :: h
real(4), intent (in) :: eta
code = asin((h / eta))
end function
sinTheta_O_m = abs(sinTheta_O) function code(sinTheta_O_m, h, eta) return asin(Float32(h / eta)) end
sinTheta_O_m = abs(sinTheta_O); function tmp = code(sinTheta_O_m, h, eta) tmp = asin((h / eta)); end
\begin{array}{l}
sinTheta_O_m = \left|sinTheta\_O\right|
\\
\sin^{-1} \left(\frac{h}{eta}\right)
\end{array}
Initial program 92.0%
Taylor expanded in eta around inf
lower-/.f3295.2
Applied rewrites95.2%
herbie shell --seed 2025139
(FPCore (sinTheta_O h eta)
:name "HairBSDF, gamma for a refracted ray"
:precision binary32
:pre (and (and (and (<= -1.0 sinTheta_O) (<= sinTheta_O 1.0)) (and (<= -1.0 h) (<= h 1.0))) (and (<= 0.0 eta) (<= eta 10.0)))
(asin (/ h (sqrt (- (* eta eta) (/ (* sinTheta_O sinTheta_O) (sqrt (- 1.0 (* sinTheta_O sinTheta_O)))))))))