math64.h revision 289569
1270710Shselasky/*-
2270710Shselasky * Copyright (c) 2007 Cisco Systems, Inc.  All rights reserved.
3289569Shselasky * Copyright (c) 2014-2015 Mellanox Technologies, Ltd. All rights reserved.
4270710Shselasky * All rights reserved.
5270710Shselasky *
6270710Shselasky * Redistribution and use in source and binary forms, with or without
7270710Shselasky * modification, are permitted provided that the following conditions
8270710Shselasky * are met:
9270710Shselasky * 1. Redistributions of source code must retain the above copyright
10270710Shselasky *    notice unmodified, this list of conditions, and the following
11270710Shselasky *    disclaimer.
12270710Shselasky * 2. Redistributions in binary form must reproduce the above copyright
13270710Shselasky *    notice, this list of conditions and the following disclaimer in the
14270710Shselasky *    documentation and/or other materials provided with the distribution.
15270710Shselasky *
16270710Shselasky * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17270710Shselasky * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18270710Shselasky * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19270710Shselasky * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20270710Shselasky * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21270710Shselasky * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22270710Shselasky * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23270710Shselasky * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24270710Shselasky * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25270710Shselasky * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26270710Shselasky */
27270710Shselasky
28270710Shselasky#ifndef _LINUX_MATH64_H
29289569Shselasky#define	_LINUX_MATH64_H
30270710Shselasky
31289569Shselasky#include <sys/stdint.h>
32270710Shselasky
33289569Shselasky#define	do_div(n, base) ({			\
34289569Shselasky	uint32_t __base = (base);		\
35289569Shselasky	uint32_t __rem;				\
36289569Shselasky	__rem = ((uint64_t)(n)) % __base;	\
37289569Shselasky	(n) = ((uint64_t)(n)) / __base;		\
38289569Shselasky	__rem;					\
39270710Shselasky})
40270710Shselasky
41289569Shselaskystatic inline uint64_t
42289569Shselaskydiv_u64_rem(uint64_t dividend, uint32_t divisor, uint32_t *remainder)
43270710Shselasky{
44289569Shselasky	*remainder = dividend % divisor;
45289569Shselasky	return (dividend / divisor);
46270710Shselasky}
47270710Shselasky
48289569Shselaskystatic inline uint64_t
49289569Shselaskydiv_u64(uint64_t dividend, uint32_t divisor)
50270710Shselasky{
51289569Shselasky	return (dividend / divisor);
52270710Shselasky}
53270710Shselasky
54289569Shselasky#endif					/* _LINUX_MATH64_H */
55