Commit Graph

1125 Commits

Author SHA1 Message Date
Denis Merigoux
b547b78683 Bugfix: encode function wasn't calling legalize function properly 2017-07-27 16:49:09 -07:00
Jakob Stoklund Olesen
051aaed43e Add Intel encodings for more conversion instructions.
The following instructions have simple encodings:

- bitcast.f32.i32
- bitcast.i32.f32
- bitcast.f64.i64
- bitcast.i64.f64
- fpromote.f64.f32
- fdemote.f32.f64

Also add helper functions enc_flt() and enc_i32_i64 to
intel.encodings.py for generating the common set of encodings for an
instruction: I32, I64 w/REX, I64 w/o REX.
2017-07-27 11:08:41 -07:00
Jakob Stoklund Olesen
4cffb7fe53 Add support for type variable wildcards in bound instructions.
Instructions will multiple type variables can now use `any` to indicate
encodings that don't care about the value of a secondary type variable:

    ishl.i32.any instead of ishl.i32.i32

This is only allowed for secondary type variables (which are converted
to instruction predicates). The controlling type variable must still be
fully specified because it is used to key the encoding tables.
2017-07-26 14:55:26 -07:00
Jakob Stoklund Olesen
ef812408f4 Remove the number field from the PredNode union type.
Predicate numbers are available in the maps
isa.settings.predicate_number and isa.instp_number instead.

Like the name field, predicate numbers don't interact well with
unique_pred().
2017-07-26 11:06:43 -07:00
Jakob Stoklund Olesen
98f0a8b8b4 Remove the name field from the PredNode union type.
The name of a predicate was only ever used for named settings that are
computed as a boolean expression of other settings.

- Record the names of these settings in named_predicates instead.
- Remove the name field from all predicates.

Named predicates does not interact well with the interning of predicates
through isa.unique_pred().
2017-07-26 10:14:26 -07:00
Jakob Stoklund Olesen
9ff785fabc Add a predicate_key() method to all predicates.
This enables interning of predicates to avoid duplicates.

Add a predicate registry to TargetIsa for interning predicates per ISA.
2017-07-26 09:58:16 -07:00
Jakob Stoklund Olesen
84aeb3eb56 Generate type check predicates for secondary type variables.
The encoding tables are keyed by the controlling type variable only. We
need to distinguish different encodings for instructions with multiple
type variables.

Add a TypePredicate instruction predicate which can check the type of an
instruction value operand. Combine type checks into the instruction
predicate for instructions with more than one type variable.

Add Intel encodings for fcvt_from_sint.f32.i64 which can now be
distinguished from fcvt_from_sint.f32.i32.
2017-07-26 08:19:44 -07:00
Jakob Stoklund Olesen
637966dc7f Add support for legalization codes in the encoding tables.
The new encoding format allows entries that mean "stop with this
legalization code" which makes it possible to configure legalization
actions per instruction, instead of only per controlling type variable.

This patch adds the Rust side of the legalization codes:

- Add an `Encodings::legalize()` method on the encoding iterator which
  can be called after the iterator has returned `None`. The returned
  code is either the default legalization action for the type, or a
  specific code encountered in the encoding list.

- Change `lookup_enclist` to return a full iterator instead of just an
  offset. The two-phase lookup can bail at multiple points, each time
  with a default legalization code from the level 1 table. This default
  legalization code is stored in the returned iterator.

- Change all the implementations of legal_encodings() in the ISA
  implementations.

This change means that we don't need to return a Result any longer. The
`Encodings` iterator can be empty with an associated legalization code.
2017-07-25 16:45:36 -07:00
Jakob Stoklund Olesen
5a2bb8ba32 Define I64 before I32 for better encoding table compression.
The encoding list compression algorithm is not the sharpest knife in the
drawer. It can reuse subsets of I64 encoding lists for I32 instructions,
but only when the I64 lists are defined first.

