1 /**
2 * Copyright 2020 Huawei Technologies Co., Ltd
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #ifdef ENABLE_ARM
17 #include <arm_neon.h>
18 #ifdef ENABLE_FP16
19 #include "nnacl/fp16/cast_fp16.h"
20 #endif
21 #endif
22 #include "nnacl/nnacl_common.h"
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
Float32ToFloat16_fp16_handler(const void * input,void * output,int number,bool support_fp16)27 static inline void Float32ToFloat16_fp16_handler(const void *input, void *output, int number, bool support_fp16) {
28 #if defined(ENABLE_ARM) && defined(ENABLE_FP16)
29 if (support_fp16) {
30 Float32ToFloat16(reinterpret_cast<const float *>(input), reinterpret_cast<float16_t *>(output), number);
31 } else {
32 #endif
33 auto src_data = reinterpret_cast<const float *>(input);
34 auto dst_data = reinterpret_cast<uint16_t *>(output);
35 for (int i = 0; i < number; i++) {
36 dst_data[i] = Float32ToShort(src_data[i]);
37 }
38 #if defined(ENABLE_ARM) && defined(ENABLE_FP16)
39 }
40 #endif
41 }
42
Float16ToFloat32_fp16_handler(const void * input,void * output,int number,bool support_fp16)43 static inline void Float16ToFloat32_fp16_handler(const void *input, void *output, int number, bool support_fp16) {
44 #if defined(ENABLE_ARM) && defined(ENABLE_FP16)
45 if (support_fp16) {
46 Float16ToFloat32(reinterpret_cast<const float16_t *>(input), reinterpret_cast<float *>(output), number);
47 } else {
48 #endif
49 auto src_data = reinterpret_cast<const uint16_t *>(input);
50 auto dst_data = reinterpret_cast<float *>(output);
51 for (int i = 0; i < number; i++) {
52 dst_data[i] = ShortToFloat32(src_data[i]);
53 }
54 #if defined(ENABLE_ARM) && defined(ENABLE_FP16)
55 }
56 #endif
57 }
58
59 #ifdef __cplusplus
60 }
61 #endif
62