comp.lang.ada
 help / color / mirror / Atom feed
* Trigonometric operations on x86 and x64 CPUs
@ 2016-12-16  0:38 Robert Eachus
  2016-12-16 14:00 ` Luke A. Guest
                   ` (2 more replies)
  0 siblings, 3 replies; 17+ messages in thread
From: Robert Eachus @ 2016-12-16  0:38 UTC (permalink / raw)


A while back I expressed surprise that there were no versions of the Elementary_Functions package for x86/x64 packages which used the built-in trig functions of the x86 family.  It looked like an easy project but...

It turns out that the only trig functions available are the former x87 instructions which use a special stack.  Not a problem--except that these instructions are not reachable in (64-bit) "Long_Mode".  You have to have a separate compilation unit that switches to one of the 32-bit modes.  Okay... But you also need to support saving and restoring the x87 register stack.  There is a protocol for doing that, but 64-bit code can't do it.  You would think "No problem 64-bit programs can't execute x87 instructions anyway."  Except, that is exactly what you are trying to do!  So you need to call a compatibility mode proceedure every time the CPU does a 64-bit context switch. 

At this point, I was ready to give up on the project as a bad job.  I could modify the stack save/restore code on Linux, but even then I would have a distributed cost.  Then I ran across a page which explains that the Intel instructions use a 66-bit representation of Pi, and that results from the range reduction folding done in the software, is some values having only four accurate significant bits!  It looks better when expressed relative to the argument in radians--but often you want to find sine or cosine of an angle in degrees...

Anyway, turns out you don't want a package that uses the built-in trig functions.  What about square root, logs, and e^x?  They should be all right but you still have the nasty distributed overhead. Oh! And the stored values for e, and the logs to convert to base 2 or 10 are all 66 bit.  Maybe some future instruction set extension will provide correct versions of the trig functions without the 32-bit mode requirement.

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2016-12-21  9:29 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-16  0:38 Trigonometric operations on x86 and x64 CPUs Robert Eachus
2016-12-16 14:00 ` Luke A. Guest
2016-12-16 20:16 ` Randy Brukardt
2016-12-16 23:20   ` Robert Eachus
2016-12-18 10:09     ` already5chosen
2016-12-18 14:19       ` Robert Eachus
2016-12-18 15:45         ` hreba
2016-12-18 15:47         ` already5chosen
2016-12-19 23:11       ` Randy Brukardt
2016-12-19 23:49         ` already5chosen
2016-12-20  5:27           ` Niklas Holsti
2016-12-20  8:37             ` Simon Wright
2016-12-20  9:12               ` G.B.
2016-12-20 18:01             ` already5chosen
2016-12-21  1:20               ` Randy Brukardt
2016-12-21  9:29                 ` already5chosen
2016-12-16 20:50 ` Vadim Godunko

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox