Added functions to factorize a value and to create the lcm of two factorized
numbers. git-svn-id: svn://svn.cc65.org/cc65/trunk@5322 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -43,23 +43,49 @@
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Data */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
/* The C file contains a list of primes up to 256, so we can factorize numbers
|
||||
* up to 0x10000 or somewhat more. The FactorizedNumber structure below
|
||||
* contains the powers of the primes from the prime table. The size of the
|
||||
* table (= the number of primes contained therein) is the constant below.
|
||||
*/
|
||||
#define PRIME_COUNT 54
|
||||
|
||||
|
||||
|
||||
|
||||
/* A number together with its prime factors */
|
||||
typedef struct FactorizedNumber FactorizedNumber;
|
||||
struct FactorizedNumber {
|
||||
unsigned long Value; /* The actual number */
|
||||
unsigned char Powers[PRIME_COUNT]; /* Powers of the factors */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Code */
|
||||
/*****************************************************************************/
|
||||
|
||||
|
||||
|
||||
#if defined(HAVE_INLINE)
|
||||
INLINE unsigned long AlignAddr (unsigned long Addr, unsigned long Alignment)
|
||||
void Factorize (unsigned long Value, FactorizedNumber* F);
|
||||
/* Factorize a value between 1 and 0x10000. */
|
||||
|
||||
FactorizedNumber* LCM (const FactorizedNumber* Left,
|
||||
const FactorizedNumber* Right,
|
||||
FactorizedNumber* Res);
|
||||
/* Calculate the least common multiple of two factorized numbers and return
|
||||
* the result.
|
||||
*/
|
||||
|
||||
unsigned long AlignAddr (unsigned long Addr, unsigned long Alignment);
|
||||
/* Align an address to the given alignment */
|
||||
{
|
||||
return ((Addr + Alignment - 1) / Alignment) * Alignment;
|
||||
}
|
||||
#else
|
||||
/* Beware: Evaluates the argument more than once! */
|
||||
# define AlignAddr(Addr, Alignment) \
|
||||
((((Addr) + (Alignment) - 1) / (Alignment)) * (Alignment))
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user