Skip to content

Commit 397339e

Browse files
authored
Rollup merge of #145278 - notJoon:doc/rotate-operation, r=antoyo
Update `rustc_codegen_gcc` rotate operation document ## Description This PR resolves a TODO comment in the `rustc_codegen_gcc` backend by documenting that the rotate operations (`rotate_left` and `rotate_right`) already implement the optimized branchless algorithm from comment. The existing implementation already uses the optimal branchless rotation pattern: - For left rotation: `(x << n) | (x >> (-n & (width-1)))` - For right rotation: `(x >> n) | (x << (-n & (width-1)))` This pattern avoids branches and generates efficient machine code across different platforms, which was the goal mentioned in the original TODO. ## Changes - Removed the TODO comment that suggested implementing the algorithm from https://blog.regehr.org/archives/1063
2 parents dc47a69 + 6d2e82b commit 397339e

File tree

1 file changed

+3
-2
lines changed
  • compiler/rustc_codegen_gcc/src/intrinsic

1 file changed

+3
-2
lines changed

compiler/rustc_codegen_gcc/src/intrinsic/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,9 +460,10 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
460460
}
461461
sym::bitreverse => self.bit_reverse(width, args[0].immediate()),
462462
sym::rotate_left | sym::rotate_right => {
463-
// TODO(antoyo): implement using algorithm from:
463+
// Using optimized branchless algorithm from:
464464
// https://blog.regehr.org/archives/1063
465-
// for other platforms.
465+
// This implementation uses the pattern (x<<n) | (x>>(-n&(width-1)))
466+
// which generates efficient code for other platforms.
466467
let is_left = name == sym::rotate_left;
467468
let val = args[0].immediate();
468469
let raw_shift = args[1].immediate();

0 commit comments

Comments
 (0)