Skip to content

Commit

Permalink
Fix for next highest power of 2 function.
Browse files Browse the repository at this point in the history
  • Loading branch information
lsgunth committed Mar 11, 2015
1 parent 3c31e91 commit 21ff9c8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/readthrd.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,17 @@ static ssize_t check_file(const char *f)
return ret;
}


static int next_power_of_2(int x)
{
return (x & -x) + x;
x--;
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
x++;

return x;
}

struct readthrd *readthrd_start(const char *fpath,
Expand Down
10 changes: 9 additions & 1 deletion src/writethrd.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,15 @@ static int check_file(const char *f, int truncate)

static int next_power_of_2(int x)
{
return (x & -x) + x;
x--;
x |= x >> 1;
x |= x >> 2;
x |= x >> 4;
x |= x >> 8;
x |= x >> 16;
x++;

return x;
}

struct writethrd *writethrd_start(const char *fpath, const char *swap_phrase,
Expand Down

0 comments on commit 21ff9c8

Please sign in to comment.