The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,856 other followers

Archive for the ‘8087’ Category

Delphi history – on the FINITEFLOAT compiler option that has no one-character shortcut

Posted by jpluimers on 2016/12/14

Back in the .NET days, Delphi had an FINITEFLOAT compile option that came without a single-character shortcut.

It was about the handling of infinite float and other special float values in cases like overflow and underflow (including +Inf, -Inf and  [Wayback] NaN).

At first – in the [Wayback] Delphi 8 (Octane) era of which few people want to be reminded off – it was the [Wayback] undocumented counterpart of the [Wayback] 8087 exception mask in x86 mode. Hallvard Vassbotn wrote an article about it and Chee Wee Chua documented it before it got documented in Delphi 2009 (that coincidentally dropped .NET support in the compiler – go figure):

Whereas the native Delphi compilers had exceptions turned on, Microsoft compilers (including .NET) had them turned off, hence the compiler option.

Like most¬†new Delphi features in this century, FINITEFLOAT didn’t come without quirks. Often these are fleshed out in 2-3 product releases, but this one wasn’t:

The¬†FINITEFLOAT¬†compile option didn’t have a single-character shortcut. This made it impossible to use the {$IFOPT ...}¬†construct as IFOPT¬†only works for single-character compiler options.

Which means you get questions like¬†[Wayback] Why doesn’t {$ifopt FINITEFLOAT ON} compile? – Stack Overflow¬†(I actually got into writing this article because I found a {$DEFINE FINFINITEFLOAT_ENABLED}¬†in some pretty old code) and compiler enhancement requests like [WayBack]¬†QualityCentral – Please enhance the IFOPT directive for long switch names. It’s easier to read¬†(which will likely never bee fixed).

For completeness some more information about exception masks in the native compiler:

  1. In the past you could only set the exception mask as part of the full control word using [Wayback] Set8087CW, nowadays you can use [Wayback] SetExceptionMask.
  2. Next to a precision mask, there are five exception masks you can set, see for instance this table from the [Wayback] Simply FPU Chap.1 Control Word section:

PM (bit 5) or Precision Mask
UM (bit 4) or Underflow Mask
OM (bit 3) or Overflow Mask
ZM (bit 2) or Zero divide Mask
DM (bit 1) or Denormalized operand Mask
IM (bit 0) or Invalid operation Mask


Posted in 8087, Algorithms, Delphi, Delphi 2005, Delphi 2006, Delphi 2007, Delphi 2009, Delphi 8, Development, Floating point handling, History, QC, Software Development | 1 Comment »

Delphi – Direct3D and the wrong FPU state: Now() function returns a wrong value (via: StackOverflow)

Posted by jpluimers on 2013/10/31

The question datetime – Delphi Now() function returns a wrong value – Stack Overflow¬†is similar to my article¬†Delphi ‚Äď Michael Justin had strange floating point results when his 8087 FPU Control Word got hosed.

Good that stackoverflow user Anton Zhuchkov found out the cause himself: his answer indicates the Precision Control (and rounding) part of the FPU state got hosed by wrongly initializing the Direct3D device.

I edited his answer with some extra links to documentation.

Finally I’ve found the solution. I needed to specify the¬†D3DCREATE_FPU_PRESERVE flag when creating a D3D device by D3D.CreateDevice.

Otherwise, without that flag, all floating point operations are performed with single precision. As the TDateTime is a simple Double, and Now() functions is consist of simple addition of date value to time value, it all get messed up by DirectX “smart” override.

Problem solved. It was a tricky one indeed. :)


via: datetime РDelphi Now() function returns a wrong value РStack Overflow.

Posted in 8087, Algorithms, Delphi, Delphi 2005, Delphi 2006, Delphi 2007, Delphi 2009, Delphi 2010, Delphi 5, Delphi 6, Delphi 7, Delphi XE, Delphi XE2, Delphi XE3, Development, Floating point handling, Software Development | 2 Comments »

More Delphi x64 bits – Allen Bauer (kylix_rd) on Twitter

Posted by jpluimers on 2010/11/01

To save people from browsing Twitter history:


@davidheff @kylix_rd x64 has SSE2 for FP ops. 8 directly addressable 64bit XMM FP registers. 8087 FP ops emulated in microcode, deprecated

28 Oct

