From 3ea9ed0d2a14468d698dfe24bdb790b6f4103596 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Sat, 4 Aug 2018 19:12:43 +0200 Subject: Initial import --- Hilbert/SetLocation.hpp | 96 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100644 Hilbert/SetLocation.hpp (limited to 'Hilbert/SetLocation.hpp') diff --git a/Hilbert/SetLocation.hpp b/Hilbert/SetLocation.hpp new file mode 100644 index 0000000..d7b5099 --- /dev/null +++ b/Hilbert/SetLocation.hpp @@ -0,0 +1,96 @@ +/* + * Copyright (C) 2006-2007 Chris Hamilton + * + * 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 2 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, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _SETLOCATION_HPP_ +#define _SETLOCATION_HPP_ + + +#include +#include + + +namespace Hilbert +{ + template + H_INLINE + void + setLocation( + P *p, + int n, + int i, + const I &l + ) + { + // Easy to understand implementation + /*int j; + for ( j = 0; j < n; j++ ) + p[j].setBit(i,l.getBit(j)); + return;*/ + + // Much faster loop-unrolled implementation. + int ir, ib; + FBV_UINT im; + BBV_MODSPLIT(ir,ib,i); + im = (FBV1<racks()[ir]|=im; if ((*lr&jm)==0) p->racks()[ir]^=im; jm<<=1; ++p; +#define SETBIT1(a) \ + case (a+1): SETBIT; +#define SETBIT2(a) \ + SETBIT1(a+1); \ + SETBIT1(a); +#define SETBIT4(a) \ + SETBIT2(a+2); \ + SETBIT2(a); +#define SETBIT8(a) \ + SETBIT4(a+4); \ + SETBIT4(a); +#define SETBIT16(a) \ + SETBIT8(a+8); \ + SETBIT8(a); +#define SETBIT32(a) \ + SETBIT16(a+16); \ + SETBIT16(a); + + int j = 0; + FBV_UINT jm = 1; + const FBV_UINT *lr = l.racks(); + while ( j < n ) + { + if ( jm == 0 ) + { + jm = 1; + ++lr; + } + + int dj = n - j; + switch ( n - j ) + { + default: dj = 32; + SETBIT32(0); + } + j += dj; + } + + return; + } + +}; + + +#endif -- cgit v1.2.1