diff --git a/apps/codecs/codecs.make b/apps/codecs/codecs.make index 9e1f909462..0c3d2fade0 100644 --- a/apps/codecs/codecs.make +++ b/apps/codecs/codecs.make @@ -59,7 +59,7 @@ CODECLIBS := $(DEMACLIB) $(A52LIB) $(ALACLIB) $(ASAPLIB) \ $(ATRACLIB) \ $(CODECLIB) -$(CODECS): $(CODEC_CRT0) $(CODECLINK_LDS) +$(CODECS): $(CODEC_CRT0) $(CODECLINK_LDS) $(CODECLINK_LDS): $(CODEC_LDS) $(CONFIGFILE) $(call PRINTS,PP $(@F)) @@ -78,6 +78,7 @@ $(CODECDIR)/wavpack.codec : $(CODECDIR)/libwavpack.a $(CODECDIR)/alac.codec : $(CODECDIR)/libalac.a $(CODECDIR)/libm4a.a $(CODECDIR)/aac.codec : $(CODECDIR)/libfaad.a $(CODECDIR)/libm4a.a $(CODECDIR)/shorten.codec : $(CODECDIR)/libffmpegFLAC.a +$(CODECDIR)/ape-pre.map : $(CODECDIR)/libdemac-pre.a $(CODECDIR)/ape.codec : $(CODECDIR)/libdemac.a $(CODECDIR)/wma.codec : $(CODECDIR)/libwma.a $(CODECDIR)/wavpack_enc.codec: $(CODECDIR)/libwavpack.a @@ -113,6 +114,13 @@ else CODECFLAGS += -UDEBUG -DNDEBUG endif +$(CODECDIR)/%-pre.map: $(CODEC_CRT0) $(CODECLINK_LDS) $(CODECDIR)/%.o $(CODECLIB) + $(call PRINTS,LD $(@F))$(CC) $(CODECFLAGS) -o $(CODECDIR)/$*-pre.elf \ + $(filter %.o, $^) \ + $(filter-out $(CODECLIB),$(filter %.a, $+)) \ + $(CODECLIB) \ + -lgcc $(subst .map,-pre.map,$(CODECLDFLAGS)) + $(CODECDIR)/%.codec: $(CODECDIR)/%.o $(call PRINTS,LD $(@F))$(CC) $(CODECFLAGS) -o $(CODECDIR)/$*.elf \ $(filter %.o, $^) \ diff --git a/apps/codecs/demac/libdemac.make b/apps/codecs/demac/libdemac.make index 5026fb1d95..dcbd35c6b1 100644 --- a/apps/codecs/demac/libdemac.make +++ b/apps/codecs/demac/libdemac.make @@ -12,6 +12,15 @@ DEMACLIB := $(CODECDIR)/libdemac.a DEMACLIB_SRC := $(call preprocess, $(APPSDIR)/codecs/demac/libdemac/SOURCES) DEMACLIB_OBJ := $(call c2obj, $(DEMACLIB_SRC)) OTHER_SRC += $(DEMACLIB_SRC) +ifeq ($(CPU),arm) +OTHER_SRC += $(APPSDIR)/codecs/demac/libdemac/udiv32_arm-pre.S +endif +DEMACLIB_PRE := $(subst .a,-pre.a,$(DEMACLIB)) +DEMACLIB_OBJ_PRE := $(subst udiv32_arm.o,udiv32_arm-pre.o,$(DEMACLIB_OBJ)) + +$(DEMACLIB_PRE): $(DEMACLIB_OBJ_PRE) + $(SILENT)$(shell rm -f $@) + $(call PRINTS,AR $(@F))$(AR) rcs $@ $^ >/dev/null $(DEMACLIB): $(DEMACLIB_OBJ) $(SILENT)$(shell rm -f $@) @@ -20,6 +29,14 @@ $(DEMACLIB): $(DEMACLIB_OBJ) DEMACFLAGS = $(filter-out -O%,$(CODECFLAGS)) DEMACFLAGS += -O3 +$(CODECDIR)/ape_free_iram.h: $(CODECDIR)/ape-pre.map + $(call PRINTS,GEN $(@F))perl -an \ + -e 'if(/^PLUGIN_IRAM/){$$istart=hex($$F[1]);$$ilen=hex($$F[2])}' \ + -e 'if(/iend = /){$$iend=hex($$F[0]);}' \ + -e '}{if($$ilen){print"#define FREE_IRAM ".($$ilen+$$istart-$$iend)."\n";}' \ + $(CODECDIR)/ape-pre.map \ + > $@ + $(CODECDIR)/demac/%.o: $(ROOTDIR)/apps/codecs/demac/%.c $(SILENT)mkdir -p $(dir $@) $(call PRINTS,CC $(subst $(ROOTDIR)/,,$<))$(CC) $(DEMACFLAGS) -c $< -o $@ diff --git a/apps/codecs/demac/libdemac/udiv32_arm-pre.S b/apps/codecs/demac/libdemac/udiv32_arm-pre.S new file mode 100644 index 0000000000..882d9b6f50 --- /dev/null +++ b/apps/codecs/demac/libdemac/udiv32_arm-pre.S @@ -0,0 +1,25 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 by Andrew Mahone + * + * Wrapper for udiv32_arm.S to test available IRAM by pre-linking the codec. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#define APE_PRE +#include "udiv32_arm.S" \ No newline at end of file diff --git a/apps/codecs/demac/libdemac/udiv32_arm.S b/apps/codecs/demac/libdemac/udiv32_arm.S index 4492492d30..939fce17d4 100644 --- a/apps/codecs/demac/libdemac/udiv32_arm.S +++ b/apps/codecs/demac/libdemac/udiv32_arm.S @@ -29,6 +29,13 @@ ****************************************************************************/ #include "config.h" +/* On targets with codec iram, a header file will be generated after an initial + link of the APE codec, stating the amount of IRAM remaining for use by the + reciprocal lookup table. */ +#if !defined(APE_PRE) && defined(USE_IRAM) && ARM_ARCH < 5 +#include "apps/codecs/ape_free_iram.h" +#endif + /* Codecs should not normally do this, but we need to check a macro, and * codecs.h would confuse the assembler. */ @@ -88,20 +95,29 @@ eor \quotient, \result, \remainder, lsl \bits .endm -#ifdef CPU_PP -#if CONFIG_CPU == PP5020 -.set recip_max, 8384 -#elif CONFIG_CPU == PP5002 -.set recip_max, 4608 +#ifndef FREE_IRAM +.set recip_max, 2 #else -.set recip_max, 16384 -#endif -#elif CONFIG_CPU == AS3525 -.set recip_max, 42752 -#elif CONFIG_CPU == S5L8701 -.set recip_max, 12800 -#elif CONFIG_CPU == S5L8700 -.set recip_max, 9088 +/* Each table entry is one word. Since a compare is done against the maximum + entry as an immediate, the maximum entry must be a valid ARM immediate, + which means a byte shifted by an even number of places. */ +.set recip_max, 2 + FREE_IRAM / 4 +.set recip_max_tmp, recip_max >> 8 +.set recip_mask_shift, 0 +.set tmp_shift, 16 +.rept 5 + .if recip_max_tmp >> tmp_shift + .set recip_max_tmp, recip_max_tmp >> tmp_shift + .set recip_mask_shift, recip_mask_shift + tmp_shift + .endif + .set tmp_shift, tmp_shift >> 1 +.endr +.if recip_max_tmp + .set recip_mask_shift, recip_mask_shift + 1 +.endif +.set recip_mask_shift, (recip_mask_shift + 1) & 62 +.set recip_max, recip_max & (255 << recip_mask_shift) +//.set recip_max, 2 #endif udiv32_arm: