Commit a910049a authored by John Koleszar's avatar John Koleszar

New RTCD implementation

This is a proof of concept RTCD implementation to replace the current
system of nested includes, prototypes, INVOKE macros, etc. Currently
only the decoder specific functions are implemented in the new system.
Additional functions will be added in subsequent commits.

Overview:
  RTCD "functions" are implemented as either a global function pointer
  or a macro (when only one eligible specialization available).
  Functions which have RTCD specializations are listed using a simple
  DSL identifying the function's base name, its prototype, and the
  architecture extensions that specializations are available for.

Advantages over the old system:
  - No INVOKE macros. A call to an RTCD function looks like an ordinary
    function call.
  - No need to pass vtables around.
  - If there is only one eligible function to call, the function is
    called directly, rather than indirecting through a function pointer.
  - Supports the notion of "required" extensions, so in combination with
    the above, on x86_64 if the best function available is sse2 or lower
    it will be called directly, since all x86_64 platforms implement
    sse2.
  - Elides all references to functions which will never be called, which
    could reduce binary size. For example if sse2 is required and there
    are both mmx and sse2 implementations of a certain function, the
    code will have no link time references to the mmx code.
  - Significantly easier to add a new function, just one file to edit.

Disadvantages:
  - Requires global writable data (though this is not a new requirement)
  - 1 new generated source file.

