You've already forked FFmpeg
							
							
				mirror of
				https://github.com/FFmpeg/FFmpeg.git
				synced 2025-10-30 23:18:11 +02:00 
			
		
		
		
	avcodec/cbrt_tablegen: Deduplicate common code
Namely the part that creates a temporary LUT. Reviewed-by: Zhao Zhili <quinkblack@foxmail.com> Reviewed-by: Lynne <dev@lynne.ee> Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
		| @@ -195,11 +195,13 @@ OBJS-$(CONFIG_A64MULTI5_ENCODER)       += a64multienc.o elbg.o | ||||
| OBJS-$(CONFIG_AAC_DECODER)             += aactab.o \ | ||||
|                                           aacsbr.o aacps_common.o aacps_float.o \ | ||||
|                                           kbdwin.o \ | ||||
|                                           sbrdsp.o aacpsdsp_float.o cbrt_data.o | ||||
|                                           sbrdsp.o aacpsdsp_float.o cbrt_data.o \ | ||||
|                                           $(if $(!CONFIG_HARDCODED_TABLES), cbrt_tablegen_common.o) | ||||
| OBJS-$(CONFIG_AAC_FIXED_DECODER)       += aactab.o \ | ||||
|                                           aacsbr_fixed.o aacps_common.o aacps_fixed.o \ | ||||
|                                           kbdwin.o \ | ||||
|                                           sbrdsp_fixed.o aacpsdsp_fixed.o cbrt_data_fixed.o | ||||
|                                           sbrdsp_fixed.o aacpsdsp_fixed.o cbrt_data_fixed.o \ | ||||
|                                           $(if $(!CONFIG_HARDCODED_TABLES), cbrt_tablegen_common.o) | ||||
| OBJS-$(CONFIG_AAC_ENCODER)             += aacenc.o aaccoder.o aacenctab.o    \ | ||||
|                                           aacpsy.o aactab.o      \ | ||||
|                                           aacenc_is.o \ | ||||
|   | ||||
| @@ -40,6 +40,11 @@ void ff_cbrt_tableinit(void); | ||||
| void ff_cbrt_tableinit_fixed(void); | ||||
|  | ||||
| #define TMP_LUT_SIZE (LUT_SIZE / 2) | ||||
| /** | ||||
|  * Creates a LUT (of doubles) for the powers of | ||||
|  * the odd integers: tmp_lut[idx] will be set to (2 * idx + 1)^{4/3}. | ||||
|  */ | ||||
| void ff_cbrt_dbl_tableinit(double tmp_lut[TMP_LUT_SIZE]); | ||||
|  | ||||
| extern union CBRT { | ||||
|     uint32_t cbrt_tab[LUT_SIZE]; | ||||
|   | ||||
| @@ -46,34 +46,7 @@ av_cold void AAC_RENAME(ff_cbrt_tableinit)(void) | ||||
|                   "unexpected sizeofs"); | ||||
|     // We reuse ff_cbrt_tab_internal.tmp as a LUT (of doubles) for the roots | ||||
|     // of the odd integers: tmp[idx] contains (2 * idx + 1)^{4/3}. | ||||
|  | ||||
|     for (int idx = 0; idx < TMP_LUT_SIZE; ++idx) | ||||
|         AAC_RENAME(ff_cbrt_tab_internal).tmp[idx] = 1; | ||||
|  | ||||
|     /* have to take care of non-squarefree numbers; notice that sqrt(LUT_SIZE) = 90; | ||||
|      * idx == 44 corresponds to 89. */ | ||||
|     for (int idx = 1; idx < 45; ++idx) { | ||||
|         if (AAC_RENAME(ff_cbrt_tab_internal).tmp[idx] == 1) { | ||||
|             int i = 2 * idx + 1; | ||||
|             double cbrt_val = i * cbrt(i); | ||||
|             for (int k = i; k < LUT_SIZE; k *= i) { | ||||
|                 // We only have to handle k, 3 * k, 5 * k,..., | ||||
|                 // because only these are odd. The corresponding indices are | ||||
|                 // k >> 1, (k >> 1) + k, (k >> 1) + 2 * k,... | ||||
|                 for (int idx2 = k >> 1; idx2 < TMP_LUT_SIZE; idx2 += k) | ||||
|                     AAC_RENAME(ff_cbrt_tab_internal).tmp[idx2] *= cbrt_val; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     for (int idx = 45; idx < TMP_LUT_SIZE; ++idx) { | ||||
|         if (AAC_RENAME(ff_cbrt_tab_internal).tmp[idx] == 1) { | ||||
|             int i = 2 * idx + 1; | ||||
|             double cbrt_val = i * cbrt(i); | ||||
|             for (int idx2 = idx; idx2 < TMP_LUT_SIZE; idx2 += i) | ||||
|                 AAC_RENAME(ff_cbrt_tab_internal).tmp[idx2] *= cbrt_val; | ||||
|         } | ||||
|     } | ||||
|     ff_cbrt_dbl_tableinit(AAC_RENAME(ff_cbrt_tab_internal).tmp); | ||||
|  | ||||
|     double cbrt_2 = 2 * cbrt(2); | ||||
|     for (int idx = TMP_LUT_SIZE - 1; idx >= 0; --idx) { | ||||
|   | ||||
							
								
								
									
										60
									
								
								libavcodec/cbrt_tablegen_common.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								libavcodec/cbrt_tablegen_common.c
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,60 @@ | ||||
| /* | ||||
|  * Common code for AAC cube-root table | ||||
|  * | ||||
|  * Copyright (c) 2010 Reimar Döffinger <Reimar.Doeffinger@gmx.de> | ||||
|  * | ||||
|  * This file is part of FFmpeg. | ||||
|  * | ||||
|  * FFmpeg is free software; you can redistribute it and/or | ||||
|  * modify it under the terms of the GNU Lesser General Public | ||||
|  * License as published by the Free Software Foundation; either | ||||
|  * version 2.1 of the License, or (at your option) any later version. | ||||
|  * | ||||
|  * FFmpeg is distributed in the hope that it will be useful, | ||||
|  * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
|  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | ||||
|  * Lesser General Public License for more details. | ||||
|  * | ||||
|  * You should have received a copy of the GNU Lesser General Public | ||||
|  * License along with FFmpeg; if not, write to the Free Software | ||||
|  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||||
|  */ | ||||
|  | ||||
| #include <math.h> | ||||
|  | ||||
| #include "cbrt_data.h" | ||||
| #include "libavutil/attributes.h" | ||||
| #ifdef HAVE_AV_CONFIG_H // Only include libm.h when building for the target, not the host | ||||
| #include "libavutil/libm.h" | ||||
| #endif | ||||
|  | ||||
| av_cold void ff_cbrt_dbl_tableinit(double tmp_lut[TMP_LUT_SIZE]) | ||||
| { | ||||
|     for (int idx = 0; idx < TMP_LUT_SIZE; ++idx) | ||||
|         tmp_lut[idx] = 1; | ||||
|  | ||||
|     /* have to take care of non-squarefree numbers; notice that sqrt(LUT_SIZE) = 90; | ||||
|      * idx == 44 corresponds to 89. */ | ||||
|     for (int idx = 1; idx < 45; ++idx) { | ||||
|         if (tmp_lut[idx] == 1) { | ||||
|             int i = 2 * idx + 1; | ||||
|             double cbrt_val = i * cbrt(i); | ||||
|             for (int k = i; k < LUT_SIZE; k *= i) { | ||||
|                 // We only have to handle k, 3 * k, 5 * k,..., | ||||
|                 // because only these are odd. The corresponding indices are | ||||
|                 // k >> 1, (k >> 1) + k, (k >> 1) + 2 * k,... | ||||
|                 for (int idx2 = k >> 1; idx2 < TMP_LUT_SIZE; idx2 += k) | ||||
|                     tmp_lut[idx2] *= cbrt_val; | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     for (int idx = 45; idx < TMP_LUT_SIZE; ++idx) { | ||||
|         if (tmp_lut[idx] == 1) { | ||||
|             int i = 2 * idx + 1; | ||||
|             double cbrt_val = i * cbrt(i); | ||||
|             for (int idx2 = idx; idx2 < TMP_LUT_SIZE; idx2 += i) | ||||
|                 tmp_lut[idx2] *= cbrt_val; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @@ -24,6 +24,7 @@ | ||||
| #define BUILD_TABLES 1 | ||||
| #include "libavutil/tablegen.h" | ||||
| #include "cbrt_tablegen.h" | ||||
| #include "cbrt_tablegen_common.c" | ||||
| #include "tableprint.h" | ||||
|  | ||||
| int main(void) | ||||
|   | ||||
		Reference in New Issue
	
	Block a user