Deutsch   English   Français   Italiano  
<646324d7$0$22266$426a34cc@news.free.fr>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!3.us.feeder.erje.net!feeder.erje.net!news-2.dfn.de!news.dfn.de!npeer.as286.net!npeer-ng0.as286.net!proxad.net!feeder1-1.proxad.net!cleanfeed3-b.proxad.net!nnrp4-1.free.fr!not-for-mail
Newsgroups: fr.comp.lang.c
From: JKB <JKB@hilbert.invalid>
Subject: =?UTF-8?Q?G=C3=A9n=C3=A9ration?= de code
 =?UTF-8?Q?incompr=C3=A9hensible?= (occupation =?UTF-8?Q?m=C3=A9moire=29?=
Reply-To: <jkb@invalid>
User-Agent: slrn/1.0.3 (Linux)
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Date: 16 May 2023 06:38:15 GMT
Lines: 129
Message-ID: <646324d7$0$22266$426a34cc@news.free.fr>
Organization: Guest of ProXad - France
NNTP-Posting-Date: 16 May 2023 08:38:15 CEST
NNTP-Posting-Host: 62.212.98.88
X-Trace: 1684219095 news-4.free.fr 22266 62.212.98.88:46815
X-Complaints-To: abuse@proxad.net
Bytes: 5007

	Bonjour à tous,

	Je suis en train de développer un firmware sur un AVR 8 bits:

hilbert:[~] > /usr/local/cross/avr/bin/avr-gcc -v
Using built-in specs.
Reading specs from /usr/local/cross/avr/lib/gcc/avr/12.2.0/device-specs/specs-avr2
COLLECT_GCC=/usr/local/cross/avr/bin/avr-gcc
COLLECT_LTO_WRAPPER=/usr/local/cross/avr/libexec/gcc/avr/12.2.0/lto-wrapper
Target: avr
Configured with: /usr/local/cross/build/avr/src/gcc/configure --build=x86_64-build_pc-linux-gnu --host=x86_64-build_pc-linux-gnu --target=avr --prefix=/usr/local/cross/avr --exec_prefix=/usr/local/cross/avr --with-local-prefix=/usr/local/cross/avr/avr --with-headers=/usr/local/cross/avr/avr/include --with-newlib --enable-threads=no --disable-shared --with-pkgversion='crosstool-NG 1.25.0.143_5248760' --disable-__cxa_atexit --disable-libgomp --disable-libmudflap --disable-libmpx --disable-libssp --disable-libquadmath --disable-libquadmath-support --disable-libstdcxx-verbose --with-gmp=/usr/local/cross/build/avr/buildtools --with-mpfr=/usr/local/cross/build/avr/buildtools --with-mpc=/usr/local/cross/build/avr/buildtools --with-isl=/usr/local/cross/build/avr/buildtools --enable-lto --enable-target-optspace --disable-nls --enable-multiarch --enable-languages=c
Thread model: single
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (crosstool-NG 1.25.0.143_5248760) 

	Il s'agit d'un cross compilateur que j'ai compilé moi-même.

	La cible est un ATmega 1284 (128 Ko de mémoire programme, 16 Ko de
	RAM et 4 Ko d'eeprom émulée par de la flash).

	Considérons le bout de code suivant :

void
task_etats(void *pointer)
{
    inter_thread        *it;

    stimuli_t           stimuli;

    uint8_t             etat;

    uint16_t            stimuli16;

    it = (inter_thread *) pointer;
    USE(it);

    memset(&stimuli, 0, sizeof(stimuli));

    etat = state_A;
    stimuli.tc_25 = 25;

    for(;;)
    {
        hz_set_t0(hz_timeout_etats);

        // pseudo différentiel, le + sur CH0
        stimuli.cp = mcp3202_get_value(spi_mcp3202_cp, 0x00);
        stimuli.pp = mcp3202_get_value(spi_mcp3202_pp, 0x00);
        stimuli.temp = 25 + (100 *
                ((mcp3202_get_value(spi_mcp3202_temp, 0x00) * (3.3 / 4096))
                 - 0.75));

		/*
			Un gros bloc switch/case sans aucune boucle.
		*/


        while(hz_get_ts(hz_timeout_etats) < stimuli.tc_25)
        {
            task_yield();
        }
    }
}

	Le code généré occupe la place suivante :

AVR Memory Usage
----------------
Device: atmega1284

Program:   14884 bytes (11.4% Full)
(.text + .data + .bootloader)

Data:        609 bytes (3.7% Full)
(.data + .bss + .noinit)

	Si maintenant, je mets la dernière boucle dans une fonction

void
hz_wait_timeout(int8_t hz, int32_t ticks)
{       
    for(;;)
    {
        if (hz_get_ts(hz) >= ticks)
        {
            break;
        }

		task_yield();
    }

    return; 
}

	et que j'appelle cette fonction à la place de la boucle 
	while(hz_get_ts(hz_timeout_etats) < stimuli.tc_25) { ... }
	le code généré utilise :

AVR Memory Usage
----------------
Device: atmega1284

Program:   75690 bytes (57.7% Full)
(.text + .data + .bootloader)

Data:        609 bytes (3.7% Full)
(.data + .bss + .noinit)

	Les sections .data/.bss/.noinit ne changent pas. Mais pourquoi ce
	simple appel de fonction fait passer mon code de 14884 à 75690 ?

	Les deux binaires se comportent identiquement.

	Je n'ai pas cherché à désassembler le code (je suis pas au point en
	assembleur AVR8) mais je ne comprends pas pourquoi le remplacement
	d'une boucle par une fonction faisant la même chose se comporte de
	la sorte. Je veux bien qu'il y ait un appel de fonction
	supplémentaire, mais ça ne fait pas la différence.

	Les options de compilation dans les deux cas sont les suivantes :
	-Os -g -Werror -Wextra --param=min-pagesize=0

	Merci pour vos lumières,

	JKB

-- 
Si votre demande me parvient en code 29, je vous titiouillerai volontiers
une réponse.