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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <534d8795-ce21-9af6-498d-22597213a3a2@c-s.fr>
Date:   Fri, 10 Mar 2017 11:54:19 +0100
From:   Christophe LEROY <christophe.leroy@....fr>
To:     Michael Ellerman <mpe@...erman.id.au>,
        Benjamin Herrenschmidt <benh@...nel.crashing.org>,
        Paul Mackerras <paulus@...ba.org>,
        Scott Wood <oss@...error.net>
Cc:     linux-kernel@...r.kernel.org, linuxppc-dev@...ts.ozlabs.org
Subject: Re: [PATCH] powerpc: sysdev: cpm1: Optimise gpio bit calculation



Le 10/03/2017 à 09:41, Michael Ellerman a écrit :
> Christophe Leroy <christophe.leroy@....fr> writes:
>
>> Help a bit the compiler to provide better code:
>>
>> unsigned int f(int i)
>> {
>> 	return 1 << (31 - i);
>> }
>>
>> unsigned int g(int i)
>> {
>> 	return 0x80000000 >> i;
>> }
>>
>> Disassembly of section .text:
>>
>> 00000000 <f>:
>>    0:	20 63 00 1f 	subfic  r3,r3,31
>>    4:	39 20 00 01 	li      r9,1
>>    8:	7d 23 18 30 	slw     r3,r9,r3
>>    c:	4e 80 00 20 	blr
>>
>> 00000010 <g>:
>>   10:	3d 20 80 00 	lis     r9,-32768
>>   14:	7d 23 1c 30 	srw     r3,r9,r3
>>   18:	4e 80 00 20 	blr
>
> Well yeah, it saves one instruction, but is it worth it? Are these gpio
> routines in some hot path I don't know about?
>

It saves one instruction, and one register (see other exemple below 
where r3 is to be preserved)

gpio_get() and gpio_set() are used extensively by some GPIO based 
drivers like SPI, NAND, so it may be worth it as it doesn't impair 
readability (if anyone prefers, we could write  (1 << 31) >> i  instead 
of  0x80000000 >> i )

unsigned int f(int i, unsigned int *a)
{
	*a = 1 << (31 - i);

	return i;
}

unsigned int g(int i, unsigned int *a)
{
	*a = 0x80000000 >> i;

	return i;
}

toto.o:     file format elf32-powerpc


Disassembly of section .text:

00000000 <f>:
    0:	21 43 00 1f 	subfic  r10,r3,31
    4:	39 20 00 01 	li      r9,1
    8:	7d 29 50 30 	slw     r9,r9,r10
    c:	91 24 00 00 	stw     r9,0(r4)
   10:	4e 80 00 20 	blr

00000014 <g>:
   14:	3d 20 80 00 	lis     r9,-32768
   18:	7d 29 1c 30 	srw     r9,r9,r3
   1c:	91 24 00 00 	stw     r9,0(r4)
   20:	4e 80 00 20 	blr

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