WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] Re: [PATCH] mini-os: lib/math.c: import FreeBSD 8 functions

To: Samuel Thibault <samuel.thibault@xxxxxxxxxxxx>
Subject: [Xen-devel] Re: [PATCH] mini-os: lib/math.c: import FreeBSD 8 functions
From: Keir Fraser <keir.xen@xxxxxxxxx>
Date: Sat, 30 Apr 2011 20:31:58 +0100
Cc: xen-devel@xxxxxxxxxxxxxxxxxxx, Bastian Blank <bastian@xxxxxxxxxxxx>
Delivery-date: Sat, 30 Apr 2011 12:33:06 -0700
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:user-agent:date:subject:from:to:cc:message-id :thread-topic:thread-index:in-reply-to:mime-version:content-type :content-transfer-encoding; bh=IaxX2t7SEb4NLwIhD3zUS+VEXGN6BYsoim9FUbNZxvg=; b=g9o/7eQRJ9yRWP/nSOj9kBAetFImPS2oo8BuWJj4X9nIVkAzjbaAL4Mi8IcgMSaJxX Daaeh/7nNeCguZ3v6mtLLY8Bg4wzoHuRLMv29QHFjozOUlJuruCOjj37R1NgcSYw9ENE d51lji0OvCIUgqsXPUP8TJw06nhASQO4Zuw10=
Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=user-agent:date:subject:from:to:cc:message-id:thread-topic :thread-index:in-reply-to:mime-version:content-type :content-transfer-encoding; b=Hki2cYHKr5GKK/d+RGSwPyWogk9TA38+PmIOUSS93Vk72B0k56Tj5ZK2Xq40eVlSSc jCamS6fG3Cio+VzrlJ2HgoabqLRNMd2JChSqaAKGIjgc7W1fWcpUXidZ+6v88JJ/oT+U iB9ZWhSKnX4OaoH6jE3DwV7fGUJbSYHbaD3CI=
Envelope-to: www-data@xxxxxxxxxxxxxxxxxxx
In-reply-to: <20110430161030.GS5073@xxxxxxxxxxxxxxxxxxxxxxxxx>
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
Thread-index: AcwHbUUoQk11SuGBp0qzz6T+bOSvXg==
Thread-topic: [PATCH] mini-os: lib/math.c: import FreeBSD 8 functions
User-agent: Microsoft-Entourage/12.29.0.110113
Should the license terms really be enumerated 1, 2, 4?

 -- Keir

On 30/04/2011 17:10, "Samuel Thibault" <samuel.thibault@xxxxxxxxxxxx> wrote:

