Changeset 5952


Ignore:
Timestamp:
Apr 8, 2018, 1:04:06 PM (11 months ago)
Author:
cameron
Message:

Use AlignedAllocator? when boost::align unavailable (Jenkins test server).

Location:
icGREP/icgrep-devel/icgrep/grep
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/grep/grep_engine.cpp

    r5947 r5952  
    4545#include <llvm/Support/raw_ostream.h>
    4646#include <util/file_select.h>
    47 #include <boost/align/aligned_allocator.hpp>
     47#include <util/aligned_allocator.h>
    4848#include <sys/stat.h>
    4949#include <fcntl.h>
     
    8181}
    8282   
     83
    8384inline static size_t ceil_log2(const size_t v) {
    8485    assert ("log2(0) is undefined!" && v != 0);
    85     return (sizeof(size_t) * CHAR_BIT) - __builtin_clzll(v - 1U);
    86 }
    87 
    88 void SearchableBuffer::addSearchCandidate(char * string_ptr, size_t length) {
    89     if (space_used + length >= allocated_capacity) {
    90         size_t new_capacity = size_t{1} << (ceil_log2(space_used + length + 1));
    91         char * new_buffer = (char *) boost::alignment::aligned_alloc(BUFFER_ALIGNMENT, new_capacity);
    92         memcpy(new_buffer, buffer_base, space_used);
    93         memset(&new_buffer[space_used], 0, new_capacity-space_used);
    94         if (buffer_base != initial_buffer) {
    95             free(buffer_base);
    96         }
    97         buffer_base = new_buffer;
    98         allocated_capacity = new_capacity;
    99     }
    100     memcpy((void * ) &buffer_base[space_used], string_ptr, length);
    101     space_used += length;
    102     buffer_base[space_used] = '\0';
    103     space_used++;
    104     entries++;
     86    assert ("sizeof(size_t) == sizeof(ulong)" && sizeof(size_t) == sizeof(ulong));
     87    return (sizeof(size_t) * CHAR_BIT) - __builtin_clzl(v - 1UL);
     88}
     89
     90void SearchableBuffer::addSearchCandidate(char * C_string_ptr, size_t length) {
     91    if (mSpace_used + length >= mAllocated_capacity) {
     92        size_t new_capacity = size_t{1} << (ceil_log2(mSpace_used + length + 1));
     93        AlignedAllocator<char, BUFFER_ALIGNMENT> alloc;
     94        char * new_buffer = alloc.allocate(new_capacity, 0);
     95        memcpy(new_buffer, mBuffer_base, mSpace_used);
     96        memset(&new_buffer[mSpace_used], 0, new_capacity-mSpace_used);
     97        if (mBuffer_base != mInitial_buffer) {
     98            alloc.deallocate(mBuffer_base, 0);
     99        }
     100        mBuffer_base = new_buffer;
     101        mAllocated_capacity = new_capacity;
     102    }
     103    memcpy((void * ) &mBuffer_base[mSpace_used], C_string_ptr, length+1);
     104    mSpace_used += length+1;
     105    assert("Search candidate not null terminated" && (buffer_base[mSpace_used] == '\0'));
     106    mEntries++;
    105107}
    106108
    107109SearchableBuffer::SearchableBuffer() :
    108 allocated_capacity(INITIAL_CAPACITY), buffer_base(initial_buffer) {
    109     memset(buffer_base, 0, INITIAL_CAPACITY);
     110    mAllocated_capacity(INITIAL_CAPACITY), mBuffer_base(mInitial_buffer) {
     111    memset(mBuffer_base, 0, INITIAL_CAPACITY);
    110112}
    111113
    112114SearchableBuffer::~SearchableBuffer() {
    113     if (buffer_base != initial_buffer) {
    114         free(buffer_base);
     115    if (mBuffer_base != mInitial_buffer) {
     116        AlignedAllocator<char, BUFFER_ALIGNMENT> alloc;
     117        alloc.deallocate(mBuffer_base, 0);
    115118    }
    116119}
  • icGREP/icgrep-devel/icgrep/grep/grep_engine.h

    r5945 r5952  
    4242    SearchableBuffer();
    4343    void addSearchCandidate(char * string_ptr, size_t length);
     44    size_t getCandidateCount() {return mEntries;}
    4445    ~SearchableBuffer();
    4546private:
    4647    static const unsigned BUFFER_ALIGNMENT = MAX_SIMD_WIDTH_SUPPORTED/8;
    47     size_t allocated_capacity;
    48     char * buffer_base;
    49     alignas(BUFFER_ALIGNMENT) char initial_buffer[INITIAL_CAPACITY];
    50     size_t space_used;
    51     size_t entries;
     48    size_t mAllocated_capacity;
     49    char * mBuffer_base;
     50    alignas(BUFFER_ALIGNMENT) char mInitial_buffer[INITIAL_CAPACITY];
     51    size_t mSpace_used;
     52    size_t mEntries;
    5253};
    5354
Note: See TracChangeset for help on using the changeset viewer.