Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > complexity of trigonometric functions

Reply
Thread Tools

complexity of trigonometric functions

 
 
osmium
Guest
Posts: n/a
 
      09-02-2010
red floyd wrote:

> On Sep 2, 7:38 am, "osmium" <(E-Mail Removed)> wrote:
>
>> You can get an idea of where things were when the computer started
>> becoming so pervasive from the link, wander around a few pages in
>> the vicinity - there are page links at the top. There may have been
>> enormous progress since then; if the upcoming Pentium MarkVII (or
>> whatever) had a sine function, I would not be *really* astonished.
>> Though I doubt it.

>
> Intel chips have had an FSIN instruction since the '486, IIRC.
> Acutally, it's
> had it since the '387, but that was a separate coprocessor chip.


Well, darn. I am going to have to start actually reading some of these
books I have. I have a reference manual for the 486 on my shelves; after
that I gave up on assembly language. Obviously, I wasn't very enthusiastic
in 486 days either.

The book shows an FSIN takes 241 "clocks" and FMUL takes (commonly) 16
clocks. Anyone who sets out to do better than that is doomed to failure.
Whether "clock" is an ink saving way of saying "clock cycle" I do not know.


 
Reply With Quote
 
 
 
 
Marc
Guest
Posts: n/a
 
      09-02-2010
On 2 sep, 19:35, "BGB / cr88192" <(E-Mail Removed)> wrote:
> "red floyd" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
> On Sep 2, 7:26 am, Vladimir Jovic <(E-Mail Removed)> wrote:
>
> > I am using standard lib's sin and cos. Where should I look how many
> > element of the series is taken? Compiler's documentation?

>
> <--
> Who says it's even using a series? *Maybe it's using your CPU's
> FSIN instruction (or equivalent).
> -->


Note that fsin causes the computer to use some microcode that uses a
series...
(there isn't an actual circuit on the chip that directly computes sin,
AFAIK).

> yes, this is what most compilers do for these functions (sin, cos, sqrt,
> ...).
>
> using a series for these calculations (in a general case) would be a serious
> waste of time (even if there were not direct CPU support).


Did you measure before posting this? I did some measurements about a
year ago, and for type double, using fsin was slower and less accurate
than a software implementation (still using x87), which itself was
slower than the same on SSE. For float, the difference is even more
visible.
 
Reply With Quote
 
 
 
 
BGB / cr88192
Guest
Posts: n/a
 
      09-02-2010

"osmium" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> red floyd wrote:
>
>> On Sep 2, 7:38 am, "osmium" <(E-Mail Removed)> wrote:
>>
>>> You can get an idea of where things were when the computer started
>>> becoming so pervasive from the link, wander around a few pages in
>>> the vicinity - there are page links at the top. There may have been
>>> enormous progress since then; if the upcoming Pentium MarkVII (or
>>> whatever) had a sine function, I would not be *really* astonished.
>>> Though I doubt it.

>>
>> Intel chips have had an FSIN instruction since the '486, IIRC.
>> Acutally, it's
>> had it since the '387, but that was a separate coprocessor chip.

>
> Well, darn. I am going to have to start actually reading some of these
> books I have. I have a reference manual for the 486 on my shelves; after
> that I gave up on assembly language. Obviously, I wasn't very
> enthusiastic in 486 days either.
>
> The book shows an FSIN takes 241 "clocks" and FMUL takes (commonly) 16
> clocks. Anyone who sets out to do better than that is doomed to failure.
> Whether "clock" is an ink saving way of saying "clock cycle" I do not
> know.


checking a newer Intel manual, FSIN is more around 130 clock cycles, whereas
FMUL is 2.

but, yeah, trying to do the calculation via a series is not likely to turn
out well, but some savings are possible if one uses lookup tables (although
this may cost accuracy and has other issues, so is not really a good
general-purpose solution in most cases...).

or such...


 
Reply With Quote
 
BGB / cr88192
Guest
Posts: n/a
 
      09-02-2010

"Marc" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
On 2 sep, 19:35, "BGB / cr88192" <(E-Mail Removed)> wrote:
> "red floyd" <(E-Mail Removed)> wrote in message
>
> news:(E-Mail Removed)...
> On Sep 2, 7:26 am, Vladimir Jovic <(E-Mail Removed)> wrote:
>
> > I am using standard lib's sin and cos. Where should I look how many
> > element of the series is taken? Compiler's documentation?

>
> <--
> Who says it's even using a series? Maybe it's using your CPU's
> FSIN instruction (or equivalent).
> -->


<--
Note that fsin causes the computer to use some microcode that uses a
series...
(there isn't an actual circuit on the chip that directly computes sin,
AFAIK).
-->

