diff --git a/common/osdep.h b/common/osdep.h index 23739b7a6bf2e076e2503c1bb8d24d4c35878c1e..d737361342893722b7989e3f3ce29cf68cc3fa22 100644 --- a/common/osdep.h +++ b/common/osdep.h @@ -285,6 +285,9 @@ static inline int x264_is_regular_file( FILE *filehandle ) #define DECLARE_ALIGNED( var, n ) var __attribute__((aligned(n))) #endif +// Use DECLARE_ASM to declare variables that are accessed from hardcoded assembly +#define DECLARE_ASM( var ) var ATTR_MCMODEL_SMALL + #define ALIGNED_4( var ) DECLARE_ALIGNED( var, 4 ) #define ALIGNED_8( var ) DECLARE_ALIGNED( var, 8 ) #define ALIGNED_16( var ) DECLARE_ALIGNED( var, 16 ) @@ -363,6 +366,18 @@ static inline int x264_is_regular_file( FILE *filehandle ) #define x264_nonconstant_p(x) 0 #endif +#ifdef __has_attribute +#define HAS_ATTRIBUTE(x) __has_attribute(x) +#else +#define HAS_ATTRIBUTE(x) 0 +#endif + +#if ARCH_X86_64 && defined(__ELF__) && HAS_ATTRIBUTE(model) +#define ATTR_MCMODEL_SMALL __attribute__((model("small"))) +#else +#define ATTR_MCMODEL_SMALL +#endif + /* threads */ #if HAVE_BEOSTHREAD #include <kernel/OS.h> diff --git a/common/tables.h b/common/tables.h index b081908d6a566357b1b09beff523aea68f56a9da..7549886acdc1fd57a91e0a55c8928808399eb2ba 100644 --- a/common/tables.h +++ b/common/tables.h @@ -27,6 +27,7 @@ #ifndef X264_TABLES_H #define X264_TABLES_H +#include "osdep.h" typedef struct { uint8_t i_bits; @@ -67,28 +68,28 @@ extern const uint8_t x264_cqm_avci300_2160p_4iy[16]; extern const uint8_t x264_cqm_avci300_2160p_4ic[16]; extern const uint8_t x264_cqm_avci300_2160p_8iy[64]; -extern const uint8_t x264_decimate_table4[16]; -extern const uint8_t x264_decimate_table8[64]; +extern DECLARE_ASM(const uint8_t x264_decimate_table4[16]); +extern DECLARE_ASM(const uint8_t x264_decimate_table8[64]); -extern const uint32_t x264_dct4_weight_tab[16]; -extern const uint32_t x264_dct8_weight_tab[64]; -extern const uint32_t x264_dct4_weight2_tab[16]; -extern const uint32_t x264_dct8_weight2_tab[64]; +extern DECLARE_ASM(const uint32_t x264_dct4_weight_tab[16]); +extern DECLARE_ASM(const uint32_t x264_dct8_weight_tab[64]); +extern DECLARE_ASM(const uint32_t x264_dct4_weight2_tab[16]); +extern DECLARE_ASM(const uint32_t x264_dct8_weight2_tab[64]); extern const int8_t x264_cabac_context_init_I[1024][2]; extern const int8_t x264_cabac_context_init_PB[3][1024][2]; -extern const uint8_t x264_cabac_range_lps[64][4]; -extern const uint8_t x264_cabac_transition[128][2]; -extern const uint8_t x264_cabac_renorm_shift[64]; -extern const uint16_t x264_cabac_entropy[128]; +extern DECLARE_ASM(const uint8_t x264_cabac_range_lps[64][4]); +extern DECLARE_ASM(const uint8_t x264_cabac_transition[128][2]); +extern DECLARE_ASM(const uint8_t x264_cabac_renorm_shift[64]); +extern DECLARE_ASM(const uint16_t x264_cabac_entropy[128]); -extern const uint8_t x264_significant_coeff_flag_offset_8x8[2][64]; -extern const uint8_t x264_last_coeff_flag_offset_8x8[63]; -extern const uint8_t x264_coeff_flag_offset_chroma_422_dc[7]; -extern const uint16_t x264_significant_coeff_flag_offset[2][16]; -extern const uint16_t x264_last_coeff_flag_offset[2][16]; -extern const uint16_t x264_coeff_abs_level_m1_offset[16]; -extern const uint8_t x264_count_cat_m1[14]; +extern DECLARE_ASM(const uint8_t x264_significant_coeff_flag_offset_8x8[2][64]); +extern DECLARE_ASM(const uint8_t x264_last_coeff_flag_offset_8x8[63]); +extern DECLARE_ASM(const uint8_t x264_coeff_flag_offset_chroma_422_dc[7]); +extern DECLARE_ASM(const uint16_t x264_significant_coeff_flag_offset[2][16]); +extern DECLARE_ASM(const uint16_t x264_last_coeff_flag_offset[2][16]); +extern DECLARE_ASM(const uint16_t x264_coeff_abs_level_m1_offset[16]); +extern DECLARE_ASM(const uint8_t x264_count_cat_m1[14]); extern const vlc_t x264_coeff0_token[6]; extern const vlc_t x264_coeff_token[6][16][4]; diff --git a/encoder/rdo.c b/encoder/rdo.c index 9fc67610e4984725b3ef13e23ac24f5bc4b347e9..89fa897572ad9643a318a74fdb69605aeaf690fa 100644 --- a/encoder/rdo.c +++ b/encoder/rdo.c @@ -33,9 +33,9 @@ /* Transition and size tables for abs<9 MVD and residual coding */ /* Consist of i_prefix-2 1s, one zero, and a bypass sign bit */ #define x264_cabac_transition_unary x264_template(cabac_transition_unary) -uint8_t x264_cabac_transition_unary[15][128]; +DECLARE_ASM(uint8_t x264_cabac_transition_unary[15][128]); #define x264_cabac_size_unary x264_template(cabac_size_unary) -uint16_t x264_cabac_size_unary[15][128]; +DECLARE_ASM(uint16_t x264_cabac_size_unary[15][128]); /* Transition and size tables for abs>9 MVD */ /* Consist of 5 1s and a bypass sign bit */ static uint8_t cabac_transition_5ones[128];