With this change and the previous change to the encoding list format, we
get the following table sizes for the Intel ISA:

ENCLISTS: 1478 B ->  662 B
LEVEL2:             1072 B (unchanged)
LEVEL1:     32 B ->   48 B
Total:    2582 B -> 1782 B (-31%)
2017-07-25 15:38:55 -07:00
Jakob Stoklund Olesen
2ccb261e8d Use a more compact encoding list representation.
Encodings has a 16-bit "recipe" field, but even Intel only has 57
recipes currently, so it is unlikely that we will ever need to full
range. Use this to represent encoding lists more compactly.

Change the encoding list to a format that:

- Doesn't need a predicate entry before every encoding entry.
- Doesn't need a terminator after the list for each instruction.
- Supports multiple "stop codes" for configurable guidance of the
  legalizer.

The encoding scheme has these limits:

- 2*NR + NS <= 0x1000
- INSTP + ISAP <= 0x1000

Where:

- NR is the number of recipes in an ISA,
- NS is the number of stop codes (legalization actions).
- INSTP is the number of instruction predicates.
- ISAP is the number of discrete ISA predicates.
2017-07-25 15:38:55 -07:00
Dimo
e41ddf2a0d Change TV ranking to select src vars as a representative during unification; Nit: cleanup dot() emitting code; Nit: fix small bug in verify_semantics() - make an internal copy of src rtl to avoid clobbering of typevars re-used in multiple definitions 2017-07-25 15:38:48 -07:00
Dimo
20d96a1ac4 Handle non-ssa Vars and Enumerator constants in Rtl substitutions 2017-07-24 15:49:34 -07:00
Jakob Stoklund Olesen
776af93ef2 Generate an INST_PREDICATES table for each ISA.
Instead of generating a single `check_instp()` function, create an array
of individual function pointers for checking instruction predicates.

This makes explicit the jump table in the old check_instp() method and
it gives us a way of determining the number of instruction predicates
that exists.
2017-07-24 14:19:17 -07:00
Jakob Stoklund Olesen
f39d75fa58 Generate a RECIPE_PREDICATES table for each ISA.
It turns out that most encoding predicates are expressed as recipe
predicates. This means that the encoding tables can be more compact
since we can check the recipe predicate separately from individual
instruction predicates, and the recipe number is already present in the
table.

- Don't combine recipe and encoding-specific predicates when creating an
  Encoding. Keep them separate.
- Generate a table of recipe predicates with function pointers. Many of
  these are null.
- Check any recipe predicate before accepting a recipe+bits pair.

This has the effect of making almost all instruction predicates
CODE_ALWAYS.
2017-07-24 14:19:17 -07:00
Dimo
b448574a49 Assert all InstructionGroups are closed in TargetIsa.__init__(); Close x86 group 2017-07-24 14:08:44 -07:00
Dimo
7caaf7fea1 Fix CI: Var was only imported when mypy was present. 2017-07-24 14:08:44 -07:00
Dimo
dfb5a524b9 TI failure due to misplaced import 2017-07-24 14:08:44 -07:00
Dimo
74f72a3b43 Documentation nits; Sematnics syntax cleanup 2017-07-24 14:08:44 -07:00
Dimo
a5fe64440f Add insturction semantics. Add semantics for vsplit,vconcat,iadd. Add initial tests 2017-07-24 14:08:44 -07:00
Dimo
a12fa86e60 Add the BVType; Add suport for bitvectors in TypeVar and TypeSet. 2017-07-24 14:08:44 -07:00
Dimo
605886a277 Rename Dict[Var, TypeVar] to VarTyping; Add VarMap (Dict[Var,Var]). Add {Ast, Def, Rtl}.{vars(), substitution()} and Def.uses(), Def.definitions() - these enable checking structural equivalence between Rtls and doing variable substitutions between compatible Rtls; Add TypeEnv.permits() routine - allows checking if a given TypeEnv allows a given concrete typing without enumerating all typings (will be useful for determing which semantic transform applies to a given concrete typing). 2017-07-24 14:08:44 -07:00
Jakob Stoklund Olesen
716cd26fbf Make legalization actions configurable.
When an instruction doesn't have a valid encoding for the target ISA, it
needs to be legalized. Different legalization strategies can be
expressed as separate XFormGroup objects.

