Commit Graph

1642 Commits

Author SHA1 Message Date
Jakob Stoklund Olesen
2888ff5bf3 Fix a corner case in fcvt_to_sint.i32.f64 legalization.
An f64 can represent multiple values in the range INT_MIN-1 < x <=
INT_MIN which all truncate to INT_MIN, so comparing the input value
against INT_MIN is not good enough.

Instead, detect overflow on x <= INT_MIN-1 when INT_MIN-1 is an exact
floating point value.
2017-09-28 14:24:39 -07:00
Jakob Stoklund Olesen
8abcdac5a1 Legalize fcvt_to_sint and fcvt_to_uint for Intel64.
We need to generate traps on NaN and overflow.
2017-09-28 12:00:38 -07:00
Jakob Stoklund Olesen
34146435e5 Legalize unsigned-to-float conversions for Intel 64.
Also make sure we generate type checks for the controlling type variable
in legalization patterns. This is not needed for encodings since the
encoding tables are already keyed on the controlling type variable.
2017-09-28 11:39:19 -07:00
Jakob Stoklund Olesen
979a22f548 Add pow2() and neg() methods for the IEEE immediate types.
These are convenient methods for creating common floating point
constants.
2017-09-28 11:34:02 -07:00
Jakob Stoklund Olesen
a274cdf275 Fix the Intel encoding of band_not.
The andnps instruction inverts its first argument while band_not inverts
is second argument.

Use a swapped-operands "fax" encoding recipe.
2017-09-27 18:14:13 -07:00
Jakob Stoklund Olesen
1d481d7897 Use the ThreadId to name cretonne.dbg in unnamed threads.
Don't use a single cretonne.dbg log file when there are multiple unnamed
threads logging. They will clobber each other.
2017-09-27 16:27:49 -07:00
Jakob Stoklund Olesen
de9b1d1004 Enable debug assertions for cretonne-tools.
The cton-util executable is used in --release mode to run the file
tests. We want assertions enabled for that.

This doesn't affect the compiler flags used to build the Cretonne crate
when it is used as a dependency in another project.
2017-09-27 12:55:34 -07:00
Jakob Stoklund Olesen
84471a8431 Add some very basic support for the Intel32 ABI.
In 32-bit mode, all function arguments are passed on the stack, not in
registers.

This ABI support is not complete or properly tested, but at least it
doesn't try to pass arguments in r8.
2017-09-27 12:55:34 -07:00
Jakob Stoklund Olesen
b6b474a8c9 Add Intel legalization for fmin and fmax.
The native x86_fmin and x86_fmax instructions don't behave correctly for
NaN inputs and when comparing +0.0 to -0.0, so we need separate branches
for those cases.
2017-09-27 12:55:34 -07:00
Jakob Stoklund Olesen
384b04b411 Fix some misnamed TailRecipes and add a consistency check. 2017-09-27 12:55:34 -07:00
Jakob Stoklund Olesen
44eab3e158 Add Intel regmove encodings for floating point types. 2017-09-27 12:49:54 -07:00
Jakob Stoklund Olesen
1fe7890700 Add x86_fmin and x86_fmax instructions.
These Intel-specific instructions represent the semantics of the minss /
maxss Intel instructions which behave more like a C ternary operator
than the WebAssembly fmin and fmax instructions.

They will be used as building blocks for implementing the WebAssembly
semantics.
2017-09-27 09:17:09 -07:00
Jakob Stoklund Olesen
ac69f3bfdf Add an Intel-specific x86_cvtt2si instruction.
This is used to represent the non-trapping semantics of the cvttss2si and
cvttsd2si instructions (and their vectorized counterparts).

The overflow behavior of this instruction is specific to the Intel ISAs.

There is no float-to-i64 instruction on the 32-bit Intel ISA.
2017-09-26 15:44:41 -07:00
Dan Gohman
d13f29cfe4 Update to wasmparser 0.11.2. 2017-09-26 14:58:50 -07:00
Jakob Stoklund Olesen
6ff681a90d Add general legalization for the select instruction. 2017-09-26 14:16:35 -07:00
Jakob Stoklund Olesen
ce767be703 Intel encodings for floating point copies. 2017-09-26 13:54:38 -07:00
Jakob Stoklund Olesen
7fb6159a85 Add Intel encodings for the fcmp instruction.
Not all floating point condition codes are directly supported by the
ucimiss/ucomisd instructions. Some inequalities need to be reversed and
eq+ne require two separate tests.
2017-09-26 11:17:32 -07:00
Jakob Stoklund Olesen
79968a2325 Add standard expansions for fcopysign.
This is also just a sign bit manipulation.
2017-09-25 15:17:32 -07:00
Jakob Stoklund Olesen
6bec5f8507 Intel encodings for nearest/floor/ceil/trunc.
These floating point rounding operations all use the roundss/roundsd
instructions that are available in SSE 4.1.
2017-09-25 15:08:04 -07:00
Jakob Stoklund Olesen
ac343ba92a Add encodings for square root instructions. 2017-09-25 13:15:09 -07:00
Dan Gohman
36585ddc4f Wasm control stack entries only need the number of return types.
This eliminates heap-allocated vectors which stored the actual types.
2017-09-25 13:05:29 -07:00
Dan Gohman
55e48ce7aa Simplify translate_type's return type. 2017-09-25 13:05:29 -07:00
Dan Gohman
14d6d1117d Clean up unneeded '&'s. 2017-09-25 13:05:29 -07:00
Jakob Stoklund Olesen
8deca67968 Add legalization patterns for fabs and fneg.
These sign bit manipulations need to use a -0.0 floating point constant
which we didn't have a way of materializing previously.

