This is the mail archive of the
mailing list for the GCC project.
Bug in divmodhi4(), plus poor inperformant code
- From: "Stefan Kanthak" <stefan dot kanthak at nexgo dot de>
- To: <gcc at gcc dot gnu dot org>
- Date: Tue, 4 Dec 2018 23:51:17 +0100
- Subject: Bug in divmodhi4(), plus poor inperformant code
libgcc's divmodhi4() function has an obvious bug; additionally
it shows rather poor inperformant code: two of the three conditions
tested in the first loop should clearly moved outside the loop!
divmodsi4() shows this inperformant code too!
--- divmodhi4.c ---
__udivmodhi4(unsigned short num, unsigned short den, int modwanted)
unsigned short bit = 1;
unsigned short res = 0;
if (den > num)
return modwanted ? num : 0;
if (den == num)
return modwanted ? 0 : 1;
while ((signed short) den >= 0)
#else // original, buggy and inperformant code
while (den < num && bit && !(den & (1L<<31))) // unsigned shorts are 16 bit!
if (num >= den)
num -= den;
res |= bit;
if (modwanted) return num;