Make ConstantData a container for any-size constant values

Previously, ConstantData was a type alias for `Vec<u8>` which prevented it from having an implementation; this meant that `V128Imm` and `&[u8; 16]` were used in places that otherwise could have accepted types of different byte lengths.
This commit is contained in:
Andrew Brown
2019-09-30 14:56:03 -07:00
parent 50b7d2827d
commit 1600dba634
6 changed files with 113 additions and 36 deletions

View File

@@ -16,6 +16,7 @@ use crate::isa::RegUnit;
use crate::isa::{self, TargetIsa};
use crate::predicates;
use crate::regalloc::RegDiversions;
use std::vec::Vec;
include!(concat!(env!("OUT_DIR"), "/encoding-x86.rs"));
include!(concat!(env!("OUT_DIR"), "/legalize-x86.rs"));
@@ -928,7 +929,7 @@ fn convert_shuffle(
.clone();
if a == b {
// PSHUFB the first argument (since it is the same as the second).
let constructed_mask = mask
let constructed_mask: Vec<u8> = mask
.iter()
// If the mask is greater than 15 it still may be referring to a lane in b.
.map(|&b| if b > 15 { b.wrapping_sub(16) } else { b })
@@ -942,7 +943,8 @@ fn convert_shuffle(
pos.func.dfg.replace(inst).x86_pshufb(a, mask_value);
} else {
// PSHUFB the first argument, placing zeroes for unused lanes.
let constructed_mask = mask.iter().cloned().map(zero_unknown_lane_index).collect();
let constructed_mask: Vec<u8> =
mask.iter().cloned().map(zero_unknown_lane_index).collect();
let handle = pos.func.dfg.constants.insert(constructed_mask);
// Move the built mask into another XMM register.
let a_type = pos.func.dfg.value_type(a);
@@ -951,7 +953,7 @@ fn convert_shuffle(
let shuffled_first_arg = pos.ins().x86_pshufb(a, mask_value);
// PSHUFB the second argument, placing zeroes for unused lanes.
let constructed_mask = mask
let constructed_mask: Vec<u8> = mask
.iter()
.map(|b| b.wrapping_sub(16))
.map(zero_unknown_lane_index)