source: trunk/lib/bitblock.hpp @ 1627

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

Template specialied over Macros.

File size: 2.1 KB
Line 
1/*
2    IDISA Library Import - Generic
3    Copyright (C) 2011, Robert D. Cameron, Kenneth S. Herdy
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#ifndef BITBLOCK_HPP
9#define BITBLOCK_HPP
10
11#include <stdint.h>
12#include <stdio.h>
13#include "config.hpp"
14#include "builtins.hpp"
15#include "idisa.hpp"
16
17#ifndef BLOCK_SIZE
18#define BLOCK_SIZE 128
19#endif
20
21template<class T> void print_register(const char * var_name, T v);
22
23/*  Default BLOCK_SIZE is 128, compatible with SSE, Altivec, SPU */
24#if (BLOCK_SIZE == 128)
25#include "bitblock128.hpp"
26#endif
27
28/*  BLOCK_SIZE 256 for AVX */
29#if (BLOCK_SIZE == 256)
30#include "bitblock256.hpp"
31#endif
32
33// Template specialization is slightly slower, but is required to differentiate on integer types unsigned long and unsigned long long.
34template<class block_t> IDISA_ALWAYS_INLINE uint32_t count_forward_zeroes(block_t s);
35template<class block_t> IDISA_ALWAYS_INLINE uint32_t count_reverse_zeroes(block_t s);
36template<> IDISA_ALWAYS_INLINE uint32_t count_forward_zeroes<unsigned long>(unsigned long s) {return cfzl(s);}
37template<> IDISA_ALWAYS_INLINE uint32_t count_forward_zeroes<unsigned long long>(unsigned long long s) {return cfzll(s);}
38template<> IDISA_ALWAYS_INLINE uint32_t count_reverse_zeroes<unsigned long>(unsigned long s) {return cbzl(s);}
39template<> IDISA_ALWAYS_INLINE uint32_t count_reverse_zeroes<unsigned long long>(unsigned long long s) {return cbzll(s);}
40
41/*
42static IDISA_ALWAYS_INLINE uint32_t count_forward_zeroes(unsigned long v) { return cfzl(v);}
43static IDISA_ALWAYS_INLINE uint32_t count_forward_zeroes(unsigned long long v) { return cfzll(v);}
44static IDISA_ALWAYS_INLINE uint32_t count_reverse_zeroes(unsigned long s) {return cbzl(s);}
45static IDISA_ALWAYS_INLINE uint32_t count_reverse_zeroes(unsigned long long s) {return cbzll(s);}
46*/
47
48template <class T>
49void print_register(const char * var_name, T v) {
50        unsigned char c;
51        printf("%20s = ", var_name);
52        for(int i=sizeof(T)-1; i>=0; i--) {
53                c = *(((unsigned char *)&v)+i);
54                printf("%02X ", c);
55        }
56        printf("\n");
57}
58
59#endif /* BITBLOCK_HPP */
60
61
Note: See TracBrowser for help on using the repository browser.