[Aurelia-svn] SF.net SVN: aurelia:[140] trunk
Status: Alpha
Brought to you by:
valentindavid
|
From: <val...@us...> - 2010-10-21 18:46:07
|
Revision: 140
http://aurelia.svn.sourceforge.net/aurelia/?rev=140&view=rev
Author: valentindavid
Date: 2010-10-21 18:46:00 +0000 (Thu, 21 Oct 2010)
Log Message:
-----------
2010-10-21 Valentin David <val...@ii...>
* src/fast/tests/test_invert_bits.cc,
* src/fast/tests/test_bin_log.cc,
* src/fast/tests/Makefile.am:
Use preprocessor to choose the type to test.
* src/fast/reset_msb.hh: Avoid costly substraction.
* src/fast/invert_bits.hh, src/fast/bin_log.hh:
Make it more generic.
* src/fast/bin_pow.hh: Fix overflow.
* src/fast/static_bin_log.hh: New.
* src/fast/Makefile.am: Update.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/fast/Makefile.am
trunk/src/fast/bin_log.hh
trunk/src/fast/bin_pow.hh
trunk/src/fast/invert_bits.hh
trunk/src/fast/reset_msb.hh
trunk/src/fast/tests/Makefile.am
trunk/src/fast/tests/test_bin_log.cc
trunk/src/fast/tests/test_invert_bits.cc
Added Paths:
-----------
trunk/src/fast/static_bin_log.hh
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2010-10-21 17:31:09 UTC (rev 139)
+++ trunk/ChangeLog 2010-10-21 18:46:00 UTC (rev 140)
@@ -1,5 +1,22 @@
2010-10-21 Valentin David <val...@ii...>
+ * src/fast/tests/test_invert_bits.cc,
+ * src/fast/tests/test_bin_log.cc,
+ * src/fast/tests/Makefile.am:
+ Use preprocessor to choose the type to test.
+
+ * src/fast/reset_msb.hh: Avoid costly substraction.
+
+ * src/fast/invert_bits.hh, src/fast/bin_log.hh:
+ Make it more generic.
+
+ * src/fast/bin_pow.hh: Fix overflow.
+
+ * src/fast/static_bin_log.hh: New.
+ * src/fast/Makefile.am: Update.
+
+2010-10-21 Valentin David <val...@ii...>
+
Make maximally shared terms fully lock-free.
* src/lockfree/vector.hh:
Modified: trunk/src/fast/Makefile.am
===================================================================
--- trunk/src/fast/Makefile.am 2010-10-21 17:31:09 UTC (rev 139)
+++ trunk/src/fast/Makefile.am 2010-10-21 18:46:00 UTC (rev 140)
@@ -22,4 +22,5 @@
bin_pow.hh \
invert_bits.hh \
bin_log.hh \
+ static_bin_log.hh \
reset_msb.hh
Modified: trunk/src/fast/bin_log.hh
===================================================================
--- trunk/src/fast/bin_log.hh 2010-10-21 17:31:09 UTC (rev 139)
+++ trunk/src/fast/bin_log.hh 2010-10-21 18:46:00 UTC (rev 140)
@@ -18,6 +18,7 @@
# define __BIN_LOG_HH
# include "bin_pow.hh"
+# include "static_bin_log.hh"
# include <type_traits>
namespace fast {
@@ -48,8 +49,15 @@
integral_type bin_log(integral_type v) {
static_assert(std::is_integral<integral_type>::value,
"Cannot use non integral types.");
+ static_assert(sizeof(integral_type) ==
+ 1<< static_bin_log<integral_type,
+ sizeof(integral_type)>::value,
+ "Type size is not a power of two.");
+
integral_type r = 0;
- bin_log_helper<integral_type, sizeof(integral_type)+1>::step(v, r);
+ bin_log_helper<integral_type,
+ static_bin_log<integral_type,
+ sizeof(integral_type)<<3>::value>::step(v, r);
return r;
}
Modified: trunk/src/fast/bin_pow.hh
===================================================================
--- trunk/src/fast/bin_pow.hh 2010-10-21 17:31:09 UTC (rev 139)
+++ trunk/src/fast/bin_pow.hh 2010-10-21 18:46:00 UTC (rev 140)
@@ -18,25 +18,33 @@
#ifndef __BIN_POW_HH
# define __BIN_POW_HH
+# include <type_traits>
+
namespace fast {
- template <typename integral_type, int N>
- struct bin_pow {
- enum: integral_type {
- value = bin_pow<integral_type, N-1>::value*2
- };
- };
+ template <typename integral_type, typename N>
+ struct bin_pow_wrapped: public
+ std::integral_constant<integral_type,
+ bin_pow_wrapped<integral_type,
+ std::integral_constant<integral_type,
+ N::value-1>
+ >::value*2> {};
+
template <typename integral_type>
- struct bin_pow<integral_type, 0> {
- enum: integral_type {
- value = 1
- };
- };
+ struct bin_pow_wrapped<integral_type,
+ std::integral_constant<integral_type, 0> >
+ : public std::integral_constant<integral_type, 1> {};
template <typename integral_type, integral_type N>
+ struct bin_pow:
+ public bin_pow_wrapped<integral_type,
+ std::integral_constant<integral_type, N> > {};
+
+ template <typename integral_type, integral_type N>
struct bin_pow_pow {
enum: integral_type {
- value = bin_pow<integral_type, bin_pow<integral_type, N-1>::value>::value
+ value = bin_pow<integral_type, bin_pow<integral_type, N-1>::value>
+ ::value
};
};
}
Modified: trunk/src/fast/invert_bits.hh
===================================================================
--- trunk/src/fast/invert_bits.hh 2010-10-21 17:31:09 UTC (rev 139)
+++ trunk/src/fast/invert_bits.hh 2010-10-21 18:46:00 UTC (rev 140)
@@ -18,6 +18,7 @@
# define __INVERT_BITS_HH
# include "bin_pow.hh"
+# include "static_bin_log.hh"
# include <type_traits>
namespace fast {
@@ -39,7 +40,7 @@
template <typename integral_type, int width, integral_type pattern>
struct repeat_pattern:
- public repeat_pattern_recurse<integral_type, 8*sizeof(integral_type),
+ public repeat_pattern_recurse<integral_type, sizeof(integral_type)<<3,
width, pattern>
{};
@@ -69,7 +70,14 @@
inline void invert_bits(integral_type& v) {
static_assert(std::is_integral<integral_type>::value,
"Cannot invert bits on non integral types.");
- inversion_helper<integral_type, sizeof(integral_type)+1>::step(v);
+ static_assert(sizeof(integral_type) ==
+ 1<< static_bin_log<integral_type,
+ sizeof(integral_type)>::value,
+ "Type size is not a power of two.");
+
+ inversion_helper<integral_type,
+ static_bin_log<integral_type,
+ sizeof(integral_type)<<3>::value>::step(v);
}
}
Modified: trunk/src/fast/reset_msb.hh
===================================================================
--- trunk/src/fast/reset_msb.hh 2010-10-21 17:31:09 UTC (rev 139)
+++ trunk/src/fast/reset_msb.hh 2010-10-21 18:46:00 UTC (rev 140)
@@ -25,8 +25,7 @@
integral_type reset_msb(integral_type v) {
static_assert(std::is_integral<integral_type>::value,
"Cannot use non integral types.");
- integral_type b = bin_log(v);
- return v&((1 << b)-1);
+ return v^(1 << bin_log(v));
}
}
Added: trunk/src/fast/static_bin_log.hh
===================================================================
--- trunk/src/fast/static_bin_log.hh (rev 0)
+++ trunk/src/fast/static_bin_log.hh 2010-10-21 18:46:00 UTC (rev 140)
@@ -0,0 +1,48 @@
+// This file is a part of Aurelia.
+// Copyright (C) 2010 Valentin David
+// Copyright (C) 2010 University of Bergen
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+#ifndef __STATIC_BIN_LOG_HH
+# define __STATIC_BIN_LOG_HH
+
+# include <type_traits>
+
+namespace fast {
+ template <typename integral_type, typename N>
+ struct static_bin_log_wrapped: public
+ std::integral_constant<integral_type,
+ static_bin_log_wrapped<integral_type,
+ std::integral_constant<
+ integral_type,
+ (N::value>>1)> >
+ ::value+1> {};
+
+ template <typename integral_type>
+ struct static_bin_log_wrapped<integral_type,
+ std::integral_constant<integral_type,
+ 1> >:
+ public std::integral_constant<integral_type, 0> {};
+
+ template <typename integral_type, integral_type N>
+ struct static_bin_log: public
+ static_bin_log_wrapped<integral_type,
+ std::integral_constant<
+ integral_type,
+ N> >
+ {};
+}
+
+#endif
Modified: trunk/src/fast/tests/Makefile.am
===================================================================
--- trunk/src/fast/tests/Makefile.am 2010-10-21 17:31:09 UTC (rev 139)
+++ trunk/src/fast/tests/Makefile.am 2010-10-21 18:46:00 UTC (rev 140)
@@ -18,7 +18,10 @@
check_PROGRAMS=test_invert_bits test_bin_log
test_invert_bits_SOURCES=test_invert_bits.cc
+test_invert_bits_CPPFLAGS=-DTYPE='unsigned'
+
test_bin_log_SOURCES=test_bin_log.cc
+test_bin_log_CPPFLAGS=-DTYPE='unsigned'
TESTS=$(check_PROGRAMS)
Modified: trunk/src/fast/tests/test_bin_log.cc
===================================================================
--- trunk/src/fast/tests/test_bin_log.cc 2010-10-21 17:31:09 UTC (rev 139)
+++ trunk/src/fast/tests/test_bin_log.cc 2010-10-21 18:46:00 UTC (rev 140)
@@ -20,10 +20,10 @@
using fast::bin_log;
-unsigned ref_impl(unsigned v) {
- unsigned res = 0;
+TYPE ref_impl(TYPE v) {
+ TYPE res = 0;
- for (unsigned i = 0; i < (sizeof(unsigned)*8); ++i) {
+ for (TYPE i = 0; i < (sizeof(TYPE)*8); ++i) {
if (v & 1)
res = i;
v >>= 1;
@@ -44,7 +44,7 @@
int main()
{
- unsigned v;
+ TYPE v;
test(0);
test(1);
Modified: trunk/src/fast/tests/test_invert_bits.cc
===================================================================
--- trunk/src/fast/tests/test_invert_bits.cc 2010-10-21 17:31:09 UTC (rev 139)
+++ trunk/src/fast/tests/test_invert_bits.cc 2010-10-21 18:46:00 UTC (rev 140)
@@ -20,10 +20,10 @@
using fast::invert_bits;
-unsigned ref_impl(unsigned v) {
- unsigned res = 0;
+TYPE ref_impl(TYPE v) {
+ TYPE res = 0;
- for (unsigned i = 0; i < (sizeof(unsigned)*8); ++i) {
+ for (TYPE i = 0; i < (sizeof(TYPE)*8); ++i) {
res <<= 1;
res |= v & 0x1;
v >>= 1;
@@ -44,7 +44,7 @@
int main()
{
- unsigned v;
+ TYPE v;
test(0x12345678);
test(0x00011111);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|