source: trunk/lib/byte_compare.hpp @ 1834

Last change on this file since 1834 was 1834, checked in by ksherdy, 7 years ago

Removed unnecessary type cast.

File size: 1.8 KB
Line 
1/*
2    byte_compare - Byte comparison methods.
3
4    Idealized SIMD Operations with SSE versions
5    Copyright (C) 2011, Robert D. Cameron, Kenneth S. Herdy.
6    Licensed to the public under the Open Software License 3.0.
7    Licensed to International Characters Inc.
8       under the Academic Free License version 3.0.
9
10
11   WARNING:
12       
13   for L is 1, choose T = uint8_t
14   for L in [2,3], choose T = uint16_t
15   for L in [4,7], choose T = uint32_t
16   for L in [8,15], choose = uint64_t
17   for L in [16,00), T = BitBlock
18
19   Otherwise results are not valid due to pointer casts.
20
21*/
22
23#ifndef BYTE_COMPARE_HPP
24#define BYTE_COMPARE_HPP
25
26#include <string.h>
27#include <stdint.h>
28#include "bitblock.hpp"
29
30#include <iostream>
31using namespace std;
32
33template<class T>
34IDISA_ALWAYS_INLINE bool compare(const T * x, const T * y, const uint32_t offset);
35
36template<class T, uint32_t L>
37IDISA_ALWAYS_INLINE bool overlap_compare(const T * x, const T * y) {
38
39    cout << sizeof(T) << endl;
40
41    bool accum = true;
42    T * p_x = x;
43    T * p_y = y;
44
45    for(int i=0; i < L/sizeof(T); i++) {
46        accum = accum && compare(p_x,p_y,0);
47        p_x++;
48        p_y++;
49    }
50    if(L & (sizeof(T)-1)) {
51        accum = accum && compare(x,y,L-sizeof(T));
52    }
53    return accum;
54}
55
56template<class T>
57IDISA_ALWAYS_INLINE bool compare(const T * x, const T * y, const uint32_t offset) {
58    cout << sizeof(T) << endl;
59    return !((*((T*)((uint8_t *)x + offset))) ^
60             (*((T*)((uint8_t *)y + offset))));
61}
62
63template<>
64IDISA_ALWAYS_INLINE bool compare<BitBlock>(const BitBlock * x, const BitBlock * y, const uint32_t offset) {
65    BitBlock temp = simd_xor(bitblock::load_unaligned((BitBlock*) ((uint8_t *)x + offset)),
66                             bitblock::load_unaligned((BitBlock*) ((uint8_t *)y + offset)));
67    return bitblock::all(simd_not(temp));
68}
69
70#endif // BYTE_COMPARE_HPP
71
72
Note: See TracBrowser for help on using the repository browser.