Commit Graph

19 Commits

Author SHA1 Message Date
Jakob Stoklund Olesen
7f3b807597 Add a calling convention to all function signatures.
A CallConv enum on every function signature makes it possible to
generate calls to functions with different calling conventions within
the same ISA / within a single function.

The calling conventions also serve as a way of customizing Cretonne's
behavior when embedded inside a VM. As an example, the SpiderWASM
calling convention is used to compile WebAssembly functions that run
inside the SpiderMonkey virtual machine.

All function signatures must have a calling convention at the end, so
this changes the textual IL syntax.

Before:

    sig1 = signature(i32, f64) -> f64

After

    sig1 = (i32, f64) -> f64 native
    sig2 = (i32) spiderwasm

When printing functions, the signature goes after the return types:

    function %r1() -> i32, f32 spiderwasm {
    ebb1:
        ...
    }

In the parser, this calling convention is optional and defaults to
"native". This is mostly to avoid updating all the existing test cases
under filetests/. When printing a function, the calling convention is
always included, including for "native" functions.
2017-08-03 11:40:24 -07:00
Jakob Stoklund Olesen
e8acad5070 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
265bd351bd 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
82fbc78f2f 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
0a7087732e 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
306ef2095b 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
02fd83cd5c Add Intel encodings for imul. 2017-07-18 09:27:36 -07:00
Jakob Stoklund Olesen
e3ff551c2b Add Intel BMI1 ctz and clz encodings. 2017-07-14 14:01:02 -07:00
Jakob Stoklund Olesen
d8e2cb2b42 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
b6f2f0d862 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
5615e4a9e7 Add Intel encodings for shift and rotate instructions. 2017-07-12 13:12:24 -07:00
Jakob Stoklund Olesen
0f285cb137 Intel 32-bit encodings for copy.i32. 2017-07-05 15:48:06 -07:00
Jakob Stoklund Olesen
1a24489a0e Add Intel call/return encodings. 2017-06-30 12:21:36 -07:00
Jakob Stoklund Olesen
3608be35a9 Add Intel iconst.i32 encoding. 2017-06-30 11:41:06 -07:00
Aleksey Kuznetsov
8b484b1c77 Binary function names (#91)
* Function names should start with %

* Create FunctionName from string

* Implement displaying of FunctionName as %nnnn with fallback to #xxxx

* Run rustfmt and fix FunctionName::with_string in parser

* Implement FunctionName::new as a generic function

* Binary function names should start with #

* Implement NameRepr for function name

* Fix examples in docs to reflect that function names start with %

* Rebase and fix filecheck tests
2017-06-10 10:30:37 -07:00
Jakob Stoklund Olesen
9629867d0c Encodings for load/store instructions.
We don't support the full set of Intel addressing modes yet. So far we
have:

- Register indirect, no displacement.
- Register indirect, 8-bit signed displacement.
- Register indirect, 32-bit signed displacement.

The SIB addressing modes will need new Cretonne instruction formats to
represent.
2017-05-12 16:49:39 -07:00
Jakob Stoklund Olesen
c998df6274 Add subtract and logical instruction encodings to Intel-32.
Also add versions with 8-bit and 32-bit immediate operands.
2017-05-12 15:37:12 -07:00
Jakob Stoklund Olesen
cdb3a71dd1 Add encodings for Intel dynamic shift instructions.
These instructions have a fixed register constraint; the shift amount is
passed in CL.

Add meta language syntax so a fixed register can be specified as
"GPR.rcx".
2017-05-09 13:11:50 -07:00
Jakob Stoklund Olesen
5bdb61a5f1 Add the very basics of Intel 32-bit instruction encodings.
Tabulate the Intel opcode representations and implement an OP() function
which computes the encoding bits.

Implement the single-byte opcode with a reg-reg ModR/M byte.
2017-05-08 16:57:38 -07:00