Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932985AbbEOHWS (ORCPT ); Fri, 15 May 2015 03:22:18 -0400 Received: from mail-la0-f51.google.com ([209.85.215.51]:36386 "EHLO mail-la0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932333AbbEOHWQ (ORCPT ); Fri, 15 May 2015 03:22:16 -0400 From: Rasmus Villemoes To: Daniel Wagner Cc: akpm@linux-foundation.org, mm-commits@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v1] lib/sort: Add 64 bit swap function Organization: D03 References: <87egml7sn6.fsf@rasmusvillemoes.dk> <1431514812-9946-1-git-send-email-daniel.wagner@bmw-carit.de> X-Hashcash: 1:20:150515:daniel.wagner@bmw-carit.de::8BBoCeEAvW4mtwxg:000000000000000000000000000000000000TiM X-Hashcash: 1:20:150515:akpm@linux-foundation.org::Jw9HOouI2B5FtZVw:0000000000000000000000000000000000003FVN X-Hashcash: 1:20:150515:linux-kernel@vger.kernel.org::6+xsL0dzT/uEsQfR:0000000000000000000000000000000004v0K X-Hashcash: 1:20:150515:mm-commits@vger.kernel.org::y7S1eGsy16pBIaz/:000000000000000000000000000000000005v/i Date: Fri, 15 May 2015 09:22:12 +0200 In-Reply-To: <1431514812-9946-1-git-send-email-daniel.wagner@bmw-carit.de> (Daniel Wagner's message of "Wed, 13 May 2015 13:00:12 +0200") Message-ID: <87egmiuwyj.fsf@rasmusvillemoes.dk> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1498 Lines: 60 On Wed, May 13 2015, Daniel Wagner wrote: > > - if (!swap_func) > - swap_func = (size == 4 ? u32_swap : generic_swap); > + if (!swap_func) { > +#if defined(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) > + switch (size) { > + case 4: > + swap_func = u32_swap; > + break; > + case 8: > + swap_func = u64_swap; > + break; > + } > +#else > + switch (size) { > + case 4: > + if (((unsigned long)base & 3) == 0) > + swap_func = u32_swap; > + break; > + case 8: > + if (((unsigned long)base & 7) == 0) > + swap_func = u64_swap; > + break; > + } > +#endif /* CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS */ > + > + if (!swap_func) > + swap_func = generic_swap; > + } I was more thinking of something like static int alignment_ok(const void *base, int align) { return IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS) || ((unsigned long)base & (align - 1)) == 0; } ... if (!swap_func) { if (size == 4 && alignment_ok(base, 4)) swap_func = u32_swap; else if (size == 8 && alignment_ok(base, 8)) swap_func = u64_swap; else swap_func = generic_swap; } It seems to generate the same code (I usually worry about how gcc messes up switches), so this is just a readability thing. Rasmus -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/