Commit Graph

46 Commits

Author SHA1 Message Date
Tyler McMullen
f636d795c5 load_complex and store_complex instructions (#309)
* Start adding the load_complex and store_complex instructions.

N.b.:
The text format is not correct yet. Requires changes to the lexer and parser.
I'm not sure why I needed to change the RuntimeError to Exception yet. Will fix.

* Get first few encodings of load_complex working. Still needs var args type checking.

* Clean up ModRM helper functions in binemit.

* Implement 32-bit displace for load_complex

* Use encoding helpers instead of doing them all by hand

* Initial implementation of store_complex

* Parse value list for load/store_complex with + as delimiter. Looks nice.

* Add sign/zero-extension and size variants for load_complex.

* Add size variants of store_complex.

* Add asm helper lines to load/store complex bin tests.

* Example of length-checking the instruction ValueList for an encoding. Extremely questionable implementation.

* Fix Python linting issues

* First draft of postopt pass to fold adds and loads into load_complex. Just simple loads for now.

* Optimization pass now works with all types of loads.

* Add store+add -> store_complex to postopt pass

* Put complex address optimization behind ISA flag.

* Add load/store complex for f32 and f64

* Fixes changes to lexer that broke NaN parsing.

Abstracts away the repeated checks for whether or not the characters
following a + or - are going to be parsed as a number or not.

* Fix formatting issues

* Fix register restrictions for complex addresses.

* Encoding tests for x86-32.

* Add documentation for newly added instructions, recipes, and cdsl changes.

* Fix python formatting again

* Apply value-list length predicates to all LoadComplex and StoreComplex instructions.

* Add predicate types to new encoding helpers for mypy.

* Import FieldPredicate to satisfy mypy.

* Add and fix some "asm" strings in the encoding tests.

* Line-up 'bin' comments in x86/binary64 test

* Test parsing of offset-less store_complex instruction.

* 'sNaN' not 'sNan'

* Bounds check the lookup for polymorphic typevar operand.

* Fix encodings for istore16_complex.
2018-05-09 14:07:00 -05:00
Steffen Butzer
5aa84a744b windows fastcall (x64) call convention (#314)
* initial set of work for windows fastcall (x64) call convention

- call conventions: rename `fastcall` to `windows_fastcall`
- add initial set of filetests
- ensure arguments are written after the shadow space/store (offset-wise)
  The shadow space available before the arguments (range 0..32)
  is not used as spill space yet.

* address review feedback
2018-05-09 13:18:30 -05:00
Ty Overby
09f883182d document that low bitsize integers don't have complete arithmetic support (#320)
* document that low bitsize integers don't have complete arithmetic support
2018-05-07 11:10:01 -05:00
Dan Gohman
5b69930e03 Legalize bnot using xor with -1. 2018-05-05 11:21:06 -05:00
Pat Hickey
bb612af37a x86 recipes: emit StackOverflow trap for all sp-relative loads and stores (#325)
* x86 recipes: emit StackOverflow trap for all sp-relative loads and stores

* x86 recipes: emit StackOverflow trap for push and pop

* x86 binary filetests: add stk_ovf trap annotations
2018-05-03 18:09:07 -07:00
Dan Gohman
846a71d93b Fixes for mypy 0.600 (#324)
* Remove the mypy version constraint and set strict_optional to False.

* Add type annotations for `ISA` variables.

mypy 0.600 seems to require explicit annotations here.

* Annotate the ISA variables in the defs.py files too.
2018-05-03 12:12:19 -07:00
Dan Gohman
b4f9eb5e55 Bump versino to 0.8.0 2018-05-01 19:54:21 -07:00
Dan Gohman
9c87f3ac87 Fix some warnings in no_std builds.
The dbg! macro expands to nothing in no_std mode, so variables that are
only used for debugging prompt unused variable warnings.

Also, allow unstable_features in no_std builds, since they use
feature(alloc), which is an unstable feature.
2018-04-30 14:04:14 -07:00
Dan Gohman
94a883abae Make settings::Flags::new consume the Builder.
This makes it more clear what the relationship is between the Builder
and the resulting Flags.
2018-04-30 13:53:36 -07:00
Dan Gohman
b7f38ac8bc Replace Builder's Vec<u8> with a Box<[u8]>.
It doesn't need to dynamically grow, and `Box<[u8]>` is smaller.
2018-04-30 13:53:29 -07:00
Dan Gohman
4942772f90 Add several more x86 CPU models. 2018-04-30 13:53:29 -07:00
pup
afd5442722 Minor comment typo fix. (#315) 2018-04-30 13:26:21 -07:00
Dan Gohman
525f01713b Bump version to 0.7.0 2018-04-27 06:10:15 -07:00
Dan Gohman
e356c742aa Bump version to 0.6.0 2018-04-23 14:35:23 -07:00
Dan Gohman
5bcfd47f3f Remove the non-REX encodings for regmove et al.
regmove, regfill, and regspill have immediates which aren't value
operands, so they aren't in the set of things that can be described by
the existing constraint system. Consequently, constraints saying that
the non-REX encodings only support registers that don't need REX
prefixes don't work. Fow now, just remove the non-REX encodings, so
that they don't get selected when they aren't valid.

This fixes the last known issue with instruction shrinking, so it can
be re-enabled.
2018-04-22 22:31:56 -07:00
Dan Gohman
9f0a35103a Update a comment. 2018-04-22 21:53:53 -07:00
Dan Gohman
beddcc50f2 Minor code refactoring. 2018-04-22 21:53:53 -07:00
Dan Gohman
3b1d805758 Stack overflow checking with stack probes.
This adds a libcall name, a calling convention, and settings for
emitting stack probes, and implements them for x86 system_v ABIs.
2018-04-22 21:52:12 -07:00
Dan Gohman
c5b15c2396 Refactor calling convention settings. (#304)
Add a calling-convention setting to the `Flags` used as part of the
`TargetIsa`. This allows Cretonne code that generates calls to use the
correct convention, such as when emitting libcalls during legalization
or when the wasm frontend is decoding functions. This setting can be
overridden per-function.

This also adds "fast", "cold", and "fastcall" conventions, with "fast"
as the new default. Note that "fast" and "cold" are not intended to be
ABI-compatible across Cretonne versions.

This will also ensure Windows users will get an `unimplemented!` rather
than silent calling-convention mismatches, which reflects the fact that
Windows calling conventions are not yet implemented.

This also renames SpiderWASM, which isn't camel-case, to Baldrdash,
which is, and which is also a more relevant name.
2018-04-22 21:35:18 -07:00
Dan Gohman
dfb24f1934 Fix x86 encoding of uextend/sextend from 8-bit inputs.
The x86-32 and non-REX encodings of movsbl and movzbl require one of
the ABCD registers as input.
2018-04-20 12:12:29 -07:00
Dan Gohman
e876529152 Merge pull request #303 from sunfishcode/no_std_merge
Merge no_std into master
2018-04-20 12:11:53 -07:00
Dan Gohman
33e266eeeb Fix missing word. 2018-04-20 11:04:13 -07:00
Dan Gohman
3e4531657c Temporarily disable the shink_instruction pass.
It appears some of the instruction encodings are incorrect. Temporarily
disable the use of shorter encodings until these are fixed.
2018-04-19 17:49:48 -07:00
Dan Gohman
bce8af97e3 Add an instruction shrinking pass.
When an instruction has multiple valid encodings, such as with and
without a REX prefix on x86-64, Cretonne typically picks the encoding
which gives the register allocator the most flexibility, which is
typically the longest encoding. This patch adds a pass that runs after
register allocation that picks the smallest encoding, working within the
constraints of the register allocator's choices. The result is smaller
and easier to read encodings.

In the future, we may want to merge this pass into the relaxation pass,
or possibly fold it into the final encoding step, however for now, a
discrete pass will suffice.
2018-04-19 17:04:56 -07:00
Dan Gohman
73c19bbf6d Fix the dbg! macro for no_std mode.
Check for the `std` feature outside the macro body rather than inside,
so that we get the `std` feature in `cretonne-codegen`, rather than in
whatever crate the macro is being expanded in.
2018-04-19 13:18:21 -07:00
Dan Gohman
d72706c478 Use use declarations rather than '::std::...' names.
This is what most of the rest of the codebase does, so this patch just
tidies up a few additional places.
2018-04-19 13:14:12 -07:00
Dan Gohman
acabcc5c8f Merge remote-tracking branch 'origin/master' into no_std 2018-04-19 12:40:10 -07:00
Dan Gohman
830ee60d28 Add no_std support in module, simplejit, and umbrella. 2018-04-19 12:39:56 -07:00
Dan Gohman
5bc0e0e188 Add a comment advertising NullTrapSink. 2018-04-19 09:40:46 -07:00
Dan Gohman
5f84afee2c Merge remote-tracking branch 'origin/master' into no_std 2018-04-18 17:20:02 -07:00
Dan Gohman
eefa1de4da Rename some local variables for consistency with the rest of the codebase. 2018-04-18 17:02:32 -07:00
Dan Gohman
d122d16f79 Style consistency: don't end error messages with exclamation points. 2018-04-18 16:59:24 -07:00
morenzg
fdf34e9d3e Fix up nostd dependencies 2018-04-18 12:01:27 -04:00
Dan Gohman
d7e13284b2 Mark emit_to_memory as unsafe, and introduce a safe emit. (#281)
* Mark emit_to_memory as unsafe, and provide a safe compile_and_emit.

Mark `Context::emit_to_memory` and `MemoryCodeSink::new` as unsafe, as
`MemoryCodeSink` does not perform bounds checking when writing to
memory.

Add a `Context::compile_and_emit` function which provides a convenient
interface for doing `compile` and `emit_to_memory` in one step, and
which can also provide a safe interface, since it allocates memory of
the needed size itself.

* Mention that `MemoryCodeSink` can't guarantee that the pointer is valid.
2018-04-18 06:35:47 -07:00
Dan Gohman
1ba468b230 Bump version to 0.5.1 2018-04-17 22:18:30 -07:00
Dan Gohman
bf597b7abf Enable and fix several more clippy lints. 2018-04-17 17:05:03 -07:00
Dan Gohman
5c6cb202d8 Suppress cast_ptr_alignment clippy errors.
These are only used in places that use `write_unaligned`, so it's ok
that the pointer might be misaligned.
2018-04-17 17:04:56 -07:00
morenzg
a10a6a0df0 Merge branch 'master' into no_std 2018-04-17 16:56:33 -04:00
Dan Gohman
58380f38e8 Refactor SimpleJITTrapSink/FaerieTrapSink into NullTrapSink.
This publishes it for use outside of simpljie/faerie as well.
2018-04-17 11:22:11 -07:00
Dan Gohman
1f43ec09f3 Bump version to 0.5.0 2018-04-17 10:58:33 -07:00
Dan Gohman
76db9f022d [WIP] Module API (#294)
* Initial skeleton.

* Add basic faerie support.

This adds enough functionality to enable simple .o file writing through
faerie. This included adding the functionality to Module to support
RelocSink implementations.

* Add basic SimpleJIT support.

This adds enough functionality to enable a simple program to be jitted
and executed.

* Make declare_func_in_func take a Function instead of a Context.

It only needs the Function, and sometimes it's useful to call it from
places that don't have a full Context.

* Temporarily disable local and exported global variables in the Faerie backend.

Faerie assumes these variables use pc-relative offset instructions, and
Cretonne is not yet emitting those instructions.

* FaerieBackend depends on PIC.

Faerie itself only supports PIC objects for now, so add an assert to
Cretonne to check that it's using a PIC target flag.

* SimpleJIT support for data objects.

* Preliminary faerie support for data objects.

* Support for data objects in faerie using the new colocated flag.

* Unit tests for DataContext and friends.

* Add a Module::consume() function.

This consumes the Module and returns the contained Backend, so that
users can call Backend-specific functions with it. For example, the
Faerie backend has functions to write an object file.

* Update the new crates to version 0.4.4.

* Make FaerieBackend own its TargetIsa.

This simplifies its interface, as it eliminates a lifetime parameter.
While we may eventually want to look into allowing multiple clients to
share a TargetIsa, it isn't worth the complexity for FaerieBackend
right now.

* Don't try to protect faerie from multiple declarations.

Let faerie decide for itself whether it wants to consider two
declarations to be compatible.

* Use debug_assert_eq rather than debug_assert with ==.

* Fix FaerieRelocSink's reloc_external to handle data object names.

* Relax the asserts in get_function_definition and get_data_definition.

These functions don't require definable symbols, but they do require
that definable symbols be defined. This is needed for the simplejit
backend.

* Add a function to the faerie backend to retrieve the artifact name.

* Sync up with cretonne changes.
2018-04-17 10:52:36 -07:00
Dan Gohman
a9edb28414 Rename InstructionFormat::IndirectCall for consistency with Opcode::CallIndirect. 2018-04-17 09:47:27 -07:00
Dan Gohman
e2f6705e28 Add a comment about why there's no is_pie setting. 2018-04-17 09:47:27 -07:00
Dan Gohman
635d14c251 Rename GlobalVarData::VmCtx for consistency with ArgumentPurpose::VMContext. 2018-04-17 09:47:27 -07:00
Dan Gohman
f43b6aca1a Use lower-case letters for github URLs.
This makes it a little more consistent; now, "cretonne" is never capitalized
in identifier, path, or URL contexts. It is capitalized in natural
language contexts when referring to the project.
2018-04-17 09:47:11 -07:00
Dan Gohman
24fa169e1f Rename the 'cretonne' crate to 'cretonne-codegen'.
This fixes the next part of #287.
2018-04-17 09:46:56 -07:00