‹ BackHN Continuity

Thread

Subnormal floating-point numbers are expensive on Intel processors

69 points · 54 comments · zdw

  1. khuey · · focus · HN ↗
    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.
    1. bee_rider · · focus · HN ↗
      IIRC intel’s compilers enable FTZ/DAZ, at least at higher optimization levels.
      1. account42 · · focus · HN ↗
        GCC does with the infamous -ffast-math as well.
        1. gpderetta · · focus · HN ↗
          IIRC that has been since split out of the flag and need to be asked for separately at link time.
          1. jcranmer · · focus · HN ↗
            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.
            1. [deleted] · · focus · HN ↗

              [deleted]

            2. gpderetta · · focus · HN ↗
              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.
      2. adrian_b · · focus · HN ↗
        Which is certain to produce big errors at every instance where a subnormal result would have been generated or propagated otherwise.

        Such options exist only for games or for experts in numeric analysis, not for general-purpose programming.

    2. adrian_b · · focus · HN ↗
      Most people who believe that they do not need subnormals do not actually know whether they need or not subnormals and it is very likely that they need subnormals.

      The options mentioned above are guaranteed to generate big errors, so they are acceptable only when errors really do not matter, e.g. in graphics for games.

      The only correct option for avoiding subnormals is to enable the underflow exception and handle it in a manner that is considered more suitable for that application than the use of subnormals.

Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.