source: trunk/lib/bitblock.hpp @ 1527

Last change on this file since 1527 was 1527, checked in by ksherdy, 8 years ago

Refactored functions to use function templates.

File size: 2.2 KB
Line 
1/*
2    IDISA Library Import - Generic
3    Copyright (C) 2011, Robert D. Cameron
4    Licensed to the public under the Open Software License 3.0.
5    Licensed to International Characters Inc.
6       under the Academic Free License version 3.0.
7*/
8
9#ifndef BITBLOCK_HPP
10#define BITBLOCK_HPP
11
12/*  Default BLOCKSIZE is 128, compatible with SSE, Altivec, SPU */
13#ifndef BLOCKSIZE                       // TODO - Remove BLOCKSIZE switcher
14#define BLOCKSIZE 128
15#endif
16
17#if (BLOCKSIZE == 128)
18#include "bitblock128.hpp"
19#endif
20
21/*  BLOCKSIZE 256 for AVX */
22#if (BLOCKSIZE == 256)
23#include "bitblock256.hpp"
24#endif
25
26#include "config.hpp"
27#include "builtins.hpp"
28#include <stdio.h>
29
30/* Wrapper Declarations */
31#define sisd_sll(blk, n) simd<128>::sll(blk, n)         // TODO - Deprecate 'sisd_f(x,y)'. bitblock_f(x,y) Migrate to simd<sizeof(BitBlock)*8>::f(x,y) or simd<bitblock128_t, 128>::f(x,y)
32#define sisd_srl(blk, n) simd<128>::srl(blk, n)
33#define sisd_slli(blk, n) simd<128>::slli<n>(blk)
34#define sisd_srli(blk, n) simd<128>::srli<n>(blk)
35#define sisd_sfl(blk, n) sisd_sll(blk, n)                       // TODO - Remove forward (f) and backward (b) do not make sense in a little endian based library, just left and right in a register representation
36#define sisd_sbl(blk, n) sisd_srl(blk, n)
37#define sisd_sfli(blk, n) sisd_slli(blk, n)
38#define sisd_sbli(blk, n) sisd_srli(blk, n)
39#define sb_op(x, n) ((x)>>(n))
40#define sf_op(x, n) ((x)<<(n))
41
42/* Utility */
43template<class T> IDISA_INLINE bool bitblock_has_bit(T arg1);
44template<class T> IDISA_INLINE uint64_t bitblock_bit_count(T arg1) IDISA_ALWAYS_INLINE;
45
46/* Debug */
47template<class T> void print_register(const char * var_name, T v);      // print integer types as array of unsigned char
48
49/* Utility */
50template<class T>
51IDISA_INLINE bool bitblock_has_bit(T arg1)
52{
53        return bitblock::any(arg1);
54}
55
56template<class T>
57IDISA_INLINE uint64_t bitblock_bit_count(T arg1)
58{
59        return mvmd<64>::extract<0>(simd<sizeof(T) * 8>::popcount(arg1));
60}
61
62/* Debug */
63template <class T>
64void print_register(const char * var_name, T v) {
65        unsigned char c;
66        printf("%20s = ", var_name);
67        for(int i=sizeof(T)-1; i>=0; i--) {
68                c = *(((unsigned char *)&v)+i);
69                printf("%02X ", c);
70        }
71        printf("\n");
72}
73
74#endif /* BITBLOCK_HPP */
75
76
Note: See TracBrowser for help on using the repository browser.