154568cb3Sopenharmony_ci/* 254568cb3Sopenharmony_ci * Copyright (c) 2009-2023 Huawei Technologies Co., Ltd. All rights reserved. 354568cb3Sopenharmony_ci * 454568cb3Sopenharmony_ci * UniProton is licensed under Mulan PSL v2. 554568cb3Sopenharmony_ci * You can use this software according to the terms and conditions of the Mulan PSL v2. 654568cb3Sopenharmony_ci * You may obtain a copy of Mulan PSL v2 at: 754568cb3Sopenharmony_ci * http://license.coscl.org.cn/MulanPSL2 854568cb3Sopenharmony_ci * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, 954568cb3Sopenharmony_ci * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, 1054568cb3Sopenharmony_ci * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE. 1154568cb3Sopenharmony_ci * See the Mulan PSL v2 for more details. 1254568cb3Sopenharmony_ci * Create: 2009-12-22 1354568cb3Sopenharmony_ci * Description: 提供64位加减操作 1454568cb3Sopenharmony_ci */ 1554568cb3Sopenharmony_ci#include "prt_lib_external.h" 1654568cb3Sopenharmony_ci#include "prt_attr_external.h" 1754568cb3Sopenharmony_ci 1854568cb3Sopenharmony_ci/* 1954568cb3Sopenharmony_ci * 描述:64位加法 2054568cb3Sopenharmony_ci */ 2154568cb3Sopenharmony_ciOS_SEC_ALW_INLINE INLINE void OsAdd64X(U32 oldLow, U32 oldHigh, U32 *low, U32 *high) 2254568cb3Sopenharmony_ci{ 2354568cb3Sopenharmony_ci if (*low > OS_MAX_U32 - oldLow) { 2454568cb3Sopenharmony_ci *high += (oldHigh + 1); 2554568cb3Sopenharmony_ci } else { 2654568cb3Sopenharmony_ci *high += oldHigh; 2754568cb3Sopenharmony_ci } 2854568cb3Sopenharmony_ci *low += oldLow; 2954568cb3Sopenharmony_ci 3054568cb3Sopenharmony_ci return; 3154568cb3Sopenharmony_ci} 3254568cb3Sopenharmony_ci 3354568cb3Sopenharmony_ciOS_SEC_L4_TEXT void OsAdd64(U32 *low, U32 *high, U32 oldLow, U32 oldHigh) 3454568cb3Sopenharmony_ci{ 3554568cb3Sopenharmony_ci OsAdd64X(oldLow, oldHigh, low, high); 3654568cb3Sopenharmony_ci} 3754568cb3Sopenharmony_ci 3854568cb3Sopenharmony_ci/* 3954568cb3Sopenharmony_ci * 描述:64位减法 4054568cb3Sopenharmony_ci */ 4154568cb3Sopenharmony_ciOS_SEC_ALW_INLINE INLINE void OsSub64X(U32 oldLow, U32 oldHigh, U32 *low, U32 *high) 4254568cb3Sopenharmony_ci{ 4354568cb3Sopenharmony_ci if (*low >= oldLow) { 4454568cb3Sopenharmony_ci *high -= oldHigh; 4554568cb3Sopenharmony_ci } else { 4654568cb3Sopenharmony_ci *high -= (oldHigh + 1); 4754568cb3Sopenharmony_ci } 4854568cb3Sopenharmony_ci *low -= oldLow; 4954568cb3Sopenharmony_ci 5054568cb3Sopenharmony_ci return; 5154568cb3Sopenharmony_ci} 5254568cb3Sopenharmony_ci 5354568cb3Sopenharmony_ciOS_SEC_L4_TEXT void OsSub64(U32 *low, U32 *high, U32 oldLow, U32 oldHigh) 5454568cb3Sopenharmony_ci{ 5554568cb3Sopenharmony_ci OsSub64X(oldLow, oldHigh, low, high); 5654568cb3Sopenharmony_ci} 5754568cb3Sopenharmony_ci 5854568cb3Sopenharmony_ciOS_SEC_L4_TEXT U32 OsGetLmb1(U32 value) 5954568cb3Sopenharmony_ci{ 6054568cb3Sopenharmony_ci int i; 6154568cb3Sopenharmony_ci U32 max = 0; 6254568cb3Sopenharmony_ci 6354568cb3Sopenharmony_ci for (i = 31; i >= 0; i--) { 6454568cb3Sopenharmony_ci if (((1U << (U32)i) & value) != 0) { 6554568cb3Sopenharmony_ci max = (U32)i; 6654568cb3Sopenharmony_ci break; 6754568cb3Sopenharmony_ci } 6854568cb3Sopenharmony_ci } 6954568cb3Sopenharmony_ci 7054568cb3Sopenharmony_ci return (31U - max); 7154568cb3Sopenharmony_ci} 7254568cb3Sopenharmony_ci 73