@kylix_rd You mean critical mass isn’t church service on Christmas and Easter?

27 Oct

@kylix_rd Bah. What do they know about floating point? :P MSVC turns off all the FP hardware (exceptions) by default already!

27 Oct

@kylix_rd Yes, we did. The reason was Extendeds don’t exist at all in CLR. x64 FP ops only supporting 64 bit floats is justification

27 Oct

@kylix_rd Ok, so your cause/effect statement was incomplete. :P Shame to see extendeds go. How to count all atoms in the universe now?

27 Oct

@kylix_rd That doesn’t follow. You could still pass extendeds on the stack (not using the x87 register stack)

27 Oct


@davidheff Yes. Alignment is critical. Even the stack must remain properly aligned. Its all part of the ABI.

27 Oct

@davidheff SSE instructions and the xmm0:xmm15 registers.

27 Oct

@danny_thorpe That and the fact that MS strongly discourages the use of the FP coproc on 64 bit Windows.

27 Oct

@danny_thorpe Extendeds don’t align well, FP ops would dumb them down, sub-optimal codegen, are other reasons to drop them.

27 Oct “The x87 register stack is unused. … must be considered volatile across function calls” So, Extended = Double.

27 Oct

As speculated, the Tag property will become a NativeInt.

27 Oct

@malcolmgroves @seanbdurkin And if we change the underlying implementation, don’t complain… mkay?

27 Oct

The elephants in the room. Max 64bit PE image size 4GB. Extended = Double (since xmm0-xmm4 are for FP param passing).

27 Oct

Number of calling conventions in x64 – 1. pascal, register, cdecl, stdcall… gone, treated as nop.

26 Oct

Wow… just a few tweets about D64 and I get flooded with new followers. Welcome to all my new followers from the last 24 hours.

26 Oct

Most common 64bit data models, LP64 and LLP64. Windows = LLP64, Linux, OSX = LP64. D64/Windows = LLP64.

26 Oct

64bit gotcha: SizeOf(THandle/HWND/HMODULE/Hxxxx) = SizeOf(Pointer) = 8. This isn’t valid: Value := Integer(Handle).

26 Oct

Type sizes for 64: SizeOf(Integer)=4, SizeOf(NativeInt)=SizeOf(Pointer)=8,

26 Oct

If you must… Value := Integer(TList[x]) -> Value := NativeInt(TList[x]). Even better, TList.

26 Oct

via Allen Bauer (kylix_rd) on Twitter
Danny Thorpe (danny_thorpe) on Twitter

Posted in 8087, Algorithms, Delphi, Development, Floating point handling, kylix_rd, SocialMedia, Software Development, Twitter | Leave a Comment »

Delphi – Michael Justin had strange floating point results when his 8087 FPU Control Word got hosed

Posted by jpluimers on 2009/05/06

Two days ago, [Wayback] Michael Justin (who just released version 1.7 of the [Wayback] Habari Active MQ Client components) posted a blog entry about a strange circumstance [Wayback] when 1.99 would not compare equally to 1.99.
He tracked it down to the [Wayback] 8087 (more formally: Intel [Wayback] FPU) Control Word being hosed on his system.

I could not reproduce his particular case, but since I have seen similar issues in the past, I wrote the DUnit test case below which shows you what can happen by manually setting the 8087 Control Word.

The difference between the 8087 Control Word values¬†$1372 (default) and $1272 (failure) is the internal mantissa precision (see the [Wayback] “Art of Assembly Language” and the [Wayback] Intel FPU Control Word documentation on this).
Edit: Found a [Wayback] much more complete description of the bits in the FPU Control word.

It changes from 64 bits to 53 bits, which is enough to make 1.99 not equal to 1.99.

I have seen behaviour like this in the past with some networking stacks in the Turbo Pascal 7 era, with some C++ DLL’s in the Delphi 1-3 era, and some printer drivers in the Delphi 5-7 era.
Let me know in the comments (or using the contact form) where you have bumped into this.

The code below makes use of the Jcl8087 unit which is part of the JCL ([Wayback] JEDI Code Library) at [Wayback] SourceForge.
Add the unit to any DUnit test project you created and observe the results.
Read the rest of this entry »

Posted in 8087, Algorithms, Delphi, Development, Floating point handling, Software Development | 8 Comments »

%d bloggers like this: