tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Default value of x87 registers' reserved bits

2010/5/30 Joerg Sonnenberger <>:
> On Fri, May 28, 2010 at 04:54:50AM +0300, Stathis Kamperis wrote:
>> Control, status, etc x87 registers (which are part of the fp
>> environment) are 16 bit wide. In protected mode though, they are
>> accessed as 32 bit. The upper bits, 31-16, are marked as `reserved'
>> and are ought to be ignored. Their default value is _not_ mentioned in
>> the CPU specs. At the same time though, when we write to these
>> registers we must not tamper with the reserved bits.
> The code to extract the state should mask out the high level bits and
> code to set it should copy / keep them. The constant should not include
> them at all and it should not use a singleton.
> Joerg

Thanks Joerg for taking time to comment.

So you suggest that we provide a partial fp env representation with
FE_DFL_ENV, that gets completed every time in the level of its
consumers (feupdateenv, fesetenv).

There's a corner case though, that needs special treatment. For
example, what would happen if for some reason (?) the user did
something like:

fenv_t tmp;
memcpy(&tmp, FE_DFL_ENV, sizeof tmp);

and then at some point:


For this to work, we should be doing a memcmp() inside feupdateenv()
and not just envp == FE_DFL_ENV, to decide if we should complete it or

On the other hand, I'm not even sure that POSIX allows FE_DFL_ENV to
be used in any other case besides fenv.h related functions, e.g.
memcpy(). Here are the exact words from the specs:

"It (FE_DFL_ENV) can be used as an argument to the functions within
the <fenv.h> header that manage the floating-point environment."

I've looked up "can" in the POSIX base definitions, but it wasn't very
"The usage of can and may were selected to contrast optional
application behavior (can) against optional implementation behavior

To cut a long story short, I tend to agree with you that we should go
this route. Also, if this any constellation, I checked glibc and they
do the same. If noone objects, I consider this case closed.

Thank you all.


Home | Main Index | Thread Index | Old Index