lwip-users
[Top][All Lists]
Advanced

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

[lwip-users] [lwip] Anyone Using An Architecture That Isn't little or b


From: John C. Toman
Subject: [lwip-users] [lwip] Anyone Using An Architecture That Isn't little or big endian?
Date: Wed, 08 Jan 2003 23:22:44 -0000

Just checking. I'm considering writing and submitting code which would 
eliminate many unnecessary byte swaps for little endian architectures, 
specifically for code constants, without affecting big endian 
architectures. I'm planning on making changes at least for my system and 
will contribute them back to the lwIP tree if others are interested. For 
instance, consider:

Currently in lwIP (one example from etharp.h):

#define ETHTYPE_ARP 0x0806
#define ETHTYPE_IP  0x0800

When these are used, they must be byte-swapped in the little endian case 
(from ethernetif.c):

    switch(htons(ethhdr->type)) {
    case ETHTYPE_IP:
      arp_ip_input(netif, p);
      pbuf_header(p, -14);
      netif->input(p, netif);
      break;
    case ETHTYPE_ARP:
      p = arp_arp_input(netif, ethernetif->ethaddr, p);
      if(p != NULL) {
        low_level_output(ethernetif, p);
        pbuf_free(p);
      }
      break;

With a #ifdef for LITTLE_ENDIAN systems in the header files, this 
example would become:

etharp.h:

#ifdef LITTLE_ENDIAN
#  define ETHTYPE_ARP 0x0608
#  define ETHTYPE_IP  0x0008
#else
#  define ETHTYPE_ARP 0x0806
#  define ETHTYPE_IP  0x0800
#endif

Then the code piece in ethernetif.c loses the htons() call, saving code 
and execution time in the little endian case without harming the big 
endian case:

    switch(ethhdr->type) {
    case ETHTYPE_IP:
      arp_ip_input(netif, p);
      pbuf_header(p, -14);
      netif->input(p, netif);
      break;
    case ETHTYPE_ARP:
      p = arp_arp_input(netif, ethernetif->ethaddr, p);
      if(p != NULL) {
        low_level_output(ethernetif, p);
        pbuf_free(p);
      }
      break;

My thinking was that dozens of htons, htonl, ntohs and ntohl calls in 
lwIP could be eliminated this way or in similar ways, resulting in 
cleaner code, as well as smaller code size and increased performance for 
little endian systems.

The one drawback I can see to this approach is if there are other 
architectures that store bytes differently than little or big endian, 
they would need to come up with their own constants that represent the 
network-storage format on their systems ...

Regards,

John


[This message was sent through the lwip discussion list.]




reply via email to

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