Since the machine architectures that came to mind all have this 3-state
result after comparison, I expected the compiler to take advantage of it
when I write something like
  if ( j < k ) m = -1;
  else if (j > k) m = 1;
  else m = 0;
  return m;

A few surprises with gcc, like pretty dumb code without -O3 and then very
smart code with -O3 :-)  and the result is below. What I considered
interesting is that we indeed have a single "CR" followed by the "JL" and
"JNLE" so the language allows me to express this situation properly. I
suppose the "LHI" at 062E is also done early to take advantage of the
pipeline?

(the setting of the scene is with R10 and R2 holding "j" and "k"
respectively')

    80000628:   19 a2                   cr      %r10,%r2
    8000062a:   a7 44 00 1a             jl      8000065e <main+0x6a>
    8000062e:   a7 28 00 00             lhi     %r2,0
    80000632:   a7 34 00 0b             jnle    80000648 <main+0x54>
    80000636:   e3 40 f1 10 00 04       lg      %r4,272(%r15)
    8000063c:   b9 14 00 22             lgfr    %r2,%r2
    80000640:   eb af f0 f0 00 04       lmg     %r10,%r15,240(%r15)
    80000646:   07 f4                   br      %r4
    80000648:   a7 28 00 01             lhi     %r2,1
    8000064c:   e3 40 f1 10 00 04       lg      %r4,272(%r15)
    80000652:   b9 14 00 22             lgfr    %r2,%r2
    80000656:   eb af f0 f0 00 04       lmg     %r10,%r15,240(%r15)
    8000065c:   07 f4                   br      %r4
    8000065e:   a7 28 ff ff             lhi     %r2,-1
    80000662:   e3 40 f1 10 00 04       lg      %r4,272(%r15)
    80000668:   b9 14 00 22             lgfr    %r2,%r2
    8000066c:   eb af f0 f0 00 04       lmg     %r10,%r15,240(%r15)
    80000672:   07 f4                   br      %r4

Reply via email to