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.
This commit is contained in:
Tyler McMullen
2018-05-09 12:07:00 -07:00
committed by Dan Gohman
parent 5aa84a744b
commit f636d795c5
25 changed files with 1127 additions and 21 deletions

View File

@@ -22,6 +22,7 @@ pub enum Token<'a> {
LBracket, // '['
RBracket, // ']'
Minus, // '-'
Plus, // '+'
Comma, // ','
Dot, // '.'
Colon, // ':'
@@ -169,6 +170,25 @@ impl<'a> Lexer<'a> {
self.source[self.pos..].starts_with(prefix)
}
// Starting from `lookahead`, are we looking at a number?
fn looking_at_numeric(&self) -> bool {
if let Some(c) = self.lookahead {
if c.is_digit(10) {
return true;
}
match c {
'-' => return true,
'+' => return true,
'.' => return true,
_ => {}
}
if self.looking_at("NaN") || self.looking_at("Inf") || self.looking_at("sNaN") {
return true;
}
}
false
}
// Scan a single-char token.
fn scan_char(&mut self, tok: Token<'a>) -> Result<LocatedToken<'a>, LocatedError> {
assert_ne!(self.lookahead, None);
@@ -234,16 +254,17 @@ impl<'a> Lexer<'a> {
match self.lookahead {
Some('-') => {
self.next_ch();
if let Some(c) = self.lookahead {
// If the next character won't parse as a number, we return Token::Minus
if !c.is_alphanumeric() && c != '.' {
return token(Token::Minus, loc);
}
if !self.looking_at_numeric() {
// If the next characters won't parse as a number, we return Token::Minus
return token(Token::Minus, loc);
}
}
Some('+') => {
self.next_ch();
if !self.looking_at_numeric() {
// If the next characters won't parse as a number, we return Token::Minus
return token(Token::Plus, loc);
}
}
_ => {}
}

View File

@@ -13,8 +13,8 @@ use cretonne_codegen::ir::{AbiParam, ArgumentExtension, ArgumentLoc, Ebb, ExtFun
Type, Value, ValueLoc};
use cretonne_codegen::isa::{self, Encoding, RegUnit, TargetIsa};
use cretonne_codegen::packed_option::ReservedValue;
use cretonne_codegen::{settings, timing};
use cretonne_codegen::settings::CallConv;
use cretonne_codegen::{settings, timing};
use error::{Error, Location, Result};
use isaspec;
use lexer::{self, Lexer, Token};
@@ -1872,6 +1872,24 @@ impl<'a> Parser<'a> {
Ok(args)
}
fn parse_value_sequence(&mut self) -> Result<VariableArgs> {
let mut args = VariableArgs::new();
if let Some(Token::Value(v)) = self.token() {
args.push(v);
self.consume();
} else {
return Ok(args);
}
while self.optional(Token::Plus) {
args.push(self.match_value("expected value in argument list")?);
}
Ok(args)
}
// Parse an optional value list enclosed in parantheses.
fn parse_opt_value_list(&mut self) -> Result<VariableArgs> {
if !self.optional(Token::LPar) {
@@ -2267,6 +2285,17 @@ impl<'a> Parser<'a> {
offset,
}
}
InstructionFormat::LoadComplex => {
let flags = self.optional_memflags();
let args = self.parse_value_sequence()?;
let offset = self.optional_offset32()?;
InstructionData::LoadComplex {
opcode,
flags,
args: args.into_value_list(&[], &mut ctx.function.dfg.value_lists),
offset,
}
}
InstructionFormat::Store => {
let flags = self.optional_memflags();
let arg = self.match_value("expected SSA value operand")?;
@@ -2283,6 +2312,23 @@ impl<'a> Parser<'a> {
offset,
}
}
InstructionFormat::StoreComplex => {
let flags = self.optional_memflags();
let src = self.match_value("expected SSA value operand")?;
self.match_token(
Token::Comma,
"expected ',' between operands",
)?;
let args = self.parse_value_sequence()?;
let offset = self.optional_offset32()?;
InstructionData::StoreComplex {
opcode,
flags,
args: args.into_value_list(&[src], &mut ctx.function.dfg.value_lists),
offset,
}
}
InstructionFormat::RegMove => {
let arg = self.match_value("expected SSA value operand")?;
self.match_token(
@@ -2402,9 +2448,9 @@ impl<'a> Parser<'a> {
#[cfg(test)]
mod tests {
use super::*;
use cretonne_codegen::ir::StackSlotKind;
use cretonne_codegen::ir::entities::AnyEntity;
use cretonne_codegen::ir::types;
use cretonne_codegen::ir::StackSlotKind;
use cretonne_codegen::ir::{ArgumentExtension, ArgumentPurpose};
use cretonne_codegen::settings::CallConv;
use error::Error;