Article

From:
To:
All
Subject:
MurmurHash3 32bit BASM implementation
Newsgroup:
embarcadero.public.delphi.language.basm

MurmurHash3 32bit BASM implementation

Hi there

Have anyone tried to convert the MurmurHash3 to a optimized BASM version? This could really be a nice BASM challenge.
Code snippet from MurmurHash3.cpp by Austin Appleby:
void MurmurHash3_x86_32 ( const void * key, int len,                           uint32_t seed, void * out ) {   const uint8_t * data = (const uint8_t*)key;   const int nblocks = len / 4;
  uint32_t h1 = seed;
  uint32_t c1 = 0xcc9e2d51;   uint32_t c2 = 0x1b873593;
  //----------   // body
  const uint32_t * blocks = (const uint32_t *)(data + nblocks*4);
  for(int i = -nblocks; i; i++)   {     uint32_t k1 = getblock(blocks,i);
    k1 *= c1;     k1 = ROTL32(k1,15);     k1 *= c2;
    h1 ^= k1;     h1 = ROTL32(h1,13);     h1 = h1*5+0xe6546b64;   }
  //----------   // tail
  const uint8_t * tail = (const uint8_t*)(data + nblocks*4);
  uint32_t k1 = 0;
  switch(len & 3)   {   case 3: k1 ^= tail[2] << 16;   case 2: k1 ^= tail[1] << 8;   case 1: k1 ^= tail[0];           k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1;   };
  //----------   // finalization
  h1 ^= len;
  h1 = fmix(h1);
  *(uint32_t*)out = h1; }
inline uint32_t rotl32 ( uint32_t x, int8_t r ) {   return (x << r) | (x >> (32 - r)); }
FORCE_INLINE uint32_t getblock ( const uint32_t * p, int i ) {   return p[i]; }
-Atle
FYI: Phrase searches are enclosed in either single or double quotes
 
 
Originally created by
Tamarack Associates
Thu, 28 Mar 2024 10:06:49 UTC
Copyright © 2009-2024
HREF Tools Corp.