Add a ieee32.bits(0x...) syntax to the Python AST nodes that creates am
f32 immediate value with the exact requested bitwise representation.
2017-09-25 12:15:33 -07:00
Jakob Stoklund Olesen
ba1c50d6c1 Test WebAssembly floating point constants.
f64.const does not yet work on 32-bit Intel.
2017-09-25 11:06:18 -07:00
Jakob Stoklund Olesen
fdb97da21b Implement a poor man's jump table.
We will eventually support real jump tables, but for now just expand
br_table into a sequence of conditional branches.
2017-09-25 10:56:14 -07:00
Jakob Stoklund Olesen
29dfcf5dfb Add spill/fill encodings for Intel ISAs.
To begin with, these are catch-all encodings with a SIB byte and a
32-bit displacement, so they can access any stack slot via both the
stack pointer and the frame pointer.

In the future, we will add encodings for 8-bit displacements as well as
EBP-relative references without a SIB byte.
2017-09-22 16:05:26 -07:00
Jakob Stoklund Olesen
76eb7df9f0 Add an isa::StackRef type.
This contains encoding details for a stack reference: The base register
and offset to use in the specific instruction encoding.

Generate StackRef objects called in_stk0 etc for the binemit recipe
code. All binemit recipes need to compute base pointer offsets for stack
references, so have the automatically generated code do it.
2017-09-22 13:34:33 -07:00
Jakob Stoklund Olesen
2946cc54d3 Add more trap codes.
These are codes that come up naturally when translating WebAssembly and
legalizing the Cretonne instruction set.
2017-09-22 08:51:55 -07:00
Angus Holder
7fbf1cb810 Revert accidental change 2017-09-22 07:54:26 -07:00
Angus Holder
b003605132 Adapt intel to be able to correctly choose compressed instruction encodings: create a register class to identify the lower 8 registers, omit unnecessary REX prefixes, and fix the tests 2017-09-22 07:54:26 -07:00
Angus Holder
3b66c0be40 Emit compressed instruction encodings for instructions where constraints allow 2017-09-22 07:54:26 -07:00
Jakob Stoklund Olesen
2d4c860187 Convert legalizer::split and generated legalization code to FuncCursor. 2017-09-21 17:05:51 -07:00
Jakob Stoklund Olesen
a9acbd1afd Convert the legalizer/boundary module to FuncCursor.
This is a larger refactoring because all the changes need to be done
together. Either you pass a Function reference around, or you pass
around references to the parts. There is no in between.
2017-09-21 16:43:47 -07:00
Jakob Stoklund Olesen
85e4e9f511 Assign source locations when translating WebAssembly to Cretonne.
The source locations are byte code offsets relative to the beginning of
the function.
2017-09-21 14:37:54 -07:00
Jakob Stoklund Olesen
4d4da2dc60 Add source location support to FuncCursor and EncCursor.
A cursor now also remembers a current source location which will be
assigned to all new instructions created with the cursor.

The old layout::Cursor can't support source locations because it doesn't
have a reference to the full ir::Function.
2017-09-21 14:37:54 -07:00
Jakob Stoklund Olesen
b2a314a229 Add per-instruction source locations to the Cretonne IR.
Source locations are opaque 32-bit entities that can be used to
represent WebAssembly byte-code positions or some other source
identifier.
2017-09-21 14:24:26 -07:00
Dan Gohman
16eb689dd1 Use Self instead of repeating the type name. 2017-09-21 14:21:30 -07:00
Dan Gohman
e5e4b59683 Tidy up some asserts. 2017-09-21 14:21:30 -07:00
Dan Gohman
e75558b800 Fix spelling of "adjustment". 2017-09-21 14:21:30 -07:00
Dan Gohman
dda8293668 Restructure code to avoid a heap allocation. 2017-09-21 14:21:30 -07:00
Dan Gohman
ff18772d0e Avoid a heap allocation. 2017-09-21 14:21:30 -07:00
Dan Gohman
22b769b716 Convert use_var and predecessors_lookup into a state machine to avoid recursion. 2017-09-21 14:21:30 -07:00
Dan Gohman
9cda4eacde Minor refactor. 2017-09-21 14:21:30 -07:00
Dan Gohman
df5ba8bbba Correct a comment. 2017-09-21 14:21:30 -07:00
Dan Gohman
f524977920 Factor some logic out of seal_ebb_header_block into parts.
This allows append_jump_argument to call just the part that it needs
instead of the whole of seal_ebb_header_block, which is a nice cleanup
on its own, and it also eliminates a cycle from the static call graph.
2017-09-21 14:21:30 -07:00
Jakob Stoklund Olesen
218959ff65 Convert more tests to FuncCursor. 2017-09-21 13:30:00 -07:00
Jakob Stoklund Olesen
8e93aa7ce7 Remove layout::Cursor from the legalizer::split API.
We still use the cursor internally, but don't require callers to use it
too.
2017-09-21 13:07:17 -07:00
Jakob Stoklund Olesen
1cd91b6f30 Eliminate layout::Cursor from cton_frontend.
Replace all uses with a FuncCursor.

Avoid the anti-pattern of passing parts of a function around as
independent references.
2017-09-21 12:24:27 -07:00
Jakob Stoklund Olesen
03dee5e442 Replace some uses of layout::Cursor with FuncCursor.
The layout::Cursor is unfortunate because it doesn't reference the whole
function.
2017-09-21 11:27:15 -07:00