Recent

Author Topic: Why use JNE, JMP instead of JE?  (Read 1181 times)

AlanTheBeast

  • Sr. Member
  • ****
  • Posts: 348
  • My software never cras....
Why use JNE, JMP instead of JE?
« on: June 08, 2020, 06:54:11 pm »
I wanted to see if using With P^ generated tighter code than using P^ repeatedly. (Yes With is tighter).

But I also notice following a compare:
        testl %eax,%eax
        jne Lj4643
        jmp Lj4641
Lj4643:

Surely
       je Lj4641

Would be better?  Is this covered in an optimization pass?

(edits: clarity/formatting)
« Last Edit: June 08, 2020, 06:58:19 pm by AlanTheBeast »
Everyone talks about the weather but nobody does anything about it.
..Samuel Clemens.

Kays

  • Hero Member
  • *****
  • Posts: 575
  • Whasup!?
    • KaiBurghardt.de
Re: Why use JNE, JMP instead of JE?
« Reply #1 on: June 08, 2020, 07:43:27 pm »
[…] Is this covered in an optimization pass? […]
Why aren’t ya tryin’ it out? Yes, FPC will eliminate the unconditional branch (-O1). However, shorter isn’t necessarily faster. That’s why FPC generates the code you see.
« Last Edit: June 08, 2020, 07:48:26 pm by Kays »
Yours Sincerely
Kai Burghardt

AlanTheBeast

  • Sr. Member
  • ****
  • Posts: 348
  • My software never cras....
Re: Why use JNE, JMP instead of JE?
« Reply #2 on: June 08, 2020, 08:11:19 pm »
Doh. 

I'm thinking in primitive mode, not x86_64 mode.  Prefetch/wide bus/speculative exec means both outcomes are computed before the branch and at least the first instructions of the near code are probably already pre-fetched...

As to optimizations, I believe I had them on (in source code) - that should cover that condition.

But a very valid point so I'll dig in again after work.

Thx.
Everyone talks about the weather but nobody does anything about it.
..Samuel Clemens.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11453
  • FPC developer.
Re: Why use JNE, JMP instead of JE?
« Reply #3 on: June 08, 2020, 08:12:11 pm »
Usually it is a matter of distance. Basic code generation usually goes for jumps that always work, and it is for the optimization passes to rectify that, and reduce long jumps to short jumps where needed.

AlanTheBeast

  • Sr. Member
  • ****
  • Posts: 348
  • My software never cras....
Re: Why use JNE, JMP instead of JE?
« Reply #4 on: June 08, 2020, 11:43:31 pm »
Yes indeed, I didn't use -O2.  With -O2 it does JE.

I put a bunch of optimization flags in the code and assumed it was equivalent to -O2 (or better...).

Assumptions bite once again ...  :-[
Everyone talks about the weather but nobody does anything about it.
..Samuel Clemens.

 

TinyPortal © 2005-2018