lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <87egmiuwyj.fsf@rasmusvillemoes.dk>
Date:	Fri, 15 May 2015 09:22:12 +0200
From:	Rasmus Villemoes <linux@...musvillemoes.dk>
To:	Daniel Wagner <daniel.wagner@...-carit.de>
Cc:	akpm@...ux-foundation.org, mm-commits@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: Re: [PATCH v1] lib/sort: Add 64 bit swap function

On Wed, May 13 2015, Daniel Wagner <daniel.wagner@...-carit.de> 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@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