From: Damian McGuckin <damianm@esi.com.au>
To: musl@lists.openwall.com
Subject: Re: [musl] Considering x86-64 fenv.s to C
Date: Sun, 26 Jan 2020 14:30:32 +1100 (AEDT) [thread overview]
Message-ID: <alpine.LRH.2.02.2001261428440.4774@key0.esi.com.au> (raw)
In-Reply-To: <20200125001100.GY30412@brightrain.aerifal.cx>
PowerPC 64:
/*
* powerpc64 ARCHITECTURE (tolterable reference is below)
*
* http://math-atlas.sourceforge.net/devel/assembly/ppc_isa.pdf
*
* PowerPC includes cause (or reason) bits which qualify why an INVALID
* exception get raised. The cause can be regarded as just an explanation
* in most cases. In fact, if only the ppropriate cause bit is set in the
* control register and this is fed to in a 'Move to FPSCR', the INVALID
* exception will be triggered automatically. The complete list is:
*
* VXSNAN caused by a floating point operation on a SNAN
* VXISI caused by the operation INFINITY - INFINITY
* VXIDI caused by the operation INFINITY / INFINITY
* VXZDZ caused by the operation 0.0 / 0.0
* VXIMZ caused by the operation INFINITY * 0
* VXCVI caused by an illegal integer conversion
* VXVC caused by an ordered comparison involving a NaN
* VXSOFT caused by an explicit sofware request
* VXSQRT caused by a sqrt/rsqrt on a negative & non-zero number
*
* The OR of all such causes is called FE_ALL_INVALID in the API.
*
* One above, VXSOFT, is that caused 'By (An Explicit Software) Request'. The
* documentation says that its purpose is to allow software to cause/raise an
* Invalid Operation Exception for a condition that is not necessarily
* associated with the execution of a floating-point instruction. It could
* even be used by a program to complain about some negative and non-zero
* operand long BEFORE it gets given to a SQRT or RSQRT imnstruction where
* it would otherwise invoke the VXSQRT cause and trigger that bit to be set.
*
* Note, when an FE_INVALID exception is cleared, all the causes including
* the ones that other instructions can generate, i.e all of the bits in the
* FE_ALL_INVALID bit mask, must be similarly also cleared. Otherwise, any
* CAUSE bit left in the mask will, when fed back into the 'MOVE to FPSCR'
* instruction (implicit in the 'fe_set_fpscr' routine) will retrigger the
* FE_INVALID exception. So MUSL must still cater for these non-standard
* causes, because to not do so will stab itself in the back.
*
* So MUSL makes the assumption that at least for a PowerPC, any raising of
* the INVALID exception must also raise a cause, that cause being by default,
* that called 'By Explicit Software Request'. That makes sense as this is
* beind done by the MUSL itself, not as a part, or side-effect, of some
* arithmetic operation. Note also that if a user has explicitly (violated
* the standard and) augmented an exception list to contain some other cause,
* that extra cause gets trashed on entry to the fenv(3) routines and only
* this default cause is added. The rejection of the benefits of the extra
* information provided by a PowerPC could be addressed in the future as
* the fix is trivial!
*
* The FE_INVALID_SOFTWARE flag is relabelled as FE_INVALID_BY_REQUEST to
* correctly explain its purpose and make any use remotely comprehensible.
* This is questionable in terms of style but without this, the ability of
* the comments to make sense is seriously compromised. For the same reason,
* FE_ALL_INVALID is relabelled FE_ALL_INVALID_CAUSES. At some stage, it is
* recommended that the IBM ISA documentation be enhanced to be more lucid.
*/
#include <fenv.h>
/*
* Remember that the floating point environment lives in a 'double' That
* is locked by the ABI defined in the architecture dependent <fenv.h>.
*
* The first routine pair gets and sets that environment for later use by
* the MUSL mandated pair of fe_get_csr_arch/fe_set_csr_arch routines
*/
static inline double fe_get_fpscr_f(void)
{
double fpscr;
__asm__ __volatile__ ("mffs %0" : "=d"(fpscr));
return fpscr;
}
static inline void fe_set_fpscr_f(double fpscr)
{
__asm__ __volatile__ ("mtfsf 255, %0" : : "d"(fpscr));
}
/*
* This routine pair move tos and from the double (of the environment) into
* MUSL's unsigned int object in which it stores control & status registers
*/
static inline unsigned int fe_get_csr_arch(void)
{
return (unsigned int) (union {double f; long i;}) {fe_get_fpscr_f()}.i;
}
static inline void fe_set_csr_arch(unsigned int fpscr)
{
fe_set_fpscr_f((union {long i; double f;}) {(long) fpscr}.f);
}
/*
* These two macros work with the environment directly
* Should they eventually move to being inline routines?
*/
#define fe_get_e(e) (*e = fe_get_fpscr_f())
#define fe_set_e(e) (fe_set_fpscr_f(*e))
/*
* the default value of a floating point environment of type fenv_t (double)
*/
#define FE_DFL_ENV_DATA 0.0
/*
* Eludicate the macros related to CAUSEs for improved readability.
* While this is tolerable at the architecture definition stage, it
* may need to change in the production code.
*/
#define FE_ALL_INVALID_CAUSES FE_ALL_INVALID
#define FE_INVALID_BY_REQUEST FE_INVALID_SOFTWARE
#include "../fenv-generic.c"
Regards - Damian
Pacific Engineering Systems International, 277-279 Broadway, Glebe NSW 2037
Ph:+61-2-8571-0847 .. Fx:+61-2-9692-9623 | unsolicited email not wanted here
Views & opinions here are mine and not those of any past or present employer
next prev parent reply other threads:[~2020-01-26 3:30 UTC|newest]
Thread overview: 63+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-01-16 4:30 Damian McGuckin
2020-01-16 15:11 ` Markus Wichmann
2020-01-16 16:14 ` Rich Felker
2020-01-16 18:56 ` Damian McGuckin
2020-01-16 19:33 ` Rich Felker
2020-01-16 21:31 ` Damian McGuckin
2020-01-17 3:36 ` Damian McGuckin
2020-01-17 3:48 ` Damian McGuckin
2020-01-17 3:53 ` David Edelsohn
2020-01-17 14:13 ` Rich Felker
2020-01-17 14:19 ` David Edelsohn
2020-01-17 14:53 ` Rich Felker
2020-01-18 4:45 ` Damian McGuckin
2020-01-18 5:29 ` Rich Felker
2020-01-19 8:50 ` Damian McGuckin
2020-01-19 9:07 ` Damian McGuckin
2020-01-19 10:42 ` Szabolcs Nagy
2020-01-19 12:25 ` Damian McGuckin
2020-01-20 5:32 ` Damian McGuckin
2020-01-20 17:38 ` Rich Felker
2020-01-20 21:11 ` [musl] Triggering Overflow (or Underflow) without triggering Inexact on i386 Damian McGuckin
2020-01-20 22:32 ` Szabolcs Nagy
2020-01-21 3:53 ` [musl] Considering x86-64 fenv.s to C Damian McGuckin
2020-01-21 4:22 ` Rich Felker
2020-01-21 4:46 ` Damian McGuckin
2020-01-21 7:26 ` Damian McGuckin
2020-01-17 16:41 ` Markus Wichmann
2020-01-18 1:15 ` Szabolcs Nagy
2020-01-18 5:03 ` Damian McGuckin
2020-01-18 5:37 ` Rich Felker
2020-01-18 9:40 ` Szabolcs Nagy
2020-01-24 0:42 ` Damian McGuckin
2020-01-24 1:11 ` Rich Felker
2020-01-24 4:13 ` Damian McGuckin
2020-01-24 4:55 ` Rich Felker
2020-01-24 6:08 ` Damian McGuckin
2020-01-24 13:44 ` Rich Felker
2020-01-24 14:45 ` Damian McGuckin
2020-01-24 23:59 ` Damian McGuckin
2020-01-25 0:11 ` Rich Felker
2020-01-26 3:28 ` Damian McGuckin
2020-01-26 3:28 ` Damian McGuckin
2020-01-26 3:30 ` Damian McGuckin [this message]
2020-01-26 3:32 ` Damian McGuckin
2020-01-26 5:25 ` Damian McGuckin
2020-01-27 3:32 ` Damian McGuckin
2020-01-27 5:39 ` Damian McGuckin
2020-02-02 0:47 ` Damian McGuckin
2020-02-03 0:54 ` Damian McGuckin
2020-02-03 2:09 ` Rich Felker
2020-02-03 2:12 ` Damian McGuckin
2020-02-22 20:17 ` Rich Felker
2020-02-22 20:53 ` Damian McGuckin
2020-02-23 5:41 ` Damian McGuckin
2020-02-23 6:25 ` Rich Felker
2020-02-23 8:35 ` Damian McGuckin
2020-02-07 21:25 ` Damian McGuckin
2020-02-07 21:38 ` Rich Felker
2020-02-07 23:53 ` Damian McGuckin
2020-02-09 5:04 ` Damian McGuckin
2020-01-24 7:10 ` Damian McGuckin
2020-01-18 5:04 ` Markus Wichmann
2020-02-03 14:16 [musl] PPC64(LE) support in musl requires ALTIVEC Romain Naour
2020-02-03 14:50 ` Rich Felker
2020-02-05 1:32 ` [musl] Considering x86-64 fenv.s to C Damian McGuckin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=alpine.LRH.2.02.2001261428440.4774@key0.esi.com.au \
--to=damianm@esi.com.au \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).