diff --git a/libkern/divdi3.c b/libkern/divdi3.c index 348a7d85..b6cfe215 100644 --- a/libkern/divdi3.c +++ b/libkern/divdi3.c @@ -34,14 +34,10 @@ /* * The code has been taken from FreeBSD (sys/libkern/divdi3.c) and is therefore * BSD-licensed. Unnecessary functions have been removed and all typedefs required - * have been added. + * have been added in quad.h. */ -#include - -typedef int64_t quad_t; -typedef uint64_t u_quad_t; -u_quad_t __qdivrem(u_quad_t uq, u_quad_t vq, u_quad_t* arq); +#include "quad.h" /* * Divide two signed quads. diff --git a/libkern/lshrdi3.c b/libkern/lshrdi3.c index 453dda9f..f1a065fc 100644 --- a/libkern/lshrdi3.c +++ b/libkern/lshrdi3.c @@ -32,51 +32,12 @@ */ /* - * The code has been taken from FreeBSD (sys/libkern/ucmpdi2.c) and is therefore + * The code has been taken from FreeBSD (sys/libkern/lshrdi3.c) and is therefore * BSD-licensed. Unnecessary functions have been removed and all typedefs required - * have been added. + * have been added in quad.h. */ -#include - -#define CHAR_BIT 8 - -#if BYTE_ORDER == LITTLE_ENDIAN -#define _QUAD_HIGHWORD 1 -#define _QUAD_LOWWORD 0 -#else -#define _QUAD_HIGHWORD 0 -#define _QUAD_LOWWORD 1 -#endif - -/* - * Define high and low longwords. - */ -#define H _QUAD_HIGHWORD -#define L _QUAD_LOWWORD - -/* - * Total number of bits in a quad_t and in the pieces that make it up. - * These are used for shifting, and also below for halfword extraction - * and assembly. - */ -#define QUAD_BITS (sizeof(quad_t) * CHAR_BIT) -#define LONG_BITS (sizeof(long) * CHAR_BIT) -#define HALF_BITS (sizeof(long) * CHAR_BIT / 2) - -typedef int64_t quad_t; -typedef uint32_t qshift_t; - -/* - * Depending on the desired operation, we view a `long long' (aka quad_t) in - * one or more of the following formats. - */ -union uu { - quad_t q; /* as a (signed) quad */ - quad_t uq; /* as an unsigned quad */ - int32_t sl[2]; /* as two signed longs */ - uint32_t ul[2]; /* as two unsigned longs */ -}; +#include "quad.h" /* * Shift an (unsigned) quad value right (logical shift right). diff --git a/libkern/moddi3.c b/libkern/moddi3.c index b67be832..5f8ad89e 100644 --- a/libkern/moddi3.c +++ b/libkern/moddi3.c @@ -34,14 +34,10 @@ /* * The code has been taken from FreeBSD (sys/libkern/moddi3.c) and is therefore * BSD-licensed. Unnecessary functions have been removed and all typedefs required - * have been added. + * have been added quad.h. */ -#include - -typedef int64_t quad_t; -typedef uint64_t u_quad_t; -u_quad_t __qdivrem(u_quad_t uq, u_quad_t vq, u_quad_t* arq); +#include "quad.h" /* * Return remainder after dividing two signed quads. diff --git a/libkern/qdivrem.c b/libkern/qdivrem.c index 8a1b6877..fa03e2e2 100644 --- a/libkern/qdivrem.c +++ b/libkern/qdivrem.c @@ -34,7 +34,7 @@ /* * The code has been taken from FreeBSD (sys/libkern/qdivrem.c) and is therefore * BSD-licensed. Unnecessary functions have been removed and all typedefs required - * have been added. + * have been added in quad.h. */ /* @@ -43,48 +43,7 @@ */ /* MetalSVM prelude */ -#include -#include - -typedef uint64_t u_quad_t; -typedef int64_t quad_t; -typedef uint32_t u_long; - -/* - * Depending on the desired operation, we view a `long long' (aka quad_t) in - * one or more of the following formats. - */ -union uu { - quad_t q; /* as a (signed) quad */ - quad_t uq; /* as an unsigned quad */ - int32_t sl[2]; /* as two signed longs */ - uint32_t ul[2]; /* as two unsigned longs */ -}; - -#define CHAR_BIT 8 - -#if BYTE_ORDER == LITTLE_ENDIAN -#define _QUAD_HIGHWORD 1 -#define _QUAD_LOWWORD 0 -#else -#define _QUAD_HIGHWORD 0 -#define _QUAD_LOWWORD 1 -#endif - -/* - * Define high and low longwords. - */ -#define H _QUAD_HIGHWORD -#define L _QUAD_LOWWORD - -/* - * Total number of bits in a quad_t and in the pieces that make it up. - * These are used for shifting, and also below for halfword extraction - * and assembly. - */ -#define QUAD_BITS (sizeof(quad_t) * CHAR_BIT) -#define LONG_BITS (sizeof(long) * CHAR_BIT) -#define HALF_BITS (sizeof(long) * CHAR_BIT / 2) +#include "quad.h" /* * Extract high and low shortwords from longword, and move low shortword of diff --git a/libkern/quad.h b/libkern/quad.h new file mode 100644 index 00000000..3a6a86a4 --- /dev/null +++ b/libkern/quad.h @@ -0,0 +1,51 @@ +#ifndef __QUAD_H__ +#define __QUAD_H__ + +/* MetalSVM prelude */ +#include +#include + +typedef uint64_t u_quad_t; +typedef int64_t quad_t; +typedef uint32_t u_long; +typedef uint32_t qshift_t; + +/* + * Depending on the desired operation, we view a `long long' (aka quad_t) in + * one or more of the following formats. + */ +union uu { + quad_t q; /* as a (signed) quad */ + quad_t uq; /* as an unsigned quad */ + int32_t sl[2]; /* as two signed longs */ + uint32_t ul[2]; /* as two unsigned longs */ +}; + +#define CHAR_BIT 8 + +#if BYTE_ORDER == LITTLE_ENDIAN +#define _QUAD_HIGHWORD 1 +#define _QUAD_LOWWORD 0 +#else +#define _QUAD_HIGHWORD 0 +#define _QUAD_LOWWORD 1 +#endif + +/* + * Define high and low longwords. + */ +#define H _QUAD_HIGHWORD +#define L _QUAD_LOWWORD + +/* + * Total number of bits in a quad_t and in the pieces that make it up. + * These are used for shifting, and also below for halfword extraction + * and assembly. + */ +#define QUAD_BITS (sizeof(quad_t) * CHAR_BIT) +#define LONG_BITS (sizeof(long) * CHAR_BIT) +#define HALF_BITS (sizeof(long) * CHAR_BIT / 2) + +u_quad_t __qdivrem(u_quad_t uq, u_quad_t vq, u_quad_t* arq); + +#endif diff --git a/libkern/strtol.c b/libkern/strtol.c index af2115eb..88acc2f9 100644 --- a/libkern/strtol.c +++ b/libkern/strtol.c @@ -33,13 +33,7 @@ */ /* - * The code has been taken from FreeBSD (sys/libkern/qdivrem.c) and is therefore - * BSD-licensed. Unnecessary functions have been removed and all typedefs required - * have been added. - */ - -/* - * The code has been taken from FreeBSD (sys/libkern/qdivrem.c) and is therefore + * The code has been taken from FreeBSD (sys/libkern/strtol.c) and is therefore * BSD-licensed. Unnecessary functions have been removed and all typedefs required * have been added. */ diff --git a/libkern/ucmpdi2.c b/libkern/ucmpdi2.c index 0ec130c0..2323e028 100644 --- a/libkern/ucmpdi2.c +++ b/libkern/ucmpdi2.c @@ -34,38 +34,10 @@ /* * The code has been taken from FreeBSD (sys/libkern/ucmpdi2.c) and is therefore * BSD-licensed. Unnecessary functions have been removed and all typedefs required - * have been added. + * have been added quad.h. */ -#include - -#if BYTE_ORDER == LITTLE_ENDIAN -#define _QUAD_HIGHWORD 1 -#define _QUAD_LOWWORD 0 -#else -#define _QUAD_HIGHWORD 0 -#define _QUAD_LOWWORD 1 -#endif - -/* - * Define high and low longwords. - */ -#define H _QUAD_HIGHWORD -#define L _QUAD_LOWWORD - -typedef int64_t quad_t; -typedef uint64_t u_quad_t; - -/* - * Depending on the desired operation, we view a `long long' (aka quad_t) in - * one or more of the following formats. - */ -union uu { - quad_t q; /* as a (signed) quad */ - quad_t uq; /* as an unsigned quad */ - int32_t sl[2]; /* as two signed longs */ - uint32_t ul[2]; /* as two unsigned longs */ -}; +#include "quad.h" /* * Return 0, 1, or 2 as a <, =, > b respectively. diff --git a/libkern/udivdi3.c b/libkern/udivdi3.c index c78e839b..ace25bd4 100644 --- a/libkern/udivdi3.c +++ b/libkern/udivdi3.c @@ -34,13 +34,10 @@ /* * The code has been taken from FreeBSD (sys/libkern/udivdi3.c) and is therefore * BSD-licensed. Unnecessary functions have been removed and all typedefs required - * have been added. + * have been added in quad.h. */ -#include - -typedef uint64_t u_quad_t; -u_quad_t __qdivrem(u_quad_t uq, u_quad_t vq, u_quad_t* arq); +#include "quad.h" /* * Divide two unsigned quads. diff --git a/libkern/umoddi3.c b/libkern/umoddi3.c index 5ddc1f70..c4c2e440 100644 --- a/libkern/umoddi3.c +++ b/libkern/umoddi3.c @@ -34,14 +34,10 @@ /* * The code has been taken from FreeBSD (sys/libkern/umoddi3.c) and is therefore * BSD-licensed. Unnecessary functions have been removed and all typedefs required - * have been added. + * have been added in quad.h. */ -#include - -typedef uint64_t u_quad_t; -u_quad_t __qdivrem(u_quad_t uq, u_quad_t vq, u_quad_t* arq); - +#include "quad.h" /* * Return remainder after dividing two unsigned quads.