source: trunk/lib/byte_compare.hpp @ 1829

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

Updated method description.

File size: 1.7 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    bool accum = true;
39    uint8_t * p_x = (uint8_t *)x;
40    uint8_t * p_y = (uint8_t *)y;
41
42    for(int i=0; i < L/sizeof(T); i++) {
43        accum = accum && compare(p_x,p_y,0);
44        p_x += sizeof(T);
45        p_y += sizeof(T);
46    }
47    if(L & (sizeof(T)-1)) {
48        accum = accum && compare(x,y,L-sizeof(T));
49    }
50    return accum;
51}
52
53template<class T>
54IDISA_ALWAYS_INLINE bool compare(const T * x, const T * y, const uint32_t offset) {
55 
56    return !((*((T*)((uint8_t *)x + offset))) ^
57             (*((T*)((uint8_t *)y + offset))));
58}
59
60template<>
61IDISA_ALWAYS_INLINE bool compare<BitBlock>(const BitBlock * x, const BitBlock * y, const uint32_t offset) {
62    BitBlock temp = simd_xor(*((BitBlock*) ((uint8_t *)x + offset)),
63                             *((BitBlock*) ((uint8_t *)y + offset)));
64    return bitblock::all(simd_not(temp));
65}
66
67#endif // BYTE_COMPARE_HPP
68
69
Note: See TracBrowser for help on using the repository browser.