Being not so skilled in ASM I would like to ask (I am interested on Win64 solution):Well, does it produce the right result? (Rhetorical question.)
- My code is correct ?
- Is it worth to do that ? I mean for example in term of speed or it does not make sense to do that ?Frankly? No. It’s too trivial. If you have some complicated calculations requiring like all 8 FPU stack registers, then maaaaayyyybe.
- I have noted that for X=Y=0 arctan=0 and if X=0 the arctan is +-90 according to the sign of Y (so X=0 is not raising any exception, in some way this make sense considering divion by zero at the limit +-inf that happens for +-90)It’s all documented. Take a look at the instruction reference (https://www.felixcloutier.com/x86/fpatan#tbl-3-30) (the comment below the table).
Thanks to all,
here my notes:
- the routine shown by Winni is grayed and I assume that the code executed is the first one shown by me being not gayed
Thanks to all,
here my notes:
- the routine shown by Winni is grayed and I assume that the code executed is the first one shown by me being not gayed
If your code is grayed you are on a 32 bit installation
- wait/fwait (same opcode) is rather a relic from the ole days (https://www.agner.org/optimize/optimizing_assembly.pdf#page=142) when you actually could purchase the 8087 (the FPU) separately and place it into a socket next to the CPU. You don’t need it.
- If you haven’t altered the calling convention (https://freepascal.org/docs-html/current/prog/progsu7.html), the default ABI on Linux (and maybe on Windoze, I don’t know) allows you to pass the result of an real function on top of the FPU stack, so you don’t need to move anything anywhere. Just place the result in st(0).
Or on Win64, cause Win64 does not use the FPU.
Or on Win64, cause Win64 does not use the FPU.
On Windows 7 / 64 the code is NOT grayed.
...
...sorry for my ignorance by why the code below compile
...
..and the code from Kays and Winni does not compile (compiler message "un reconignized op code FLDT or FLD", in my ASM version I have FLD op code !)
...
The whole question is whether it is a bug or a feature.
Right, right, from a compiler’s or library developer’s point of view it’s necessary to do that, because you don’t positively know the current exception mask. From an application programmer’s POV, though, you can omit fwait in this particular case: fpatan won’t raise the Stack Underflow, nor the Invalid Argument exception here, and the Denormalized, Underflow and Precision exceptions are masked, usually.It is needed if one wants a potential FPU exception raised at the correct location. Otherwise it will be raised at the next FPU instruction which might be far away.
- wait/fwait (same opcode) is rather a relic from the ole days (https://www.agner.org/optimize/optimizing_assembly.pdf#page=142) when you actually could purchase the 8087 (the FPU) separately and place it into a socket next to the CPU. You don’t need it.