Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 9c01aa1 | 2016-09-01 14:32:49 -0700 | [diff] [blame] | 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. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 12 | #ifndef AOM_DSP_AOM_DSP_COMMON_H_ |
| 13 | #define AOM_DSP_AOM_DSP_COMMON_H_ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 14 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 15 | #include "./aom_config.h" |
| 16 | #include "aom/aom_integer.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 17 | #include "aom_ports/mem.h" |
| 18 | |
| 19 | #ifdef __cplusplus |
| 20 | extern "C" { |
| 21 | #endif |
| 22 | |
| 23 | #ifndef MAX_SB_SIZE |
Debargha Mukherjee | 2ccf4b9 | 2018-02-27 17:30:46 -0800 | [diff] [blame] | 24 | #if CONFIG_AV1 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 25 | #define MAX_SB_SIZE 128 |
| 26 | #else |
| 27 | #define MAX_SB_SIZE 64 |
Debargha Mukherjee | 2ccf4b9 | 2018-02-27 17:30:46 -0800 | [diff] [blame] | 28 | #endif // CONFIG_AV1 |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 29 | #endif // ndef MAX_SB_SIZE |
| 30 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 31 | #define AOMMIN(x, y) (((x) < (y)) ? (x) : (y)) |
| 32 | #define AOMMAX(x, y) (((x) > (y)) ? (x) : (y)) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 33 | |
| 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 | |
Timothy B. Terriberry | 4e6a8f3 | 2017-02-24 11:00:59 -0800 | [diff] [blame] | 38 | /* Left shifting a negative value became undefined behavior in C99 (downgraded |
| 39 | from merely implementation-defined in C89). This should still compile to the |
| 40 | correct thing on any two's-complement machine, but avoid ubsan warnings.*/ |
| 41 | #define AOM_SIGNED_SHL(x, shift) ((x) * (((x)*0 + 1) << (shift))) |
| 42 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 43 | // These can be used to give a hint about branch outcomes. |
| 44 | // This can have an effect, even if your target processor has a |
| 45 | // good branch predictor, as these hints can affect basic block |
| 46 | // ordering by the compiler. |
| 47 | #ifdef __GNUC__ |
| 48 | #define LIKELY(v) __builtin_expect(v, 1) |
| 49 | #define UNLIKELY(v) __builtin_expect(v, 0) |
| 50 | #else |
| 51 | #define LIKELY(v) (v) |
| 52 | #define UNLIKELY(v) (v) |
| 53 | #endif |
| 54 | |
Yaowu Xu | cd44a05 | 2018-02-19 14:23:40 -0800 | [diff] [blame] | 55 | typedef uint8_t qm_val_t; |
Thomas Davies | 92aa22a | 2017-06-07 12:30:04 +0100 | [diff] [blame] | 56 | #define AOM_QM_BITS 5 |
Thomas Davies | f3b5ee1 | 2017-07-18 15:16:43 +0100 | [diff] [blame] | 57 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 58 | // Note: |
| 59 | // tran_low_t is the datatype used for final transform coefficients. |
| 60 | // tran_high_t is the datatype used for intermediate transform stages. |
| 61 | typedef int64_t tran_high_t; |
| 62 | typedef int32_t tran_low_t; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 63 | |
| 64 | static INLINE uint8_t clip_pixel(int val) { |
| 65 | return (val > 255) ? 255 : (val < 0) ? 0 : val; |
| 66 | } |
| 67 | |
| 68 | static INLINE int clamp(int value, int low, int high) { |
| 69 | return value < low ? low : (value > high ? high : value); |
| 70 | } |
| 71 | |
Debargha Mukherjee | f053cba | 2017-06-21 19:04:00 -0700 | [diff] [blame] | 72 | static INLINE int64_t clamp64(int64_t value, int64_t low, int64_t high) { |
| 73 | return value < low ? low : (value > high ? high : value); |
| 74 | } |
| 75 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 76 | static INLINE double fclamp(double value, double low, double high) { |
| 77 | return value < low ? low : (value > high ? high : value); |
| 78 | } |
| 79 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 80 | static INLINE uint16_t clip_pixel_highbd(int val, int bd) { |
| 81 | switch (bd) { |
| 82 | case 8: |
| 83 | default: return (uint16_t)clamp(val, 0, 255); |
| 84 | case 10: return (uint16_t)clamp(val, 0, 1023); |
| 85 | case 12: return (uint16_t)clamp(val, 0, 4095); |
| 86 | } |
| 87 | } |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 88 | |
| 89 | #ifdef __cplusplus |
| 90 | } // extern "C" |
| 91 | #endif |
| 92 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 93 | #endif // AOM_DSP_AOM_DSP_COMMON_H_ |