Last active
December 21, 2018 12:49
-
-
Save udoprog/8c330d2cba9b4e0383f507a25610df9d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test_fixed: | |
movl 112(%rdi), %eax | |
movl 116(%rdi), %edx | |
retq | |
test_array: | |
movl 116(%rdi), %edx | |
xorl %eax, %eax | |
cmpl $1, 112(%rdi) | |
sete %al | |
retq |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro_rules! expand { | |
($len:expr, ($($member:ident),*), $get:ident) => { | |
#[allow(unused)] | |
#[derive(Clone, Copy, fixed_map::Key)] | |
pub enum FixedKey { | |
$($member,)* | |
} | |
#[no_mangle] | |
pub fn test_fixed(map: &fixed_map::Map<FixedKey, u32>) -> Option<u32> { | |
map.get(FixedKey::$get).cloned() | |
} | |
#[allow(unused)] | |
#[repr(usize)] | |
pub enum ArrayKey { | |
$($member,)* | |
} | |
#[no_mangle] | |
pub fn test_array(map: &[Option<u32>; $len]) -> Option<u32> { | |
map[ArrayKey::$get as usize].clone() | |
} | |
} | |
} | |
expand! { | |
16, | |
(T00, T01, T02, T03, T04, T05, T06, T07, T8, T9, T10, T11, T12, T13, T14, T15), | |
T14 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment