source:trunk/lib/byte_compare.hpp@1827

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

Update byte compare routine. Added generatated test cases.

File size: 2.1 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.
7    Licensed to International Characters Inc.
9*/
10
11#ifndef BYTE_COMPARE_HPP
12#define BYTE_COMPARE_HPP
13
14#include <string.h>
15#include <stdint.h>
16#include "bitblock.hpp"
17
18#include <iostream>
19using namespace std;
20
21template<class T>
22IDISA_ALWAYS_INLINE bool compare(const T * x, const T * y, const uint32_t offset);
23
24// if L is 1, choose T = uint8_t
25// if L in [2,3], choose T = uint16_t
26// if L in [4,7], choose T = uint32_t
27// if L in [8,15], choose = uint64_t
28// if L in [16,00), T = SIMD_type
29
30template<class T, uint32_t L>
31IDISA_ALWAYS_INLINE bool overlap_compare(const T * x, const T * y) {
32    bool accum = true;
33//cout << "accum: " << accum << endl;
34
35    uint8_t * p_x = (uint8_t *)x;
36    uint8_t * p_y = (uint8_t *)y;
37
38    for(int i=0; i < L/sizeof(T); i++) {
39
40//cout << "x " << *( (T*)(p_x) ) << endl;
41//cout << "y " << *( (T*)(p_y) ) << endl;
42//      cout << compare(p_x,p_y,0) << endl;
43        accum = accum && compare(p_x,p_y,0);
44        p_x += sizeof(T);
45        p_y += sizeof(T);
46//cout << (void *)p_x << endl;
47//cout << (void *)p_y << endl;
48//cout << "accum: " << accum << endl;
49    }
50    if(L & (sizeof(T)-1)) {
51//      cout << L - sizeof(T) << endl;
52        accum = accum && compare(x,y,L-sizeof(T));
53
54//cout << "x " << *( (T*)( (uint8_t *)x + L-sizeof(T)) ) << endl;
55//cout << "y " << *( (T*)( (uint8_t *)y + L-sizeof(T)) ) << endl;
56
57//cout << "accum: " << accum << endl;
58  }
59    return accum;
60}
61
62template<class T>
63IDISA_ALWAYS_INLINE bool compare(const T * x, const T * y, const uint32_t offset) {
64
65    return !((*((T*)((uint8_t *)x + offset))) ^
66             (*((T*)((uint8_t *)y + offset))));
67}
68
69template<>
70IDISA_ALWAYS_INLINE bool compare<BitBlock>(const BitBlock * x, const BitBlock * y, const uint32_t offset) {
71    BitBlock temp = simd_xor(*((BitBlock*) ((uint8_t *)x + offset)),
72                             *((BitBlock*) ((uint8_t *)y + offset)));
73    return bitblock::all(simd_not(temp));
74}
75
76#endif // BYTE_COMPARE_HPP
77
78
Note: See TracBrowser for help on using the repository browser.