#define HAVE_CHUNKMEMSET_8
static inline void chunkmemset_4(uint8_t *from, chunk_t *chunk) {
-#if defined(UNALIGNED64_OK)
- uint32_t half_chunk;
- half_chunk = *(uint32_t *)from;
- *chunk = 0x0000000100000001 * (uint64_t)half_chunk;
-#elif defined(UNALIGNED_OK)
- chunk->u32[0] = *(uint32_t *)from;
- chunk->u32[1] = chunk->u32[0];
-#else
- uint8_t *chunkptr = (uint8_t *)chunk;
- memcpy(chunkptr, from, 4);
- memcpy(chunkptr+4, from, 4);
-#endif
+ uint8_t *dest = (uint8_t *)chunk;
+ memcpy(dest, from, sizeof(uint32_t));
+ memcpy(dest+4, from, sizeof(uint32_t));
}
static inline void chunkmemset_8(uint8_t *from, chunk_t *chunk) {
-#if defined(UNALIGNED64_OK)
- *chunk = *(uint64_t *)from;
-#elif defined(UNALIGNED_OK)
- uint32_t* p = (uint32_t *)from;
- chunk->u32[0] = p[0];
- chunk->u32[1] = p[1];
-#else
- memcpy(chunk, from, sizeof(chunk_t));
-#endif
+ memcpy(chunk, from, sizeof(uint64_t));
}
static inline void loadchunk(uint8_t const *s, chunk_t *chunk) {
- chunkmemset_8((uint8_t *)s, chunk);
+ memcpy(chunk, (uint8_t *)s, sizeof(uint64_t));
}
static inline void storechunk(uint8_t *out, chunk_t *chunk) {
-#if defined(UNALIGNED64_OK)
- *(uint64_t *)out = *chunk;
-#elif defined(UNALIGNED_OK)
- ((uint32_t *)out)[0] = chunk->u32[0];
- ((uint32_t *)out)[1] = chunk->u32[1];
-#else
- memcpy(out, chunk, sizeof(chunk_t));
-#endif
+ memcpy(out, chunk, sizeof(uint64_t));
}
#define CHUNKSIZE chunksize_c
* IN assertion: there is enough room in pending_buf.
*/
static inline void put_short(deflate_state *s, uint16_t w) {
-#if defined(UNALIGNED_OK)
- *(uint16_t *)(&s->pending_buf[s->pending]) = w;
- s->pending += 2;
-#else
- put_byte(s, (w & 0xff));
- put_byte(s, ((w >> 8) & 0xff));
+#if BYTE_ORDER == BIG_ENDIAN
+ w = ZSWAP16(w);
#endif
+ memcpy(&s->pending_buf[s->pending], &w, sizeof(w));
+ s->pending += 2;
}
/* ===========================================================================
* IN assertion: there is enough room in pending_buf.
*/
static inline void put_short_msb(deflate_state *s, uint16_t w) {
- put_byte(s, ((w >> 8) & 0xff));
- put_byte(s, (w & 0xff));
+#if BYTE_ORDER == LITTLE_ENDIAN
+ w = ZSWAP16(w);
+#endif
+ memcpy(&s->pending_buf[s->pending], &w, sizeof(w));
+ s->pending += 2;
}
/* ===========================================================================
* IN assertion: there is enough room in pending_buf.
*/
static inline void put_uint32(deflate_state *s, uint32_t dw) {
-#if defined(UNALIGNED_OK)
- *(uint32_t *)(&s->pending_buf[s->pending]) = dw;
- s->pending += 4;
-#else
- put_byte(s, (dw & 0xff));
- put_byte(s, ((dw >> 8) & 0xff));
- put_byte(s, ((dw >> 16) & 0xff));
- put_byte(s, ((dw >> 24) & 0xff));
+#if BYTE_ORDER == BIG_ENDIAN
+ dw = ZSWAP32(dw);
#endif
+ memcpy(&s->pending_buf[s->pending], &dw, sizeof(dw));
+ s->pending += 4;
}
/* ===========================================================================
* IN assertion: there is enough room in pending_buf.
*/
static inline void put_uint32_msb(deflate_state *s, uint32_t dw) {
-#if defined(UNALIGNED_OK)
- *(uint32_t *)(&s->pending_buf[s->pending]) = ZSWAP32(dw);
- s->pending += 4;
-#else
- put_byte(s, ((dw >> 24) & 0xff));
- put_byte(s, ((dw >> 16) & 0xff));
- put_byte(s, ((dw >> 8) & 0xff));
- put_byte(s, (dw & 0xff));
+#if BYTE_ORDER == LITTLE_ENDIAN
+ dw = ZSWAP32(dw);
#endif
+ memcpy(&s->pending_buf[s->pending], &dw, sizeof(dw));
+ s->pending += 4;
}
/* ===========================================================================
* IN assertion: there is enough room in pending_buf.
*/
static inline void put_uint64(deflate_state *s, uint64_t lld) {
-#if defined(UNALIGNED64_OK)
- *(uint64_t *)(&s->pending_buf[s->pending]) = lld;
- s->pending += 8;
-#elif defined(UNALIGNED_OK)
- *(uint32_t *)(&s->pending_buf[s->pending]) = lld & 0xffffffff;
- s->pending += 4;
- *(uint32_t *)(&s->pending_buf[s->pending]) = (lld >> 32) & 0xffffffff;
- s->pending += 4;
-#else
- put_byte(s, (lld & 0xff));
- put_byte(s, ((lld >> 8) & 0xff));
- put_byte(s, ((lld >> 16) & 0xff));
- put_byte(s, ((lld >> 24) & 0xff));
- put_byte(s, ((lld >> 32) & 0xff));
- put_byte(s, ((lld >> 40) & 0xff));
- put_byte(s, ((lld >> 48) & 0xff));
- put_byte(s, ((lld >> 56) & 0xff));
+#if BYTE_ORDER == BIG_ENDIAN
+ lld = ZSWAP64(lld);
#endif
+ memcpy(&s->pending_buf[s->pending], &lld, sizeof(lld));
+ s->pending += 8;
}
#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)