1 /* insert_string_sse42.c -- insert_string integer hash variant using SSE4.2's CRC instructions
2  *
3  * Copyright (C) 1995-2013 Jean-loup Gailly and Mark Adler
4  * For conditions of distribution and use, see copyright notice in zlib.h
5  *
6  */
7 
8 #include "../../zbuild.h"
9 #include <immintrin.h>
10 #ifdef _MSC_VER
11 #  include <nmmintrin.h>
12 #endif
13 #include "../../deflate.h"
14 
15 #ifdef X86_SSE42_CRC_INTRIN
16 #  ifdef _MSC_VER
17 #    define HASH_CALC(s, h, val)\
18         h = _mm_crc32_u32(h, val)
19 #  else
20 #    define HASH_CALC(s, h, val)\
21         h = __builtin_ia32_crc32si(h, val)
22 #  endif
23 #else
24 #  ifdef _MSC_VER
25 #    define HASH_CALC(s, h, val) {\
26         __asm mov edx, h\
27         __asm mov eax, val\
28         __asm crc32 eax, edx\
29         __asm mov h, eax\
30     }
31 #  else
32 #    define HASH_CALC(s, h, val) \
33         __asm__ __volatile__ (\
34             "crc32 %1,%0\n\t"\
35             : "+r" (h)\
36             : "r" (val)\
37         );
38 #  endif
39 #endif
40 
41 #define HASH_CALC_VAR       h
42 #define HASH_CALC_VAR_INIT  uint32_t h = 0
43 
44 #define UPDATE_HASH         update_hash_sse4
45 #define INSERT_STRING       insert_string_sse4
46 #define QUICK_INSERT_STRING quick_insert_string_sse4
47 
48 #ifdef X86_SSE42_CRC_HASH
49 #  include "../../insert_string_tpl.h"
50 #endif
51