Skip to content

Commit 129e777

Browse files
committed
Merge branch 'grow-libm' into growlibm-newbench
2 parents 83dc6c9 + 4088b7f commit 129e777

File tree

9 files changed

+476
-159
lines changed

9 files changed

+476
-159
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,5 @@ herbie-compiled/
2626

2727
# Python
2828
.env/
29+
30+
.vscode/

bench/omerc.fpcore

Lines changed: 124 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -1,110 +1,131 @@
1-
; Hard benchmarks extracted from growlibm/omerc.cpp Oblique Mercator setup, focusing on tight domain guards and coupled trig/hyperbolic transforms.
1+
(FPCore (W)
2+
:name "omerc-forward-half-diff"
3+
:pre (not (= W 0.0))
4+
(* 0.5 (- W (/ 1.0 W))))
25

3-
(FPCore (S V singam cosgam T)
4-
:name "omerc-hard-u-mix"
5-
:pre (and (> (fabs T) 1e-12)
6-
(< (fabs singam) 1)
7-
(< (fabs cosgam) 1)
8-
(< (fabs V) 1))
9-
(/ (- (* S singam) (* V cosgam)) T))
6+
(FPCore (W)
7+
:name "omerc-forward-half-sum"
8+
:pre (not (= W 0.0))
9+
(* 0.5 (+ W (/ 1.0 W))))
10+
11+
(FPCore (S T singam cosgam B lam)
12+
:name "omerc-forward-U"
13+
:pre (not (= T 0.0))
14+
(let* ((V (sin (* B lam))))
15+
(/ (- (* S singam) (* V cosgam)) T)))
1016

1117
(FPCore (U ArB)
12-
:name "omerc-hard-log-ratio"
13-
:pre (and (< (fabs U) 0.999999)
14-
(> ArB 0))
15-
(* 0.5
16-
(* ArB
17-
(log (/ (- 1 U)
18-
(+ 1 U))))))
19-
20-
(FPCore (ArB S V singam cosgam temp)
21-
:name "omerc-hard-atan2-rot"
22-
:pre (and (>= (fabs temp) 1e-7)
23-
(< (fabs singam) 1)
24-
(< (fabs cosgam) 1)
25-
(< (fabs V) 1))
26-
(* ArB
27-
(atan2 (+ (* S cosgam)
28-
(* V singam))
29-
temp)))
18+
:name "omerc-forward-v"
19+
:pre (< (fabs U) 1.0)
20+
(* 0.5 (* ArB (log (/ (- 1.0 U) (+ 1.0 U))))))
21+
22+
(FPCore (S B lam cosgam singam ArB)
23+
:name "omerc-forward-u-atan"
24+
:pre (>= (fabs (cos (* B lam))) 1e-7)
25+
(let* ((V (sin (* B lam)))
26+
(temp (cos (* B lam)))
27+
(numer (+ (* S cosgam) (* V singam))))
28+
(* ArB (atan2 numer temp))))
29+
30+
(FPCore (A lam)
31+
:name "omerc-forward-u-linear"
32+
(* A lam))
33+
34+
(FPCore (u v cosrot sinrot u0)
35+
:name "omerc-forward-rot-x"
36+
(let* ((udiff (- u u0)))
37+
(+ (* v cosrot) (* udiff sinrot))))
38+
39+
(FPCore (u v cosrot sinrot u0)
40+
:name "omerc-forward-rot-y"
41+
(let* ((udiff (- u u0)))
42+
(- (* udiff cosrot) (* v sinrot))))
43+
44+
(FPCore (BrA v)
45+
:name "omerc-inverse-exp"
46+
(exp (- (* BrA v))))
3047

3148
(FPCore (Qp)
32-
:name "omerc-hard-sinh-sp"
33-
:pre (> Qp 0)
34-
(* 0.5
35-
(- Qp
36-
(/ 1 Qp))))
49+
:name "omerc-inverse-Sp"
50+
:pre (not (= Qp 0.0))
51+
(* 0.5 (- Qp (/ 1.0 Qp))))
3752

