Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 1 | /* |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 2 | * Copyright (c) 2001-2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 3 | * |
| 4 | * This source code is subject to the terms of the BSD 2 Clause License and |
| 5 | * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License |
| 6 | * was not distributed with this source code in the LICENSE file, you can |
| 7 | * obtain it at www.aomedia.org/license/software. If the Alliance for Open |
| 8 | * Media Patent License 1.0 was not distributed with this source code in the |
| 9 | * PATENTS file, you can obtain it at www.aomedia.org/license/patent. |
| 10 | */ |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 11 | |
| 12 | /* clang-format off */ |
| 13 | |
Bohan Li | 3adb660d | 2021-08-24 17:59:14 -0700 | [diff] [blame] | 14 | #ifndef AOM_AOM_DSP_ODINTRIN_H_ |
| 15 | #define AOM_AOM_DSP_ODINTRIN_H_ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 16 | |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 17 | #include <stdlib.h> |
| 18 | #include <string.h> |
| 19 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 20 | #include "aom/aom_integer.h" |
| 21 | #include "aom_dsp/aom_dsp_common.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 22 | #include "aom_ports/bitops.h" |
| 23 | |
James Zern | 5d986e5 | 2016-09-06 23:25:51 -0700 | [diff] [blame] | 24 | #ifdef __cplusplus |
| 25 | extern "C" { |
| 26 | #endif |
| 27 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 28 | typedef int od_coeff; |
| 29 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 30 | #define OD_DIVU_DMAX (1024) |
| 31 | |
| 32 | extern uint32_t OD_DIVU_SMALL_CONSTS[OD_DIVU_DMAX][2]; |
| 33 | |
| 34 | /*Translate unsigned division by small divisors into multiplications.*/ |
| 35 | #define OD_DIVU_SMALL(_x, _d) \ |
| 36 | ((uint32_t)((OD_DIVU_SMALL_CONSTS[(_d)-1][0] * (uint64_t)(_x) + \ |
| 37 | OD_DIVU_SMALL_CONSTS[(_d)-1][1]) >> \ |
| 38 | 32) >> \ |
Alex Converse | 6f345c6 | 2017-01-19 16:15:05 -0800 | [diff] [blame] | 39 | (OD_ILOG_NZ(_d) - 1)) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 40 | |
| 41 | #define OD_DIVU(_x, _d) \ |
| 42 | (((_d) < OD_DIVU_DMAX) ? (OD_DIVU_SMALL((_x), (_d))) : ((_x) / (_d))) |
| 43 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 44 | #define OD_MINI AOMMIN |
Nathan E. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 45 | #define OD_MAXI AOMMAX |
Rostislav Pehlivanov | 002e7b7 | 2017-02-15 19:45:54 +0000 | [diff] [blame] | 46 | #define OD_CLAMPI(min, val, max) (OD_MAXI(min, OD_MINI(val, max))) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 47 | |
Wan-Teh Chang | 72c1f07 | 2018-08-08 17:54:08 -0700 | [diff] [blame] | 48 | /*Integer logarithm (base 2) of a nonzero unsigned 32-bit integer. |
| 49 | OD_ILOG_NZ(x) = (int)floor(log2(x)) + 1.*/ |
| 50 | #define OD_ILOG_NZ(x) (1 + get_msb(x)) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 51 | |
Nathan E. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 52 | /*Enable special features for gcc and compatible compilers.*/ |
| 53 | #if defined(__GNUC__) && defined(__GNUC_MINOR__) && defined(__GNUC_PATCHLEVEL__) |
| 54 | #define OD_GNUC_PREREQ(maj, min, pat) \ |
| 55 | ((__GNUC__ << 16) + (__GNUC_MINOR__ << 8) + __GNUC_PATCHLEVEL__ >= \ |
Yaowu Xu | 931bc2a | 2016-10-14 13:53:51 -0700 | [diff] [blame] | 56 | ((maj) << 16) + ((min) << 8) + pat) // NOLINT |
Nathan E. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 57 | #else |
| 58 | #define OD_GNUC_PREREQ(maj, min, pat) (0) |
| 59 | #endif |
| 60 | |
| 61 | #if OD_GNUC_PREREQ(3, 4, 0) |
| 62 | #define OD_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) |
| 63 | #else |
| 64 | #define OD_WARN_UNUSED_RESULT |
| 65 | #endif |
| 66 | |
| 67 | #if OD_GNUC_PREREQ(3, 4, 0) |
| 68 | #define OD_ARG_NONNULL(x) __attribute__((__nonnull__(x))) |
| 69 | #else |
| 70 | #define OD_ARG_NONNULL(x) |
| 71 | #endif |
| 72 | |
Nathan E. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 73 | /** Copy n elements of memory from src to dst. The 0* term provides |
| 74 | compile-time type checking */ |
| 75 | #if !defined(OVERRIDE_OD_COPY) |
| 76 | #define OD_COPY(dst, src, n) \ |
| 77 | (memcpy((dst), (src), sizeof(*(dst)) * (n) + 0 * ((dst) - (src)))) |
| 78 | #endif |
| 79 | |
| 80 | /** Copy n elements of memory from src to dst, allowing overlapping regions. |
| 81 | The 0* term provides compile-time type checking */ |
| 82 | #if !defined(OVERRIDE_OD_MOVE) |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 83 | # define OD_MOVE(dst, src, n) \ |
| 84 | (memmove((dst), (src), sizeof(*(dst))*(n) + 0*((dst) - (src)) )) |
Nathan E. Egge | 1078dee | 2016-03-06 10:59:29 -0500 | [diff] [blame] | 85 | #endif |
| 86 | |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 87 | /*All of these macros should expect floats as arguments.*/ |
Yushin Cho | 77bba8d | 2016-11-04 16:36:56 -0700 | [diff] [blame] | 88 | # define OD_SIGNMASK(a) (-((a) < 0)) |
| 89 | # define OD_FLIPSIGNI(a, b) (((a) + OD_SIGNMASK(b)) ^ OD_SIGNMASK(b)) |
| 90 | |
James Zern | 5d986e5 | 2016-09-06 23:25:51 -0700 | [diff] [blame] | 91 | #ifdef __cplusplus |
| 92 | } // extern "C" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 93 | #endif |
James Zern | 5d986e5 | 2016-09-06 23:25:51 -0700 | [diff] [blame] | 94 | |
Bohan Li | 3adb660d | 2021-08-24 17:59:14 -0700 | [diff] [blame] | 95 | #endif // AOM_AOM_DSP_ODINTRIN_H_ |