xref: /isa-l_crypto/rolling_hash/rolling_hashx_base.c (revision 81c7feeeb9cf25d8080286d86bc1e13ecc129c7a)
153dc9fa0SGreg Tucker /**********************************************************************
253dc9fa0SGreg Tucker   Copyright(c) 2011-2017 Intel Corporation All rights reserved.
353dc9fa0SGreg Tucker 
453dc9fa0SGreg Tucker   Redistribution and use in source and binary forms, with or without
553dc9fa0SGreg Tucker   modification, are permitted provided that the following conditions
653dc9fa0SGreg Tucker   are met:
753dc9fa0SGreg Tucker     * Redistributions of source code must retain the above copyright
853dc9fa0SGreg Tucker       notice, this list of conditions and the following disclaimer.
953dc9fa0SGreg Tucker     * Redistributions in binary form must reproduce the above copyright
1053dc9fa0SGreg Tucker       notice, this list of conditions and the following disclaimer in
1153dc9fa0SGreg Tucker       the documentation and/or other materials provided with the
1253dc9fa0SGreg Tucker       distribution.
1353dc9fa0SGreg Tucker     * Neither the name of Intel Corporation nor the names of its
1453dc9fa0SGreg Tucker       contributors may be used to endorse or promote products derived
1553dc9fa0SGreg Tucker       from this software without specific prior written permission.
1653dc9fa0SGreg Tucker 
1753dc9fa0SGreg Tucker   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1853dc9fa0SGreg Tucker   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1953dc9fa0SGreg Tucker   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2053dc9fa0SGreg Tucker   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2153dc9fa0SGreg Tucker   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2253dc9fa0SGreg Tucker   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2353dc9fa0SGreg Tucker   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2453dc9fa0SGreg Tucker   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2553dc9fa0SGreg Tucker   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2653dc9fa0SGreg Tucker   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2753dc9fa0SGreg Tucker   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2853dc9fa0SGreg Tucker **********************************************************************/
2953dc9fa0SGreg Tucker 
3053dc9fa0SGreg Tucker #include <stdint.h>
3153dc9fa0SGreg Tucker #ifdef _MSC_VER
3253dc9fa0SGreg Tucker #define inline __inline
3353dc9fa0SGreg Tucker #endif
3453dc9fa0SGreg Tucker 
3559ca9063SMarcel Cornu static inline int
floor_pow2(uint32_t in)3659ca9063SMarcel Cornu floor_pow2(uint32_t in)
3753dc9fa0SGreg Tucker {
3853dc9fa0SGreg Tucker         uint32_t x = in;
3953dc9fa0SGreg Tucker 
4053dc9fa0SGreg Tucker         while (in) {
4153dc9fa0SGreg Tucker                 x = in;
4253dc9fa0SGreg Tucker                 in &= (in - 1);
4353dc9fa0SGreg Tucker         }
4453dc9fa0SGreg Tucker         return x;
4553dc9fa0SGreg Tucker }
4653dc9fa0SGreg Tucker 
4759ca9063SMarcel Cornu static inline uint32_t
rol(uint32_t x,int i)4859ca9063SMarcel Cornu rol(uint32_t x, int i)
4953dc9fa0SGreg Tucker {
5053dc9fa0SGreg Tucker         return x << i | x >> (8 * sizeof(x) - i);
5153dc9fa0SGreg Tucker }
5253dc9fa0SGreg Tucker 
5359ca9063SMarcel Cornu uint32_t
_rolling_hashx_mask_gen(long mean,int shift)54*81c7feeeSMarcel Cornu _rolling_hashx_mask_gen(long mean, int shift)
5553dc9fa0SGreg Tucker {
5653dc9fa0SGreg Tucker         if (mean <= 2)
5753dc9fa0SGreg Tucker                 mean = 2;
5853dc9fa0SGreg Tucker 
5953dc9fa0SGreg Tucker         return rol(floor_pow2(mean) - 1, shift);
6053dc9fa0SGreg Tucker }
6153dc9fa0SGreg Tucker 
6253dc9fa0SGreg Tucker struct slver {
6353dc9fa0SGreg Tucker         uint16_t snum;
6453dc9fa0SGreg Tucker         uint8_t ver;
6553dc9fa0SGreg Tucker         uint8_t core;
6653dc9fa0SGreg Tucker };
67*81c7feeeSMarcel Cornu struct slver _rolling_hashx_mask_gen_slver_00000260;
68*81c7feeeSMarcel Cornu struct slver _rolling_hashx_mask_gen_slver = { 0x0260, 0x00, 0x00 };
69