On 20/05/2020 05:30, Sebastian Riedel wrote:
It’s integer promotion.
Ah, yes, I see it now. Some sort of sign-extension. But it still doesn't
make any sense to me.
I tried compiling with --no-peep, to see if the optimiser was removing
anything that would put the extraneous code in context,
Am 19.05.20 um 23:37 schrieb Basil Hussain:
> Here's a self-contained example that I can replicate the issue with:
>
> #include
> uint8_t foo(uint16_t value) {
> return value;
> }
> uint8_t bar(uint16_t value) {
> return (value ? foo(value) + 1 : 0);
> }
> void main(void) {
> uint8_t
It’s integer promotion.
When I write it like this, it does not occur on gbz80:
UINT8 foo(UINT16 value) {
return value;
}
UINT8 bar(UINT16 value) {
return (value ? foo(value) + (UINT8)1 : (UINT8)0);
}
On 20.05.20 06:19, Sebastian Riedel wrote:
I think I can partly reproduce this on gbz80
I think I can partly reproduce this on gbz80.
It appears to prepare a 16 bit return value, even though it only returns
8 bit?
_bar::
;main.c:54: return (value ? foo(value) + 1 : 0);
ldhlsp,#3
lda, (hl-)
ora, (hl)
jrZ,00103$
popbc
pophl
pus
Here's a self-contained example that I can replicate the issue with:
#include
uint8_t foo(uint16_t value) {
return value;
}
uint8_t bar(uint16_t value) {
return (value ? foo(value) + 1 : 0);
}
void main(void) {
uint8_t x = bar(0xFF);
}
Compiled with:
sdcc.exe -mstm8 --std-c99 -I"C:\
Am 19.05.20 um 17:48 schrieb Basil Hussain:
> Hi all,
>
> I found today some very odd STM8 assembly code generated by SDCC. I
> can't figure out what it was trying to do, or why.
>
> The C code is really simple:
>
> uint8_t ffs_16(uint16_t value) {
> return (value ? ctz_16(value) + 1 : 0);
>
Hi all,
I found today some very odd STM8 assembly code generated by SDCC. I
can't figure out what it was trying to do, or why.
The C code is really simple:
uint8_t ffs_16(uint16_t value) {
return (value ? ctz_16(value) + 1 : 0);
}
But I get this bizarre assembly code:
19