mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-10 12:09:31 +00:00
aml: Use the shortest form possible to generate integers
Values 0 and 1 can be represented with one-byte binaries. BUG=None TEST=./tools/presubmit Change-Id: If5d61c598087118858a6b57799ab1b90ad729f70 Reviewed-on: https://chromium-review.googlesource.com/c/crosvm/crosvm/+/3859217 Reviewed-by: Daniel Verkamp <dverkamp@chromium.org> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org> Auto-Submit: Victor Ding <victording@chromium.org> Tested-by: Victor Ding <victording@chromium.org>
This commit is contained in:
parent
eeb11115a8
commit
8d72733baf
1 changed files with 27 additions and 1 deletions
|
@ -348,7 +348,11 @@ impl Aml for EISAName {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_integer(v: usize, bytes: &mut Vec<u8>) {
|
fn create_integer(v: usize, bytes: &mut Vec<u8>) {
|
||||||
if v <= u8::max_value().into() {
|
if v == 0_usize {
|
||||||
|
ZERO.to_aml_bytes(bytes);
|
||||||
|
} else if v == 1_usize {
|
||||||
|
ONE.to_aml_bytes(bytes);
|
||||||
|
} else if v <= u8::max_value().into() {
|
||||||
(v as u8).to_aml_bytes(bytes);
|
(v as u8).to_aml_bytes(bytes);
|
||||||
} else if v <= u16::max_value().into() {
|
} else if v <= u16::max_value().into() {
|
||||||
(v as u16).to_aml_bytes(bytes);
|
(v as u16).to_aml_bytes(bytes);
|
||||||
|
@ -1709,6 +1713,28 @@ mod tests {
|
||||||
aml.clear();
|
aml.clear();
|
||||||
0xdeca_fbad_deca_fbadu64.to_aml_bytes(&mut aml);
|
0xdeca_fbad_deca_fbadu64.to_aml_bytes(&mut aml);
|
||||||
assert_eq!(aml, [0x0e, 0xad, 0xfb, 0xca, 0xde, 0xad, 0xfb, 0xca, 0xde]);
|
assert_eq!(aml, [0x0e, 0xad, 0xfb, 0xca, 0xde, 0xad, 0xfb, 0xca, 0xde]);
|
||||||
|
aml.clear();
|
||||||
|
0x00_usize.to_aml_bytes(&mut aml);
|
||||||
|
assert_eq!(aml, [0x00]);
|
||||||
|
aml.clear();
|
||||||
|
0x01_usize.to_aml_bytes(&mut aml);
|
||||||
|
assert_eq!(aml, [0x01]);
|
||||||
|
aml.clear();
|
||||||
|
0x86_usize.to_aml_bytes(&mut aml);
|
||||||
|
assert_eq!(aml, [0x0a, 0x86]);
|
||||||
|
aml.clear();
|
||||||
|
0xF00D_usize.to_aml_bytes(&mut aml);
|
||||||
|
assert_eq!(aml, [0x0b, 0x0d, 0xf0]);
|
||||||
|
aml.clear();
|
||||||
|
0xDECAF_usize.to_aml_bytes(&mut aml);
|
||||||
|
assert_eq!(aml, [0x0c, 0xaf, 0xec, 0x0d, 0x00]);
|
||||||
|
aml.clear();
|
||||||
|
#[cfg(target_pointer_width = "64")]
|
||||||
|
{
|
||||||
|
0xDECAFC0FFEE_usize.to_aml_bytes(&mut aml);
|
||||||
|
assert_eq!(aml, [0x0e, 0xee, 0xff, 0xc0, 0xaf, 0xec, 0x0d, 0x00, 0x00]);
|
||||||
|
aml.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
Loading…
Reference in a new issue