hash.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef _ASM_HASH_H
  2. #define _ASM_HASH_H
  3. /*
  4. * The later H8SX models have a 32x32-bit multiply, but the H8/300H
  5. * and H8S have only 16x16->32. Since it's tolerably compact, this is
  6. * basically an inlined version of the __mulsi3 code. Since the inputs
  7. * are not expected to be small, it's also simplfied by skipping the
  8. * early-out checks.
  9. *
  10. * (Since neither CPU has any multi-bit shift instructions, a
  11. * shift-and-add version is a non-starter.)
  12. *
  13. * TODO: come up with an arch-specific version of the hashing in fs/namei.c,
  14. * since that is heavily dependent on rotates. Which, as mentioned, suck
  15. * horribly on H8.
  16. */
  17. #if defined(CONFIG_CPU_H300H) || defined(CONFIG_CPU_H8S)
  18. #define HAVE_ARCH__HASH_32 1
  19. /*
  20. * Multiply by k = 0x61C88647. Fitting this into three registers requires
  21. * one extra instruction, but reducing register pressure will probably
  22. * make that back and then some.
  23. *
  24. * GCC asm note: %e1 is the high half of operand %1, while %f1 is the
  25. * low half. So if %1 is er4, then %e1 is e4 and %f1 is r4.
  26. *
  27. * This has been designed to modify x in place, since that's the most
  28. * common usage, but preserve k, since hash_64() makes two calls in
  29. * quick succession.
  30. */
  31. static inline u32 __attribute_const__ __hash_32(u32 x)
  32. {
  33. u32 temp;
  34. asm( "mov.w %e1,%f0"
  35. "\n mulxu.w %f2,%0" /* klow * xhigh */
  36. "\n mov.w %f0,%e1" /* The extra instruction */
  37. "\n mov.w %f1,%f0"
  38. "\n mulxu.w %e2,%0" /* khigh * xlow */
  39. "\n add.w %e1,%f0"
  40. "\n mulxu.w %f2,%1" /* klow * xlow */
  41. "\n add.w %f0,%e1"
  42. : "=&r" (temp), "=r" (x)
  43. : "%r" (GOLDEN_RATIO_32), "1" (x));
  44. return x;
  45. }
  46. #endif
  47. #endif /* _ASM_HASH_H */