gcc miscompiles csum_tcpudp_magic() on ARMv5

2 messages, 2 authors, 2013-12-12 · open the first message on its own page

gcc miscompiles csum_tcpudp_magic() on ARMv5

From: Måns Rullgård <hidden>
Date: 2013-12-12 14:37:59

Willy Tarreau [off-list ref] writes:
quoted
#include <stdint.h>
#include <stdio.h>

static inline uint32_t asm_add(uint16_t len, uint32_t sum)
{
        __asm__(
        "add    %0, %1, %2 \n"
        : "=&r"(sum)
        : "r" (sum), "r" (len)
        );
        return sum;
}
Hmmm aren't you passing a 16-bit register directly to the ASM for being used
as a 32-bit one ? This seems hasardous to me since nowhere you tell gcc how
you're going to use the register.
There is no such thing as a 16-bit register on ARM.  What this code does
is ask the compiler to take the 16-bit value 'len' and put it in a register
for use in the asm code.  All registers are 32-bit, so there is no ambiguity.

-- 
M?ns Rullg?rd
mans at mansr.com

gcc miscompiles csum_tcpudp_magic() on ARMv5

From: Maxime Bizon <hidden>
Date: 2013-12-12 14:40:42

On Thu, 2013-12-12 at 14:37 +0000, M?ns Rullg?rd wrote:
There is no such thing as a 16-bit register on ARM.  What this code does
is ask the compiler to take the 16-bit value 'len' and put it in a register
for use in the asm code.  All registers are 32-bit, so there is no ambiguity.
which strictly speaking the compiler did ;)

it took the 16 bits value and put it inside the lower 16 bits of the 32
bits register, it just didn't touch the higher ones

-- 
Maxime
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help