|
From: | Timmy Brolin |
Subject: | Re: [lwip-users] [PATCH] fix warning for gcc and possible unaligned access |
Date: | Sat, 22 Apr 2006 13:27:44 +0200 |
User-agent: | Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4) Gecko/20030624 Netscape/7.1 (ax) |
Curt McDowell wrote:
Pedro Alves wroteSeems like the right thing to do.If the packing is removed from struct ip_addr, and struct ip_addr2 is removed, then there is no need to memcpy anymore.A simple: sipaddr = hdr->sipaddr; will do.memcpy may still be needed because hdr->sipaddr is misaligned at +2 due to the format of the ARP packet. My theory is that struct ip_addr2 was originally invented because the 4-byte struct/uint32 copy was crashing on someone's 2-byte aligned CPU! Regards, Curt McDowell Broadcom Corp.
Either ip_addr2 or memcpy is needed.The code "sipaddr = hdr->sipaddr;" would crash on any CPU which do not support unaligned accesses. The current ip_addr2 solution is technically more efficient than memcpy since it copies the ip_addr with just two 16bit reads+writes. The only solution which would be slightly more efficient is to copy hdr->sipaddr to a 32bit register using two 16bit accesses, and then write the 32bit register to sipaddr. But since this is not a critical code path, it is more important to keep the code as clean as possible rather than trying to save one single memory access.
The ip_addr2 solution makes the code nice and clean. Regards, Timmy Brolin
[Prev in Thread] | Current Thread | [Next in Thread] |