Changeset 2538 in CLRX


Ignore:
Timestamp:
Nov 6, 2016, 5:01:57 PM (4 years ago)
Author:
matszpk
Message:

CLRadeonExtender: ElfBinaries?. Add routine to create hash table. small fixes in hash routines.

Location:
CLRadeonExtender/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • CLRadeonExtender/trunk/CLRX/amdbin/ElfBinaries.h

    r2537 r2538  
    611611   
    612612    /// get hash section
    613     static ElfRegionTemplate hashSection()
     613    static ElfRegionTemplate hashSection(uint16_t link)
    614614    { return ElfRegionTemplate(0, (const cxbyte*)nullptr, sizeof(typename Types::Word),
    615                 ".hash", SHT_HASH, SHF_ALLOC); }
     615                ".hash", SHT_HASH, SHF_ALLOC, link); }
    616616};
    617617
  • CLRadeonExtender/trunk/amdbin/ElfBinaries.cpp

    r2537 r2538  
    538538    uint32_t bestBucketNum = 0;
    539539    uint64_t bestValue = UINT64_MAX;
    540     uint64_t maxSteps = (uint64_t(hashNum)<<1) - (hashNum>>2) + 1;
     540    uint32_t firstStep = std::max(uint32_t(hashNum>>2), 1U);
     541    uint64_t maxSteps = (uint64_t(hashNum)<<1) - (firstStep) + 1;
    541542    const uint32_t steps = (maxSteps<=1000U) ? hashNum : hashNum<<((32-CLZ32(hashNum))>>1);
    542543   
    543     std::unique_ptr<uint32_t[]> chainLengths(new uint32_t[maxSteps]);
     544    std::unique_ptr<uint32_t[]> chainLengths(new uint32_t[(hashNum<<2)+1]);
    544545    const uint32_t stepSize = maxSteps / steps;
    545     for (uint32_t buckets = hashNum>>2; buckets < (hashNum<<1); buckets += stepSize)
     546    for (uint32_t buckets = firstStep; buckets <= (hashNum<<1); buckets += stepSize)
    546547    {   //
    547548        std::fill(chainLengths.get(), chainLengths.get() + buckets, 0U);
     
    550551            chainLengths[hashCodes[i] % buckets]++;
    551552        /// value, smaller is better
    552         uint64_t value = uint64_t(buckets)*4;
     553        uint64_t value = uint64_t(buckets);
    553554        for (uint32_t i = 0; i < buckets; i++)
    554555            value += chainLengths[i]*chainLengths[i];
     
    560561    }
    561562    return bestBucketNum;
     563}
     564
     565static void createHashTable(uint32_t bucketsNum, uint32_t hashNum,
     566                           const uint32_t* hashCodes, uint32_t* output)
     567{
     568    SULEV(output[0], bucketsNum);
     569    SULEV(output[1], hashNum);
     570    uint32_t* buckets = output + 2;
     571    uint32_t* chains = output + bucketsNum + 2;
     572    std::fill(buckets, buckets + bucketsNum, 0U);
     573    std::fill(chains, chains + hashNum, STN_UNDEF);
     574   
     575    std::unique_ptr<uint32_t[]> lastNodes(new uint32_t[bucketsNum]);
     576    std::fill(lastNodes.get(), lastNodes.get() + bucketsNum, UINT32_MAX);
     577    for (uint32_t i = 0; i < hashNum; i++)
     578    {
     579        const uint32_t bucket = hashCodes[i] % bucketsNum;
     580        if (lastNodes[bucket] == UINT32_MAX)
     581        {   // first entry of chain
     582            SULEV(buckets[bucket], i);
     583            lastNodes[bucket] = i;
     584        }
     585        else
     586        {
     587            chains[lastNodes[bucket]] = i;
     588            lastNodes[bucket] = i;
     589        }
     590    }
    562591}
    563592
  • CLRadeonExtender/trunk/amdbin/ROCmBinaries.cpp

    r2537 r2538  
    195195    elfBinGen64.addRegion(ElfRegion64::programHeaderTable());
    196196    elfBinGen64.addRegion(ElfRegion64::dynsymSection());
    197     elfBinGen64.addRegion(ElfRegion64::hashSection());
     197    elfBinGen64.addRegion(ElfRegion64::hashSection(1));
    198198    elfBinGen64.addRegion(ElfRegion64::dynstrSection());
    199199    elfBinGen64.addRegion(ElfRegion64(input->codeSize, (const cxbyte*)input->code,
Note: See TracChangeset for help on using the changeset viewer.