Hacker News

Top stories

Live mirror
30 storiesupdated just nowView source snapshot
  1. Claude Code now reads AGENTS.md if there is no Claude.md(claude.com ↗)
    164comments
  2. Android 17 is the first since 3.x to add new APIs without releasing to the AOSP(grapheneos.social ↗)
    210comments
  3. How OpenAI Used Its Own LLMs to Design Its Jalapeño Chip(ieee.org ↗)
    21comments
  4. Saving another 100TB of RAM(cloudflare.com ↗)
    36comments
  5. Cloudflare Quick Tunnels(cloudflare.com ↗)
    237comments
  6. Xcode 27.1 Beta Release Notes(developer.apple.com ↗)
    63comments
  7. A 1542 papal cipher cracked with simulated annealing(simonklee.dk ↗)
    1comments
  8. Cache-to-Cache: Direct Semantic Communication Between LLMs (2025)(arxiv.org ↗)
    11comments
  9. How to Write with an LLM(sockpuppet.org ↗)
    258comments
  10. Photon-Emission-Guided Laser Fault Injection Enables RP2350 Secure Debug(ledger.com ↗)
    49comments
  11. Show HN: Cactus Needle 3: 8-29MB automation models can match DeepSeek V4 Flash(cactuscompute.com ↗)
    74comments
  12. The first new cat species discovered in 100 years(nationalgeographic.com ↗)
    48comments
  13. OpenJev(openjev.com ↗)
    240comments
  14. Cyclomatic Complexity in C#(ndepend.com ↗)
    12comments
  15. US troop deaths during Iran war exceed Pentagon count by at least four(reuters.com ↗)
    74comments
  16. Two parallel neural ectoderm progenitors contribute to the developing brain(newscientist.com ↗)
    51comments
  17. The Implications of Linguistic Illegibility for LLM Security(arxiv.org ↗)
    17comments
  18. C++26: Trivial infinite loops are no longer undefined behaviour(sandordargo.com ↗)
    175comments
  19. Warez: The Infrastructure and Aesthetics of Piracy (2021)(archive.org ↗)
    14comments
  20. Minimal Phone 2(minimalcompany.com ↗)
    161comments
  21. Size-Specialized Memory Allocation(go.dev ↗)
    3comments
  22. Inside ZCode: Silently uploading your Git history to the cloud(ferstar.org ↗)
    89comments
  23. How SpaceX streamlined the Raptor engine(construction-physics.com ↗)
    28comments
  24. A search-and-inference database from scratch in pure Zig(antfly.io ↗)
    16comments
  25. I vibed a proof of Conway's conjecture(overreacted.io ↗)
    180comments
  26. From Geometry to Algebra and Back Again: 4000 Years of Papers (2023) [video](youtube.com ↗)
    discuss
  27. US Military had close call after using AI for hallucinated intelligence report(cnn.com ↗)
    291comments
  28. Korea raises data breach fines to 10% of revenue(koreajoongangdaily.com ↗)
    79comments
  29. Cekura (YC F24) Is Hiring(ycombinator.com ↗)
    discuss
  30. Mathematicians Build Long-Awaited Graph Sandwich(quantamagazine.org ↗)
    18comments

Subnormal floating-point numbers are expensive on Intel processors

61 pointsby 3d agolemire.me
46 comments
12h agoHN ↗

...Is this running extra micro code to fix some hardware bug/unreliability? How can this happen? Doesn't look like a normal design decision.

12h agoHN ↗

Subnormal numbers have a different, basically fixed-point, representation. They exist in order to bridge the large (relatively speaking; indeed "infinite" in a sense) gap between the least positive normal number, zero, and the greatest negative normal number, caused by the usual significand-exponent representation.

Most "mundane" uses of floating point have no need for subnormal numbers, and results that underflow could just be flushed to zero. But they’re sometimes important in scientific computing to ensure sufficient smoothness around zero, avoiding precision issues.

10h agoHN ↗

I don’t know how useful they are in scientific computing either, really. They are less precise than normalized numbers… if flushing them makes a difference I think it is a bad algorithm smell.

10h agoHN ↗

I can think of one useful property of subnormal numbers off the top of my head. If subnormal processing is enabled, then for all finite values of `a` and `b`, `a != b` if and only if `a - b != 0`. But if subnormals are flushed to zero, then two tiny normal distinct values `a` and `b` would have a subnormal difference that is flushed to zero.

9h agoHN ↗

Isn't that just a scale issue that exists with or without subnormals? If a and b are closer to zero than the smallest representable number, a and b compare as the same. With subnormals your smallest possible number is smaller than without, but it's still the same issue.

9h agoHN ↗

Because subnormals are fixed point, ie. have a fixed exponent, the difference of any two distinct subnormal values is nonzero like with integers.

9h agoHN ↗

