• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #include "nnacl/common_func.h"
18 
Offset(const int * shape,const int dim0,const int dim1,const int dim2,const int dim3)19 int Offset(const int *shape, const int dim0, const int dim1, const int dim2, const int dim3) {
20   return ((dim0 * shape[1] + dim1) * shape[2] + dim2) * shape[3] + dim3;
21 }
22 
OffsetComm(const int * shape,const int dim0,const int dim1,const int dim2)23 int OffsetComm(const int *shape, const int dim0, const int dim1, const int dim2) {
24   return ((dim0 * shape[1] + dim1) * shape[2] + dim2) * shape[3];
25 }
26 
Offset4d(const int * shape,const int * dims)27 int Offset4d(const int *shape, const int *dims) { return Offset(shape, dims[0], dims[1], dims[2], dims[3]); }
28 
Offset6d(const int * shape,const int * dims)29 int Offset6d(const int *shape, const int *dims) {
30   return ((OffsetComm(shape, dims[0], dims[1], dims[2]) + dims[3]) * shape[4] + dims[4]) * shape[5];
31 }
32 
MinInt8(int8_t a,int8_t b)33 int8_t MinInt8(int8_t a, int8_t b) { return b ^ ((a ^ b) & -(a < b)); }
34 
MaxInt8(int8_t a,int8_t b)35 int8_t MaxInt8(int8_t a, int8_t b) { return a ^ ((a ^ b) & -(a < b)); }
36