3853
(FPCore (Qp)
39-
:name "omerc-hard-cosh-tp"
40-
:pre (> Qp 0)
41-
(* 0.5
42-
(+ Qp
43-
(/ 1 Qp))))
44-
45-
(FPCore (Vp Sp singam cosgam Tp)
46-
:name "omerc-hard-up-frac"
47-
:pre (and (> (fabs Tp) 1e-12)
48-
(< (fabs singam) 1)
49-
(< (fabs cosgam) 1)
50-
(< (fabs Vp) 1))
51-
(/ (+ (* Vp cosgam)
52-
(* Sp singam))
53-
Tp))
54-
55-
(FPCore (Esc Up)
56-
:name "omerc-hard-phi-scale"
57-
:pre (and (> Esc 0)
58-
(< (fabs Up) 0.999999))
59-
(/ Esc
60-
(sqrt (/ (+ 1 Up)
61-
(- 1 Up)))))
62-
63-
(FPCore (rB Sp Vp singam cosgam BrAu)
64-
:name "omerc-hard-lambda-atan2"
65-
:pre (and (< (fabs singam) 1)
66-
(< (fabs cosgam) 1)
67-
(< (fabs Vp) 1))
68-
(* -1
69-
(* rB
70-
(atan2 (- (* Sp cosgam)
71-
(* Vp singam))
72-
(cos BrAu)))))
73-
74-
(FPCore (B lamDiff denom)
75-
:name "omerc-hard-gamma0-atan"
76-
:pre (and (> (fabs denom) 1e-12)
77-
(< (fabs lamDiff) 10))
78-
(atan (/ (* 2 (sin (* B lamDiff)))
79-
denom)))
80-
81-
(FPCore (lamc F gamma0 B)
82-
:name "omerc-hard-lam0-shift"
83-
:pre (and (> (fabs B) 1e-12)
84-
(> (fabs F) 1e-12)
85-
(< (fabs (* (* 0.5 (- F (/ 1 F)))
86-
(tan gamma0)))
87-
0.999999))
88-
(let ((asinArg (* (* 0.5 (- F (/ 1 F)))
89-
(tan gamma0))))
90-
(- lamc
91-
(/ (asin asinArg)
92-
B))))
93-
94-
(FPCore (ArB D alpha_c)
95-
:name "omerc-hard-u0-atan"
96-
:pre (and (> ArB 0)
97-
(>= (- (* D D) 1) 0)
98-
(> (fabs (cos alpha_c)) 1e-12))
99-
(fabs (* ArB
100-
(atan (/ (sqrt (- (* D D) 1))
101-
(cos alpha_c))))))
102-
103-
(FPCore (ArB gamma0 fortpi)
104-
:name "omerc-hard-v-pole"
105-
:pre (and (> ArB 0)
106-
(< (fabs gamma0) 3)
107-
(> (tan (- fortpi (* 0.5 gamma0))) 0))
108-
(* ArB
109-
(log (tan (- fortpi
110-
(* 0.5 gamma0))))))
54+
:name "omerc-inverse-Tp"
55+
:pre (not (= Qp 0.0))
56+
(* 0.5 (+ Qp (/ 1.0 Qp))))
57+
58+
(FPCore (Sp Tp Vp singam cosgam)
59+
:name "omerc-inverse-Up"
60+
:pre (not (= Tp 0.0))
61+
(/ (+ (* Vp cosgam) (* Sp singam)) Tp))
62+
63+
(FPCore (Up Esc)
64+
:name "omerc-inverse-prephi"
65+
:pre (< (fabs Up) 1.0)
66+
(/ Esc (sqrt (/ (+ 1.0 Up) (- 1.0 Up)))))
67+
68+
(FPCore (Sp Vp cosgam singam BrA u rB)
69+
:name "omerc-inverse-lambda"
70+
(let* ((temp (cos (* BrA u)))
71+
(numer (- (* Sp cosgam) (* Vp singam))))
72+
(- (* rB (atan2 numer temp)))))
73+
74+
(FPCore (phi0 es)
75+
:name "omerc-init-con"
76+
:pre (and (>= es 0.0)
77+
(< es 1.0)
78+
(< (fabs phi0) (/ PI 2.0)))
79+
(let* ((sinphi0 (sin phi0)))
80+
(- 1.0 (* es (* sinphi0 sinphi0)))))
81+
82+
(FPCore (phi0 es one_es)
83+
:name "omerc-init-B"
84+
:pre (and (>= es 0.0)
85+
(< es 1.0)
86+
(> one_es 0.0)
87+
(< (fabs phi0) (/ PI 2.0)))
88+
(let* ((cosphi0 (cos phi0))
89+
(cos2 (* cosphi0 cosphi0))
90+
(cos4 (* cos2 cos2)))
91+
(sqrt (+ 1.0 (/ (* es cos4) one_es)))))
92+
93+
(FPCore (phi0 es one_es com)
94+
:name "omerc-init-D"
95+
:pre (and (>= es 0.0)
96+
(< es 1.0)
97+
(> one_es 0.0)
98+
(> com 0.0)
99+
(< (fabs phi0) (/ PI 2.0))
100+
(> (fabs (cos phi0)) 0.0)
101+
(> (- 1.0 (* es (* (sin phi0) (sin phi0)))) 0.0))
102+
(let* ((sinphi0 (sin phi0))
103+
(cosphi0 (cos phi0))
104+
(cos2 (* cosphi0 cosphi0))
105+
(cos4 (* cos2 cos2))
106+
(con (- 1.0 (* es (* sinphi0 sinphi0))))
107+
(B (sqrt (+ 1.0 (/ (* es cos4) one_es))))
108+
(root (sqrt con)))
109+
(/ (* B com) (* cosphi0 root))))
110+
111+
(FPCore (ArB D alpha_c phi0)
112+
:name "omerc-init-u0"
113+
:pre (and (>= (- (* D D) 1.0) 0.0)
114+
(not (= (cos alpha_c) 0.0)))
115+
(let* ((ratio (/ (sqrt (- (* D D) 1.0)) (cos alpha_c)))
116+
(angle (atan ratio))
117+
(scaled (* ArB angle))
118+
(mag (fabs scaled)))
119+
(if (< phi0 0.0)
120+
(- mag)
121+
mag)))
122+
123+
(FPCore (ArB gamma0)
124+
:name "omerc-init-v-pole-n"
125+
:pre (> (tan (- (/ PI 4.0) (* 0.5 gamma0))) 0.0)
126+
(* ArB (log (tan (- (/ PI 4.0) (* 0.5 gamma0))))))
127+
128+
(FPCore (ArB gamma0)
129+
:name "omerc-init-v-pole-s"
130+
:pre (> (tan (+ (/ PI 4.0) (* 0.5 gamma0))) 0.0)
131+
(* ArB (log (tan (+ (/ PI 4.0) (* 0.5 gamma0))))))

bench/tmerc.fpcore

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
(FPCore (phi)
2+
:name "approx-t-guarded"
3+
(let* ((sinphi (sin phi))
4+
(cosphi (cos phi)))
5+
(if (> (fabs cosphi) 1e-10)
6+
(/ sinphi cosphi)
7+
0.0)))
8+
9+
(FPCore (phi lam es)
10+
:name "approx-scaled-lambda"
11+
:pre (and (>= es 0.0)
12+
(< es 1.0)
13+
(> (- 1.0 (* es (* (sin phi) (sin phi)))) 0.0))
14+
(let* ((sinphi (sin phi))
15+
(cosphi (cos phi))
16+
(den (- 1.0 (* es (* sinphi sinphi)))))
17+
(/ (* cosphi lam)
18+
(sqrt den))))
19+
20+
(FPCore (phi es)
21+
:name "approx-inv-meridional-con"
22+
:pre (and (>= es 0.0)
23+
(< es 1.0))
24+
(let* ((sinphi (sin phi)))
25+
(- 1.0 (* es (* sinphi sinphi)))))
26+
27+
(FPCore (phi x es k0)
28+
:name "approx-inv-d-term"
29+
:pre (and (>= es 0.0)
30+
(< es 1.0)
31+
(> k0 0.0)
32+
(> (- 1.0 (* es (* (sin phi) (sin phi)))) 0.0))
33+
(let* ((sinphi (sin phi))
34+
(con (- 1.0 (* es (* sinphi sinphi)))))
35+
(/ (* x (sqrt con)) k0)))
36+
37+
(FPCore (x esp)
38+
:name "spherical-inv-g-from-exp"
39+
:pre (> esp 0.0)
40+
(let* ((h (exp (/ x esp))))
41+
(* 0.5 (- h (/ 1.0 h)))))
42+
43+
(FPCore (y esp phi0 g)
44+
:name "spherical-inv-latitude-angle"
45+
:pre (and (> esp 0.0)
46+
(> (+ 1.0 (* g g)) 0.0)
47+
(>= (- 1.0 (* (cos (+ phi0 (/ y esp)))
48+
(cos (+ phi0 (/ y esp))))) 0.0))
49+
(let* ((D (+ phi0 (/ y esp)))
50+
(cosD (cos D))
51+
(numer (- 1.0 (* cosD cosD)))
52+
(denom (+ 1.0 (* g g))))
53+
(asin (sqrt (/ numer denom)))))
54+
55+
(FPCore (y esp phi0 g)
56+
:name "spherical-inv-longitude"
57+
:pre (and (> esp 0.0)
58+
(or (> (fabs g) 0.0)
59+
(> (fabs (cos (+ phi0 (/ y esp)))) 0.0)))
60+
(atan2 g (cos (+ phi0 (/ y esp)))))
61+
62+
(FPCore (angle esp phi0)
63+
:name "spherical-y-scale-shift"
64+
:pre (> esp 0.0)
65+
(* esp (- angle phi0)))
66+
67+
(FPCore (Cn lam)
68+
:name "exact-forward-conformal-lat"
69+
(let* ((sC (sin Cn))
70+
(cC (cos Cn))
71+
(cE (cos lam)))
72+
(atan2 sC (* cC cE))))
73+
74+
(FPCore (Cn lam)
75+
:name "exact-forward-tanCe"
76+
:pre (> (+ (* (sin Cn) (sin Cn))
77+
(* (cos Cn) (cos Cn) (* (cos lam) (cos lam)))) 0.0)
78+
(let* ((sC (sin Cn))
79+
(cC (cos Cn))
80+
(sE (sin lam))
81+
(cE (cos lam))
82+
(den (sqrt (+ (* sC sC)
83+
(* cC cC (* cE cE))))))
84+
(/ (* sE cC) den)))
85+
86+
(FPCore (Cn lam)
87+
:name "exact-forward-two-inv-denom"
88+
:pre (> (+ (* (sin Cn) (sin Cn))
89+
(* (cos Cn) (cos Cn) (* (cos lam) (cos lam)))) 0.0)
90+
(let* ((sC (sin Cn))
91+
(cC (cos Cn))
92+
(cE (cos lam))
93+
(den (sqrt (+ (* sC sC)
94+
(* cC cC (* cE cE))))))
95+
(/ 2.0 den)))
96+
97+
(FPCore (Ce)
98+
:name "exact-inv-exp2Ce"
99+
(exp (* 2.0 Ce)))
100+
101+
(FPCore (Ce)
102+
:name "exact-inv-half-inv-exp"
103+
(let* ((exp2 (exp (* 2.0 Ce))))
104+
(/ 0.5 exp2)))
105+
106+
(FPCore (Ce)
107+
:name "exact-inv-cosh-arg"
108+
(let* ((exp2 (exp (* 2.0 Ce)))
109+
(half (/ 0.5 exp2)))
110+
(+ (* 0.5 exp2) half)))
111+
112+
(FPCore (Cn Ce)
113+
:name "exact-inv-rr"
114+
(let* ((sinhCe (sinh Ce))
115+
(cosC (cos Cn))
116+
(sinC (sin Cn))
117+
(mod (sqrt (+ (* sinhCe sinhCe)
118+
(* cosC cosC)))))
119+
(sqrt (+ (* sinC sinC)
120+
(* mod mod)))))
121+
122+
(FPCore (cos_arg_r cosh_arg_i)
123+
:name "clenshaw-initial-r"
124+
(* 2.0 cos_arg_r cosh_arg_i))
125+
126+
(FPCore (sin_arg_r sinh_arg_i)
127+
:name "clenshaw-initial-i"
128+
(* -2.0 sin_arg_r sinh_arg_i))
129+
130+
(FPCore (sin_arg_r cosh_arg_i cos_arg_r sinh_arg_i hr hi)
131+
:name "clenshaw-final-real"
132+
(let* ((r (* sin_arg_r cosh_arg_i))
133+
(i (* cos_arg_r sinh_arg_i)))
134+
(- (* r hr) (* i hi))))
135+
136+
(FPCore (sin_arg_r cosh_arg_i cos_arg_r sinh_arg_i hr hi)
137+
:name "clenshaw-final-imag"
138+
(let* ((r (* sin_arg_r cosh_arg_i))
139+
(i (* cos_arg_r sinh_arg_i)))
140+
(+ (* r hi) (* i hr))))

0 commit comments

Comments
 (0)