Skip to content

The fast encoder enc2

Mark Charney edited this page Jun 2, 2020 · 14 revisions

The fast encoder (enc2) generates one small function per instruction form. The XED scripts can generate checked and unchecked forms of these functions as well as a tests for each of these functions. The enc2 build is much larger (and thus slower) than the standard XED build so it is not part of the default build.

Generating an all instruction test and filtering it

A small side effect of generating testing for all instructions is that we can also dump those tests in different raw source forms for other uses. In this example, we will dump the all-instructions test in two different forms for compilation with the Intel compiler(icc) or GNU gcc.

  1. (LINUX) Since the files we are working with in the later steps can be large, make sure you have an unlimited stack size. When using a csh-like shell use limit stacksize unlimited and for a bash-like shell use ulimit -s.

  2. First we build XED with the enc2 encoder and generate tests for each function generated:

    % ./mfile.py examples --enc2-test -j 30

  3. This runs the generated test program for 64b addressing, and dumps a C source file containing assembly-like emits compatable with inline assembly for the Intel compiler. (See below for GNU ASM and gcc). This file a.c contains an example of emitting every allowed form of every x86 instruction.

    % obj/enc2-m64-a64/enc2tester-enc2-m64-a64 --emit --main > a.c

  4. Now we can compile that test using the Intel compiler. -fasm-blocks is required.

    % your-installed-path-to-icc/bin/icc -fasm-blocks a.c

  5. Finally, we can take the output of the compiler, a.out, and run that through XED and filter out instances of instructions that are not valid for the specified chip. In this case GOLDMONT was used as an example.

    % obj/wkit/bin/xed -i a.out -chip-check GOLDMONT > z

  6. This next command would show which instructions in the binary are invalid for the specified chip.

    % grep -B1 INVALID z


To generate tests that can be compiled by GCC or CLANG instead of ICC, we change steps 2 and 3 above as follows:

2'. Generate the file containing the tests a.c, using the --gnuasm knob (instead of --emit):

% obj/enc2-m64-a64/enc2tester-enc2-m64-a64 --main --gnuasm > a.c

3'. And then instead of using the Intel compiler, we can use gcc (or clang):

% gcc a.c
Clone this wiki locally