enums.h: Combine related #defines into packed enums.

enums for BLOCK_SIZE, TX_SIZE and PREDICTION_MODE.

Note: These were converted to #defines earlier to save on memory:
https://chromium-review.googlesource.com/#/c/269854/

But we, instead, use attribute 'packed' (see here:
https://gcc.gnu.org/onlinedocs/gcc/Common-Type-Attributes.html#Common-Type-Attributes)
to ensure that these enums use the smallest possible integer type,
and so use smallest memory when used in structs/arrays etc.

Change-Id: If1fc136686b28847109c9f3a06f8728165e7e475
This commit is contained in:
Urvang Joshi 2016-09-20 11:36:33 -07:00
Родитель 7a9ad9c83f
Коммит cb586f3ba9
7 изменённых файлов: 104 добавлений и 104 удалений

Просмотреть файл

@ -76,6 +76,17 @@ extern "C" {
#define UNUSED #define UNUSED
#endif #endif
/*!\brief Decorator indicating that given struct/union/enum is packed */
#ifndef ATTRIBUTE_PACKED
#if defined(__GNUC__) && __GNUC__
#define ATTRIBUTE_PACKED __attribute__((packed))
#elif defined(_MSC_VER)
#define ATTRIBUTE_PACKED
#else
#define ATTRIBUTE_PACKED
#endif
#endif /* ATTRIBUTE_PACKED */
/*!\brief Current ABI version number /*!\brief Current ABI version number
* *
* \internal * \internal

Просмотреть файл

@ -399,7 +399,7 @@ typedef struct macroblockd {
static INLINE BLOCK_SIZE get_subsize(BLOCK_SIZE bsize, static INLINE BLOCK_SIZE get_subsize(BLOCK_SIZE bsize,
PARTITION_TYPE partition) { PARTITION_TYPE partition) {
if (partition == PARTITION_INVALID) if (partition == PARTITION_INVALID)
return PARTITION_INVALID; return BLOCK_INVALID;
else else
return subsize_lookup[partition][bsize]; return subsize_lookup[partition][bsize];
} }
@ -756,8 +756,10 @@ static INLINE int is_interintra_allowed(const MB_MODE_INFO *mbmi) {
static INLINE int is_interintra_allowed_bsize_group(const int group) { static INLINE int is_interintra_allowed_bsize_group(const int group) {
int i; int i;
for (i = 0; i < BLOCK_SIZES; i++) { for (i = 0; i < BLOCK_SIZES; i++) {
if (size_group_lookup[i] == group && is_interintra_allowed_bsize(i)) if (size_group_lookup[i] == group &&
is_interintra_allowed_bsize((BLOCK_SIZE)i)) {
return 1; return 1;
}
} }
return 0; return 0;
} }

Просмотреть файл

@ -13,6 +13,7 @@
#define AV1_COMMON_ENUMS_H_ #define AV1_COMMON_ENUMS_H_
#include "./aom_config.h" #include "./aom_config.h"
#include "aom/aom_codec.h"
#include "aom/aom_integer.h" #include "aom/aom_integer.h"
#ifdef __cplusplus #ifdef __cplusplus
@ -72,55 +73,49 @@ typedef enum BITSTREAM_PROFILE {
MAX_PROFILES MAX_PROFILES
} BITSTREAM_PROFILE; } BITSTREAM_PROFILE;
#define BLOCK_4X4 0 // Note: Some enums use the attribute 'packed' to use smallest possible integer
#define BLOCK_4X8 1 // type, so that we can save memory when they are used in structs/arrays.
#define BLOCK_8X4 2
#define BLOCK_8X8 3
#define BLOCK_8X16 4
#define BLOCK_16X8 5
#define BLOCK_16X16 6
#define BLOCK_16X32 7
#define BLOCK_32X16 8
#define BLOCK_32X32 9
#define BLOCK_32X64 10
#define BLOCK_64X32 11
#define BLOCK_64X64 12
#if !CONFIG_EXT_PARTITION
#define BLOCK_SIZES 13
#else
#define BLOCK_64X128 13
#define BLOCK_128X64 14
#define BLOCK_128X128 15
#define BLOCK_SIZES 16
#endif // !CONFIG_EXT_PARTITION
#define BLOCK_INVALID BLOCK_SIZES
#define BLOCK_LARGEST (BLOCK_SIZES - 1)
typedef uint8_t BLOCK_SIZE;
#if CONFIG_EXT_PARTITION_TYPES typedef enum ATTRIBUTE_PACKED {
typedef enum PARTITION_TYPE { BLOCK_4X4,
BLOCK_4X8,
BLOCK_8X4,
BLOCK_8X8,
BLOCK_8X16,
BLOCK_16X8,
BLOCK_16X16,
BLOCK_16X32,
BLOCK_32X16,
BLOCK_32X32,
BLOCK_32X64,
BLOCK_64X32,
BLOCK_64X64,
#if CONFIG_EXT_PARTITION
BLOCK_64X128,
BLOCK_128X64,
BLOCK_128X128,
#endif // CONFIG_EXT_PARTITION
BLOCK_SIZES,
BLOCK_INVALID = BLOCK_SIZES,
BLOCK_LARGEST = (BLOCK_SIZES - 1)
} BLOCK_SIZE;
typedef enum {
PARTITION_NONE, PARTITION_NONE,
PARTITION_HORZ, PARTITION_HORZ,
PARTITION_VERT, PARTITION_VERT,
PARTITION_SPLIT, PARTITION_SPLIT,
#if CONFIG_EXT_PARTITION_TYPES
PARTITION_HORZ_A, // HORZ split and the left partition is split again PARTITION_HORZ_A, // HORZ split and the left partition is split again
PARTITION_HORZ_B, // HORZ split and the right partition is split again PARTITION_HORZ_B, // HORZ split and the right partition is split again
PARTITION_VERT_A, // VERT split and the top partition is split again PARTITION_VERT_A, // VERT split and the top partition is split again
PARTITION_VERT_B, // VERT split and the bottom partition is split again PARTITION_VERT_B, // VERT split and the bottom partition is split again
EXT_PARTITION_TYPES, EXT_PARTITION_TYPES,
PARTITION_TYPES = PARTITION_SPLIT + 1,
PARTITION_INVALID = EXT_PARTITION_TYPES
} PARTITION_TYPE;
#else
typedef enum PARTITION_TYPE {
PARTITION_NONE,
PARTITION_HORZ,
PARTITION_VERT,
PARTITION_SPLIT,
PARTITION_TYPES,
PARTITION_INVALID = PARTITION_TYPES
} PARTITION_TYPE;
#endif // CONFIG_EXT_PARTITION_TYPES #endif // CONFIG_EXT_PARTITION_TYPES
PARTITION_TYPES = PARTITION_SPLIT + 1,
PARTITION_INVALID = 255
} PARTITION_TYPE;
typedef char PARTITION_CONTEXT; typedef char PARTITION_CONTEXT;
#define PARTITION_PLOFFSET 4 // number of probability models per block size #define PARTITION_PLOFFSET 4 // number of probability models per block size
@ -131,25 +126,23 @@ typedef char PARTITION_CONTEXT;
#endif // CONFIG_EXT_PARTITION #endif // CONFIG_EXT_PARTITION
// block transform size // block transform size
typedef uint8_t TX_SIZE; typedef enum ATTRIBUTE_PACKED {
#define TX_4X4 ((TX_SIZE)0) // 4x4 transform TX_4X4, // 4x4 transform
#define TX_8X8 ((TX_SIZE)1) // 8x8 transform TX_8X8, // 8x8 transform
#define TX_16X16 ((TX_SIZE)2) // 16x16 transform TX_16X16, // 16x16 transform
#define TX_32X32 ((TX_SIZE)3) // 32x32 transform TX_32X32, // 32x32 transform
#define TX_SIZES ((TX_SIZE)4)
#define TX_INVALID ((TX_SIZE)255) // Invalid transform size
#if CONFIG_EXT_TX #if CONFIG_EXT_TX
#define TX_4X8 ((TX_SIZE)4) // 4x8 transform TX_4X8, // 4x8 transform
#define TX_8X4 ((TX_SIZE)5) // 8x4 transform TX_8X4, // 8x4 transform
#define TX_8X16 ((TX_SIZE)6) // 8x16 transform TX_8X16, // 8x16 transform
#define TX_16X8 ((TX_SIZE)7) // 16x8 transform TX_16X8, // 16x8 transform
#define TX_16X32 ((TX_SIZE)8) // 16x32 transform TX_16X32, // 16x32 transform
#define TX_32X16 ((TX_SIZE)9) // 32x16 transform TX_32X16, // 32x16 transform
#define TX_SIZES_ALL ((TX_SIZE)10) // Includes rectangular transforms #endif // CONFIG_EXT_TX
#else TX_SIZES_ALL, // Includes rectangular transforms
#define TX_SIZES_ALL ((TX_SIZE)4) TX_SIZES = TX_32X32 + 1, // Does NOT include rectangular transforms
#endif // CONFIG_EXT_TX TX_INVALID = 255 // Invalid transform size
} TX_SIZE;
#define MAX_TX_SIZE_LOG2 5 #define MAX_TX_SIZE_LOG2 5
#define MAX_TX_SIZE (1 << MAX_TX_SIZE_LOG2) #define MAX_TX_SIZE (1 << MAX_TX_SIZE_LOG2)
@ -253,39 +246,37 @@ typedef enum {
PALETTE_COLORS PALETTE_COLORS
} PALETTE_COLOR; } PALETTE_COLOR;
#define DC_PRED 0 // Average of above and left pixels typedef enum ATTRIBUTE_PACKED {
#define V_PRED 1 // Vertical DC_PRED, // Average of above and left pixels
#define H_PRED 2 // Horizontal V_PRED, // Vertical
#define D45_PRED 3 // Directional 45 deg = round(arctan(1/1) * 180/pi) H_PRED, // Horizontal
#define D135_PRED 4 // Directional 135 deg = 180 - 45 D45_PRED, // Directional 45 deg = round(arctan(1/1) * 180/pi)
#define D117_PRED 5 // Directional 117 deg = 180 - 63 D135_PRED, // Directional 135 deg = 180 - 45
#define D153_PRED 6 // Directional 153 deg = 180 - 27 D117_PRED, // Directional 117 deg = 180 - 63
#define D207_PRED 7 // Directional 207 deg = 180 + 27 D153_PRED, // Directional 153 deg = 180 - 27
#define D63_PRED 8 // Directional 63 deg = round(arctan(2/1) * 180/pi) D207_PRED, // Directional 207 deg = 180 + 27
#define TM_PRED 9 // True-motion D63_PRED, // Directional 63 deg = round(arctan(2/1) * 180/pi)
#define NEARESTMV 10 TM_PRED, // True-motion
#define NEARMV 11 NEARESTMV,
#define ZEROMV 12 NEARMV,
#define NEWMV 13 ZEROMV,
NEWMV,
#if CONFIG_EXT_INTER #if CONFIG_EXT_INTER
#define NEWFROMNEARMV 14 NEWFROMNEARMV,
#define NEAREST_NEARESTMV 15 NEAREST_NEARESTMV,
#define NEAREST_NEARMV 16 NEAREST_NEARMV,
#define NEAR_NEARESTMV 17 NEAR_NEARESTMV,
#define NEAR_NEARMV 18 NEAR_NEARMV,
#define NEAREST_NEWMV 19 NEAREST_NEWMV,
#define NEW_NEARESTMV 20 NEW_NEARESTMV,
#define NEAR_NEWMV 21 NEAR_NEWMV,
#define NEW_NEARMV 22 NEW_NEARMV,
#define ZERO_ZEROMV 23 ZERO_ZEROMV,
#define NEW_NEWMV 24 NEW_NEWMV,
#define MB_MODE_COUNT 25
#else
#define MB_MODE_COUNT 14
#endif // CONFIG_EXT_INTER #endif // CONFIG_EXT_INTER
typedef uint8_t PREDICTION_MODE; MB_MODE_COUNT,
INTRA_MODES = TM_PRED + 1
#define INTRA_MODES (TM_PRED + 1) } PREDICTION_MODE;
typedef enum { typedef enum {
SIMPLE_TRANSLATION = 0, SIMPLE_TRANSLATION = 0,

Просмотреть файл

@ -226,8 +226,8 @@ static void update_tx_counts(AV1_COMMON *cm, MACROBLOCKD *xd,
const int offsetc = blk_col + ((i & 0x01) << bsl); const int offsetc = blk_col + ((i & 0x01) << bsl);
if (offsetr >= max_blocks_high || offsetc >= max_blocks_wide) continue; if (offsetr >= max_blocks_high || offsetc >= max_blocks_wide) continue;
update_tx_counts(cm, xd, mbmi, plane_bsize, tx_size - 1, offsetr, offsetc, update_tx_counts(cm, xd, mbmi, plane_bsize, (TX_SIZE)(tx_size - 1),
max_tx_size, ctx); offsetr, offsetc, max_tx_size, ctx);
} }
} }
} }

Просмотреть файл

@ -2132,7 +2132,7 @@ static void get_coef_counts_diff(AV1_COMP *cpi, int index,
int i, j, k, l, m, tx_size, val; int i, j, k, l, m, tx_size, val;
const int max_idx = cpi->common.coef_probs_update_idx; const int max_idx = cpi->common.coef_probs_update_idx;
const TX_MODE tx_mode = cpi->common.tx_mode; const TX_MODE tx_mode = cpi->common.tx_mode;
const TX_SIZE max_tx_size = tx_mode_to_biggest_tx_size[tx_mode]; const int max_tx_size = tx_mode_to_biggest_tx_size[tx_mode];
const SUBFRAME_STATS *subframe_stats = &cpi->subframe_stats; const SUBFRAME_STATS *subframe_stats = &cpi->subframe_stats;
assert(max_idx < COEF_PROBS_BUFS); assert(max_idx < COEF_PROBS_BUFS);
@ -3265,7 +3265,7 @@ static void write_uncompressed_header(AV1_COMP *cpi,
encode_quantization(cm, wb); encode_quantization(cm, wb);
encode_segmentation(cm, xd, wb); encode_segmentation(cm, xd, wb);
if (!cm->seg.enabled && xd->lossless[0]) if (!cm->seg.enabled && xd->lossless[0])
cm->tx_mode = TX_4X4; cm->tx_mode = ONLY_4X4;
else else
write_txfm_mode(cm->tx_mode, wb); write_txfm_mode(cm->tx_mode, wb);

Просмотреть файл

@ -1069,7 +1069,7 @@ void av1_update_rd_thresh_fact(const AV1_COMMON *const cm,
int mode; int mode;
for (mode = 0; mode < top_mode; ++mode) { for (mode = 0; mode < top_mode; ++mode) {
const BLOCK_SIZE min_size = AOMMAX(bsize - 1, BLOCK_4X4); const BLOCK_SIZE min_size = AOMMAX(bsize - 1, BLOCK_4X4);
const BLOCK_SIZE max_size = AOMMIN(bsize + 2, cm->sb_size); const BLOCK_SIZE max_size = AOMMIN(bsize + 2, (int)cm->sb_size);
BLOCK_SIZE bs; BLOCK_SIZE bs;
for (bs = min_size; bs <= max_size; ++bs) { for (bs = min_size; bs <= max_size; ++bs) {
int *const fact = &factor_buf[bs][mode]; int *const fact = &factor_buf[bs][mode];

Просмотреть файл

@ -179,17 +179,13 @@ class AV1QuantizeTest : public ::testing::TestWithParam<QuantizeFuncParams> {
private: private:
TX_SIZE getTxSize(int count) { TX_SIZE getTxSize(int count) {
TX_SIZE txSize = 0; switch (count) {
if (16 == count) { case 16: return TX_4X4;
txSize = 0; case 64: return TX_8X8;
} else if (64 == count) { case 256: return TX_16X16;
txSize = 1; case 1024: return TX_32X32;
} else if (256 == count) { default: return TX_4X4;
txSize = 2;
} else if (1024 == count) {
txSize = 3;
} }
return txSize;
} }
QuantizeFuncParams params_; QuantizeFuncParams params_;