But that same statement applies to normal values too, right? With normal numbers you might get the oddity of a-b -> a even if b is nonzero, but you don't get the oddity of a-b -> 0 unless the same number is represented, IIUC. A and B might not be bit identical, but they represent the same number if the difference is 0.

9h agoHN ↗

One nice thing that subnormals get you is the property that if x-y == 0 then x == y. If you want to guard against division by 0, and your denominator is a difference of two terms, it’s nice to be able to check equality of those terms and know that if they are not equal, then their difference will not be 0.

More generally, subnormals are needed for Sterbenz Lemma to hold everywhere: https://en.wikipedia.org/wiki/Sterbenz_lemma

12h agoHN ↗

I don’t know if any bugs contribute to this but this in the intel case but it has been very common historically for subnormal performance to be lower on many processors, and things like the Alpha required you to handle them in software if the COU fired a trap.

Have a look at https://en.wikipedia.org/wiki/Subnormal_number for some context.

10h agoHN ↗

It's to satisfy IEEE 754 and it's been this way for decades.

10h agoHN ↗

Does that mean that the ARM processors in the writeup are not satisfying IEEE 754?

10h agoHN ↗

It probably means Apple spent the silicon to handle subnormals at full speed in hardware, rather than triggering a slow microcode handler for such numbers.

10h agoHN ↗

I don't know who is down voting you. AFAIK IEEE 754:2008 does require support for subnormals. You can optionally have modes that flush them to zero, but you must support subnormals.

I haven't done any work on this stuff since 2019, so my memory may be hazy.

11h agoHN ↗

Apparently it only happens on P-cores, recent E-cores have a fast path for subnormals.

10h agoHN ↗

That seems weird. They did throw extra hardware at it to speed it up for the efficient cores, but not for the performance cores?

10h agoHN ↗

Probably different teams. Plus you can not underestimate the role that momentum plays in semiconductor engineering teams. If some respected person determined that subnormals are either Hard (tm) or not a Real Problem (tm), it will take a long time to correct this mistaken belief. I believe there have been some recent academic papers on FP implementation from the Intel E-Core team, which is a sign that they are a bit more with the times.

9h agoHN ↗

larger SIMD ALUs, which also have been around for longer?

11h agoHN ↗

If you don't _need_ subnormals MXCSR.DAZ/FTZ (which you can get gcc to set via -mdaz-ftz) will let you ignore all of this.

10h agoHN ↗

IIRC intel’s compilers enable FTZ/DAZ, at least at higher optimization levels.

10h agoHN ↗

GCC does with the infamous -ffast-math as well.

9h agoHN ↗

IIRC that has been since split out of the flag and need to be asked for separately at link time.

9h agoHN ↗

If you use -ffast-math when linking an executable but not a shared library, both gcc and clang will link in crtfastmath.o which has the bit of code to set the DAZ/FTZ flags.

2h agoHN ↗

right, but the issue was that if an application was linked with a library that happened to link with a fast-math shared library, it would unknowingly bring along the crt code. Now the only way to get it is to use the fast-math flag when linking the final binary, which at least is an explicit request.

10h agoHN ↗

I'm still trying to understand what a subnormal number is; IE, I'm looking for the TLDR so I know just enough to know if I'm using them and need to learn more.

Unfortunately, the Wikipedia article, while probably being accurate, doesn't give a clear and concise answer.

IE, is 0.0001 a subnormal? Or is it 0.000000000000000000001?

10h agoHN ↗

Usually IEEE floats have an implied 1 in the front. So for the standard represented numbers, there's some minimum number 1.bbbbbb.. * 2^-N. This allows 1bit more precision than is actually stored.

between any two numbers, there's basically the same epsilon difference, but from the smallest number to zero it's bigger.

A subnormal number breaks that convention, it just becomes 0.bbbbb... * 2^-N. As the numbers get smaller, the relative difference between the numbers gets larger. That also means their precision is smaller than the normal floats.

10h agoHN ↗

Floating point numbers are usually interpreted as

    sign * 1.mantissa * 2 ^ exponent

where sign, mantissa and exponent are fixed bit width integers. The 1. before the number is normally implicit because it would be a waste of a bit to encode it when you could just use a diferent exponent to represent such a number.

However with this simple scheme the number zero and a relatively large gap around it cannot be represented (relatively large to the gap between the smallest and next smalles number that can be represented).

So there is a special case where for the smallest encodeable exponent the mantissa must also specify that 1. or 0. prefix. Because its a special case it needs special handling that clever silicon engineers might think is unimportant enough to handle in microcode instead of dedicated silicon.

x86 has a mode to assume that all such small numbers are actually equal to zero which can then be handle without microcode fallback. Technically its even a bit more complicated because x86 has two different float implementations and for at least SSE floats you can control the denormals-are-zero and flush-(denormals)-to-zero-(when writing) modes independently. GCC -ffast-math actual enables that mode for the entire main thread.