Change-Id: Iae6edab65315f79c168485c96872641c5aa09d55
parent 57cc35dd
......@@ -391,6 +391,7 @@ LDFLAGS = ${LDFLAGS}
ASFLAGS = ${ASFLAGS}
extralibs = ${extralibs}
AS_SFX = ${AS_SFX:-.asm}
RTCD_OPTIONS = ${RTCD_OPTIONS}
EOF
if enabled rvct; then cat >> $1 << EOF
......@@ -454,9 +455,22 @@ process_common_cmdline() {
;;
--enable-?*|--disable-?*)
eval `echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g'`
echo "${CMDLINE_SELECT} ${ARCH_EXT_LIST}" | grep "^ *$option\$" >/dev/null || die_unknown $opt
if echo "${ARCH_EXT_LIST}" | grep "^ *$option\$" >/dev/null; then
[ $action = "disable" ] && RTCD_OPTIONS="${RTCD_OPTIONS}${opt} "
else
echo "${CMDLINE_SELECT}" | grep "^ *$option\$" >/dev/null ||
die_unknown $opt
fi
$action $option
;;
--require-?*)
eval `echo "$opt" | sed 's/--/action=/;s/-/ option=/;s/-/_/g'`
if echo "${ARCH_EXT_LIST}" none | grep "^ *$option\$" >/dev/null; then
RTCD_OPTIONS="${RTCD_OPTIONS}${opt} "
else
die_unknown $opt
fi
;;
--force-enable-?*|--force-disable-?*)
eval `echo "$opt" | sed 's/--force-/action=/;s/-/ option=/;s/-/_/g'`
$action $option
......
#!/bin/sh
self=$0
usage() {
cat <<EOF >&2
Usage: $self [options] FILE
Reads the Run Time CPU Detections definitions from FILE and generates a
C header file on stdout.
Options:
--arch=ARCH Architecture to generate defs for (required)
--disable-EXT Disable support for EXT extensions
--require-EXT Require support for EXT extensions
--sym=SYMBOL Unique symbol to use for RTCD initialization function
--config=FILE File with CONFIG_FOO=yes lines to parse
EOF
exit 1
}
die() {
echo "$@" >&2
exit 1
}
die_argument_required() {
die "Option $opt requires argument"
}
for opt; do
optval="${opt#*=}"
case "$opt" in
--arch) die_argument_required;;
--arch=*) arch=${optval};;
--disable-*) eval "disable_${opt#--disable-}=true";;
--require-*) REQUIRES="${REQUIRES}${opt#--require-} ";;
--sym) die_argument_required;;
--sym=*) symbol=${optval};;
--config=*) config_file=${optval};;
-h|--help)
usage
;;
-*)
die "Unrecognized option: ${opt%%=*}"
;;
*)
defs_file="$defs_file $opt"
;;
esac
shift
done
for f in $defs_file; do [ -f "$f" ] || usage; done
[ -n "$arch" ] || usage
# Import the configuration
[ -f "$config_file" ] && eval $(grep CONFIG_ "$config_file")
#
# Routines for the RTCD DSL to call
#
prototype() {
local rtyp
case "$1" in
unsigned) rtyp="$1 "; shift;;
esac
rtyp="${rtyp}$1"
local fn="$2"
local args="$3"
eval "${2}_rtyp='$rtyp'"
eval "${2}_args='$3'"
ALL_FUNCS="$ALL_FUNCS $fn"
specialize $fn c
}
specialize() {
local fn="$1"
shift
for opt in "$@"; do
eval "${fn}_${opt}=${fn}_${opt}"
done
}
require() {
for fn in $ALL_FUNCS; do
for opt in "$@"; do
local ofn=$(eval "echo \$${fn}_${opt}")
[ -z "$ofn" ] && continue
# if we already have a default, then we can disable it, as we know
# we can do better.
local best=$(eval "echo \$${fn}_default")
local best_ofn=$(eval "echo \$${best}")
[ -n "$best" ] && [ "$best_ofn" != "$ofn" ] && eval "${best}_link=false"
eval "${fn}_default=${fn}_${opt}"
eval "${fn}_${opt}_link=true"
done
done
}
forward_decls() {
ALL_FORWARD_DECLS="$ALL_FORWARD_DECLS $1"
}
#
# Include the user's directives
#
for f in $defs_file; do
. $f
done
#
# Process the directives according to the command line
#
process_forward_decls() {
for fn in $ALL_FORWARD_DECLS; do
eval $fn
done
}
determine_indirection() {
[ "$CONFIG_RUNTIME_CPU_DETECT" = "yes" ] || require $ALL_ARCHS
for fn in $ALL_FUNCS; do
local n=""
local rtyp="$(eval "echo \$${fn}_rtyp")"
local args="$(eval "echo \"\$${fn}_args\"")"
local dfn="$(eval "echo \$${fn}_default")"
dfn=$(eval "echo \$${dfn}")
for opt in "$@"; do
local ofn=$(eval "echo \$${fn}_${opt}")
[ -z "$ofn" ] && continue
local link=$(eval "echo \$${fn}_${opt}_link")
[ "$link" = "false" ] && continue
n="${n}x"
done
if [ "$n" = "x" ]; then
eval "${fn}_indirect=false"
else
eval "${fn}_indirect=true"
fi
done
}
declare_function_pointers() {
for fn in $ALL_FUNCS; do
local rtyp="$(eval "echo \$${fn}_rtyp")"
local args="$(eval "echo \"\$${fn}_args\"")"
local dfn="$(eval "echo \$${fn}_default")"
dfn=$(eval "echo \$${dfn}")
for opt in "$@"; do
local ofn=$(eval "echo \$${fn}_${opt}")
[ -z "$ofn" ] && continue
echo "$rtyp ${ofn}($args);"
done
if [ "$(eval "echo \$${fn}_indirect")" = "false" ]; then
echo "#define ${fn} ${dfn}"
else
echo "RTCD_EXTERN $rtyp (*${fn})($args);"
fi
echo
done
}
set_function_pointers() {
for fn in $ALL_FUNCS; do
local n=""
local rtyp="$(eval "echo \$${fn}_rtyp")"
local args="$(eval "echo \"\$${fn}_args\"")"
local dfn="$(eval "echo \$${fn}_default")"
dfn=$(eval "echo \$${dfn}")
if $(eval "echo \$${fn}_indirect"); then
echo " $fn = $dfn;"
for opt in "$@"; do
local ofn=$(eval "echo \$${fn}_${opt}")
[ -z "$ofn" ] && continue
[ "$ofn" = "$dfn" ] && continue;
local link=$(eval "echo \$${fn}_${opt}_link")
[ "$link" = "false" ] && continue
local cond="$(eval "echo \$have_${opt}")"
echo " if (${cond}) $fn = $ofn;"
done
fi
echo
done
}
filter() {
local filtered
for opt in "$@"; do
[ -z $(eval "echo \$disable_${opt}") ] && filtered="$filtered $opt"
done
echo $filtered
}
#
# Helper functions for generating the arch specific RTCD files
#
common_top() {
local outfile_basename=$(basename ${outfile:-rtcd.h})
local include_guard=$(echo -n $outfile_basename | tr '[a-z]' '[A-Z]' | tr -c '[A-Z]' _)
cat <<EOF
#ifndef ${include_guard}
#define ${include_guard}
#ifdef RTCD_C
#define RTCD_EXTERN
#else
#define RTCD_EXTERN extern
#endif
$(process_forward_decls)
$(declare_function_pointers c $ALL_ARCHS)
EOF
}
common_bottom() {
cat <<EOF
#endif
EOF
}
x86() {
determine_indirection c $ALL_ARCHS
# Assign the helper variable for each enabled extension
for opt in $ALL_ARCHS; do
local uc=$(echo -n $opt | tr '[a-z]' '[A-Z]')
eval "have_${opt}=\"flags & HAS_${uc}\""
done
cat <<EOF
$(common_top)
void ${symbol:-rtcd}(void);
#ifdef RTCD_C
#include "vpx_ports/x86.h"
void ${symbol:-rtcd}(void)
{
int flags = x86_simd_caps();
(void)flags;
$(set_function_pointers c $ALL_ARCHS)
}
#endif
$(common_bottom)
EOF
}
arm() {
determine_indirection c $ALL_ARCHS
# Assign the helper variable for each enabled extension
for opt in $ALL_ARCHS; do
local uc=$(echo -n $opt | tr '[a-z]' '[A-Z]')
eval "have_${opt}=\"flags & HAS_${uc}\""
done
cat <<EOF
$(common_top)
#include "vpx_config.h"
void ${symbol:-rtcd}(void);
#ifdef RTCD_C
#include "vpx_ports/arm.h"
void ${symbol:-rtcd}(void)
{
int flags = arm_cpu_caps();
(void)flags;
$(set_function_pointers c $ALL_ARCHS)
}
#endif
$(common_bottom)
EOF
}
unoptimized() {
determine_indirection c
cat <<EOF
$(common_top)
#include "vpx_config.h"
void ${symbol:-rtcd}(void);
#ifdef RTCD_C
void ${symbol:-rtcd}(void)
{
$(set_function_pointers c)
}
#endif
$(common_bottom)
EOF
}
#
# Main Driver
#
require c
case $arch in
x86)
ALL_ARCHS=$(filter mmx sse sse2 sse3 ssse3 sse4_1)
x86
;;
x86_64)
ALL_ARCHS=$(filter mmx sse sse2 sse3 ssse3 sse4_1)
REQUIRES=${REQUIRES:-mmx sse sse2}
require $(filter $REQUIRES)
x86
;;
armv5te)
ALL_ARCHS=$(filter edsp)
arm
;;
armv6)
ALL_ARCHS=$(filter edsp media)
arm
;;
armv7)
ALL_ARCHS=$(filter edsp media neon)
arm
;;
*)
unoptimized
;;
esac
......@@ -48,7 +48,6 @@ ifeq ($(CONFIG_VP8_DECODER),yes)
CODEC_SRCS-yes += $(addprefix $(VP8_PREFIX),$(call enabled,VP8_DX_SRCS))
CODEC_EXPORTS-yes += $(addprefix $(VP8_PREFIX),$(VP8_DX_EXPORTS))
CODEC_SRCS-yes += $(VP8_PREFIX)vp8dx.mk vpx/vp8.h vpx/vp8dx.h
CODEC_SRCS-$(ARCH_ARM) += $(VP8_PREFIX)vp8dx_arm.mk
INSTALL-LIBS-yes += include/vpx/vp8.h include/vpx/vp8dx.h
INSTALL_MAPS += include/vpx/% $(SRC_PATH_BARE)/$(VP8_PREFIX)/%
CODEC_DOC_SRCS += vpx/vp8.h vpx/vp8dx.h
......@@ -90,6 +89,7 @@ endif
$(eval $(if $(filter universal%,$(TOOLCHAIN)),LIPO_LIBVPX,BUILD_LIBVPX):=yes)
CODEC_SRCS-$(BUILD_LIBVPX) += build/make/version.sh
CODEC_SRCS-$(BUILD_LIBVPX) += build/make/rtcd.sh
CODEC_SRCS-$(BUILD_LIBVPX) += vpx/vpx_integer.h
CODEC_SRCS-$(BUILD_LIBVPX) += vpx_ports/asm_offsets.h
CODEC_SRCS-$(BUILD_LIBVPX) += vpx_ports/vpx_timer.h
......@@ -183,6 +183,7 @@ vpx.vcproj: $(CODEC_SRCS) vpx.def
PROJECTS-$(BUILD_LIBVPX) += vpx.vcproj
vpx.vcproj: vpx_config.asm
vpx.vcproj: vpx_rtcd.h
endif
else
......@@ -322,6 +323,18 @@ endif
$(shell $(SRC_PATH_BARE)/build/make/version.sh "$(SRC_PATH_BARE)" $(BUILD_PFX)vpx_version.h)
CLEAN-OBJS += $(BUILD_PFX)vpx_version.h
#
# Rule to generate runtime cpu detection files
#
$(OBJS-yes:.o=.d): vpx_rtcd.h
vpx_rtcd.h: $(sort $(filter %rtcd_defs.sh,$(CODEC_SRCS)))
@echo " [CREATE] $@"
$(qexec)$(SRC_PATH_BARE)/build/make/rtcd.sh --arch=$(TGT_ISA) \
--sym=vpx_rtcd \
--config=$(target)$(if $(FAT_ARCHS),,-$(TOOLCHAIN)).mk \
$(RTCD_OPTIONS) $^ > $@
CLEAN-OBJS += $(BUILD_PFX)vpx_rtcd.h
CODEC_DOC_SRCS += vpx/vpx_codec.h \
vpx/vpx_decoder.h \
vpx/vpx_encoder.h \
......
......@@ -62,12 +62,6 @@ void vp8_arch_arm_common_init(VP8_COMMON *ctx)
rtcd->recon.copy8x8 = vp8_copy_mem8x8_v6;
rtcd->recon.copy8x4 = vp8_copy_mem8x4_v6;
rtcd->recon.intra4x4_predict = vp8_intra4x4_predict_armv6;
rtcd->dequant.block = vp8_dequantize_b_v6;
rtcd->dequant.idct_add = vp8_dequant_idct_add_v6;
rtcd->dequant.idct_add_y_block = vp8_dequant_idct_add_y_block_v6;
rtcd->dequant.idct_add_uv_block = vp8_dequant_idct_add_uv_block_v6;
}
#endif
......@@ -102,12 +96,6 @@ void vp8_arch_arm_common_init(VP8_COMMON *ctx)
vp8_build_intra_predictors_mby_neon;
rtcd->recon.build_intra_predictors_mby_s =
vp8_build_intra_predictors_mby_s_neon;
rtcd->dequant.block = vp8_dequantize_b_neon;
rtcd->dequant.idct_add = vp8_dequant_idct_add_neon;
rtcd->dequant.idct_add_y_block = vp8_dequant_idct_add_y_block_neon;
rtcd->dequant.idct_add_uv_block = vp8_dequant_idct_add_uv_block_neon;
}
#endif
......
......@@ -10,7 +10,6 @@
#include "vpx_config.h"
#include "vp8/common/idct.h"
#include "vp8/common/dequantize.h"
void vp8_dequant_idct_add_y_block_v6(short *q, short *dq,
......
......@@ -10,8 +10,7 @@
#include "vpx_config.h"
#include "vp8/common/dequantize.h"
#include "vp8/common/idct.h"
#include "vp8/common/blockd.h"
#if HAVE_NEON
extern void vp8_dequantize_b_loop_neon(short *Q, short *DQC, short *DQ);
......
/*
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef DEQUANTIZE_ARM_H
#define DEQUANTIZE_ARM_H
#if HAVE_MEDIA
extern prototype_dequant_block(vp8_dequantize_b_v6);
extern prototype_dequant_idct_add(vp8_dequant_idct_add_v6);
extern prototype_dequant_idct_add_y_block(vp8_dequant_idct_add_y_block_v6);
extern prototype_dequant_idct_add_uv_block(vp8_dequant_idct_add_uv_block_v6);
#if !CONFIG_RUNTIME_CPU_DETECT
#undef vp8_dequant_block
#define vp8_dequant_block vp8_dequantize_b_v6
#undef vp8_dequant_idct_add
#define vp8_dequant_idct_add vp8_dequant_idct_add_v6
#undef vp8_dequant_idct_add_y_block
#define vp8_dequant_idct_add_y_block vp8_dequant_idct_add_y_block_v6
#undef vp8_dequant_idct_add_uv_block
#define vp8_dequant_idct_add_uv_block vp8_dequant_idct_add_uv_block_v6
#endif
#endif
#if HAVE_NEON
extern prototype_dequant_block(vp8_dequantize_b_neon);
extern prototype_dequant_idct_add(vp8_dequant_idct_add_neon);
extern prototype_dequant_idct_add_y_block(vp8_dequant_idct_add_y_block_neon);
extern prototype_dequant_idct_add_uv_block(vp8_dequant_idct_add_uv_block_neon);
#if !CONFIG_RUNTIME_CPU_DETECT
#undef vp8_dequant_block
#define vp8_dequant_block vp8_dequantize_b_neon
#undef vp8_dequant_idct_add
#define vp8_dequant_idct_add vp8_dequant_idct_add_neon
#undef vp8_dequant_idct_add_y_block
#define vp8_dequant_idct_add_y_block vp8_dequant_idct_add_y_block_neon
#undef vp8_dequant_idct_add_uv_block
#define vp8_dequant_idct_add_uv_block vp8_dequant_idct_add_uv_block_neon
#endif
#endif
#endif
......@@ -10,7 +10,6 @@
#include "vpx_config.h"
#include "vp8/common/idct.h"
#include "vp8/common/dequantize.h"
/* place these declarations here because we don't want to maintain them
* outside of this scope
......
......@@ -179,7 +179,7 @@ typedef struct
} LOWER_RES_INFO;
#endif
typedef struct
typedef struct blockd
{
short *qcoeff;
short *dqcoeff;
......
......@@ -10,7 +10,8 @@
#include "vpx_config.h"
#include "dequantize.h"
#include "vpx_rtcd.h"
#include "vp8/common/blockd.h"
#include "vp8/common/idct.h"
#include "vpx_mem/vpx_mem.h"
......
/*
* Copyright (c) 2010 The WebM project authors. All Rights Reserved.
*
* Use of this source code is governed by a BSD-style license
* that can be found in the LICENSE file in the root of the source
* tree. An additional intellectual property rights grant can be found
* in the file PATENTS. All contributing project authors may
* be found in the AUTHORS file in the root of the source tree.
*/
#ifndef DEQUANTIZE_H
#define DEQUANTIZE_H
#include "vp8/common/blockd.h"
#define prototype_dequant_block(sym) \
void sym(BLOCKD *x, short *DQC)
#define prototype_dequant_idct_add(sym) \
void sym(short *input, short *dq, \
unsigned char *output, \
int stride)
#define prototype_dequant_idct_add_y_block(sym) \
void sym(short *q, short *dq, \
unsigned char *dst, \
int stride, char *eobs)
#define prototype_dequant_idct_add_uv_block(sym) \
void sym(short *q, short *dq, \
unsigned char *dst_u, \
unsigned char *dst_v, int stride, char *eobs)
#if ARCH_X86 || ARCH_X86_64
#include "x86/dequantize_x86.h"
#endif
#if ARCH_ARM
#include "arm/dequantize_arm.h"
#endif
#ifndef vp8_dequant_block
#define vp8_dequant_block vp8_dequantize_b_c
#endif
extern prototype_dequant_block(vp8_dequant_block);
#ifndef vp8_dequant_idct_add
#define vp8_dequant_idct_add vp8_dequant_idct_add_c
#endif
extern prototype_dequant_idct_add(vp8_dequant_idct_add);
#ifndef vp8_dequant_idct_add_y_block
#define vp8_dequant_idct_add_y_block vp8_dequant_idct_add_y_block_c
#endif
extern prototype_dequant_idct_add_y_block(vp8_dequant_idct_add_y_block);
#ifndef vp8_dequant_idct_add_uv_block
#define vp8_dequant_idct_add_uv_block vp8_dequant_idct_add_uv_block_c
#endif
extern prototype_dequant_idct_add_uv_block(vp8_dequant_idct_add_uv_block);
typedef prototype_dequant_block((*vp8_dequant_block_fn_t));
typedef prototype_dequant_idct_add((*vp8_dequant_idct_add_fn_t));
typedef prototype_dequant_idct_add_y_block((*vp8_dequant_idct_add_y_block_fn_t));
typedef prototype_dequant_idct_add_uv_block((*vp8_dequant_idct_add_uv_block_fn_t));
typedef struct
{
vp8_dequant_block_fn_t block;
vp8_dequant_idct_add_fn_t idct_add;
vp8_dequant_idct_add_y_block_fn_t idct_add_y_block;
vp8_dequant_idct_add_uv_block_fn_t idct_add_uv_block;
} vp8_dequant_rtcd_vtable_t;
#if CONFIG_RUNTIME_CPU_DETECT
#define DEQUANT_INVOKE(ctx,fn) (ctx)->fn
#else
#define DEQUANT_INVOKE(ctx,fn) vp8_dequant_##fn
#endif
#endif
......@@ -10,6 +10,7 @@
#include "vpx_config.h"
#include "vpx_rtcd.h"
#include "vp8/common/subpixel.h"
#include "vp8/common/loopfilter.h"
#include "vp8/common/recon.h"
......@@ -70,13 +71,6 @@ void vp8_machine_specific_config(VP8_COMMON *ctx)
VP8_COMMON_RTCD *rtcd = &ctx->rtcd;
rtcd->dequant.block = vp8_dequantize_b_c;
rtcd->dequant.idct_add = vp8_dequant_idct_add_c;
rtcd->dequant.idct_add_y_block = vp8_dequant_idct_add_y_block_c;
rtcd->dequant.idct_add_uv_block =
vp8_dequant_idct_add_uv_block_c;
rtcd->idct.idct16 = vp8_short_idct4x4llm_c;
rtcd->idct.idct1_scalar_add = vp8_dc_only_idct_add_c;
rtcd->idct.iwalsh1 = vp8_short_inv_walsh4x4_1_c;
......@@ -138,4 +132,6 @@ void vp8_machine_specific_config(VP8_COMMON *ctx)
<