Created
June 2, 2017 13:39
-
-
Save x100ex/426b29b3805302e2d54672699e8558b6 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// https://schani.wordpress.com/2010/04/30/linear-vs-binary-search/ | |
static int | |
binary_cmov (const int *arr, int n, int key) { | |
int min = 0, max = n; | |
while (min < max) { | |
int middle = (min + max) >> 1; | |
asm ("cmpl %3, %2\n\tcmovg %4, %0\n\tcmovle %5, %1" | |
: "+r" (min), | |
"+r" (max) | |
: "r" (key), "g" (arr [middle]), | |
"g" (middle + 1), "g" (middle)); | |
} | |
return min; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment