From 1ae43265d9dada8dd25d5f3bd333745e6de97501 Mon Sep 17 00:00:00 2001 From: Marko Bencun <mbencun@gmail.com> Date: Fri, 6 Sep 2013 11:14:08 +0200 Subject: [PATCH] forgot bitlog2 files --- src/c_wrapper/bitlog.cpp | 26 +++++++++++++++++++++ src/c_wrapper/bitlog.hpp | 50 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 src/c_wrapper/bitlog.cpp create mode 100644 src/c_wrapper/bitlog.hpp diff --git a/src/c_wrapper/bitlog.cpp b/src/c_wrapper/bitlog.cpp new file mode 100644 index 00000000..67b82511 --- /dev/null +++ b/src/c_wrapper/bitlog.cpp @@ -0,0 +1,26 @@ +#include "bitlog.hpp" + + + +/* from http://graphics.stanford.edu/~seander/bithacks.html */ +const char pyopencl::log_table_8[] = +{ + 0, 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, + 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7 +}; + + diff --git a/src/c_wrapper/bitlog.hpp b/src/c_wrapper/bitlog.hpp new file mode 100644 index 00000000..86e11710 --- /dev/null +++ b/src/c_wrapper/bitlog.hpp @@ -0,0 +1,50 @@ +// Base-2 logarithm bithack. + + + + +#ifndef _AFJDFJSDFSD_PYOPENCL_HEADER_SEEN_BITLOG_HPP +#define _AFJDFJSDFSD_PYOPENCL_HEADER_SEEN_BITLOG_HPP + + + + +#include <climits> +#include <stdint.h> + +namespace pyopencl +{ + extern const char log_table_8[]; + + inline unsigned bitlog2_16(uint16_t v) + { + if (unsigned long t = v >> 8) + return 8+log_table_8[t]; + else + return log_table_8[v]; + } + + inline unsigned bitlog2_32(uint32_t v) + { + if (uint16_t t = v >> 16) + return 16+bitlog2_16(t); + else + return bitlog2_16(v); + } + + inline unsigned bitlog2(unsigned long v) + { +#if (ULONG_MAX != 4294967295) + if (uint32_t t = v >> 32) + return 32+bitlog2_32(t); + else +#endif + return bitlog2_32(v); + } +} + + + + + +#endif -- GitLab