> Import lib/math.c functions (and thus licence) from FreeBSD 8,
> and re-apply a few of our changes. Whitespaces left aside, this
> leads to almost no source change except s/int64_t/quad_t/ and
> s/uint64_t/u_quad_t/.
> 
> Signed-off-by: Samuel Thibault <samuel.thibault@xxxxxxxxxxxx>
> 
> diff -r 7745109e3c6e extras/mini-os/lib/math.c
> --- a/extras/mini-os/lib/math.c Wed Apr 27 13:36:15 2011 +0100
> +++ b/extras/mini-os/lib/math.c Sat Apr 30 18:06:08 2011 +0200
> @@ -13,10 +13,6 @@
>   * Description:  Library functions for 64bit arith and other
>   *               from freebsd, files in sys/libkern/ (qdivrem.c, etc)
>   *
> - ****************************************************************************
> - * $Id: c-insert.c,v 1.7 2002/11/08 16:04:34 rn Exp $
> - ****************************************************************************
> - *-
>   * Copyright (c) 1992, 1993
>   * The Regents of the University of California.  All rights reserved.
>   *
> @@ -32,10 +28,6 @@
>   * 2. Redistributions in binary form must reproduce the above copyright
>   *    notice, this list of conditions and the following disclaimer in the
>   *    documentation and/or other materials provided with the distribution.
> - * 3. All advertising materials mentioning features or use of this software
> - *    must display the following acknowledgement:
> - * This product includes software developed by the University of
> - * California, Berkeley and its contributors.
>   * 4. Neither the name of the University nor the names of its contributors
>   *    may be used to endorse or promote products derived from this software
>   *    without specific prior written permission.
> @@ -52,7 +44,6 @@
>   * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
>   * SUCH DAMAGE.
>   *
> - * $FreeBSD: src/sys/libkern/divdi3.c,v 1.6 1999/08/28 00:46:31 peter Exp $
>  */
>  
>  #include <mini-os/types.h>
> @@ -63,49 +54,62 @@
> * assembler functions. */
>  #if !defined(__ia64__)
>  
> +/* XXX RN: Yuck hardcoded endianess :) */
> +#define _QUAD_HIGHWORD 1
> +#define _QUAD_LOWWORD 0
> +
> +/*
> + * From
> + * @(#)quad.h 8.1 (Berkeley) 6/4/93
> + */
> +
>  /*
>   * Depending on the desired operation, we view a `long long' (aka quad_t) in
>   * one or more of the following formats.
>   */
>  union uu {
> -        int64_t           q;              /* as a (signed) quad */
> -        int64_t          uq;             /* as an unsigned quad */
> -        int32_t        sl[2];          /* as two signed ints */
> -        uint32_t       ul[2];          /* as two unsigned ints */
> + 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 */
>  };
> -/* XXX RN: Yuck hardcoded endianess :) */
> -#define _QUAD_HIGHWORD 1
> -#define _QUAD_LOWWORD 0
> +
>  /*
>   * Define high and low longwords.
>   */
> -#define H               _QUAD_HIGHWORD
> -#define L               _QUAD_LOWWORD
> +#define H  _QUAD_HIGHWORD
> +#define L  _QUAD_LOWWORD
>  
>  /*
> - * Total number of bits in a quad_t and in the pieces that make it up.
> + * Total number of bits in an quad_t and in the pieces that make it up.
>   * These are used for shifting, and also below for halfword extraction
>   * and assembly.
>   */
>  #ifndef HAVE_LIBC
>  #define CHAR_BIT        8               /* number of bits in a char */
>  #endif
> -#define QUAD_BITS       (sizeof(int64_t) * CHAR_BIT)
> -#define LONG_BITS       (sizeof(int32_t) * CHAR_BIT)
> -#define HALF_BITS       (sizeof(int32_t) * CHAR_BIT / 2)
> +#define QUAD_BITS (sizeof(quad_t) * CHAR_BIT)
> +#define LONG_BITS (sizeof(int32_t) * CHAR_BIT)
> +#define HALF_BITS (sizeof(int32_t) * CHAR_BIT / 2)
>  
>  /*
> - * Extract high and low shortwords from intword, and move low shortword of
> - * intword to upper half of int32_t, i.e., produce the upper intword of
> - * ((quad_t)(x) << (number_of_bits_in_int/2)).  (`x' must actually be
> uint32_t.)
> + * Extract high and low shortwords from longword, and move low shortword of
> + * longword to upper half of int32_t, i.e., produce the upper longword of
> + * ((quad_t)(x) << (number_of_bits_in_long/2)).  (`x' must actually be
> uint32_t.)
>   *
> - * These are used in the multiply code, to split a intword into upper
> + * These are used in the multiply code, to split a longword into upper
>   * and lower halves, and to reassemble a product as a quad_t, shifted left
>   * (sizeof(int32_t)*CHAR_BIT/2).
>   */
> -#define HHALF(x)        ((x) >> HALF_BITS)
> -#define LHALF(x)        ((x) & ((1UL << HALF_BITS) - 1))
> -#define LHUP(x)         ((x) << HALF_BITS)
> +#define HHALF(x) ((x) >> HALF_BITS)
> +#define LHALF(x) ((x) & ((1UL << HALF_BITS) - 1))
> +#define LHUP(x)  ((x) << HALF_BITS)
> +
> +
> +/*
> + * From
> + * qdivrem.c
> + */
>  
>  /*
>   * Multiprecision divide.  This algorithm is from Knuth vol. 2 (2nd ed),
> @@ -119,7 +123,6 @@
>  /* select a type for digits in base B: */
>  typedef uint16_t digit;
>  
> -
>  /*
>   * Shift p[0]..p[len] left `sh' bits, ignoring any bits that
>   * `fall out' the left (there never will be any such anyway).
> @@ -143,8 +146,8 @@
>   * divisor are 4 `digits' in this base (they are shorter if they have
>   * leading zeros).
>   */
> -uint64_t
> -__qdivrem(uint64_t uq, uint64_t vq, uint64_t *arq)
> +u_quad_t
> +__qdivrem(u_quad_t uq, u_quad_t vq, u_quad_t *arq)
>  {
> union uu tmp;
> digit *u, *v, *q;
> @@ -339,38 +342,51 @@
> return (tmp.q);
>  }
>  
> +/*
> + * From
> + * divdi3.c
> + */
>  
>  /*
>   * Divide two signed quads.
>   * ??? if -1/2 should produce -1 on this machine, this code is wrong
>   */
> -int64_t
> -__divdi3(int64_t a, int64_t b)
> +quad_t
> +__divdi3(quad_t a, quad_t b)
>  {
> - uint64_t ua, ub, uq;
> + u_quad_t ua, ub, uq;
> int neg;
>  
> if (a < 0)
> -  ua = -(uint64_t)a, neg = 1;
> +  ua = -(u_quad_t)a, neg = 1;
> else
> ua = a, neg = 0;
> if (b < 0)
> -  ub = -(uint64_t)b, neg ^= 1;
> +  ub = -(u_quad_t)b, neg ^= 1;
> else
> ub = b;
> - uq = __qdivrem(ua, ub, (uint64_t *)0);
> + uq = __qdivrem(ua, ub, (u_quad_t *)0);
> return (neg ? -uq : uq);
>  }
>  
>  /*
> + * From
> + * udivdi3.c
> + */
> +
> +/*
>   * Divide two unsigned quads.
>   */
> -uint64_t
> -__udivdi3(uint64_t a, uint64_t b)
> +u_quad_t
> +__udivdi3(u_quad_t a, u_quad_t b)
>  {
> -        return (__qdivrem(a, b, (uint64_t *)0));
> + return (__qdivrem(a, b, (u_quad_t *)0));
>  }
>  
> +/*
> + * From
> + * umoddi3.c
> + */
>  
>  /*
>   * Return remainder after dividing two unsigned quads.
> @@ -378,13 +394,18 @@
>  u_quad_t
>  __umoddi3(u_quad_t a, u_quad_t b)
>  {
> -        u_quad_t r;
> + u_quad_t r;
>  
> -        (void)__qdivrem(a, b, &r);
> -        return (r);
> + (void)__qdivrem(a, b, &r);
> + return (r);
>  }
>  
>  /*
> + * From
> + * moddi3.c
> + */
> +
> +/*
>   * Return remainder after dividing two signed quads.
>   *
>   * XXX



_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel