1 /* SPDX-License-Identifier: GPL-2.0 */
6 * Fortunately, most people who want to run Linux on Microblaze enable
7 * both multiplier and barrel shifter, but omitting them is technically
8 * a supported configuration.
10 * With just a barrel shifter, we can implement an efficient constant
11 * multiply using shifts and adds. GCC can find a 9-step solution, but
12 * this 6-step solution was found by Yevgen Voronenko's implementation
13 * of the Hcub algorithm at http://spiral.ece.cmu.edu/mcm/gen.html.
15 * That software is really not designed for a single multiplier this large,
16 * but if you run it enough times with different seeds, it'll find several
17 * 6-shift, 6-add sequences for computing x * 0x61C88647. They are all
21 * return (a<<11) + (b<<6) + (c<<3) - b;
22 * with variations on the order of the final add.
24 * Without even a shifter, it's hopless; any hash function will suck.
27 #if CONFIG_XILINX_MICROBLAZE0_USE_HW_MUL == 0
29 #define HAVE_ARCH__HASH_32 1
31 /* Multiply by GOLDEN_RATIO_32 = 0x61C88647 */
32 static inline u32 __attribute_const__
__hash_32(u32 a
)
34 #if CONFIG_XILINX_MICROBLAZE0_USE_BARREL
37 /* Phase 1: Compute three intermediate values */
43 /* Phase 2: Compute (a << 11) + (b << 6) + (c << 3) - b */
45 a
+= b
; /* (a << 5) + b */
47 a
+= c
; /* (a << 8) + (b << 3) + c */
49 return a
- b
; /* (a << 11) + (b << 6) + (c << 3) - b */
52 * "This is really going to hurt."
54 * Without a barrel shifter, left shifts are implemented as
55 * repeated additions, and the best we can do is an optimal
56 * addition-subtraction chain. This one is not known to be
57 * optimal, but at 37 steps, it's decent for a 31-bit multiplier.
59 * Question: given its size (37*4 = 148 bytes per instance),
60 * and slowness, is this worth having inline?
70 d
= c
<< 7; /* 7 18 */
77 return d
+ c
; /* 1 37 total instructions*/
81 #endif /* !CONFIG_XILINX_MICROBLAZE0_USE_HW_MUL */
82 #endif /* _ASM_HASH_H */