fair enough...


> yes, this is what most compilers do for these functions (sin, cos, sqrt,
> ...).
>
> using a series for these calculations (in a general case) would be a
> serious
> waste of time (even if there were not direct CPU support).


<--
Did you measure before posting this? I did some measurements about a
year ago, and for type double, using fsin was slower and less accurate
than a software implementation (still using x87), which itself was
slower than the same on SSE. For float, the difference is even more
visible.
-->

well, partly by this I also meant:
there are actually faster ways of even doing SW implementations than to use
a series...
(this is what I meant by "even if there were not direct CPU support", or
IOW, there are faster ways in SW, but they were not so likely be via using a
series...).

examples of faster ways include several variations on using a lookup table,
....


I have used series before, but mostly 12-stage series, as I had estimated by
12-steps that the result would largely converge with 32-bit floats (it would
take a longer series to entirely converge with doubles though).

however, my results showed the opposite effect, with the series being
slower...

granted, one could possibly make it faster by precalculating some of the
values (using precalculated divisors and using multiplies instead of
divides, and also expanding out any for loops, ...), but whatever...



 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      09-03-2010
[Please do not mail me a copy of your followup]

red floyd <(E-Mail Removed)> spake the secret code
<(E-Mail Removed)> thusly:

>On Sep 2, 7:38*am, "osmium" <(E-Mail Removed)> wrote:
>
>> You can get an idea of where things were when the computer started becoming
>> so pervasive from the link, wander around a few pages in the vicinity -
>> there are page links at the top. *There may have been enormous progress
>> since then; if the upcoming Pentium MarkVII *(or whatever) had a sine
>> function, I would not be *really* astonished. *Though I doubt it.

>
>Intel chips have had an FSIN instruction since the '486, IIRC.
>Acutally, it's
>had it since the '387, but that was a separate coprocessor chip.


There were FPU coprocessor chips for the 8088 (8087), the 80286
(80287), 80386 (80387) and early 80486 (80487) chips which didn't have
an on-board FPU. Eventually a version of the 80486 was developed
which integrated the FPU and all subsequent entries in the x86
architecture evolution have included an on-chip FPU.

All of these FPUs, whether integrated on-chip or not, have had the
FSIN, FCOS, etc., instructions for computing trigonometric functions.
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://legalizeadulthood.wordpress.com/the-direct3d-graphics-pipeline/>

Legalize Adulthood! <http://legalizeadulthood.wordpress.com>
 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      09-03-2010
On 9/2/2010 9:04 PM, Richard wrote:
> red floyd<(E-Mail Removed)> spake the secret code
> <(E-Mail Removed)> thusly:
>
>> On Sep 2, 7:38 am, "osmium"<(E-Mail Removed)> wrote:
>>
>>> You can get an idea of where things were when the computer started becoming
>>> so pervasive from the link, wander around a few pages in the vicinity -
>>> there are page links at the top. There may have been enormous progress
>>> since then; if the upcoming Pentium MarkVII (or whatever) had a sine
>>> function, I would not be *really* astonished. Though I doubt it.

>>
>> Intel chips have had an FSIN instruction since the '486, IIRC.
>> Acutally, it's
>> had it since the '387, but that was a separate coprocessor chip.

>
> There were FPU coprocessor chips for the 8088 (8087), the 80286
> (80287), 80386 (80387) and early 80486 (80487) chips which didn't have
> an on-board FPU. Eventually a version of the 80486 was developed
> which integrated the FPU and all subsequent entries in the x86
> architecture evolution have included an on-chip FPU.


Not quite. The early original 80486 (no DX or SX) had an on-board FPU.
The 486SX was a 486 with the FPU disabled, but it could use an 80487
FPU, which was essentially a 486 with the integer unit disabled.
I know this because I had an early 486/33 (no DX or SX).

Once the DX/SX split came along, the DX (and DX/2, DX/3 and DX/4) series
had the integrated FPU.

> All of these FPUs, whether integrated on-chip or not, have had the
> FSIN, FCOS, etc., instructions for computing trigonometric functions.


