
(FPCore (ux uy maxCos)
:precision binary32
:pre (and (and (and (<= 2.328306437e-10 ux) (<= ux 1.0))
(and (<= 2.328306437e-10 uy) (<= uy 1.0)))
(and (<= 0.0 maxCos) (<= maxCos 1.0)))
(+ (- 1.0 ux) (* ux maxCos)))float code(float ux, float uy, float maxCos) {
return (1.0f - ux) + (ux * maxCos);
}
real(4) function code(ux, uy, maxcos)
use fmin_fmax_functions
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = (1.0e0 - ux) + (ux * maxcos)
end function
function code(ux, uy, maxCos) return Float32(Float32(Float32(1.0) - ux) + Float32(ux * maxCos)) end
function tmp = code(ux, uy, maxCos) tmp = (single(1.0) - ux) + (ux * maxCos); end
\left(1 - ux\right) + ux \cdot maxCos
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (ux uy maxCos)
:precision binary32
:pre (and (and (and (<= 2.328306437e-10 ux) (<= ux 1.0))
(and (<= 2.328306437e-10 uy) (<= uy 1.0)))
(and (<= 0.0 maxCos) (<= maxCos 1.0)))
(+ (- 1.0 ux) (* ux maxCos)))float code(float ux, float uy, float maxCos) {
return (1.0f - ux) + (ux * maxCos);
}
real(4) function code(ux, uy, maxcos)
use fmin_fmax_functions
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = (1.0e0 - ux) + (ux * maxcos)
end function
function code(ux, uy, maxCos) return Float32(Float32(Float32(1.0) - ux) + Float32(ux * maxCos)) end
function tmp = code(ux, uy, maxCos) tmp = (single(1.0) - ux) + (ux * maxCos); end
\left(1 - ux\right) + ux \cdot maxCos
(FPCore (ux uy maxCos)
:precision binary32
:pre (and (and (and (<= 2.328306437e-10 ux) (<= ux 1.0))
(and (<= 2.328306437e-10 uy) (<= uy 1.0)))
(and (<= 0.0 maxCos) (<= maxCos 1.0)))
(fma ux maxCos (- 1.0 ux)))float code(float ux, float uy, float maxCos) {
return fmaf(ux, maxCos, (1.0f - ux));
}
function code(ux, uy, maxCos) return fma(ux, maxCos, Float32(Float32(1.0) - ux)) end
\mathsf{fma}\left(ux, maxCos, 1 - ux\right)
Initial program 99.9%
Applied rewrites99.9%
(FPCore (ux uy maxCos)
:precision binary32
:pre (and (and (and (<= 2.328306437e-10 ux) (<= ux 1.0))
(and (<= 2.328306437e-10 uy) (<= uy 1.0)))
(and (<= 0.0 maxCos) (<= maxCos 1.0)))
(- (fma maxCos ux 1.0) ux))float code(float ux, float uy, float maxCos) {
return fmaf(maxCos, ux, 1.0f) - ux;
}
function code(ux, uy, maxCos) return Float32(fma(maxCos, ux, Float32(1.0)) - ux) end
\mathsf{fma}\left(maxCos, ux, 1\right) - ux
Initial program 99.9%
Applied rewrites99.8%
(FPCore (ux uy maxCos)
:precision binary32
:pre (and (and (and (<= 2.328306437e-10 ux) (<= ux 1.0))
(and (<= 2.328306437e-10 uy) (<= uy 1.0)))
(and (<= 0.0 maxCos) (<= maxCos 1.0)))
(- 1.0 ux))float code(float ux, float uy, float maxCos) {
return 1.0f - ux;
}
real(4) function code(ux, uy, maxcos)
use fmin_fmax_functions
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = 1.0e0 - ux
end function
function code(ux, uy, maxCos) return Float32(Float32(1.0) - ux) end
function tmp = code(ux, uy, maxCos) tmp = single(1.0) - ux; end
1 - ux
Initial program 99.9%
Taylor expanded in maxCos around 0
Applied rewrites98.1%
(FPCore (ux uy maxCos)
:precision binary32
:pre (and (and (and (<= 2.328306437e-10 ux) (<= ux 1.0))
(and (<= 2.328306437e-10 uy) (<= uy 1.0)))
(and (<= 0.0 maxCos) (<= maxCos 1.0)))
1.0)float code(float ux, float uy, float maxCos) {
return 1.0f;
}
real(4) function code(ux, uy, maxcos)
use fmin_fmax_functions
real(4), intent (in) :: ux
real(4), intent (in) :: uy
real(4), intent (in) :: maxcos
code = 1.0e0
end function
function code(ux, uy, maxCos) return Float32(1.0) end
function tmp = code(ux, uy, maxCos) tmp = single(1.0); end
1
Initial program 99.9%
Taylor expanded in maxCos around 0
Applied rewrites98.1%
Taylor expanded in ux around 0
Applied rewrites71.3%
herbie shell --seed 2025359
(FPCore (ux uy maxCos)
:name "UniformSampleCone, z"
:precision binary32
:pre (and (and (and (<= 2.328306437e-10 ux) (<= ux 1.0)) (and (<= 2.328306437e-10 uy) (<= uy 1.0))) (and (<= 0.0 maxCos) (<= maxCos 1.0)))
(+ (- 1.0 ux) (* ux maxCos)))