xref: /aosp_15_r20/external/pytorch/aten/src/ATen/native/quantized/cpu/qnnpack/src/qnnpack/math.h (revision da0073e96a02ea20f0ac840b70461e3646d07c45)
1 /*
2  * Copyright (c) Facebook, Inc. and its affiliates.
3  * All rights reserved.
4  *
5  * This source code is licensed under the BSD-style license found in the
6  * LICENSE file in the root directory of this source tree.
7  */
8 
9 #pragma once
10 
11 #include <stddef.h>
12 #ifdef _MSC_VER
13 #undef min
14 #undef max
15 #endif
16 
min(size_t a,size_t b)17 inline static size_t min(size_t a, size_t b) {
18   return a < b ? a : b;
19 }
20 
max(size_t a,size_t b)21 inline static size_t max(size_t a, size_t b) {
22   return a > b ? a : b;
23 }
24 
doz(size_t a,size_t b)25 inline static size_t doz(size_t a, size_t b) {
26   return a < b ? 0 : a - b;
27 }
28 
divide_round_up(size_t n,size_t q)29 inline static size_t divide_round_up(size_t n, size_t q) {
30   return n % q == 0 ? n / q : n / q + 1;
31 }
32 
round_up(size_t n,size_t q)33 inline static size_t round_up(size_t n, size_t q) {
34   return divide_round_up(n, q) * q;
35 }
36