From owner-svn-src-all@freebsd.org Mon Oct 19 11:16:39 2015 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 69AADA18BE8; Mon, 19 Oct 2015 11:16:39 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 42C8310E5; Mon, 19 Oct 2015 11:16:39 +0000 (UTC) (envelope-from hselasky@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id t9JBGcbj058405; Mon, 19 Oct 2015 11:16:38 GMT (envelope-from hselasky@FreeBSD.org) Received: (from hselasky@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id t9JBGcwT058404; Mon, 19 Oct 2015 11:16:38 GMT (envelope-from hselasky@FreeBSD.org) Message-Id: <201510191116.t9JBGcwT058404@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: hselasky set sender to hselasky@FreeBSD.org using -f From: Hans Petter Selasky Date: Mon, 19 Oct 2015 11:16:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r289569 - head/sys/ofed/include/linux X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Oct 2015 11:16:39 -0000 Author: hselasky Date: Mon Oct 19 11:16:38 2015 New Revision: 289569 URL: https://svnweb.freebsd.org/changeset/base/289569 Log: Merge LinuxKPI changes from DragonflyBSD: - Reimplement math64 header file to distinguish more from Linux. Sponsored by: Mellanox Technologies Modified: head/sys/ofed/include/linux/math64.h Modified: head/sys/ofed/include/linux/math64.h ============================================================================== --- head/sys/ofed/include/linux/math64.h Mon Oct 19 11:11:15 2015 (r289568) +++ head/sys/ofed/include/linux/math64.h Mon Oct 19 11:16:38 2015 (r289569) @@ -1,6 +1,6 @@ /*- * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved. - * Copyright (c) 2014 Mellanox Technologies, Ltd. All rights reserved. + * Copyright (c) 2014-2015 Mellanox Technologies, Ltd. All rights reserved. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,108 +26,29 @@ */ #ifndef _LINUX_MATH64_H -#define _LINUX_MATH64_H +#define _LINUX_MATH64_H -#include -#include +#include -#if BITS_PER_LONG == 64 - -# define do_div(n, base) ({ \ - uint32_t __base = (base); \ - uint32_t __rem; \ - __rem = ((uint64_t)(n)) % __base; \ - (n) = ((uint64_t)(n)) / __base; \ - __rem; \ +#define do_div(n, base) ({ \ + uint32_t __base = (base); \ + uint32_t __rem; \ + __rem = ((uint64_t)(n)) % __base; \ + (n) = ((uint64_t)(n)) / __base; \ + __rem; \ }) -/** -* div_u64_rem - unsigned 64bit divide with 32bit divisor with remainder -* -* This is commonly provided by 32bit archs to provide an optimized 64bit -* divide. -*/ -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder) +static inline uint64_t +div_u64_rem(uint64_t dividend, uint32_t divisor, uint32_t *remainder) { - *remainder = dividend % divisor; - return dividend / divisor; + *remainder = dividend % divisor; + return (dividend / divisor); } - -#elif BITS_PER_LONG == 32 - -static uint32_t __div64_32(uint64_t *n, uint32_t base) -{ - uint64_t rem = *n; - uint64_t b = base; - uint64_t res, d = 1; - uint32_t high = rem >> 32; - - /* Reduce the thing a bit first */ - res = 0; - if (high >= base) { - high /= base; - res = (uint64_t) high << 32; - rem -= (uint64_t) (high*base) << 32; - } - - while ((int64_t)b > 0 && b < rem) { - b = b+b; - d = d+d; - } - - do { - if (rem >= b) { - rem -= b; - res += d; - } - b >>= 1; - d >>= 1; - } while (d); - - *n = res; - return rem; -} - -# define do_div(n, base) ({ \ - uint32_t __base = (base); \ - uint32_t __rem; \ - (void)(((typeof((n)) *)0) == ((uint64_t *)0)); \ - if (likely(((n) >> 32) == 0)) { \ - __rem = (uint32_t)(n) % __base; \ - (n) = (uint32_t)(n) / __base; \ - } else \ - __rem = __div64_32(&(n), __base); \ - __rem; \ -}) - -#ifndef div_u64_rem -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder) -{ - *remainder = do_div(dividend, divisor); - return dividend; -} -#endif - - -#endif /* BITS_PER_LONG */ - - - -/** - ** div_u64 - unsigned 64bit divide with 32bit divisor - ** - ** This is the most common 64bit divide and should be used if possible, - ** as many 32bit archs can optimize this variant better than a full 64bit - ** divide. - * */ -#ifndef div_u64 - -static inline u64 div_u64(u64 dividend, u32 divisor) +static inline uint64_t +div_u64(uint64_t dividend, uint32_t divisor) { - u32 remainder; - return div_u64_rem(dividend, divisor, &remainder); + return (dividend / divisor); } -#endif -#endif /* _LINUX_MATH64_H */ +#endif /* _LINUX_MATH64_H */