• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2009-2022 Huawei Technologies Co., Ltd. All rights reserved.
3  *
4  * UniProton is licensed under Mulan PSL v2.
5  * You can use this software according to the terms and conditions of the Mulan PSL v2.
6  * You may obtain a copy of Mulan PSL v2 at:
7  *          http://license.coscl.org.cn/MulanPSL2
8  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
9  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
10  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
11  * See the Mulan PSL v2 for more details.
12  * Create: 2009-12-22
13  * Description: 提供64位加减操作
14  */
15 #include "prt_lib_external.h"
16 #include "prt_attr_external.h"
17 
18 /*
19  * 描述:64位加法
20  */
OsAdd64X(U32 oldLow,U32 oldHigh,U32 * low,U32 * high)21 OS_SEC_ALW_INLINE INLINE void OsAdd64X(U32 oldLow, U32 oldHigh, U32 *low, U32 *high)
22 {
23     if (*low > OS_MAX_U32 - oldLow) {
24         *high += (oldHigh + 1);
25     } else {
26         *high += oldHigh;
27     }
28     *low += oldLow;
29 
30     return;
31 }
32 
OsAdd64(U32 * low,U32 * high,U32 oldLow,U32 oldHigh)33 OS_SEC_L4_TEXT void OsAdd64(U32 *low, U32 *high, U32 oldLow, U32 oldHigh)
34 {
35     OsAdd64X(oldLow, oldHigh, low, high);
36 }
37 
38 /*
39  * 描述:64位减法
40  */
OsSub64X(U32 oldLow,U32 oldHigh,U32 * low,U32 * high)41 OS_SEC_ALW_INLINE INLINE void OsSub64X(U32 oldLow, U32 oldHigh, U32 *low, U32 *high)
42 {
43     if (*low >= oldLow) {
44         *high -= oldHigh;
45     } else {
46         *high -= (oldHigh + 1);
47     }
48     *low -= oldLow;
49 
50     return;
51 }
52 
OsSub64(U32 * low,U32 * high,U32 oldLow,U32 oldHigh)53 OS_SEC_L4_TEXT void OsSub64(U32 *low, U32 *high, U32 oldLow, U32 oldHigh)
54 {
55     OsSub64X(oldLow, oldHigh, low, high);
56 }
57 
OsGetLmb1(U32 value)58 OS_SEC_L4_TEXT U32 OsGetLmb1(U32 value)
59 {
60     int i;
61     U32 max = 0;
62 
63     for (i = 31; i >= 0; i--) {
64         if (((1U << (U32)i) & value) != 0) {
65             max = (U32)i;
66 	    break;
67         }
68     }
69 
70     return (31U - max);
71 }
72 
73