Make the choice of XFormGroup configurable per CPU mode, rather than
depending on a hard-coded default.

Add a CPUMode.legalize_type() method which assigns an XFormGroup to
controlling type variables and lets you set a default.

Add a `legalize` field to Level1Entry so the first-level hash table
lookup gives us the configured default legalization action for the
instruction's controlling type variable.
2017-07-24 12:49:06 -07:00
Dimo
db28e733ec test-all.sh should print the versions for both python2 and python3 its using 2017-07-24 12:11:01 -07:00
Jakob Stoklund Olesen
f651ec4f78 Add a PredicateView type to abstract the predicate bit vector a bit.
The encoding tables contain references to numbered ISA predicates.

- Give the ISA Flags types a predicate_view() method which returns a
  PredicateView.
- Delete the old predicate_bytes() method which returned a raw &[u8].
- Use a 'static lifetime for the encoding list slice in the Encodings
  iterator, and a single 'a lifetime for everything else.
2017-07-24 09:10:58 -07:00
Jakob Stoklund Olesen
4142a9ca9c Return a Result from constant_hash::probe.
When a hash table probe fails, return the index of the failed entry.
This can be used to store default values in the sentinel entries.
2017-07-21 21:10:32 -07:00
Jakob Stoklund Olesen
35cbe68a70 Intel encodings for floating point bitwise ops.
band, bor, bxor, band_not are all available on XMM registers.
2017-07-20 11:45:06 -07:00
Jakob Stoklund Olesen
a42eaa77b4 Add bitwise ops that invert the second operand.
ARM has all of these as scalar integer instructions. Intel has band_not
in SSE and as a scalar in BMI1.

Add the trivial legalization patterns that use a bnot instruction.
2017-07-20 11:20:06 -07:00
Jakob Stoklund Olesen
43e190ad20 Intel encodings for fadd, fsub, fmul, fdiv. 2017-07-20 10:40:11 -07:00
Jakob Stoklund Olesen
e3f6755264 Add some signed int to float conversions.
These map to single Intel instructions.

The i64 to float conversions are not tested yet. The encoding tables
can't yet differentiate instructions on a secondary type variable alone.
2017-07-19 15:35:13 -07:00
Jakob Stoklund Olesen
87c5f27ff7 Intel encodings for trap.
Use a ud2 instruction which generates an undefined instruction
exception.
2017-07-19 15:01:32 -07:00
Jakob Stoklund Olesen
b59b348a1e Add Intel encodings for sextend and uextend. 2017-07-19 13:46:49 -07:00
Jakob Stoklund Olesen
9f105145af Add a null encoding for ireduce.i32.i64.
This conversion doesn't require any code, we're just looking at the bits
differently.
2017-07-19 13:11:11 -07:00
Jakob Stoklund Olesen
f03f1e1898 Add tests for WebAssembly i64 operators.
This only works on 64-bit haswell for now. We need more legalization
patterns for 32-bit ISAs.
2017-07-19 12:56:54 -07:00
Jakob Stoklund Olesen
cfcbf44764 Add tests for WebAssembly i32 comparisons.
One function for each comparison operator.
2017-07-19 12:36:36 -07:00
Jakob Stoklund Olesen
1a662575a5 Add Intel encodings for the bint instructions.
Convert b1 to i32 or i64 by zero-extending the byte.
2017-07-19 12:01:28 -07:00
Jakob Stoklund Olesen
421a88123d Add Intel encodings for the icmp instruction.
This instruction returns a `b1` value which is represented as the output
of a setCC instruction which is the low 8 bits of a GPR register. Use a
cmp+setCC macro recipe to encode this. That is not ideal, but we can't
represent CPU flags yet.
2017-07-19 11:30:15 -07:00
Jakob Stoklund Olesen
c9bbc1e86e Don't require that the fallthrough instruction has an encoding.
A fallthrough jump is actually represented as 0 bytes, so no encoding is
needed.

