Changeset 1837


Ignore:
Timestamp:
Jan 7, 2012, 6:13:57 PM (8 years ago)
Author:
ksherdy
Message:

Added general compare case.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/byte_compare.hpp

    r1836 r1837  
    1919   Otherwise results are not valid due to pointer casts.
    2020
     21   TODO - STATIC ASSERT - sizeof(T) <= L
     22
    2123*/
    2224
     
    3133using namespace std;
    3234
    33 template<class T>
    34 IDISA_ALWAYS_INLINE bool compare(const T * x, const T * y, const uint32_t offset);
     35template<class T, uint32_t L> IDISA_ALWAYS_INLINE bool overlap_compare(const T * x, const T * y);
     36template<class T> IDISA_ALWAYS_INLINE bool compare(const T * x, const T * y, const uint32_t offset);
     37IDISA_ALWAYS_INLINE bool mem_compare(const unsigned char * x, const unsigned char * y, uint32_t lgth);
     38
    3539
    3640template<class T, uint32_t L>
     
    5357
    5458template<class T>
     59IDISA_ALWAYS_INLINE bool overlap_compare(const uint8_t * x, const uint8_t * y, uint32_t lgth) {
     60
     61    bool accum = true;
     62    T * p_x = (T*) x;
     63    T * p_y = (T*) y;
     64
     65    for(int i=0; i < lgth/sizeof(T); i++) {
     66        accum = accum && compare(p_x,p_y,0);
     67        p_x++;
     68        p_y++;
     69    }
     70    if(lgth & (sizeof(T)-1)) {
     71        accum = accum && compare(x,y,lgth-sizeof(T));
     72    }
     73    return accum;
     74}
     75
     76template<class T>
    5577IDISA_ALWAYS_INLINE bool compare(const T * x, const T * y, const uint32_t offset) {
    5678    return !((*((T*)((uint8_t *)x + offset))) ^
     
    6587}
    6688
     89IDISA_ALWAYS_INLINE bool mem_compare(const unsigned char * x, const unsigned char * y, uint32_t lgth) {
     90        return (0 == memcmp(x, y, lgth));
     91}
     92
     93
    6794#endif // BYTE_COMPARE_HPP
    6895
Note: See TracChangeset for help on using the changeset viewer.