blob: a7ea1b973ff216b972ceaf5568f633608c594838 [file] [log] [blame]
Yaowu Xuc27fc142016-08-22 16:08:15 -07001/*
Yaowu Xu9c01aa12016-09-01 14:32:49 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc27fc142016-08-22 16:08:15 -07003 *
Yaowu Xu9c01aa12016-09-01 14:32:49 -07004 * 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.
Yaowu Xuc27fc142016-08-22 16:08:15 -070010 */
11
Yaowu Xuf883b422016-08-30 14:01:10 -070012#ifndef AOM_DSP_AOM_DSP_COMMON_H_
13#define AOM_DSP_AOM_DSP_COMMON_H_
Yaowu Xuc27fc142016-08-22 16:08:15 -070014
Yaowu Xuf883b422016-08-30 14:01:10 -070015#include "./aom_config.h"
16#include "aom/aom_integer.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070017#include "aom_ports/mem.h"
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23#ifndef MAX_SB_SIZE
Yaowu Xuf883b422016-08-30 14:01:10 -070024#if CONFIG_AV1 && CONFIG_EXT_PARTITION
Yaowu Xuc27fc142016-08-22 16:08:15 -070025#define MAX_SB_SIZE 128
26#else
27#define MAX_SB_SIZE 64
Yaowu Xuf883b422016-08-30 14:01:10 -070028#endif // CONFIG_AV1 && CONFIG_EXT_PARTITION
Yaowu Xuc27fc142016-08-22 16:08:15 -070029#endif // ndef MAX_SB_SIZE
30
Yaowu Xuf883b422016-08-30 14:01:10 -070031#define AOMMIN(x, y) (((x) < (y)) ? (x) : (y))
32#define AOMMAX(x, y) (((x) > (y)) ? (x) : (y))
Yaowu Xuc27fc142016-08-22 16:08:15 -070033
34#define IMPLIES(a, b) (!(a) || (b)) // Logical 'a implies b' (or 'a -> b')
35
36#define IS_POWER_OF_TWO(x) (((x) & ((x)-1)) == 0)
37
38// These can be used to give a hint about branch outcomes.
39// This can have an effect, even if your target processor has a
40// good branch predictor, as these hints can affect basic block
41// ordering by the compiler.
42#ifdef __GNUC__
43#define LIKELY(v) __builtin_expect(v, 1)
44#define UNLIKELY(v) __builtin_expect(v, 0)
45#else
46#define LIKELY(v) (v)
47#define UNLIKELY(v) (v)
48#endif
49
Yaowu Xuf883b422016-08-30 14:01:10 -070050#define AOM_SWAP(type, a, b) \
Yaowu Xuc27fc142016-08-22 16:08:15 -070051 do { \
52 type c = (b); \
53 b = a; \
54 a = c; \
55 } while (0)
56
57#if CONFIG_AOM_QM
58typedef uint16_t qm_val_t;
59#define AOM_QM_BITS 6
60#endif
Yaowu Xuf883b422016-08-30 14:01:10 -070061#if CONFIG_AOM_HIGHBITDEPTH
Yaowu Xuc27fc142016-08-22 16:08:15 -070062// Note:
63// tran_low_t is the datatype used for final transform coefficients.
64// tran_high_t is the datatype used for intermediate transform stages.
65typedef int64_t tran_high_t;
66typedef int32_t tran_low_t;
67#else
68// Note:
69// tran_low_t is the datatype used for final transform coefficients.
70// tran_high_t is the datatype used for intermediate transform stages.
71typedef int32_t tran_high_t;
72typedef int16_t tran_low_t;
Yaowu Xuf883b422016-08-30 14:01:10 -070073#endif // CONFIG_AOM_HIGHBITDEPTH
Yaowu Xuc27fc142016-08-22 16:08:15 -070074
75static INLINE uint8_t clip_pixel(int val) {
76 return (val > 255) ? 255 : (val < 0) ? 0 : val;
77}
78
79static INLINE int clamp(int value, int low, int high) {
80 return value < low ? low : (value > high ? high : value);
81}
82
83static INLINE double fclamp(double value, double low, double high) {
84 return value < low ? low : (value > high ? high : value);
85}
86
Yaowu Xuf883b422016-08-30 14:01:10 -070087#if CONFIG_AOM_HIGHBITDEPTH
Yaowu Xuc27fc142016-08-22 16:08:15 -070088static INLINE uint16_t clip_pixel_highbd(int val, int bd) {
89 switch (bd) {
90 case 8:
91 default: return (uint16_t)clamp(val, 0, 255);
92 case 10: return (uint16_t)clamp(val, 0, 1023);
93 case 12: return (uint16_t)clamp(val, 0, 4095);
94 }
95}
Yaowu Xuf883b422016-08-30 14:01:10 -070096#endif // CONFIG_AOM_HIGHBITDEPTH
Yaowu Xuc27fc142016-08-22 16:08:15 -070097
98#ifdef __cplusplus
99} // extern "C"
100#endif
101
Yaowu Xuf883b422016-08-30 14:01:10 -0700102#endif // AOM_DSP_AOM_DSP_COMMON_H_