Created
November 21, 2013 17:00
-
-
Save astocko/7585496 to your computer and use it in GitHub Desktop.
Absolute value and sign flip demo with bitmask and SSE instructions.
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
#include <iostream> | |
static constexpr int kAbsMask = 0x7FFFFFFF; | |
static constexpr int kFlipMask = 0x80000000; | |
int main(int argc, char const *argv[]) | |
{ | |
float y = -30.234; | |
float z = 40.023; | |
// abs value | |
__asm { | |
movss xmm9, kAbsMask | |
movss xmm0, y | |
andps xmm0, xmm9 | |
movss y, xmm0 | |
} | |
// flip sign | |
__asm { | |
movss xmm9, kFlipMask | |
movss xmm0, z | |
xorps xmm0, xmm9 | |
movss z, xmm0 | |
} | |
std::cout << "Abs Value: " << y << std::endl; | |
std::cout << "Flipped: " << z << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment