| 1 |
|
| 2 | #ifndef _ASM_HASH_H
|
| 3 | #define _ASM_HASH_H
|
| 4 |
|
| 5 | |
| 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.
|
| 9 | *
|
| 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.
|
| 14 | *
|
| 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
|
| 18 | * c = (x << 19) + x;
|
| 19 | * a = (x << 9) + c;
|
| 20 | * b = (x << 23) + a;
|
| 21 | * return (a<<11) + (b<<6) + (c<<3) - b;
|
| 22 | * with variations on the order of the final add.
|
| 23 | *
|
| 24 | * Without even a shifter, it's hopless; any hash function will suck.
|
| 25 |
|
| 26 |
|
| 27 | #if CONFIG_XILINX_MICROBLAZE0_USE_HW_MUL == 0
|
| 28 |
|
| 29 | #define HAVE_ARCH__HASH_32 1
|
| 30 |
|
| 31 |
|
| 32 | static inline u32 __attribute_const__ __hash_32(u32 a)
|
| 33 | {
|
| 34 | #if CONFIG_XILINX_MICROBLAZE0_USE_BARREL
|
| 35 | unsigned int b, c;
|
| 36 |
|
| 37 |
|
| 38 | b = a << 23;
|
| 39 | c = (a << 19) + a;
|
| 40 | a = (a << 9) + c;
|
| 41 | b += a;
|
| 42 |
|
| 43 |
|
| 44 | a <<= 5;
|
| 45 | a += b;
|
| 46 | a <<= 3;
|
| 47 | a += c;
|
| 48 | a <<= 3;
|
| 49 | return a - b;
|
| 50 | #else
|
| 51 | |
| 52 | * "This is really going to hurt."
|
| 53 | *
|
| 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.
|
| 58 | *
|
| 59 | * Question: given its size (37*4 = 148 bytes per instance),
|
| 60 | * and slowness, is this worth having inline?
|
| 61 |
|
| 62 | unsigned int b, c, d;
|
| 63 |
|
| 64 | b = a << 4;
|
| 65 | c = b << 1;
|
| 66 | b += a;
|
| 67 | c += b;
|
| 68 | c <<= 3;
|
| 69 | c -= a;
|
| 70 | d = c << 7;
|
| 71 | d += b;
|
| 72 | d <<= 8;
|
| 73 | d += a;
|
| 74 | d <<= 1;
|
| 75 | d += b;
|
| 76 | d <<= 6;
|
| 77 | return d + c;
|
| 78 | #endif
|
| 79 | }
|
| 80 |
|
| 81 | #endif
|
| 82 | #endif
|