Return the first applicable encoding from general_encoding().

We'll arrange encoding lists such that the first suitable encoding is
the best choice for the legalizer. This is the most intuitive way of
generating the encodings.

After register allocation, we may choose a different encoding, but that
will require looking at the whole list.
This commit is contained in:
Jakob Stoklund Olesen
2017-05-12 15:31:08 -07:00
parent 6fd95c1158
commit 31b7330b8d

View File

@@ -114,11 +114,11 @@ const CODE_ALWAYS: EncListEntry = PRED_MASK;
/// The encoding list terminator. /// The encoding list terminator.
const CODE_FAIL: EncListEntry = 0xffff; const CODE_FAIL: EncListEntry = 0xffff;
/// Find the most general encoding of `inst`. /// Find the first applicable general encoding of `inst`.
/// ///
/// Given an encoding list offset as returned by `lookup_enclist` above, search the encoding list /// Given an encoding list offset as returned by `lookup_enclist` above, search the encoding list
/// for the most general encoding that applies to `inst`. The encoding lists are laid out such that /// for the most first encoding that applies to `inst`. The encoding lists are laid out such that
/// this is the last valid entry in the list. /// this is the first valid entry in the list.
/// ///
/// This function takes two closures that are used to evaluate predicates: /// This function takes two closures that are used to evaluate predicates:
/// - `instp` is passed an instruction predicate number to be evaluated on the current instruction. /// - `instp` is passed an instruction predicate number to be evaluated on the current instruction.
@@ -133,14 +133,13 @@ pub fn general_encoding<InstP, IsaP>(offset: usize,
where InstP: Fn(EncListEntry) -> bool, where InstP: Fn(EncListEntry) -> bool,
IsaP: Fn(EncListEntry) -> bool IsaP: Fn(EncListEntry) -> bool
{ {
let mut found = None;
let mut pos = offset; let mut pos = offset;
while enclist[pos] != CODE_FAIL { while enclist[pos] != CODE_FAIL {
let pred = enclist[pos]; let pred = enclist[pos];
if pred <= CODE_ALWAYS { if pred <= CODE_ALWAYS {
// This is an instruction predicate followed by recipe and encbits entries. // This is an instruction predicate followed by recipe and encbits entries.
if pred == CODE_ALWAYS || instp(pred) { if pred == CODE_ALWAYS || instp(pred) {
found = Some(Encoding::new(enclist[pos + 1], enclist[pos + 2])) return Some(Encoding::new(enclist[pos + 1], enclist[pos + 2]));
} }
pos += 3; pos += 3;
} else { } else {
@@ -152,5 +151,6 @@ pub fn general_encoding<InstP, IsaP>(offset: usize,
} }
} }
} }
found
None
} }