Also allow for unencoded instructions in the generated emit_inst
implementations. The verifier has stricter rules for when this is
allowed.
2017-07-19 09:30:04 -07:00
Jakob Stoklund Olesen
efdbf0d735 Add Intel encodings for jump and branch instructions.
Just implement jump, brz, and brnz as needed for WebAssembly.
2017-07-19 09:15:19 -07:00
Jakob Stoklund Olesen
53d9232d39 Track regmove instruction during binemit.
Register locations can change throughout an EBB. Make sure the
emit_inst() function considers this when encoding instructions and
update the register diversion tracker.
2017-07-18 12:52:53 -07:00
Jakob Stoklund Olesen
c4db4c124b Begin an Intel-specific instruction group.
Add instructions representing Intel's division instructions which use a
numerator that is twice as wide as the denominator and produce both the
quotient and remainder.

Add encodings for the x86_[su]divmodx instructions.
2017-07-18 11:20:00 -07:00
Jakob Stoklund Olesen
cf876e492a Add Intel encodings for imul. 2017-07-18 09:27:36 -07:00
Jakob Stoklund Olesen
2f7057b96f Add a Context::emit_to_memory function.
This function will emit the binary machine code into contiguous raw
memory while sending relocations to a RelocSink.

Add a MemoryCodeSink for generating machine code directly into memory
efficiently. Allow the TargetIsa to provide emit_function
implementations that are specialized to the MemoryCodeSink type to avoid
needless small virtual callbacks to put1() et etc.
2017-07-18 08:03:53 -07:00
Jakob Stoklund Olesen
9dc92eb8b3 Add Intel BMI1 ctz and clz encodings. 2017-07-14 14:01:02 -07:00
Jakob Stoklund Olesen
f91d747bda Add support for setting presets.
Fixes #11.

Presets are groups of settings and values applied at once. This is used
as a shorthand in test files, so for example "isa intel nehalem" enables
all of the CPUID bits that the Nehalem micro-architecture provides.
2017-07-14 13:57:44 -07:00
Dan Gohman
130b7fa2fa Add documentation for immediates with type bool.
This makes the documentation for the new bconst instruction more complete.
2017-07-13 16:23:41 -07:00
Jakob Stoklund Olesen
6d6035b918 CSSA verifier.
During register allocation, the code must be kept in conventional SSA
form. Add a verifier that checks this property.
2017-07-13 13:18:18 -07:00
Dan Gohman
5a4aa11274 Add a bconst instruction. (#116)
* Add a bconst instruction.
2017-07-13 10:12:25 -07:00
Jakob Stoklund Olesen
5cbcd59cf0 Add some ISA predicates for Intel CPUID features.
Guard the popcnt instruction on the proper CPUID bits.
2017-07-12 16:05:20 -07:00
Jakob Stoklund Olesen
435a15b88d Add Intel encodings for popcnt.
Change the result type for the bit-counting instructions from a fixed i8
to the iB type variable which is the type of the input. This matches the
convention in WebAssembly, and at least Intel's instructions will set a
full register's worth of count result, even if it is always < 64.

Duplicate the Intel 'ur' encoding recipe into 'umr' and 'urm' variants
corresponding to the RM and MR encoding variants. The difference is
which register is encoded as 'reg' and which is 'r/m' in the ModR/M
byte. A 'mov' register copy uses the MR variant, a unary popcnt uses the
RM variant.
2017-07-12 14:17:16 -07:00
Jakob Stoklund Olesen
f57c666d8a Add Intel encodings for shift and rotate instructions. 2017-07-12 13:12:24 -07:00