mult.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /*
  2. * This file is part of GNU CC.
  3. *
  4. * GNU CC is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published
  6. * by the Free Software Foundation; either version 2, or (at your
  7. * option) any later version.
  8. *
  9. * GNU CC is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public
  15. * License along with GNU CC; see the file COPYING. If not, write
  16. * to the Free Software Foundation, 59 Temple Place - Suite 330,
  17. * Boston, MA 02111-1307, USA.
  18. */
  19. #include <common.h>
  20. #if !defined(CONFIG_SYS_NIOS_MULT_HW) && !defined(CONFIG_SYS_NIOS_MULT_MSTEP)
  21. #include "math.h"
  22. USItype __mulsi3 (USItype a, USItype b)
  23. {
  24. USItype c = 0;
  25. while (a != 0) {
  26. if (a & 1)
  27. c += b;
  28. a >>= 1;
  29. b <<= 1;
  30. }
  31. return c;
  32. }
  33. UHItype __mulhi3 (UHItype a, UHItype b)
  34. {
  35. UHItype c = 0;
  36. while (a != 0) {
  37. if (a & 1)
  38. c += b;
  39. a >>= 1;
  40. b <<= 1;
  41. }
  42. return c;
  43. }
  44. #endif /*!defined(CONFIG_SYS_NIOS_MULT_HW) && !defined(CONFIG_SYS_NIOS_MULT_MSTEP) */