https://github.com/tgymnich/bitwiserotate
🔄 Safe and efficient bitwise rotation in Swift
https://github.com/tgymnich/bitwiserotate
bitwise-operators bitwise-rotation rol ror rotation swift swift-library
Last synced: 4 days ago
JSON representation
🔄 Safe and efficient bitwise rotation in Swift
- Host: GitHub
- URL: https://github.com/tgymnich/bitwiserotate
- Owner: tgymnich
- License: mit
- Created: 2020-06-09T20:50:35.000Z (about 5 years ago)
- Default Branch: main
- Last Pushed: 2021-12-02T02:47:21.000Z (over 3 years ago)
- Last Synced: 2025-03-31T08:30:38.632Z (3 months ago)
- Topics: bitwise-operators, bitwise-rotation, rol, ror, rotation, swift, swift-library
- Language: Swift
- Homepage:
- Size: 50.8 KB
- Stars: 3
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# BitwiseRotate

[](https://codecov.io/gh/tgymnich/BitwiseRotate)A swift package providing bitwise rotation operators for `FixedWidthInteger` and `SIMD` vectors with a `FixedWidthInteger` scalar.
This package is written in a sepcific way to [compile](https://www.godbolt.org/z/4Ggohy) to `ror` and `rol` on x86. On ARM only `UInt32`, `UInt64`, `Int32` and `Int64` [compile](https://gist.github.com/tgymnich/84f1cfed5038dff435c9cdb28ceb8f10) to `ror`. Rotations on `SIMD` vectors don't yet compile to the most efficient instructions possible.# Setup
In your Package.swift add:
```swift
.package(url: "https://github.com/tgymnich/BitwiseRotate.git", from: "1.1.1")
```# Usage
## rol
```swift
let someBits: UInt8 = 0b01010100 <<< 3 // returns 0b10100010
```## ror
```swift
let someBits: UInt8 = 0b01010100 >>> 3 // returns 0b10001010
```## SIMD
```swift
let someBitVector = SIMD3(arrayLiteral: 0b01010100,0b11011100,0b00011000) <<< 1 // (0b10101000, 0b10111001, 0b00110000)
```