Guest User

Untitled

a guest
Jun 24th, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. /* calculate the 32-bit product of unsigned 16-bit op16 and 32-bit op32 */
  2. static inline uint32_t mul_u16_u32(uint32_t op16, uint32_t op32)
  3. {
  4. unsigned t1, r;
  5. asm (
  6. "swap.w %[b], %[t1]\n\t"
  7. "mulu %[a], %[t1]\n\t"
  8. "sts macl, %[t1]\n\t"
  9. "mulu %[a], %[b]\n\t"
  10. "sts macl, %[r]\n\t"
  11. "shll16 %[t1]\n\t"
  12. "add %[t1], %[r]\n\t"
  13. : [r] "=r" (r),
  14. [t1] "=&r" (t1)
  15. : [a] "r" (op16),
  16. [b] "r" (op32)
  17. );
  18. return r;
  19. }
  20.  
  21. /* calculate the 32-bit product of signed 32-bit op16 and unsigned 32-bit op32,
  22. * where op16 is known to have only 16 significant bits */
  23. static inline uint32_t mul_s16_u32(int32_t op16, int32_t op32)
  24. {
  25. unsigned t1, t2, r;
  26. asm (
  27. "swap.w %[b], %[t1]\n\t"
  28. "mulu %[a], %[b]\n\t"
  29. "sts macl, %[r]\n\t"
  30. "mulu %[a], %[t1]\n\t"
  31. "sts macl, %[t1]\n\t"
  32. "cmp/pz %[a]\n\t"
  33. "bt 1f\n\t"
  34. "extu.w %[b], %[t2]\n\t"
  35. "sub %[t2], %[t1]\n"
  36. "1:\n\t"
  37. "shll16 %[t1]\n\t"
  38. "add %[t1], %[r]\n\t"
  39. : [r] "=&r" (r),
  40. [t1] "=&r" (t1),
  41. [t2] "=r" (t2)
  42. : [a] "r" (op16),
  43. [b] "r" (op32)
  44. );
  45. return r;
  46. }
Add Comment
Please, Sign In to add comment