Or consider the code from:
http://nemesis.sourceforge.net/browse/lib/static/intmath/ix86/intmath.c.html
Adapted as follows...
Chris
---#define DIV 0 #define REM 1
// Function copied/adapted/optimized from: // // nemesis.sourceforge.net/browse/lib/static/intmath/ix86/intmath.c.html // // Copyright 1994, University of Cambridge Computer Laboratory // All Rights Reserved. // // TODO: When running on a 64-bit CPU platform, this should no longer be // TODO: necessary. // s64 divremdi3(s64 x, s64 y, int type) { u64 a = (x < 0) ? -x : x; u64 b = (y < 0) ? -y : y; u64 res = 0, d = 1;
if (b > 0) while (b < a) b <<= 1, d <<= 1;
do { if ( a >= b ) a -= b, res += d; b >>= 1; d >>= 1; } while (d);
if (DIV == type) { return (((x ^ y) & (1ll<<63)) == 0) ? res : -(s64)res; } else { return ((x & (1ll<<63)) == 0) ? a : -(s64)a; } }
- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/