blob: 20a7f583bc2b523571ca48e059bd5a2eb5c9a661 [file] [log] [blame]
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07001/*
Yushin Cho77bba8d2016-11-04 16:36:56 -07002 * Copyright (c) 2001-2016, Alliance for Open Media. All rights reserved
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07003 *
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 Cho77bba8d2016-11-04 16:36:56 -070011
12/* clang-format off */
13
Bohan Li3adb660d2021-08-24 17:59:14 -070014#ifndef AOM_AOM_DSP_ODINTRIN_H_
15#define AOM_AOM_DSP_ODINTRIN_H_
Yaowu Xuc27fc142016-08-22 16:08:15 -070016
Yushin Cho77bba8d2016-11-04 16:36:56 -070017#include <stdlib.h>
18#include <string.h>
19
Yaowu Xuf883b422016-08-30 14:01:10 -070020#include "aom/aom_integer.h"
21#include "aom_dsp/aom_dsp_common.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070022#include "aom_ports/bitops.h"
23
James Zern5d986e52016-09-06 23:25:51 -070024#ifdef __cplusplus
25extern "C" {
26#endif
27
Yaowu Xuc27fc142016-08-22 16:08:15 -070028typedef int od_coeff;
29
Yaowu Xuc27fc142016-08-22 16:08:15 -070030#define OD_DIVU_DMAX (1024)
31
32extern 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 Converse6f345c62017-01-19 16:15:05 -080039 (OD_ILOG_NZ(_d) - 1))
Yaowu Xuc27fc142016-08-22 16:08:15 -070040
41#define OD_DIVU(_x, _d) \
42 (((_d) < OD_DIVU_DMAX) ? (OD_DIVU_SMALL((_x), (_d))) : ((_x) / (_d)))
43
Yaowu Xuf883b422016-08-30 14:01:10 -070044#define OD_MINI AOMMIN
Nathan E. Egge1078dee2016-03-06 10:59:29 -050045#define OD_MAXI AOMMAX
Rostislav Pehlivanov002e7b72017-02-15 19:45:54 +000046#define OD_CLAMPI(min, val, max) (OD_MAXI(min, OD_MINI(val, max)))
Yaowu Xuc27fc142016-08-22 16:08:15 -070047
Wan-Teh Chang72c1f072018-08-08 17:54:08 -070048/*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 Xuc27fc142016-08-22 16:08:15 -070051
Nathan E. Egge1078dee2016-03-06 10:59:29 -050052/*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 Xu931bc2a2016-10-14 13:53:51 -070056 ((maj) << 16) + ((min) << 8) + pat) // NOLINT
Nathan E. Egge1078dee2016-03-06 10:59:29 -050057#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. Egge1078dee2016-03-06 10:59:29 -050073/** 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 Cho77bba8d2016-11-04 16:36:56 -070083# define OD_MOVE(dst, src, n) \
84 (memmove((dst), (src), sizeof(*(dst))*(n) + 0*((dst) - (src)) ))
Nathan E. Egge1078dee2016-03-06 10:59:29 -050085#endif
86
Yushin Cho77bba8d2016-11-04 16:36:56 -070087/*All of these macros should expect floats as arguments.*/
Yushin Cho77bba8d2016-11-04 16:36:56 -070088# define OD_SIGNMASK(a) (-((a) < 0))
89# define OD_FLIPSIGNI(a, b) (((a) + OD_SIGNMASK(b)) ^ OD_SIGNMASK(b))
90
James Zern5d986e52016-09-06 23:25:51 -070091#ifdef __cplusplus
92} // extern "C"
Yaowu Xuc27fc142016-08-22 16:08:15 -070093#endif
James Zern5d986e52016-09-06 23:25:51 -070094
Bohan Li3adb660d2021-08-24 17:59:14 -070095#endif // AOM_AOM_DSP_ODINTRIN_H_