Created
November 9, 2015 17:45
-
-
Save sw17ch/83e721a7593eb78a878c 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
static void signed_promote(void const * in, size_t in_size, void * out, size_t out_size) { | |
assert(in_size <= out_size); | |
assert(in_size == 1 || in_size == 2 || in_size == 4 || in_size == 8); | |
assert(out_size == 1 || out_size == 2 || out_size == 4 || out_size == 8); | |
uint64_t word_in = 0; | |
memcpy(&word_in, in, in_size); | |
if (word_in & (1 << ((in_size * 8) - 1))) { | |
memset(out, 0xFF, out_size); | |
} | |
memcpy(out, in, in_size); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment