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), |
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 (const int *arr, int n, int key) { | |
int min = 0, max = n; | |
while (min < max) { | |
int middle = (min + max) >> 1; | |
if (key > arr [middle]) | |
min = middle + 1; |
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 | |
linear_sentinel_sse2_nobranch (const int *arr, int n, int key) { | |
v4si *in_data = (v4si*)arr; | |
v4si key4 = { key, key, key, key }; | |
int i = 0; | |
for (;;) { | |
v4si cmp0 = __builtin_ia32_pcmpgtd128 (key4, in_data [i + 0]); |
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 | |
linear_sentinel_sse2 (const int *arr, int n, int key) { | |
v4si *in_data = (v4si*)arr; | |
v4si key4 = { key, key, key, key }; | |
int i = 0; | |
for (;;) { | |
v4si tmp = __builtin_ia32_pcmpgtd128 (key4, in_data [i]); |
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 | |
linear_sentinel (const int *arr, int key) { | |
int i = 0; | |
for (;;) { | |
if (arr [i] >= key) | |
return i; | |
++i; |
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 | |
linear_4 (const int *arr, int n, int key) { | |
int i = 0; | |
while (i + 3 < n) { | |
if (arr [i + 0] >= key) return i + 0; | |
if (arr [i + 1] >= key) return i + 1; | |
if (arr [i + 2] >= key) return i + 2; |
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
#!/bin/bash | |
abspath() { | |
local thePath | |
if [[ ! "$1" =~ ^/ ]] | |
then | |
thePath="$PWD/$1" | |
else | |
thePath="$1" | |
fi |
NewerOlder