2 * Copyright (c) 2001-2016, Alliance for Open Media. All rights reserved
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.
12 /* clang-format off */
14 #ifndef AOM_AOM_DSP_ODINTRIN_H_
15 #define AOM_AOM_DSP_ODINTRIN_H_
20 #include "aom/aom_integer.h"
21 #include "aom_dsp/aom_dsp_common.h"
22 #include "aom_ports/bitops.h"
30 #define OD_DIVU_DMAX (1024)
32 extern uint32_t OD_DIVU_SMALL_CONSTS
[OD_DIVU_DMAX
][2];
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]) >> \
41 #define OD_DIVU(_x, _d) \
42 (((_d) < OD_DIVU_DMAX) ? (OD_DIVU_SMALL((_x), (_d))) : ((_x) / (_d)))
44 #define OD_MINI AOMMIN
45 #define OD_MAXI AOMMAX
46 #define OD_CLAMPI(min, val, max) (OD_MAXI(min, OD_MINI(val, max)))
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))
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__ >= \
56 ((maj) << 16) + ((min) << 8) + pat) // NOLINT
58 #define OD_GNUC_PREREQ(maj, min, pat) (0)
61 #if OD_GNUC_PREREQ(3, 4, 0)
62 #define OD_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
64 #define OD_WARN_UNUSED_RESULT
67 #if OD_GNUC_PREREQ(3, 4, 0)
68 #define OD_ARG_NONNULL(x) __attribute__((__nonnull__(x)))
70 #define OD_ARG_NONNULL(x)
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))))
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)
83 # define OD_MOVE(dst, src, n) \
84 (memmove((dst), (src), sizeof(*(dst))*(n) + 0*((dst) - (src)) ))
87 /*All of these macros should expect floats as arguments.*/
88 # define OD_SIGNMASK(a) (-((a) < 0))
89 # define OD_FLIPSIGNI(a, b) (((a) + OD_SIGNMASK(b)) ^ OD_SIGNMASK(b))
95 #endif // AOM_AOM_DSP_ODINTRIN_H_