I have an 8087 manual at my office, I'll have to check. I didn't think
the 8087 and the 80287 had trig. I'll double-check the 8087 manual to
see (some websites indicate the 287 and earlier didn't have it).




 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      09-03-2010
On Sep 2, 10:21*pm, red floyd <(E-Mail Removed)> wrote:
> On 9/2/2010 9:04 PM, Richard wrote:
>
>
>
> > red floyd<(E-Mail Removed)> *spake the secret code
> > <(E-Mail Removed)> *thusly:

>
> >> On Sep 2, 7:38 am, "osmium"<(E-Mail Removed)> *wrote:

>
> >>> You can get an idea of where things were when the computer started becoming
> >>> so pervasive from the link, wander around a few pages in the vicinity -
> >>> there are page links at the top. *There may have been enormous progress
> >>> since then; if the upcoming Pentium MarkVII *(or whatever) had a sine
> >>> function, I would not be *really* astonished. *Though I doubt it.

>
> >> Intel chips have had an FSIN instruction since the '486, IIRC.
> >> Acutally, it's
> >> had it since the '387, but that was a separate coprocessor chip.

>
> > There were FPU coprocessor chips for the 8088 (8087), the 80286
> > (80287), 80386 (80387) and early 80486 (80487) chips which didn't have
> > an on-board FPU. *Eventually a version of the 80486 was developed
> > which integrated the FPU and all subsequent entries in the x86
> > architecture evolution have included an on-chip FPU.

>
> Not quite. *The early original 80486 (no DX or SX) had an on-board FPU.
> The 486SX was a 486 with the FPU disabled, but it could use an 80487
> FPU, which was essentially a 486 with the integer unit disabled.
> I know this because I had an early 486/33 (no DX or SX).
>
> Once the DX/SX split came along, the DX (and DX/2, DX/3 and DX/4) series
> had the integrated FPU.
>
> > All of these FPUs, whether integrated on-chip or not, have had the
> > FSIN, FCOS, etc., instructions for computing trigonometric functions.

>
> I have an 8087 manual at my office, I'll have to check. *I didn't think
> the 8087 and the 80287 had trig. *I'll double-check the 8087 manual to
> see (some websites indicate the 287 and earlier didn't have it).


According to my 8087 manual (Intel 8086 manual, July 1981, appendix
S), the 8087 instruction set did not include FSIN or FCOS.
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      09-06-2010
On Sep 2, 5:46 pm, red floyd <(E-Mail Removed)> wrote:
> On Sep 2, 7:26 am, Vladimir Jovic <(E-Mail Removed)> wrote:


> > I am using standard lib's sin and cos. Where should I look how many
> > element of the series is taken? Compiler's documentation?


> Who says it's even using a series? Maybe it's using your CPU's
> FSIN instruction (or equivalent).


The hardware implementations of FSIN or equivalent that I've
seen have all used microcode... which evaluated a series.

--
James Kanze
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      09-06-2010
On Sep 2, 5:48 pm, red floyd <(E-Mail Removed)> wrote:
> On Sep 2, 7:38 am, "osmium" <(E-Mail Removed)> wrote:


> > You can get an idea of where things were when the computer
> > started becoming so pervasive from the link, wander around
> > a few pages in the vicinity - there are page links at the
> > top. There may have been enormous progress since then; if
> > the upcoming Pentium MarkVII (or whatever) had a sine
> > function, I would not be *really* astonished. Though
> > I doubt it.


> Intel chips have had an FSIN instruction since the '486, IIRC.
> Acutally, it's had it since the '387, but that was a separate
> coprocessor chip.


The Intel 8087 (1981) had an FSIN function, although it only
worked over a small range. (It required the client to scale the
input first.)

Given the way things have evolved, I would not be surprised if
on a modern chip, one could do it faster by programming the
series directly using standard multiples and divides.

--
James Kanze
 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      09-06-2010
On Sep 3, 5:39 pm, red floyd <(E-Mail Removed)> wrote:
> On Sep 2, 10:21 pm, red floyd <(E-Mail Removed)> wrote:


[...]
> According to my 8087 manual (Intel 8086 manual, July 1981,
> appendix S), the 8087 instruction set did not include FSIN or
> FCOS.


The 8087 definitely had some support for trig, since I used it
back then. IIRC, it was in the form of an FSINCOS or FCOSSIN
function, which calculated both sin and cos (over a very limited
range).

My 8087 manual was lost in a move, many, many years ago; if
you've got one and can check it, I'd be curious to know.

--
James Kanze
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to write vhdl code for 1-d trigonometric function rajeswari01 Hardware 0 10-20-2010 11:21 AM
java trigonometric solver Guntius.GIBLI@gmail.com Java 13 09-08-2006 12:56 PM
2.0 Controlling password complexity in Membership =?Utf-8?B?TW9yZ2FuIFJvZGVyaWNr?= ASP .Net 3 04-22-2005 12:23 AM
reducing complexity foldface@yahoo.co.uk ASP .Net 0 10-12-2004 01:05 PM
please help me in distinguish redefining functions, overloading functions and overriding functions. Xiangliang Meng C++ 1 06-21-2004 03:11 AM



Advertisments