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> |
---|

31 | using namespace std; |
---|

32 | |
---|

33 | template<class T> |
---|

34 | IDISA_ALWAYS_INLINE bool compare(const T * x, const T * y, const uint32_t offset); |
---|

35 | |
---|

36 | template<class T, uint32_t L> |
---|

37 | IDISA_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 = (T *)x; |
---|

43 | T * p_y = (T *)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 | |
---|

56 | template<class T> |
---|

57 | IDISA_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 | |
---|

63 | template<> |
---|

64 | IDISA_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 | |
---|