This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] PR90838: Support ctz idioms
- From: Wilco Dijkstra <Wilco dot Dijkstra at arm dot com>
- To: Segher Boessenkool <segher at kernel dot crashing dot org>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Richard Biener <richard dot guenther at gmail dot com>
- Date: Wed, 13 Nov 2019 12:19:37 +0000
- Subject: Re: [PATCH] PR90838: Support ctz idioms
- Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=arm.com; dmarc=pass action=none header.from=arm.com; dkim=pass header.d=arm.com; arc=none
- Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=H0KyklovL7Yz7UMwUaQ5ebekb8heYYBtN1eD51OQNlA=; b=FXyNEExm4pKS+4TUrCLhLAqQV1PAOP6EP1HEhazeumO5ArcekbzT57/Vm5vwZcVtALANDVQmjao98eZC3gxbfiC2VwOLc3qwf3QKN7fIJ9IRI1qgb7SqZ+08rqUX56jTg3dvbcdcw6v57Y9uAw2Sr/MqsLNaGwiUEXzadOVMvkUk3/0XGqdcC41a8Td3aJkGlbbgJi4SBs39YFlKaeqPwpOk46FTgc6yh98aNY8966jNe8I4gIQ34gCU6/qFwV6nrWbKh3vxgETT33P0ewyDYCCVpU6bggxL4omXqMTKwVP7XixokVuDiaAfjeSeoINlh5LfsGBccWlgpnv8yc4L/g==
- Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ln5uHO06jOcEnb/hUuZFm7lD1/isFH9HvL8wQOAYUYPoPlr6OC1o7RtGVbKAV8ELAVd+w6hKeKAUA0L3C+GjS1r5qvNHxcVSxy+4hVrgNUbiJXwfQLGuNf4dQJvYIjPs3J6lTY5Aww8OEWkO50lgKGuPhaxcETjKKXWMPOi2sVOLbSYS677HNA8s/cY1/VPNd+QcBDQAdjKmc0JoRPYGYlg2Z1Rvl1SmvsnD6tDT8vXmoKdPfw0QLwGPAIbr1rnE2S9pmYRlBJB+2H6mQkQ2syBSnEXk5OozMsTtRAv994U7nFcG6Zlpfk2bx9LGDREOwtbugiCayGD3EHlfb2hMJg==
- Original-authentication-results: spf=none (sender IP is ) smtp.mailfrom=Wilco dot Dijkstra at arm dot com;
- References: <VI1PR0801MB212780CDB6061AD5045E74B283770@VI1PR0801MB2127.eurprd08.prod.outlook.com>,<20191113113945.GF16031@gate.crashing.org>
Hi Segher,
> Out of interest, what uses this? I have never seen it before.
It's used in sjeng in SPEC and gives a 2% speedup on Cortex-A57.
Tricks like this used to be very common 20 years ago since a loop or binary search
is way too slow and few CPUs supported fast clz/ctz instructions. It's one of those
instructions you rarely need, but when you do, performance is absolutely critical...
As Jakub mentioned in the PR, https://doc.lagout.org/security/Hackers%20Delight.pdf
is a good resource for these bit tricks.
Cheers,
Wilco