lwip-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [lwip-devel] Is there any interest in an inlined IP checksum compile


From: bill
Subject: RE: [lwip-devel] Is there any interest in an inlined IP checksum compile-time option?
Date: Mon, 2 Feb 2009 08:47:05 -0500

> Did you mean inlining inet_chksum_pseudo()? Because LWIP_CHKSUM() can
> already be aligned as it is a define. Of course, the IP code could use
> that define instead of using the function that directly calls this
> (inet_chksum())! The problem with inlining inet_chksum_pseudo() would
> be
> that it has to be in a header file to do that. And after all, I think
> creating an optimized LWIP_CHKSUM routine in assembly has more impact
> than inlining this code...

No, I meant adding the words and building the checksum as the words are
being stored.  I forgot to put in the original post that this 1.25%+ gain
includes using a highly optimized assembly inet_chksum.  I would expect much
more improvement over the default C check sum.

Here's a snippet - it's not pretty, but could be considered in place of the
existing code to make a runtime call:

    IPH_TTL_SET(iphdr, ttl);
    IPH_PROTO_SET(iphdr, proto);
#if INLINE_IP_CHKSUM && CHECKSUM_GEN_IP
    chk_sum = iphdr->_ttl_proto;
#endif

    ip_addr_set(&(iphdr->dest), dest);
#if INLINE_IP_CHKSUM && CHECKSUM_GEN_IP
    chk_sum += iphdr->dest.addr & 0xFFFF;
    chk_sum += iphdr->dest.addr >> 16;
#endif

    IPH_VHLTOS_SET(iphdr, 4, IP_HLEN / 4, tos);
#if INLINE_IP_CHKSUM && CHECKSUM_GEN_IP
    chk_sum += iphdr->_v_hl_tos;
#endif
    IPH_LEN_SET(iphdr, htons(p->tot_len));
#if INLINE_IP_CHKSUM && CHECKSUM_GEN_IP
    chk_sum += iphdr->_len;
#endif
    IPH_OFFSET_SET(iphdr, 0);
    IPH_ID_SET(iphdr, htons(ip_id));
#if INLINE_IP_CHKSUM && CHECKSUM_GEN_IP
    chk_sum += iphdr->_id;
#endif
    ++ip_id;

    if (ip_addr_isany(src)) {
      ip_addr_set(&(iphdr->src), &(netif->ip_addr));
    } else {
      ip_addr_set(&(iphdr->src), src);
    }
#if INLINE_IP_CHKSUM && CHECKSUM_GEN_IP
    chk_sum += iphdr->src.addr & 0xFFFF;
    chk_sum += iphdr->src.addr >> 16;
        chk_sum = (chk_sum >> 16) + (chk_sum & 0xFFFF);
        chk_sum = (chk_sum >> 16) + chk_sum;
        chk_sum = ~chk_sum;
        iphdr->_chksum = chk_sum;               //      It's in network
order
#else
    IPH_CHKSUM_SET(iphdr, 0);
#if CHECKSUM_GEN_IP
    IPH_CHKSUM_SET(iphdr, inet_chksum(iphdr, IP_HLEN));
#endif
#endif

Bill





reply via email to

[Prev in Thread] Current Thread [Next in Thread]