Page MenuHomeFreeBSD

Improve FPU Tag Word reconstruction on i386 to indicate register states

Authored by on Oct 19 2020, 11:29 AM.



Improve the code reconstructing en_tw in struct fpreg32 from FXSAVE results so that all register states are indicated correctly. The previous code unconditionally mapped non-empty register state to 'normalized value' constant. The new code explicitly distinguishes the 'zero value' and 'special value' constants as well. This improves consistency between real FSAVE and translation from FXSAVE, and ensures that tests using PT_GETFPREGS can rely on a single correct value independently of the underlying implementation.

Sponsored by: The FreeBSD Foundation
Obtained from: Moritz Systems
Submitted by: Michał Górny <>

Diff Detail

rS FreeBSD src repository - subversion
Automatic diff as part of commit; lint not applicable.
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

That said:

  1. I'm wondering if there's a common place we could move this function too not to duplicate it.
  2. I suppose we could use a packed struct to look at the float80 instead of pointer hacks.

Merging i386/npx.c and amd64/fpu.c is a lot of work for many reasons, I evaluated that several years ago. For now keeping them separate is better IMO.

178 ↗(On Diff #78419)

Merge these two lines into multiline comment.

185 ↗(On Diff #78419)

if ((ab_tw & i) != 0)

187 ↗(On Diff #78419)

Style requires struct fpacc87 *fx_reg.

188 ↗(On Diff #78419)

(uint16_t *)&fx_reg

Also a comment like 'masking the sign bit' would be due there.

189 ↗(On Diff #78419)

Please move fx_reg, exp, and mantissa declarations to the declaration block at the start of the function.

1193 ↗(On Diff #78419)

All comments from the amd64 ia32 version are applicable there as well.

If you update the review with the style(9) items @kib identified he or I will commit. marked 6 inline comments as done.

Fixed per review comments.

This revision is now accepted and ready to land.Oct 20 2020, 11:28 PM