Do we need branch prediction?

By: Carlie Coats (carlie.delete@this.jyarborough.com), August 25, 2022 7:39 am
Room: Moderated Discussions
ananon (whhhyy.delete@this.trashcan8765.com) on August 25, 2022 12:56 am wrote:
[snip...]
> How you write code is extremely important, because it has to be read and understood by both
> humans and compilers. Aiming for clean and straightforward code whenever possible should
> be your priority, not to try doing micro-optimizations while writing functional code.

I've documented one extreme example here, at :

The early-1990's vintage MM5v3 weather model (and likewise, the early-2000's WRF) frequently had routines written for the limitations of early-1980's vector machines and their compilers (where the innermost loop should be "long" and there should be at most one conditional and at most one AX+B in each innermost loop). One example is the EXMOISR MM5 moist-thermodynamics routine (and the WRF WSM* family of routines), where there is a long sequence of loops of
the form:

LOOP OVER Z-SUBSCRIPT
LOOP OVER X-SUBSCRIPT
....
ENDLOOP
ENDLOOP
,
among which data is transferred by a large set of cache-busting (X,Z)-subscripted scratch variables (over 1 MB-worth, for a typical case), and most of which contain an

IF FREEZING
...
ELSE
...
ENDIF

conditional, resulting in LOTS of small basic blocks and lots of memory traffic, just to fit the limitations of then-obsolete hardware.

Rewriting the code for simplicity:
LOOP OVER X-SUBSCRIPT
LOOP OVER Z-SUBSCRIPT
....
IF FREEZING
...
ELSE
...
ENDIF
ENDLOOP
ENDLOOP
has a much simpler huge-basic-block structure, and allows one to replace nearly all the scratch variables by scalars. The resulting source-code has less than half the size of the original, is much less cluttered by now-unnecessary subscripting, loop-nests, and logic, and is eight times faster for a typical case (on 2000-vintage processors).

And the same people mirrored that original slow and complex code-structure a decade later for the WRF meteorology model. Note that met-modeling is a classic "real-time Blue-Book" problem for which performance is critical...

FWIW.

[Sorry about the indentation; the idiot who specified the "code" markup did not properly support it.]




< Previous Post in ThreadNext Post in Thread >
TopicPosted ByDate
Do we need branch prediction?Kara2022/08/24 02:07 PM
  Do we need branch prediction?Rayla2022/08/24 03:04 PM
  Do we need branch prediction?Mark Roulo2022/08/24 04:25 PM
    Do we need branch prediction?Paul A. Clayton2022/08/24 06:28 PM
      Do we need branch prediction?Anon2022/08/24 06:52 PM
    Do we need branch prediction?rwessel2022/08/24 06:40 PM
    Do we need branch prediction?ananon2022/08/25 12:56 AM
      Do we need branch prediction?Carlie Coats2022/08/25 07:39 AM
        OT: You wanted rather than Mark Roulo2022/08/25 09:57 AM
          OT: You wanted "pre" rather than "code" rather than Mark Roulo2022/08/25 09:57 AM
            OT: You wanted "pre" rather than "code" rather than Carlie Coats2022/08/25 11:43 AM
    Do we need branch prediction?Kevin G2022/08/25 08:47 AM
      Do we need branch prediction?rwessel2022/08/25 11:10 AM
          Do we need branch prediction?rwessel2022/08/26 10:37 AM
  Do we need branch prediction?Geoff Langdale2022/08/24 07:18 PM
  Do we need branch prediction?Adrian2022/08/25 12:58 AM
  Do we need branch prediction?Brendan2022/08/25 07:54 AM
    Do we need branch prediction?Anon42022/08/25 11:45 AM
      Do we need branch prediction?anon22022/08/25 09:08 PM
  Predicable branching patterns (aykm; )Kara2022/08/27 01:00 PM
    Predicable branching patterns (aykm; )Jukka Larja2022/08/27 11:38 PM
    Predicable branching patterns (aykm; )Eric Fink2022/08/28 01:22 AM
      Predicable branching patterns (aykm; )Doug S2022/08/28 10:17 AM
    Predicable branching patterns (aykm; )---2022/08/28 02:16 PM
      Predicable branching patterns (aykm; )Anon2022/08/28 02:35 PM
  Q: Do we need branch prediction? A: We don't need it, but....2022/08/29 02:17 PM
    Quantum stuff.Kara2022/08/29 03:01 PM
      Q: Do we need branch prediction? A: We don't need it, but....2022/08/30 11:48 AM
    "Quantum Woo" (hint; that's NOT how it works) (NT)anonymous22022/08/29 04:19 PM
      Q: Do we need branch prediction? A: We don't need it, but....2022/08/30 12:14 PM
Reply to this Topic
Name:
Email:
Topic:
Body: No Text
How do you spell tangerine? 🍊