Skip to content

Instantly share code, notes, and snippets.

@sw17ch
Created November 9, 2015 17:45
Show Gist options
  • Save sw17ch/83e721a7593eb78a878c to your computer and use it in GitHub Desktop.
Save sw17ch/83e721a7593eb78a878c to your computer and use it in GitHub Desktop.
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