Skip to content

Reduce sin polynomial degree - #10819

Merged
copybara-service[bot] merged 1 commit into
masterfrom
test_952536329
Jul 23, 2026
Merged

Reduce sin polynomial degree#10819
copybara-service[bot] merged 1 commit into
masterfrom
test_952536329

Conversation

@copybara-service

Copy link
Copy Markdown
Contributor

Reduce sin polynomial degree

5 (fp32) and 9 (fp64) was overkill, it actually slightly reduces error to drop down one degree, and of course this improves performance.

This change also adds some missing test and benchmark coverage. The test coverage isn't really necessary, because there is no architecture-specific behavior that is not covered by at least one architecture. But I think we should add these tests for completeness.

Other minor fixes in this change:

  • Add missing plot lines for multiples of epsilon on the sin approximations
  • Add IWYU pragmas for gnu_vector to silence warnings

Benchmarks:

name                                                  time/op         time/op      vs base               
bench_reference/sine_float/m:1/n:4096/real_time        50.08µ ±  4%    48.55µ ± 11%        ~ (p=0.180 n=6)
bench_reference/sine_double/m:1/n:4096/real_time       147.0µ ±  3%    149.2µ ±  6%        ~ (p=0.394 n=6)
bench_reference/cosine_float/m:1/n:4096/real_time      50.92µ ±  5%    53.09µ ± 10%        ~ (p=0.485 n=6)
bench_reference/cosine_double/m:1/n:4096/real_time     148.3µ ±  3%    146.6µ ±  3%        ~ (p=0.485 n=6)
bench/cosine_fp32_avx512/m:1/n:4096/real_time          1.796µ ±  5%    1.707µ ±  2%   -4.93% (p=0.002 n=6)
bench/cosine_fp64_avx512/m:1/n:4096/real_time          13.72µ ±  1%    13.37µ ±  1%   -2.53% (p=0.002 n=6)
bench/sine_fp32_avx512/m:1/n:4096/real_time            1.731µ ±  2%    1.620µ ±  1%   -6.43% (p=0.002 n=6)
bench/sine_fp64_avx512/m:1/n:4096/real_time            13.67µ ±  1%    13.24µ ±  3%   -3.18% (p=0.002 n=6)
bench/cosine_fp32_avx2_fma3/m:1/n:4096/real_time       2.645µ ±  5%    2.513µ ±  4%   -5.00% (p=0.009 n=6)
bench/cosine_fp64_avx2_fma3/m:1/n:4096/real_time       9.510µ ± 19%   10.409µ ±  5%        ~ (p=0.065 n=6)
bench/sine_fp32_avx2_fma3/m:1/n:4096/real_time         2.766µ ±  6%    2.470µ ±  4%  -10.71% (p=0.002 n=6)
bench/sine_fp64_avx2_fma3/m:1/n:4096/real_time         9.140µ ±  3%   10.041µ ±  4%   +9.86% (p=0.002 n=6)
bench/cosine_fp32_fma3/m:1/n:4096/real_time            3.489µ ±  4%    3.331µ ±  4%   -4.54% (p=0.002 n=6)
bench/cosine_fp64_fma3/m:1/n:4096/real_time            10.77µ ±  4%    11.75µ ±  3%   +9.03% (p=0.002 n=6)
bench/sine_fp32_fma3/m:1/n:4096/real_time              3.262µ ±  5%    3.276µ ±  5%        ~ (p=0.937 n=6)
bench/sine_fp64_fma3/m:1/n:4096/real_time              9.986µ ±  3%   10.275µ ±  7%        ~ (p=0.180 n=6)
bench/cosine_fp32_avx2/m:1/n:4096/real_time            4.251µ ±  2%    3.927µ ±  4%   -7.62% (p=0.002 n=6)
bench/cosine_fp64_avx2/m:1/n:4096/real_time            15.53µ ±  8%    17.05µ ±  3%   +9.75% (p=0.004 n=6)
bench/sine_fp32_avx2/m:1/n:4096/real_time              4.238µ ±  3%    4.064µ ±  4%   -4.10% (p=0.004 n=6)
bench/sine_fp64_avx2/m:1/n:4096/real_time              15.06µ ±  3%    16.69µ ±  6%  +10.81% (p=0.002 n=6)
bench/cosine_fp32_avx/m:1/n:4096/real_time             6.647µ ±  3%    5.981µ ±  4%  -10.02% (p=0.002 n=6)
bench/cosine_fp64_avx/m:1/n:4096/real_time             18.07µ ±  3%    16.89µ ±  3%   -6.48% (p=0.002 n=6)
bench/sine_fp32_avx/m:1/n:4096/real_time               5.621µ ±  3%    5.237µ ±  7%   -6.83% (p=0.004 n=6)
bench/sine_fp64_avx/m:1/n:4096/real_time               17.44µ ±  1%    17.00µ ±  3%   -2.55% (p=0.015 n=6)
bench/cosine_fp32_sse41/m:1/n:4096/real_time           11.68µ ±  2%    10.58µ ±  3%   -9.44% (p=0.002 n=6)
bench/cosine_fp64_sse41/m:1/n:4096/real_time           33.61µ ±  2%    31.63µ ±  4%   -5.88% (p=0.002 n=6)
bench/sine_fp32_sse41/m:1/n:4096/real_time             11.15µ ±  4%    10.01µ ±  2%  -10.18% (p=0.002 n=6)
bench/sine_fp64_sse41/m:1/n:4096/real_time             36.07µ ±  3%    31.63µ ±  4%  -12.31% (p=0.002 n=6)
bench/cosine_fp32_sse2/m:1/n:4096/real_time            12.06µ ±  6%    10.62µ ±  4%  -11.94% (p=0.002 n=6)
bench/cosine_fp64_sse2/m:1/n:4096/real_time            36.62µ ±  4%    34.48µ ±  2%   -5.83% (p=0.002 n=6)
bench/sine_fp32_sse2/m:1/n:4096/real_time              13.10µ ±  5%    11.53µ ±  3%  -11.98% (p=0.002 n=6)
bench/sine_fp64_sse2/m:1/n:4096/real_time              36.74µ ±  3%    34.86µ ±  5%   -5.13% (p=0.002 n=6)
bench/cosine_fp32_sse2_fma/m:1/n:4096/real_time       107.84µ ±  2%    96.53µ ±  0%  -10.49% (p=0.002 n=6)
bench/sine_fp32_sse2_fma/m:1/n:4096/real_time         107.89µ ±  2%    96.86µ ±  2%  -10.23% (p=0.002 n=6)
geomean                                               13.74µ          13.24µ         -3.60%

5 (fp32) and 9 (fp64) was overkill, it actually slightly reduces error to drop down one degree, and of course this improves performance.

This change also adds some missing test and benchmark coverage. The test coverage isn't really necessary, because there is no architecture-specific behavior that is not covered by at least one architecture. But I think we should add these tests for completeness.

Other minor fixes in this change:
- Add missing plot lines for multiples of epsilon on the sin approximations
- Add IWYU pragmas for gnu_vector to silence warnings

Benchmarks:
```
name                                                  time/op         time/op      vs base
bench_reference/sine_float/m:1/n:4096/real_time        50.08µ ±  4%    48.55µ ± 11%        ~ (p=0.180 n=6)
bench_reference/sine_double/m:1/n:4096/real_time       147.0µ ±  3%    149.2µ ±  6%        ~ (p=0.394 n=6)
bench_reference/cosine_float/m:1/n:4096/real_time      50.92µ ±  5%    53.09µ ± 10%        ~ (p=0.485 n=6)
bench_reference/cosine_double/m:1/n:4096/real_time     148.3µ ±  3%    146.6µ ±  3%        ~ (p=0.485 n=6)
bench/cosine_fp32_avx512/m:1/n:4096/real_time          1.796µ ±  5%    1.707µ ±  2%   -4.93% (p=0.002 n=6)
bench/cosine_fp64_avx512/m:1/n:4096/real_time          13.72µ ±  1%    13.37µ ±  1%   -2.53% (p=0.002 n=6)
bench/sine_fp32_avx512/m:1/n:4096/real_time            1.731µ ±  2%    1.620µ ±  1%   -6.43% (p=0.002 n=6)
bench/sine_fp64_avx512/m:1/n:4096/real_time            13.67µ ±  1%    13.24µ ±  3%   -3.18% (p=0.002 n=6)
bench/cosine_fp32_avx2_fma3/m:1/n:4096/real_time       2.645µ ±  5%    2.513µ ±  4%   -5.00% (p=0.009 n=6)
bench/cosine_fp64_avx2_fma3/m:1/n:4096/real_time       9.510µ ± 19%   10.409µ ±  5%        ~ (p=0.065 n=6)
bench/sine_fp32_avx2_fma3/m:1/n:4096/real_time         2.766µ ±  6%    2.470µ ±  4%  -10.71% (p=0.002 n=6)
bench/sine_fp64_avx2_fma3/m:1/n:4096/real_time         9.140µ ±  3%   10.041µ ±  4%   +9.86% (p=0.002 n=6)
bench/cosine_fp32_fma3/m:1/n:4096/real_time            3.489µ ±  4%    3.331µ ±  4%   -4.54% (p=0.002 n=6)
bench/cosine_fp64_fma3/m:1/n:4096/real_time            10.77µ ±  4%    11.75µ ±  3%   +9.03% (p=0.002 n=6)
bench/sine_fp32_fma3/m:1/n:4096/real_time              3.262µ ±  5%    3.276µ ±  5%        ~ (p=0.937 n=6)
bench/sine_fp64_fma3/m:1/n:4096/real_time              9.986µ ±  3%   10.275µ ±  7%        ~ (p=0.180 n=6)
bench/cosine_fp32_avx2/m:1/n:4096/real_time            4.251µ ±  2%    3.927µ ±  4%   -7.62% (p=0.002 n=6)
bench/cosine_fp64_avx2/m:1/n:4096/real_time            15.53µ ±  8%    17.05µ ±  3%   +9.75% (p=0.004 n=6)
bench/sine_fp32_avx2/m:1/n:4096/real_time              4.238µ ±  3%    4.064µ ±  4%   -4.10% (p=0.004 n=6)
bench/sine_fp64_avx2/m:1/n:4096/real_time              15.06µ ±  3%    16.69µ ±  6%  +10.81% (p=0.002 n=6)
bench/cosine_fp32_avx/m:1/n:4096/real_time             6.647µ ±  3%    5.981µ ±  4%  -10.02% (p=0.002 n=6)
bench/cosine_fp64_avx/m:1/n:4096/real_time             18.07µ ±  3%    16.89µ ±  3%   -6.48% (p=0.002 n=6)
bench/sine_fp32_avx/m:1/n:4096/real_time               5.621µ ±  3%    5.237µ ±  7%   -6.83% (p=0.004 n=6)
bench/sine_fp64_avx/m:1/n:4096/real_time               17.44µ ±  1%    17.00µ ±  3%   -2.55% (p=0.015 n=6)
bench/cosine_fp32_sse41/m:1/n:4096/real_time           11.68µ ±  2%    10.58µ ±  3%   -9.44% (p=0.002 n=6)
bench/cosine_fp64_sse41/m:1/n:4096/real_time           33.61µ ±  2%    31.63µ ±  4%   -5.88% (p=0.002 n=6)
bench/sine_fp32_sse41/m:1/n:4096/real_time             11.15µ ±  4%    10.01µ ±  2%  -10.18% (p=0.002 n=6)
bench/sine_fp64_sse41/m:1/n:4096/real_time             36.07µ ±  3%    31.63µ ±  4%  -12.31% (p=0.002 n=6)
bench/cosine_fp32_sse2/m:1/n:4096/real_time            12.06µ ±  6%    10.62µ ±  4%  -11.94% (p=0.002 n=6)
bench/cosine_fp64_sse2/m:1/n:4096/real_time            36.62µ ±  4%    34.48µ ±  2%   -5.83% (p=0.002 n=6)
bench/sine_fp32_sse2/m:1/n:4096/real_time              13.10µ ±  5%    11.53µ ±  3%  -11.98% (p=0.002 n=6)
bench/sine_fp64_sse2/m:1/n:4096/real_time              36.74µ ±  3%    34.86µ ±  5%   -5.13% (p=0.002 n=6)
bench/cosine_fp32_sse2_fma/m:1/n:4096/real_time       107.84µ ±  2%    96.53µ ±  0%  -10.49% (p=0.002 n=6)
bench/sine_fp32_sse2_fma/m:1/n:4096/real_time         107.89µ ±  2%    96.86µ ±  2%  -10.23% (p=0.002 n=6)
geomean                                               13.74µ          13.24µ         -3.60%
```
PiperOrigin-RevId: 952840776
@copybara-service
copybara-service Bot merged commit c18ab58 into master Jul 23, 2026
@copybara-service
copybara-service Bot deleted the test_952536329 branch July 23, 2026 17:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant