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