David Sterba | 9888c34 | 2018-04-03 19:16:55 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Miao Xie | 3fed40c | 2012-09-13 04:51:36 -0600 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2012 Fujitsu. All rights reserved. |
| 4 | * Written by Miao Xie <miaox@cn.fujitsu.com> |
Miao Xie | 3fed40c | 2012-09-13 04:51:36 -0600 | [diff] [blame] | 5 | */ |
| 6 | |
David Sterba | 9888c34 | 2018-04-03 19:16:55 +0200 | [diff] [blame] | 7 | #ifndef BTRFS_MATH_H |
| 8 | #define BTRFS_MATH_H |
Miao Xie | 3fed40c | 2012-09-13 04:51:36 -0600 | [diff] [blame] | 9 | |
| 10 | #include <asm/div64.h> |
| 11 | |
| 12 | static inline u64 div_factor(u64 num, int factor) |
| 13 | { |
| 14 | if (factor == 10) |
| 15 | return num; |
| 16 | num *= factor; |
David Sterba | f8c269d | 2015-01-16 17:21:12 +0100 | [diff] [blame] | 17 | return div_u64(num, 10); |
Miao Xie | 3fed40c | 2012-09-13 04:51:36 -0600 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | static inline u64 div_factor_fine(u64 num, int factor) |
| 21 | { |
| 22 | if (factor == 100) |
| 23 | return num; |
| 24 | num *= factor; |
David Sterba | f8c269d | 2015-01-16 17:21:12 +0100 | [diff] [blame] | 25 | return div_u64(num, 100); |
Miao Xie | 3fed40c | 2012-09-13 04:51:36 -0600 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | #endif |