1 #ifndef STRATEGYSELECTOR_H_ 2 #define STRATEGYSELECTOR_H_ 3 /***************************************************************************** 4 * This file is part of Kvazaar HEVC encoder. 5 * 6 * Copyright (c) 2021, Tampere University, ITU/ISO/IEC, project contributors 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without modification, 10 * are permitted provided that the following conditions are met: 11 * 12 * * Redistributions of source code must retain the above copyright notice, this 13 * list of conditions and the following disclaimer. 14 * 15 * * Redistributions in binary form must reproduce the above copyright notice, this 16 * list of conditions and the following disclaimer in the documentation and/or 17 * other materials provided with the distribution. 18 * 19 * * Neither the name of the Tampere University or ITU/ISO/IEC nor the names of its 20 * contributors may be used to endorse or promote products derived from 21 * this software without specific prior written permission. 22 * 23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 25 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 26 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 27 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 * INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION HOWEVER CAUSED AND ON 30 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * INCLUDING NEGLIGENCE OR OTHERWISE ARISING IN ANY WAY OUT OF THE USE OF THIS 33 ****************************************************************************/ 34 35 /** 36 * \ingroup Optimization 37 * \file 38 * Dynamic dispatch based on cpuid. 39 */ 40 41 #include "global.h" // IWYU pragma: keep 42 43 #if defined(KVZ_DEBUG) && !defined(DEBUG_STRATEGYSELECTOR) 44 # define DEBUG_STRATEGYSELECTOR 45 #endif 46 47 typedef struct { 48 const char *type; //Type of the function, usually its name 49 const char *strategy_name; //Name of the strategy (e.g. sse2) 50 unsigned int priority; //Priority. 0 = lowest (default strategy) 51 void *fptr; //Pointer to the function 52 } strategy_t; 53 54 typedef struct { 55 unsigned int count; 56 unsigned int allocated;//How much memory is allocated 57 strategy_t* strategies; 58 } strategy_list_t; 59 60 #define STRATEGY_LIST_ALLOC_SIZE 16 61 62 typedef struct { 63 const char *strategy_type; 64 void **fptr; 65 } strategy_to_select_t; 66 67 typedef struct { 68 struct { 69 int mmx; 70 int sse; 71 int sse2; 72 int sse3; 73 int ssse3; 74 int sse41; 75 int sse42; 76 int avx; 77 int avx2; 78 79 bool hyper_threading; 80 } intel_flags; 81 82 struct { 83 int altivec; 84 } powerpc_flags; 85 86 struct { 87 int neon; 88 } arm_flags; 89 90 int logical_cpu_count; 91 int physical_cpu_count; 92 } hardware_flags_t; 93 94 extern hardware_flags_t kvz_g_hardware_flags; 95 extern hardware_flags_t kvz_g_strategies_in_use; 96 extern hardware_flags_t kvz_g_strategies_available; 97 98 int kvz_strategyselector_init(int32_t cpuid, uint8_t bitdepth); 99 int kvz_strategyselector_register(void *opaque, const char *type, const char *strategy_name, int priority, void *fptr); 100 101 102 //Strategy to include 103 #include "strategies/strategies-nal.h" 104 #include "strategies/strategies-picture.h" 105 #include "strategies/strategies-dct.h" 106 #include "strategies/strategies-ipol.h" 107 #include "strategies/strategies-quant.h" 108 #include "strategies/strategies-intra.h" 109 #include "strategies/strategies-sao.h" 110 #include "strategies/strategies-encode.h" 111 112 static const strategy_to_select_t strategies_to_select[] = { 113 STRATEGIES_NAL_EXPORTS 114 STRATEGIES_PICTURE_EXPORTS 115 STRATEGIES_DCT_EXPORTS 116 STRATEGIES_IPOL_EXPORTS 117 STRATEGIES_QUANT_EXPORTS 118 STRATEGIES_INTRA_EXPORTS 119 STRATEGIES_SAO_EXPORTS 120 STRATEGIES_ENCODE_EXPORTS 121 { NULL, NULL }, 122 }; 123 124 #endif //STRATEGYSELECTOR_H_ 125