ashrdi3.c 681 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /*
  2. * Copyright 2004-2009 Analog Devices Inc.
  3. *
  4. * Licensed under the GPL-2 or later.
  5. */
  6. #include "gcclib.h"
  7. #ifdef CONFIG_ARITHMETIC_OPS_L1
  8. DItype __ashrdi3(DItype u, word_type b)__attribute__((l1_text));
  9. #endif
  10. DItype __ashrdi3(DItype u, word_type b)
  11. {
  12. DIunion w;
  13. word_type bm;
  14. DIunion uu;
  15. if (b == 0)
  16. return u;
  17. uu.ll = u;
  18. bm = (sizeof(SItype) * BITS_PER_UNIT) - b;
  19. if (bm <= 0) {
  20. /* w.s.high = 1..1 or 0..0 */
  21. w.s.high = uu.s.high >> (sizeof(SItype) * BITS_PER_UNIT - 1);
  22. w.s.low = uu.s.high >> -bm;
  23. } else {
  24. USItype carries = (USItype) uu.s.high << bm;
  25. w.s.high = uu.s.high >> b;
  26. w.s.low = ((USItype) uu.s.low >> b) | carries;
  27. }
  28. return w.ll;
  29. }