source: trunk/lib/byte_compare.hpp @ 1816

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

Added byte_compare.hpp header.

File size: 1.5 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
12#ifndef BYTE_COMPARE_HPP
13#define BYTE_COMPARE_HPP
14
15#include <string.h>
16#include <stdint.h>
17#include "bitblock.hpp"
18
19
20template<class T>
21IDISA_ALWAYS_INLINE bool compare(const T * x, const T * y, const uint32_t offset);
22
23// if L is 1, choose T = uint8_t
24// if L in [2,3], choose T = uint16_t
25// if L in [4,7], choose T = uint32_t
26// if L in [8,15], choose = uint64_t
27// if L in [16,00), T = SIMD_type
28
29template<class T, uint32_t L>
30IDISA_ALWAYS_INLINE bool overlap_compare(const T * x, const T * y) {
31    bool accum = true;
32    for(int i=0; i < L/sizeof(T); i++) {
33        accum &= compare(x,y,0);
34        x++;
35        y++;
36    }
37    if(L & (sizeof(T)-1)) {
38        accum &= compare(x,y,L-sizeof(T));
39    }
40    return accum;
41}
42
43template<class T>
44IDISA_ALWAYS_INLINE bool compare(const T * x, const T * y, const uint32_t offset) {
45    return !((*((T*)((uint8_t *)x + offset))) ^
46             (*((T*)((uint8_t *)y + offset))));
47}
48
49template<>
50IDISA_ALWAYS_INLINE bool compare<BitBlock>(const BitBlock * x, const BitBlock * y, const uint32_t offset) {
51    BitBlock temp = simd_xor(*((BitBlock*) ((uint8_t *)x + offset)),
52                             *((BitBlock*) ((uint8_t *)y + offset)));
53    return bitblock::all(simd_not(temp));
54}
55
56#endif // BYTE_COMPARE_HPP
57
58
Note: See TracBrowser for help on using the repository browser.