C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Fixing std::bit_cast padding bit issues

From: Thiago Macieira <thiago_at_[hidden]>
Date: Fri, 16 Jan 2026 08:52:16 -0800
On Friday, 16 January 2026 08:40:32 Pacific Standard Time David Brown wrote:
> > It happens *all* the time with long double. And it depends on *how* the
> > thing is copied. If it is done by copying memory, the bits will come
> > through. If it is done by the x87 stack, they will not and the
> > destination's previous bits will remain unchanged.
>
> I did not think x87 floating point was much used any more - my
> understanding was that floating point was primarily handled with SIMD
> instructions and registers for greater efficiency. But my knowledge
> here is minimal (I target small embedded systems), so I accept your
> experience.

long double on most ABIs is still 80-bit extended precision and therefore uses
the x87.
https://gcc.godbolt.org/z/9K7vdWPx9

As you can see from the MSVC pane, Windows is the outlier.

BTW, this does mean the Standard Library <random> routines that use long
double are extremely slow.

PS: strictly speaking, it's "SSE instructions" not "SIMD": as the MSVC output
shows, it's using a scalar instruction, therefore not SIMD.

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
  Principal Engineer - Intel Data Center - Platform & Sys. Eng.

Received on 2026-01-16 16:52:27