Thanks for using Compiler Explorer
Sponsors
Jakt
C++
Ada
Analysis
Android Java
Android Kotlin
Assembly
C
C3
Carbon
C++ (Circle)
CIRCT
Clean
CMake
CMakeScript
COBOL
C++ for OpenCL
MLIR
Cppx
Cppx-Blue
Cppx-Gold
Cpp2-cppfront
Crystal
C#
CUDA C++
D
Dart
Elixir
Erlang
Fortran
F#
Go
Haskell
HLSL
Hook
Hylo
ispc
Java
Julia
Kotlin
LLVM IR
LLVM MIR
Modula-2
Nim
Objective-C
Objective-C++
OCaml
OpenCL C
Pascal
Pony
Python
Racket
Ruby
Rust
Snowball
Scala
Solidity
Spice
Swift
LLVM TableGen
Toit
TypeScript Native
V
Vala
Visual Basic
Zig
Javascript
GIMPLE
swift source #1
Output
Compile to binary object
Link to binary
Execute the code
Intel asm syntax
Demangle identifiers
Verbose demangling
Filters
Unused labels
Library functions
Directives
Comments
Horizontal whitespace
Debug intrinsics
Compiler
x86-64 swiftc 3.1.1
x86-64 swiftc 4.0.2
x86-64 swiftc 4.0.3
x86-64 swiftc 4.1
x86-64 swiftc 4.1.1
x86-64 swiftc 4.1.2
x86-64 swiftc 4.2
x86-64 swiftc 5.0
x86-64 swiftc 5.1
x86-64 swiftc 5.10
x86-64 swiftc 5.2
x86-64 swiftc 5.3
x86-64 swiftc 5.4
x86-64 swiftc 5.5
x86-64 swiftc 5.6
x86-64 swiftc 5.7
x86-64 swiftc 5.8
x86-64 swiftc 5.9
x86-64 swiftc nightly
Options
Source code
infix operator >>> infix operator <<< public extension FixedWidthInteger { /// Shift the bits to the left. Shifted bits are rotated to the right. /// - Parameter n: Number of places to shift. /// - Returns: Bits rotated n places to the left. func rotateLeft(_ n: Int) -> Self { assert(n < self.bitWidth) if n == 0 { return self } return (self &<< n) | (self &>> (Self(truncatingIfNeeded: self.bitWidth) &- Self(truncatingIfNeeded: n))) } /// Shift the bits to the right. Shifted bits are rotated to the left. /// - Parameter n: Number of places to shift. /// - Returns: Bits rotated n places to the right. func rotateRight(_ n: Int) -> Self { assert(n < self.bitWidth) if n == 0 { return self } return (self &>> n) | (self &<< (Self(truncatingIfNeeded: self.bitWidth) &- Self(truncatingIfNeeded: n))) } /// Shift the bits to the left. Shifted bits are rotated to the right. /// - Parameter n: Number of places to shift. mutating func rotatedLeft(_ n: Int) { self = rotateLeft(n) } /// Shift the bits to the right. Shifted bits are rotated to the left. /// - Parameter n: Number of places to shift. mutating func rotatedRight(_ n: Int) { self = rotateLeft(n) } static func <<<(lhs: Self, n: Int) -> Self { return lhs.rotateLeft(n) } static func >>>(lhs: Self, n: Int) -> Self { return lhs.rotateRight(n) } } public extension FixedWidthInteger where Self == UInt { /// Shift the bits to the left. Shifted bits are rotated to the right. /// - Parameter n: Number of places to shift. /// - Returns: Bits rotated n places to the left. func rotateLeft<Other>(_ n: Other) -> Self where Other : BinaryInteger { assert(n < 64) if n == 0 { return self } return (self &<< n) | (self &>> (64 &- Self(truncatingIfNeeded: n))) } /// Shift the bits to the right. Shifted bits are rotated to the left. /// - Parameter n: Number of places to shift. /// - Returns: Bits rotated n places to the right. func rotateRight(_ n: Int) -> Self { assert(n < 64) if n == 0 { return self } return (self &>> n) | (self &<< (64 &- Self(truncatingIfNeeded: n))) } /// Shift the bits to the left. Shifted bits are rotated to the right. /// - Parameter n: Number of places to shift. mutating func rotatedLeft(_ n: Int) { self = rotateLeft(n) } /// Shift the bits to the right. Shifted bits are rotated to the left. /// - Parameter n: Number of places to shift. mutating func rotatedRight(_ n: Int) { self = rotateLeft(n) } static func <<<(lhs: Self, n: Int) -> Self { return lhs.rotateLeft(n) } static func >>>(lhs: Self, n: Int) -> Self { return lhs.rotateRight(n) } } public extension FixedWidthInteger where Self == UInt32 { /// Shift the bits to the left. Shifted bits are rotated to the right. /// - Parameter n: Number of places to shift. /// - Returns: Bits rotated n places to the left. func rotateLeft(_ n: Int) -> Self { assert(n < 32) if n == 0 { return self } return (self &<< n) | (self &>> (32 &- Self(truncatingIfNeeded: n))); } /// Shift the bits to the right. Shifted bits are rotated to the left. /// - Parameter n: Number of places to shift. /// - Returns: Bits rotated n places to the right. func rotateRight(_ n: Int) -> Self { assert(n < 32) if n == 0 { return self } return (self &>> n) | (self &<< (32 &- Self(truncatingIfNeeded: n))) } /// Shift the bits to the left. Shifted bits are rotated to the right. /// - Parameter n: Number of places to shift. mutating func rotatedLeft(_ n: Int) { self = rotateLeft(n) } /// Shift the bits to the right. Shifted bits are rotated to the left. /// - Parameter n: Number of places to shift. mutating func rotatedRight(_ n: Int) { self = rotateLeft(n) } static func <<<(lhs: Self, n: Int) -> Self { return lhs.rotateLeft(n) } static func >>>(lhs: Self, n: Int) -> Self { return lhs.rotateRight(n) } } public extension FixedWidthInteger where Self == UInt16 { /// Shift the bits to the left. Shifted bits are rotated to the right. /// - Parameter n: Number of places to shift. /// - Returns: Bits rotated n places to the left. func rotateLeft(_ n: Int) -> Self { assert(n < 16) if n == 0 { return self } return (self &<< n) | (self &>> (16 &- Self(truncatingIfNeeded: n))); } /// Shift the bits to the right. Shifted bits are rotated to the left. /// - Parameter n: Number of places to shift. /// - Returns: Bits rotated n places to the right. func rotateRight(_ n: Int) -> Self { assert(n < 16) if n == 0 { return self } return (self &>> n) | (self &<< (16 &- Self(truncatingIfNeeded: n))) } /// Shift the bits to the left. Shifted bits are rotated to the right. /// - Parameter n: Number of places to shift. mutating func rotatedLeft(_ n: Int) { self = rotateLeft(n) } /// Shift the bits to the right. Shifted bits are rotated to the left. /// - Parameter n: Number of places to shift. mutating func rotatedRight(_ n: Int) { self = rotateLeft(n) } static func <<<(lhs: Self, n: Int) -> Self { return lhs.rotateLeft(n) } static func >>>(lhs: Self, n: Int) -> Self { return lhs.rotateRight(n) } } public extension FixedWidthInteger where Self == UInt8 { /// Shift the bits to the left. Shifted bits are rotated to the right. /// - Parameter n: Number of places to shift. /// - Returns: Bits rotated n places to the left. func rotateLeft(_ n: Int) -> Self { assert(n < 8) if n == 0 { return self } return (self &<< n) | (self &>> (8 &- Self(truncatingIfNeeded: n))); } /// Shift the bits to the right. Shifted bits are rotated to the left. /// - Parameter n: Number of places to shift. /// - Returns: Bits rotated n places to the right. func rotateRight(_ n: Int) -> Self { assert(n < 8) if n == 0 { return self } return (self &>> n) | (self &<< (8 &- Self(truncatingIfNeeded: n))) } /// Shift the bits to the left. Shifted bits are rotated to the right. /// - Parameter n: Number of places to shift. /// - Returns: Bits rotated n places to the left. mutating func rotatedLeft(_ n: Int) { self = rotateLeft(n) } /// Shift the bits to the right. Shifted bits are rotated to the left. /// - Parameter n: Number of places to shift. mutating func rotatedRight(_ n: Int) { self = rotateLeft(n) } static func <<<(lhs: Self, n: Int) -> Self { return lhs.rotateLeft(n) } static func >>>(lhs: Self, n: Int) -> Self { return lhs.rotateRight(n) } } public extension FixedWidthInteger where Self == Int { /// Shift the bits to the left. Shifted bits are rotated to the right. /// - Parameter n: Number of places to shift. /// - Returns: Bits rotated n places to the left. func rotateLeft(_ n: Int) -> Self { return Self(truncatingIfNeeded: UInt(truncatingIfNeeded: self).rotateLeft(n)) } /// Shift the bits to the right. Shifted bits are rotated to the left. /// - Parameter n: Number of places to shift. /// - Returns: Bits rotated n places to the right. func rotateRight(_ n: Int) -> Self { return Self(truncatingIfNeeded: UInt(truncatingIfNeeded: self).rotateRight(n)) } /// Shift the bits to the left. Shifted bits are rotated to the right. /// - Parameter n: Number of places to shift. mutating func rotatedLeft(_ n: Int) { self = rotateLeft(n) } /// Shift the bits to the right. Shifted bits are rotated to the left. /// - Parameter n: Number of places to shift. mutating func rotatedRight(_ n: Int) { self = rotateLeft(n) } static func <<<(lhs: Self, n: Int) -> Self { return lhs.rotateLeft(n) } static func >>>(lhs: Self, n: Int) -> Self { return lhs.rotateRight(n) } } public extension FixedWidthInteger where Self == Int32 { /// Shift the bits to the left. Shifted bits are rotated to the right. /// - Parameter n: Number of places to shift. /// - Returns: Bits rotated n places to the left. func rotateLeft(_ n: Int) -> Self { return Self(truncatingIfNeeded: UInt32(truncatingIfNeeded: self).rotateLeft(n)) } /// Shift the bits to the right. Shifted bits are rotated to the left. /// - Parameter n: Number of places to shift. /// - Returns: Bits rotated n places to the right. func rotateRight(_ n: Int) -> Self { return Self(truncatingIfNeeded: UInt32(truncatingIfNeeded: self).rotateRight(n)) } /// Shift the bits to the left. Shifted bits are rotated to the right. /// - Parameter n: Number of places to shift. mutating func rotatedLeft(_ n: Int) { self = rotateLeft(n) } /// Shift the bits to the right. Shifted bits are rotated to the left. /// - Parameter n: Number of places to shift. mutating func rotatedRight(_ n: Int) { self = rotateLeft(n) } static func <<<(lhs: Self, n: Int) -> Self { return lhs.rotateLeft(n) } static func >>>(lhs: Self, n: Int) -> Self { return lhs.rotateRight(n) } } public extension FixedWidthInteger where Self == Int16 { /// Shift the bits to the left. Shifted bits are rotated to the right. /// - Parameter n: Number of places to shift. /// - Returns: Bits rotated n places to the left. func rotateLeft(_ n: Int) -> Self { return Self(truncatingIfNeeded: UInt16(truncatingIfNeeded: self).rotateLeft(n)) } /// Shift the bits to the right. Shifted bits are rotated to the left. /// - Parameter n: Number of places to shift. /// - Returns: Bits rotated n places to the right. func rotateRight(_ n: Int) -> Self { return Self(truncatingIfNeeded: UInt16(truncatingIfNeeded: self).rotateRight(n)) } /// Shift the bits to the left. Shifted bits are rotated to the right. /// - Parameter n: Number of places to shift. mutating func rotatedLeft(_ n: Int) { self = rotateLeft(n) } /// Shift the bits to the right. Shifted bits are rotated to the left. /// - Parameter n: Number of places to shift. mutating func rotatedRight(_ n: Int) { self = rotateLeft(n) } static func <<<(lhs: Self, n: Int) -> Self { return lhs.rotateLeft(n) } static func >>>(lhs: Self, n: Int) -> Self { return lhs.rotateRight(n) } } public extension FixedWidthInteger where Self == Int8 { /// Shift the bits to the left. Shifted bits are rotated to the right. /// - Parameter n: Number of places to shift. /// - Returns: Bits rotated n places to the left. func rotateLeft(_ n: Int) -> Self { return Self(truncatingIfNeeded: UInt8(truncatingIfNeeded: self).rotateLeft(n)) } /// Shift the bits to the right. Shifted bits are rotated to the left. /// - Parameter n: Number of places to shift. /// - Returns: Bits rotated n places to the right. func rotateRight(_ n: Int) -> Self { return Self(truncatingIfNeeded: UInt8(truncatingIfNeeded: self).rotateRight(n)) } /// Shift the bits to the left. Shifted bits are rotated to the right. /// - Parameter n: Number of places to shift. /// - Returns: Bits rotated n places to the left. mutating func rotatedLeft(_ n: Int) { self = rotateLeft(n) } /// Shift the bits to the right. Shifted bits are rotated to the left. /// - Parameter n: Number of places to shift. mutating func rotatedRight(_ n: Int) { self = rotateLeft(n) } static func <<<(lhs: Self, n: Int) -> Self { return lhs.rotateLeft(n) } static func >>>(lhs: Self, n: Int) -> Self { return lhs.rotateRight(n) } }
Become a Patron
Sponsor on GitHub
Donate via PayPal
Source on GitHub
Mailing list
Installed libraries
Wiki
Report an issue
How it works
Contact the author
CE on Mastodon
About the author
Statistics
Changelog
Version tree