Skip to content

Instantly share code, notes, and snippets.

View x100ex's full-sized avatar

Aleksander A. Popov x100ex

View GitHub Profile
@x100ex
x100ex / abspath.sh
Last active August 29, 2015 14:05
pure bash abspath
#!/bin/bash
abspath() {
local thePath
if [[ ! "$1" =~ ^/ ]]
then
thePath="$PWD/$1"
else
thePath="$1"
fi
@x100ex
x100ex / linear_4.c
Created June 2, 2017 13:34
linear_4.c
// 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;
// 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;
// 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]);
// 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]);
// 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;
// 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),

Keybase proof

I hereby claim:

  • I am x100ex on github.
  • I am aap (https://keybase.io/aap) on keybase.
  • I have a public key ASCXWEe4dEfsXVnNXx4O2jgcow0kN0RRM_PHw5NhPL8Rlgo

To claim this, I am signing this object:

@x100ex
x100ex / README-default.md
Created June 17, 2017 09:37
template of the README.md file

Logo of the project

Name of the project

Additional information or tagline

A brief description of your project, what it is used for and how does life get awesome when someone starts to use it.

Installing / Getting started

@x100ex
x100ex / ccassert.h
Created June 17, 2017 09:39
static assert in C
// C compiler check for structure size
// from: http://bytes.com/topic/c/answers/220022-if-sizeof
#define _x_CCASERT_LINE_CAT(predicate, line) typedef char constraint_violated_on_line_##line[2*((predicate) != 0)-1];
#define CCASSERT(predicate) _x_CCASERT_LINE_CAT(predicate, __LINE__)
// Usage: CCASSERT(1) to pass; CCASSERT(0) to fail
/*
typedef struct {
long x;