• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  *   Copyright (c) 2020 HiSilicon (Shanghai) Technologies CO., LIMITED.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  * Description: math
15  *
16  * Create: 2021-12-16
17  */
18 
19 #include <linux/module.h>
20 #include <linux/kernel.h>
21 #include "soc_osal.h"
22 
23 /* the result of u64/u32. */
osal_div_u64(unsigned long long dividend,unsigned int divisor)24 unsigned long long osal_div_u64(unsigned long long dividend, unsigned int divisor)
25 {
26     return div_u64(dividend, divisor);
27 }
28 
29 /* the result of s64/s32. */
osal_div_s64(long long dividend,int divisor)30 long long osal_div_s64(long long dividend, int divisor)
31 {
32     return div_s64(dividend, divisor);
33 }
34 
35 /* the result of u64/u64. */
osal_div64_u64(unsigned long long dividend,unsigned long long divisor)36 unsigned long long osal_div64_u64(unsigned long long dividend, unsigned long long divisor)
37 {
38     return div64_u64(dividend, divisor);
39 }
40 
41 /* the result of s64/s64. */
osal_div64_s64(long long dividend,long long divisor)42 long long osal_div64_s64(long long dividend, long long divisor)
43 {
44     return div64_s64(dividend, divisor);
45 }
46 
47 /* the remainder of u64/u32. */
osal_div_u64_rem(unsigned long long dividend,unsigned int divisor)48 unsigned long long osal_div_u64_rem(unsigned long long dividend, unsigned int divisor)
49 {
50     unsigned int remainder = 0;
51 
52     div_u64_rem(dividend, divisor, &remainder);
53 
54     return remainder;
55 }
56 
57 /* the remainder of s64/s32. */
osal_div_s64_rem(long long dividend,int divisor)58 long long osal_div_s64_rem(long long dividend, int divisor)
59 {
60     int remainder = 0;
61 
62     div_s64_rem(dividend, divisor, &remainder);
63 
64     return remainder;
65 }
66 
67 /* the remainder of u64/u64. */
osal_div64_u64_rem(unsigned long long dividend,unsigned long long divisor)68 unsigned long long osal_div64_u64_rem(unsigned long long dividend, unsigned long long divisor)
69 {
70     unsigned long long remainder = 0;
71 
72     div64_u64_rem(dividend, divisor, &remainder);
73     return remainder;
74 }
75 
osal_get_random_int(void)76 unsigned int osal_get_random_int(void)
77 {
78     return (unsigned int)random();
79 }
80