From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp62.i.mail.ru (smtp62.i.mail.ru [217.69.128.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 93584469710 for ; Mon, 18 May 2020 15:55:40 +0300 (MSK) References: <172feb69ec2caea2aa63a24de8b76a4dba13bebb.1589583614.git.v.shpilevoy@tarantool.org> From: Aleksandr Lyapunov Message-ID: <52af1bb7-b125-7490-3882-ce74698789d2@tarantool.org> Date: Mon, 18 May 2020 15:55:38 +0300 MIME-Version: 1.0 In-Reply-To: <172feb69ec2caea2aa63a24de8b76a4dba13bebb.1589583614.git.v.shpilevoy@tarantool.org> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Subject: Re: [Tarantool-patches] [PATCH 2/2] uuid: fix unaligned memory access List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Vladislav Shpilevoy , tarantool-patches@dev.tarantool.org, tsafin@tarantool.org, gorcunov@gmail.com Thanks for the patch! see my comment below. On 5/16/20 2:03 AM, Vladislav Shpilevoy wrote: > tt_uuid_is_nil(const struct tt_uuid *uu) > { > - const uint64_t *p = (const uint64_t *) uu; > - return !p[0] && !p[1]; > + const uint32_t *p = (const uint32_t *) uu; > + return p[0] == 0 && p[1] == 0 && p[2] == 0 && p[3] == 0; > } > > /** > @@ -172,9 +172,10 @@ tt_uuid_is_nil(const struct tt_uuid *uu) > inline bool > tt_uuid_is_equal(const struct tt_uuid *lhs, const struct tt_uuid *rhs) > { > - const uint64_t *lp = (const uint64_t *) lhs; > - const uint64_t *rp = (const uint64_t *) rhs; > - return lp[0] == rp[0] && lp[1] == rp[1]; > + const uint32_t *lp = (const uint32_t *) lhs; > + const uint32_t *rp = (const uint32_t *) rhs; > + return lp[0] == rp[0] && lp[1] == rp[1] && lp[2] == rp[2] && > + lp[3] == rp[3]; It seems that we degrade performance just for clang to be happy.. I would suggest to use memcmp in this case. It's portable and allows a compiler to generate the best possible code. I've measured it (gcc) and memcmp version is twice faster than your solution. Even for _is_nil method it's better to use memcmp with statically allocated zero buffer.