0

Seaching through the GCC source, I see things like

My goal is to get an answer for myself whether or not GCC generates BT, BTS, BTR, and BTC. I started with BT and I found the things above, but I can't find where they are used. Does GCC generate BT instructions at all?

It seems like from this bug report, since resolved, that it now does but where is this instruction shown?

1

Those constants are used in the i386 machine definition file, gcc/config/i386/i386.md; the core instructions themselves are defined here, and a number of combinations are also defined, such as this AND / BTR one.

To understand how machine definitions are used, see corresponding manual. The overview gives the following summary:

There are three main conversions that happen in the compiler:

  1. The front end reads the source code and builds a parse tree.
  2. The parse tree is used to generate an RTL insn list based on named instruction patterns.
  3. The insn list is matched against the RTL templates to produce assembler code.

An instruction definition is used both to generate the RTL instruction in the second conversion, and also to produce the resulting assembly code in the third conversion.

To see the BT instructions in action:

#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv) {
  if (argc > 2) {
    int x = atoi(argv[1]);
    int n = atoi(argv[2]);
    if (x & (1 << n)) {
      printf("Set");
    }
  }
}

With -O2, that generates a btl for me with GCC 7.3.1.

  • But where is BTL anywhere in that definition at :8664 that you linked or the machine code for the instruction? Is there a trick to reading this? How would I know what code to write to generate those instructions? – Evan Carroll Sep 25 '18 at 2:23
  • I think the generation is done from the AST and it's just too scary to make sense out of easy to reverse engineer from the AST tokens what the C looks like. But I would like to know how you go from the define_insn_and_split to the btl token. – Evan Carroll Sep 25 '18 at 2:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.