AFAIK ARM NEON always works in that mode so the Gravion and Apple benchmarks might be unfair here undless you compare with DAZ and FTZ enabled on Intel. No idea if the AMD benchmarks might have used different modes. Because the flags are global per thread you can easily have unrelated loaded libraries messing the benchmark up.

8h agoHN ↗

AFAIK ARM NEON always works in that mode

This was only true for ARMv7 NEON (32-bit). ARMv8 / AArch64 NEON is IEEE compliant.

10h agoHN ↗

That depends on how you store it.

Each number can be written in infinitely many ways, for example 12, 1.2E1, and 0.012E3 all are “twelve”

In (binary) IEEE floats, the canonical way to write floats is

  significant × 2^exponent

with 1 ≤ significant < 2. So, “twelve” gets stored as 1.5 × 2³ and not as, for example, 0.375 × 2⁵, 12 × 2⁰ or 96 × 2⁻³.

Float operations normally return numbers satisfying that.

However, in IEEE, the exponent cannot be made arbitrary small. Because of that, some very small numbers cannot be represented that way.

In those cases the standard says operations can return numbers with the value closest to the correct value with a significant less than 1. Those number representations are called subnormals.

9h agoHN ↗

For 32-bit floats, subnormals are the numbers closer to 0 than 2**(-126) == 0.0000000000000000000000000000000000000117549. For 64-bit doubles, it's 2**(-1022), a number starting with 308 decimal zeroes.

9h agoHN ↗

The 32-bit subnormals are all the non-zero 32-bit floating point values between but not including -0.000000000000000000000000000000000000011754943508222875079687365372222456778186655567720875215087517062784172594547271728515625 and +0.000000000000000000000000000000000000011754943508222875079687365372222456778186655567720875215087517062784172594547271728515625

Does that help you?

[Edited: correct decimal after noticing that my calculator defaulted to the wrong setting]

[And again because I think there's a bug in the last few digits, so debugging that's a fun activity for the weekend]

[And a third time because nope, those were correct and I can't type]

8h agoHN ↗

Yes, that's a perfect explanation!

(And thankfully, for when I work with small numbers, they are still much larger than that.)

7h agoHN ↗

Very interesting, you are right. The IEEE 754 standard defines positive/negative zero as not subnormal numbers.

Mechanically speaking, the two zeros use the subnormal number format, so in that sense they are subnormal (but definitionally they aren't). Also, I guess FPUs treat zero differently from other subnormal numbers, which is why zero doesn't have a performance penalty.

Relevant articles to read: https://stackoverflow.com/questions/73890260/why-is-zero-not... , https://en.wikipedia.org/wiki/Sterbenz_lemma , https://en.wikipedia.org/wiki/Subnormal_number

8h agoHN ↗

Binary floating-point numbers are scientific notation except the pieces are all in binary. In proper scientific notation, the only time the digit before the decimal point can be 0 is when the number itself is 0. Since the only other digit in binary notation is 1, there is no need to store the digit before the decimal point, since it's always 1... except now you can't store 0.

This problem is fixed by reserving one of the exponents for the representation of 0. Some of the formats (e.g. VAX floating point) that introduced this implicit-1-bit for the binary format said that every number with this special-0-exponent was a zero. But IEEE 754 introduced the concept of gradual underflow, and says instead that it is a bit string with the implicit digit before the decimal point as a 0 instead of 1.

Putting it differently and more succinctly: a subnormal number is a number that has fewer digits of precision than is normally implied by the format. Which numbers are subnormal numbers is entirely dependent on the floating-point format.

10h agoHN ↗

This has been the case since a zillion years, since the Core 2 Duo days at minimum.

10h agoHN ↗

The interesting part is that this seems to be Intel-specific.

10h agoHN ↗

That's what I mean though- in the Core 2 Duo vs K8 / Athlon days, Intel was much slower for denormals and subnormals than AMD. I'm not sure why but I thought this was common knowledge.

9h agoHN ↗

This is true on most hardware. Running ftz on H100s or B200 gives a free 10-20% boost for GEMM-epilogue workload

9h agoHN ↗

I mean the values of the computation not the runtime. I don’t know enough about ARM to say if doubles simply punt denormals to 0 for example.

9h agoHN ↗

IEEE 754 defines bit exact results for a lot of FP operations, including denormals.

8h agoHN ↗

And yet floating point math in general is non-deterministic across different CPUs. IEEE 754 was not good enough, so it's a valid question.

10h agoHN ↗

It used to be quite normal to add a low level random signal to inputs when writing DSP code so as to avoid dropping into subnormal territory. Careful analysis of the algorithm would identify any points where this was also necessary (e.g. feedback paths when running delays).

Obviously those lucky/unlucky enough to be writing 56k fixed precision code wouldn't have this concern, but other ones instead :)

I think flush to zero is probably the preferred strategy these days.