Created
March 3, 2019 01:23
-
-
Save NattyNarwhal/172b7fbf646adad71e74d604ce7c9a4a to your computer and use it in GitHub Desktop.
getsign
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
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