From owner-freebsd-hackers@FreeBSD.ORG Tue Aug 21 06:35:57 2012 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id CC53A106566B; Tue, 21 Aug 2012 06:35:57 +0000 (UTC) (envelope-from mitya@cabletv.dp.ua) Received: from mail.cabletv.dp.ua (mail.cabletv.dp.ua [193.34.20.8]) by mx1.freebsd.org (Postfix) with ESMTP id 831A58FC19; Tue, 21 Aug 2012 06:35:57 +0000 (UTC) Received: from [193.34.20.2] (helo=m18.cabletv.dp.ua) by mail.cabletv.dp.ua with esmtp (Exim 4.72 (FreeBSD)) (envelope-from ) id 1T3iXa-000FDf-N9; Tue, 21 Aug 2012 10:06:18 +0300 Message-ID: <50332AD8.6020800@cabletv.dp.ua> Date: Tue, 21 Aug 2012 09:29:44 +0300 From: Mitya User-Agent: Mozilla/5.0 (X11; FreeBSD i386; rv:12.0) Gecko/20120425 Thunderbird/12.0 MIME-Version: 1.0 To: freebsd-net@freebsd.org, freebsd-hackers@freebsd.org References: <50324DB4.6080905@cabletv.dp.ua> <5452BF37-3658-4C1F-B965-CE3EA28B6EA5@bsdimp.com> In-Reply-To: <5452BF37-3658-4C1F-B965-CE3EA28B6EA5@bsdimp.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Mailman-Approved-At: Tue, 21 Aug 2012 11:39:56 +0000 Cc: Subject: Re: Replace bcopy() to update ether_addr X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 21 Aug 2012 06:35:57 -0000 20.08.2012 22:20, Warner Losh написал: > On Aug 20, 2012, at 1:17 PM, Wojciech Puchar wrote: > >>>> or use ++. >>>> >>>> i think it is always aligned to 2 bytes and this should produce usable code on any CPU? should be 6 instructions on MIPS and PPC IMHO. >>> We should tag it as __aligned(2) then, no? If so, then the compiler should generate the code you posted. >> should is the most important word in Your post. what it actually do - i don't know. > If we are requiring this to be __aligned(2), we should tag it as such to enforce this. > > Even without this tagging, the code to do a structure level copy of 6 bytes is going to be tiny... > > Warner > I try some times different algorithms. This is one of thees: *(u_int32_t *)(dst) = *(u_int32_t *)(src); *(u_int16_t *)&(dst->octet[4]) = *(u_int16_t *)&(src->octet[4]); But, internal gcc and clang optimisations are much better, than my attempt. For aligned platforms (2 bytes aligned) best choice is *dst = *src;