[LLVMdev] rotate

Michael Gottesman mgottesman at apple.com
Sat Jul 28 20:55:46 PDT 2012


I can get clang/llvm to emit a rotate instruction on x86-64 when compiling C by just using -Os and the rotate from Hacker's Delight i.e.,

======
#include <stdlib.h>
#include <stdint.h>

uint32_t ror(uint32_t input, size_t rot_bits)
{
  return (input >> rot_bits) | (input << ((sizeof(input) << 3) - rot_bits));
}
======

Then compile with (assuming you are on OS X):
======
ISYSROOT=$(xcodebuild -sdk macosx -version PlatformPath)/Developer/SDKs/MacOSX10.8.sdk
$(xcrun -find clang) -isysroot $ISYSROOT ror.c -c -S -Os -o -
======

yielding an assembly output of:
======
	.section	__TEXT,__text,regular,pure_instructions
	.globl	_rotr
_rotr:                                  ## @rotr
	.cfi_startproc
## BB#0:
	pushq	%rbp
Ltmp2:
	.cfi_def_cfa_offset 16
Ltmp3:
	.cfi_offset %rbp, -16
	movq	%rsp, %rbp
Ltmp4:
	.cfi_def_cfa_register %rbp
	movb	%sil, %cl
	rorl	%cl, %edi                              <==== Rotate instruction
	movl	%edi, %eax
	popq	%rbp
	ret
	.cfi_endproc
.subsections_via_symbols
======

I hope this helps.

Michael

On Jul 28, 2012, at 8:29 PM, reed kotler <rkotler at mips.com> wrote:

> in C or C++, how can I get clang/llvm to try and do a "rotate".
> 
> (want to test this code in the mips16 port)
> 
> i.e. emit rotr node.
> 
> tia.
> 
> reed
> 
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list