Branch: Tag:

2014-12-04

2014-12-04 19:25:07 by Tobias S. Josefowitz <tobij@tobij.de>

some portable helpers for unaligned memory access

unlike manually shifted bytes, memset() gets optimized to one
load/store on x86.

158:    return (void *)p;   }    + static INLINE unsigned INT64 get_unaligned64(const void * ptr) { +  unsigned INT64 v; +  memcpy(&v, ptr, 8); +  return v; + } +  + static INLINE void set_unaligned64(void * ptr, unsigned INT64 v) { +  memcpy(ptr, &v, 8); + } +  + static INLINE unsigned INT64 get_unaligned32(const void * ptr) { +  unsigned INT32 v; +  memcpy(&v, ptr, 4); +  return v; + } +  + static INLINE void set_unaligned32(void * ptr, unsigned INT32 v) { +  memcpy(ptr, &v, 4); + } +  + static INLINE unsigned INT16 get_unaligned16(const void * ptr) { +  unsigned INT16 v; +  memcpy(&v, ptr, 2); +  return v; + } +  + static INLINE void set_unaligned16(void * ptr, unsigned INT16 v) { +  memcpy(ptr, &v, 2); + } +    #include "pike_search.h"      #include "block_alloc_h.h"