Skip to content

Instantly share code, notes, and snippets.

@NattyNarwhal
Created March 3, 2019 01:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NattyNarwhal/172b7fbf646adad71e74d604ce7c9a4a to your computer and use it in GitHub Desktop.
Save NattyNarwhal/172b7fbf646adad71e74d604ce7c9a4a to your computer and use it in GitHub Desktop.
getsign
int getsign (register int x) {
register int z;
/* it would be nice not to have to clobber the input, but isel doesn't like r0 */
asm (
"cmpi 0, 0, %2, 0\n"
"addi %2, 0, -1\n"
"isel %0, %2, %0, 0\n" // lt
"addi %2, 0, 1\n"
"isel %0, %2, %0, 1\n" // gt
"addi %2, 0, 0\n"
"isel %0, %2, %0, 2\n" // eq
: "=r"(z), "=r"(x) // output
: "r"(x) // inputs
: "cr0", "r0"
);
return z;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment