Author Topic: Fast Sinus() and Cosinus() algos  (Read 12588 times)

Farabi

  • Member
  • ****
  • Posts: 969
  • Neuroscience Fans
Re: Fast Sinus() and Cosinus() algos
« Reply #15 on: October 16, 2015, 11:22:40 PM »
Hi jj how much time it was called? Fsin was 100microsecond for 1 million loop. 358ms was too slow.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

jj2007

  • Member
  • *****
  • Posts: 11526
  • Assembler is fun ;-)
    • MasmBasic
Re: Fast Sinus() and Cosinus() algos
« Reply #16 on: October 17, 2015, 02:25:16 AM »
Hi jj how much time it was called? Fsin was 100microsecond for 1 million loop. 358ms was too slow.

Can you explain a bit what you are referring to?

Farabi

  • Member
  • ****
  • Posts: 969
  • Neuroscience Fans
Re: Fast Sinus() and Cosinus() algos
« Reply #17 on: October 17, 2015, 12:25:24 PM »
Edit:

Sorry I get a wrong perception.
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

Farabi

  • Member
  • ****
  • Posts: 969
  • Neuroscience Fans
Re: Fast Sinus() and Cosinus() algos
« Reply #18 on: October 17, 2015, 12:30:12 PM »
Hi folks,
Just uploaded a new version featuring faster Sinus() and Cosinus() algos. The absolute error is rather small, here compared to the FPU fsin and fcos functions:
Code: [Select]
x       sin x                   error
-90     -1.000000000000000000   0.0
-45     -0.7071067811865475244  -9.38e-18
0       0.0     0.0
45      0.7071067811865475244   9.38e-18
90      1.000000000000000000    0.0
135     0.7071067811865475244   -2.82e-17
180     0.0     -5.31e-17
225     -0.7071067811865475244  -4.69e-17
270     -1.000000000000000000   0.0
315     -0.7071067811865475244  6.57e-17
360     0.0     1.06e-16
405     0.7071067811865475244   8.44e-17
450     1.000000000000000000    0.0

x       cos x                   error
-90     0.0     0.0
-45     0.7071067811865475244   -9.38e-18
0       1.000000000000000000    0.0
45      0.7071067811865475244   -9.38e-18
90      0.0     -2.65e-17
135     -0.7071067811865475244  -2.81e-17
180     -1.000000000000000000   0.0
225     -0.7071067811865475244  4.69e-17
270     0.0     7.96e-17
315     0.7071067811865475244   6.56e-17
360     1.000000000000000000    0.0
405     0.7071067811865475244   -8.45e-17
450     0.0     -1.33e-16

On my machine, they are almost five times as fast. Can I have some timings please? Thanks.

Code: [Select]
Intel(R) Core(TM) i5-2450M CPU @ 2.50GHz
293 ms fpu fsin         71 ms MasmBasic
295 ms fpu fsin         61 ms MasmBasic
294 ms fpu fsin         61 ms MasmBasic
295 ms fpu fsin         66 ms MasmBasic
290 ms fpu fsin         60 ms MasmBasic
290 ms fpu fsin         61 ms MasmBasic
299 ms fpu fsin         61 ms MasmBasic
288 ms fpu fsin         67 ms MasmBasic

Ah my mistake, your are faster.  :dazzled:
http://farabidatacenter.url.ph/MySoftware/
My 3D Game Engine Demo.

Contact me at Whatsapp: 6283818314165

Adamanteus

  • Member
  • **
  • Posts: 241
    • LLC "AMS"
Re: Fast Sinus() and Cosinus() algos
« Reply #19 on: December 16, 2015, 09:57:52 AM »
 And looks not only yours, as with sameness  of 18 digits with fpu-CRT - not sure as my test of original C++ algo, shows minimal sameness of 6 digits, as in this angel
Code: [Select]
36.66666 0.59715859 0.59715860- mostly correct are 7 digits, in 8 digits output already many difference with MS-CRT sin in test tabels.

jj2007

  • Member
  • *****
  • Posts: 11526
  • Assembler is fun ;-)
    • MasmBasic
Re: Fast Sinus() and Cosinus() algos
« Reply #20 on: December 16, 2015, 07:51:25 PM »
Could you post your source, please? I have tried to mimic your tabels output, but somehow the steps are not exactly the same.

include \masm32\MasmBasic\MasmBasic.inc      ; download
  SetGlobals fct:REAL10
  Init
  For_ fct=0.0 To 0.785398 Step 0.00289814760147601476014760147601
      Print Str$("\n%9f\t", fct), Str$("%8f", Sinus(fct, rad)#)
  Next

EndOfCode


Sinus() has the same precision as the FPU fsin function when used with integer arguments such as 45°, 123° etc.

Adamanteus

  • Member
  • **
  • Posts: 241
    • LLC "AMS"
Re: Fast Sinus() and Cosinus() algos
« Reply #21 on: December 16, 2015, 08:23:00 PM »
 Source on C++ - there exactness of REAL8, step equal 10 minutes in degrees and asm source of REAL10 I not had, so full test can't.
P.S. Translating source if need yourself, so it's and me disturbing.
« Last Edit: December 26, 2015, 02:34:15 PM by Adamanteus »

TWell

  • Member
  • ****
  • Posts: 748
Re: Fast Sinus() and Cosinus() algos
« Reply #22 on: December 16, 2015, 11:05:54 PM »
Slower in this AMD? Why?
Code: [Select]
AMD Athlon(tm) II X2 220 Processor 2.8 GHz
230 ms fpu fsin         725 ms CRT sin          116 ms MasmBasic
231 ms fpu fsin         706 ms CRT sin          119 ms MasmBasic
234 ms fpu fsin         704 ms CRT sin          116 ms MasmBasic
229 ms fpu fsin         707 ms CRT sin          116 ms MasmBasic
229 ms fpu fsin         708 ms CRT sin          116 ms MasmBasic
231 ms fpu fsin         710 ms CRT sin          116 ms MasmBasic
229 ms fpu fsin         714 ms CRT sin          117 ms MasmBasic
230 ms fpu fsin         710 ms CRT sin          115 ms MasmBasic