Skip to content

tgymnich/BitwiseRotate

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

33 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

BitwiseRotate

Swift codecov

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 to ror and rol on x86. On ARM only UInt32, UInt64, Int32 and Int64 compile to ror. Rotations on SIMD vectors don't yet compile to the most efficient instructions possible.

Setup

In your Package.swift add:

.package(url: "https://github.com/tgymnich/BitwiseRotate.git", from: "1.1.1")

Usage

rol

let someBits: UInt8 = 0b01010100 <<< 3 // returns 0b10100010

ror

let someBits: UInt8 = 0b01010100 >>> 3 // returns 0b10001010

SIMD

let someBitVector = SIMD3<UInt8>(arrayLiteral: 0b01010100,0b11011100,0b00011000) <<< 1 // (0b10101000, 0b10111001, 0b00110000)