Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #ifndef AICPU_TYPE_DEF_H
12 : #define AICPU_TYPE_DEF_H
13 :
14 : #include <cstdint>
15 : #include <cstddef>
16 : #ifndef char_t
17 : typedef char char_t;
18 : #endif
19 :
20 : #ifndef float32_t
21 : typedef float float32_t;
22 : #endif
23 :
24 : #ifndef float64_t
25 : typedef double float64_t;
26 : #endif
27 :
28 576 : inline uint64_t PtrToValue(const void* ptr) { return static_cast<uint64_t>(reinterpret_cast<uintptr_t>(ptr)); }
29 :
30 742 : inline void* ValueToPtr(const uint64_t value) { return reinterpret_cast<void*>(static_cast<uintptr_t>(value)); }
31 :
32 : template <typename TI, typename TO>
33 1516 : inline TO* PtrToPtr(TI* ptr)
34 : {
35 1516 : return reinterpret_cast<TO*>(ptr);
36 : }
37 :
38 : template <typename TI, typename TO>
39 19 : inline const TO* PtrToPtr(const TI* const ptr)
40 : {
41 19 : return reinterpret_cast<const TO*>(ptr);
42 : }
43 :
44 : template <typename TI, typename TO>
45 102 : inline TO PtrToFunctionPtr(TI* const ptr)
46 : {
47 102 : return reinterpret_cast<TO>(ptr);
48 : }
49 :
50 : template <typename TI, typename TO>
51 : inline const TO PtrToFunctionPtr(const TI* const ptr)
52 : {
53 : return reinterpret_cast<const TO>(ptr);
54 : }
55 :
56 : template <typename T>
57 118 : inline T* PtrAdd(T* const ptr, const size_t maxIdx, const size_t idx)
58 : {
59 118 : if ((ptr != nullptr) && (idx < maxIdx)) {
60 118 : return reinterpret_cast<T*>(ptr + idx);
61 : }
62 0 : return nullptr;
63 : }
64 : #endif // AICPU_TYPE_DEF_H
|