xref: /netbsd-src/external/gpl3/gcc.old/dist/libgcc/divmod.c (revision 8feb0f0b7eaff0608f8350bbfa3098827b4bb91b)
1*8feb0f0bSmrg /* Copyright (C) 2000-2020 Free Software Foundation, Inc.
21debfc3dSmrg 
31debfc3dSmrg This file is part of GCC.
41debfc3dSmrg 
51debfc3dSmrg GCC is free software; you can redistribute it and/or modify it under
61debfc3dSmrg the terms of the GNU General Public License as published by the Free
71debfc3dSmrg Software Foundation; either version 3, or (at your option) any later
81debfc3dSmrg version.
91debfc3dSmrg 
101debfc3dSmrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
111debfc3dSmrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
121debfc3dSmrg FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
131debfc3dSmrg for more details.
141debfc3dSmrg 
151debfc3dSmrg Under Section 7 of GPL version 3, you are granted additional
161debfc3dSmrg permissions described in the GCC Runtime Library Exception, version
171debfc3dSmrg 3.1, as published by the Free Software Foundation.
181debfc3dSmrg 
191debfc3dSmrg You should have received a copy of the GNU General Public License and
201debfc3dSmrg a copy of the GCC Runtime Library Exception along with this program;
211debfc3dSmrg see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
221debfc3dSmrg <http://www.gnu.org/licenses/>.  */
231debfc3dSmrg 
24c0a68be4Smrg extern unsigned long __udivmodsi4(unsigned long num, unsigned long den,
25c0a68be4Smrg 								  int modwanted);
261debfc3dSmrg 
271debfc3dSmrg long
__divsi3(long a,long b)281debfc3dSmrg __divsi3 (long a, long b)
291debfc3dSmrg {
301debfc3dSmrg   int neg = 0;
311debfc3dSmrg   long res;
321debfc3dSmrg 
331debfc3dSmrg   if (a < 0)
341debfc3dSmrg     {
351debfc3dSmrg       a = -a;
361debfc3dSmrg       neg = !neg;
371debfc3dSmrg     }
381debfc3dSmrg 
391debfc3dSmrg   if (b < 0)
401debfc3dSmrg     {
411debfc3dSmrg       b = -b;
421debfc3dSmrg       neg = !neg;
431debfc3dSmrg     }
441debfc3dSmrg 
45c0a68be4Smrg   res = __udivmodsi4 (a, b, 0);
461debfc3dSmrg 
471debfc3dSmrg   if (neg)
481debfc3dSmrg     res = -res;
491debfc3dSmrg 
501debfc3dSmrg   return res;
511debfc3dSmrg }
521debfc3dSmrg 
531debfc3dSmrg long
__modsi3(long a,long b)541debfc3dSmrg __modsi3 (long a, long b)
551debfc3dSmrg {
561debfc3dSmrg   int neg = 0;
571debfc3dSmrg   long res;
581debfc3dSmrg 
591debfc3dSmrg   if (a < 0)
601debfc3dSmrg     {
611debfc3dSmrg       a = -a;
621debfc3dSmrg       neg = 1;
631debfc3dSmrg     }
641debfc3dSmrg 
651debfc3dSmrg   if (b < 0)
661debfc3dSmrg     b = -b;
671debfc3dSmrg 
68c0a68be4Smrg   res = __udivmodsi4 (a, b, 1);
691debfc3dSmrg 
701debfc3dSmrg   if (neg)
711debfc3dSmrg     res = -res;
721debfc3dSmrg 
731debfc3dSmrg   return res;
741debfc3dSmrg }
75