From 5b468182487e59d14a1aa0899da9e866215e4846 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Bystr=C3=B6m=20Ericsson?= Date: Mon, 23 Oct 2023 10:04:09 +0200 Subject: [PATCH 1/2] No bit rotations (#100). --- Sources/NBKCoreKit/NBKFixedWidthInteger.swift | 100 -------- .../NBKDoubleWidth+Rotations.swift | 240 ------------------ .../NBKCoreInteger+Rotations.swift | 93 ------- .../NBKCoreInteger+Rotations.swift | 102 -------- .../NBKDoubleWidth+Rotations.swift | 185 -------------- .../NBKDoubleWidth+Rotations.swift | 213 ---------------- 6 files changed, 933 deletions(-) delete mode 100644 Sources/NBKDoubleWidthKit/NBKDoubleWidth+Rotations.swift delete mode 100644 Tests/NBKCoreKitBenchmarks/NBKCoreInteger+Rotations.swift delete mode 100644 Tests/NBKCoreKitTests/NBKCoreInteger+Rotations.swift delete mode 100644 Tests/NBKDoubleWidthKitBenchmarks/NBKDoubleWidth+Rotations.swift delete mode 100644 Tests/NBKDoubleWidthKitTests/NBKDoubleWidth+Rotations.swift diff --git a/Sources/NBKCoreKit/NBKFixedWidthInteger.swift b/Sources/NBKCoreKit/NBKFixedWidthInteger.swift index 4f915b32..8ee30e9a 100644 --- a/Sources/NBKCoreKit/NBKFixedWidthInteger.swift +++ b/Sources/NBKCoreKit/NBKFixedWidthInteger.swift @@ -493,74 +493,6 @@ Digit: NBKFixedWidthInteger, Magnitude: NBKFixedWidthInteger, Magnitude.BitPatte /// - distance: `0 <= distance < Self.bitWidth` /// @inlinable func bitshiftedRight(by distance: Int) -> Self - - //=------------------------------------------------------------------------= - // MARK: Details x Rotations - //=------------------------------------------------------------------------= - - /// Performs a left rotation. - /// - /// ``` - /// ┌────────────┬───────── → ───────────┐ - /// │ self │ distance │ self │ - /// ├────────────┼───────── → ───────────┤ - /// │ Int256( 1) │ Int(255) │ Int256.min │ - /// │ Int256.min │ Int( 1) │ Int256( 1) │ - /// └────────────┴───────── → ───────────┘ - /// ``` - /// - /// - Parameters: - /// - distance: `0 <= distance < Self.bitWidth` - /// - @inlinable mutating func bitrotateLeft(by distance: Int) - - /// Performs a left rotation. - /// - /// ``` - /// ┌────────────┬───────── → ───────────┐ - /// │ self │ distance │ self │ - /// ├────────────┼───────── → ───────────┤ - /// │ Int256( 1) │ Int(255) │ Int256.min │ - /// │ Int256.min │ Int( 1) │ Int256( 1) │ - /// └────────────┴───────── → ───────────┘ - /// ``` - /// - /// - Parameters: - /// - distance: `0 <= distance < Self.bitWidth` - /// - @inlinable func bitrotatedLeft(by distance: Int) -> Self - - /// Performs a right rotation. - /// - /// ``` - /// ┌────────────┬───────── → ───────────┐ - /// │ self │ distance │ self │ - /// ├────────────┼───────── → ───────────┤ - /// │ Int256.min │ Int(255) │ Int256( 1) │ - /// │ Int256( 1) │ Int( 1) │ Int256.min │ - /// └────────────┴───────── → ───────────┘ - /// ``` - /// - /// - Parameters: - /// - distance: `0 <= distance < Self.bitWidth` - /// - @inlinable mutating func bitrotateRight(by distance: Int) - - /// Performs a right rotation. - /// - /// ``` - /// ┌────────────┬───────── → ───────────┐ - /// │ self │ distance │ self │ - /// ├────────────┼───────── → ───────────┤ - /// │ Int256.min │ Int(255) │ Int256( 1) │ - /// │ Int256( 1) │ Int( 1) │ Int256.min │ - /// └────────────┴───────── → ───────────┘ - /// ``` - /// - /// - Parameters: - /// - distance: `0 <= distance < Self.bitWidth` - /// - @inlinable func bitrotatedRight(by distance: Int) -> Self } //=----------------------------------------------------------------------------= @@ -758,38 +690,6 @@ extension NBKFixedWidthInteger { precondition(0 ..< self.bitWidth ~= distance, NBK.callsiteOutOfBoundsInfo()) return self &>> distance } - - //=------------------------------------------------------------------------= - // MARK: Details x Rotations - //=------------------------------------------------------------------------= - - @inlinable public mutating func bitrotateLeft(by distance: Int) { - self = self.bitrotatedLeft(by: distance) - } - - @inlinable public func bitrotatedLeft(by distance: Int) -> Self { - precondition(0 ..< Self.bitWidth ~= distance, NBK.callsiteOutOfBoundsInfo()) - //=--------------------------------------= - if distance.isZero { return self } - //=--------------------------------------= - let pushed = self &<< (distance) - let pulled = Magnitude(bitPattern: self) &>> (Self.bitWidth &- distance) - return pushed | Self(bitPattern: pulled) - } - - @inlinable public mutating func bitrotateRight(by distance: Int) { - self = self.bitrotatedRight(by: distance) - } - - @inlinable public func bitrotatedRight(by distance: Int) -> Self { - precondition(0 ..< Self.bitWidth ~= distance, NBK.callsiteOutOfBoundsInfo()) - //=--------------------------------------= - if distance.isZero { return self } - //=--------------------------------------= - let pulled = self &<< (Self.bitWidth &- distance) - let pushed = Magnitude(bitPattern: self) &>> (distance) - return Self(bitPattern: pushed) | pulled - } //=------------------------------------------------------------------------= // MARK: Details x Text diff --git a/Sources/NBKDoubleWidthKit/NBKDoubleWidth+Rotations.swift b/Sources/NBKDoubleWidthKit/NBKDoubleWidth+Rotations.swift deleted file mode 100644 index 5086b732..00000000 --- a/Sources/NBKDoubleWidthKit/NBKDoubleWidth+Rotations.swift +++ /dev/null @@ -1,240 +0,0 @@ -//=----------------------------------------------------------------------------= -// This source file is part of the Numberick open source project. -// -// Copyright (c) 2023 Oscar Byström Ericsson -// Licensed under Apache License, Version 2.0 -// -// See http://www.apache.org/licenses/LICENSE-2.0 for license information. -//=----------------------------------------------------------------------------= - -import NBKCoreKit - -//*============================================================================* -// MARK: * NBK x Double Width x Rotations x Left -//*============================================================================* - -extension NBKDoubleWidth { - - //=------------------------------------------------------------------------= - // MARK: Transformations - //=------------------------------------------------------------------------= - - /// Performs a left rotation. - /// - /// - Parameters: - /// - distance: `0 <= distance < self.bitWidth` - /// - @inlinable public mutating func bitrotateLeft(by distance: Int) { - self = self.bitrotatedLeft(by: distance) - } - - /// Performs a left rotation. - /// - /// - Parameters: - /// - distance: `0 <= distance < self.bitWidth` - /// - @inlinable public func bitrotatedLeft(@NBK.ZeroOrMore by distance: Int) -> Self { - let major = NBK .quotient(dividing: $distance, by: NBK.PowerOf2(bitWidth: UInt.self)) - let minor = NBK.remainder(dividing: $distance, by: NBK.PowerOf2(bitWidth: UInt.self)) - return self.bitrotatedLeft(major: major, minor: minor) - } - - /// Performs a left rotation. - /// - /// - Parameters: - /// - major: `0 <= major < self.endIndex` - /// - minor: `0 <= minor < UInt.bitWidth` - /// - @inlinable public mutating func bitrotateLeft(major: Int, minor: Int) { - self = self.bitrotatedLeft(major: major, minor: minor) - } - - /// Performs a left rotation. - /// - /// - Parameters: - /// - major: `0 <= major < self.endIndex` - /// - minor: `0 <= minor < UInt.bitWidth` - /// - @inlinable public func bitrotatedLeft(major: Int, minor: Int) -> Self { - precondition(0 ..< self.endIndex ~= major, NBK.callsiteOutOfBoundsInfo()) - precondition(0 ..< UInt.bitWidth ~= minor, NBK.callsiteOutOfBoundsInfo()) - //=--------------------------------------= - if minor.isZero { - return self.bitrotatedLeft(major: major) - } - //=--------------------------------------= - let push = UInt(bitPattern: minor) - let pull = UInt(bitPattern: UInt.bitWidth - minor) - //=--------------------------------------= - return Self.uninitialized(as: UInt.self) { - var (word) = self.last as UInt - let result = NBK.TwinHeaded($0, reversed: NBK.isBigEndian) - var destination = result.index(result.startIndex, offsetBy: major) - //=----------------------------------= - for source in self.indices { - //=------------------------------= - let pulled = word &>> pull - (word) = self[source] - let pushed = word &<< push - //=------------------------------= - result.base.baseAddress!.advanced(by: result.baseSubscriptIndex(destination)).initialize(to: pulled | pushed) - //=------------------------------= - result.formIndex(after: &destination) - if destination >= result.endIndex { - destination -= result.endIndex - } - } - } - } - - /// Performs a left rotation. - /// - /// - Parameters: - /// - major: `0 <= major < self.endIndex` - /// - @inlinable public mutating func bitrotateLeft(major: Int) { - self = self.bitrotatedLeft(major: major) - } - - /// Performs a left rotation. - /// - /// - Parameters: - /// - major: `0 <= major < self.endIndex` - /// - @inlinable public func bitrotatedLeft(major: Int) -> Self { - precondition(0 ..< self.endIndex ~= major, NBK.callsiteOutOfBoundsInfo()) - //=--------------------------------------= - if major.isZero { return self } - //=--------------------------------------= - return Self.uninitialized(as: UInt.self) { - let result = NBK.TwinHeaded($0, reversed: NBK.isBigEndian) - var destination = result.index(result.startIndex, offsetBy: major) - //=----------------------------------= - for source in self.indices { - //=------------------------------= - result.base.baseAddress!.advanced(by: result.baseSubscriptIndex(destination)).initialize(to: self[source]) - //=------------------------------= - result.formIndex(after: &destination) - if destination >= result.endIndex { - destination -= result.endIndex - } - } - } - } -} - -//*============================================================================* -// MARK: * NBK x Double Width x Rotations x Right -//*============================================================================* - -extension NBKDoubleWidth { - - //=------------------------------------------------------------------------= - // MARK: Transformations - //=------------------------------------------------------------------------= - - /// Performs a right rotation. - /// - /// - Parameters: - /// - distance: `0 <= distance < self.bitWidth` - /// - @inlinable public mutating func bitrotateRight(by distance: Int) { - self = self.bitrotatedRight(by: distance) - } - - /// Performs a right rotation. - /// - /// - Parameters: - /// - distance: `0 <= distance < self.bitWidth` - /// - @inlinable public func bitrotatedRight(@NBK.ZeroOrMore by distance: Int) -> Self { - let major = NBK .quotient(dividing: $distance, by: NBK.PowerOf2(bitWidth: UInt.self)) - let minor = NBK.remainder(dividing: $distance, by: NBK.PowerOf2(bitWidth: UInt.self)) - return self.bitrotatedRight(major: major, minor: minor) - } - - /// Performs a right rotation. - /// - /// - Parameters: - /// - major: `0 <= major < self.endIndex` - /// - minor: `0 <= minor < UInt.bitWidth` - /// - @inlinable public mutating func bitrotateRight(major: Int, minor: Int) { - self = self.bitrotatedRight(major: major, minor: minor) - } - - /// Performs a right rotation. - /// - /// - Parameters: - /// - major: `0 <= major < self.endIndex` - /// - minor: `0 <= minor < UInt.bitWidth` - /// - @inlinable public func bitrotatedRight(major: Int, minor: Int) -> Self { - precondition(0 ..< self.endIndex ~= major, NBK.callsiteOutOfBoundsInfo()) - precondition(0 ..< UInt.bitWidth ~= minor, NBK.callsiteOutOfBoundsInfo()) - //=--------------------------------------= - if minor.isZero { - return self.bitrotatedRight(major: major) - } - //=--------------------------------------= - let push = UInt(bitPattern: minor) - let pull = UInt(bitPattern: UInt.bitWidth - minor) - //=--------------------------------------= - return Self.uninitialized(as: UInt.self) { - var (word) = self.last as UInt - let result = NBK.TwinHeaded($0, reversed: NBK.isBigEndian) - var destination = result.index(result.endIndex, offsetBy: ~major) - //=----------------------------------= - precondition(result.indices ~= destination) - for source in self.indices { - //=------------------------------= - let pushed = word &>> push - (word) = self[source] - let pulled = word &<< pull - //=------------------------------= - result.base.baseAddress!.advanced(by: result.baseSubscriptIndex(destination)).initialize(to: pushed | pulled) - //=------------------------------= - result.formIndex(after: &destination) - if destination >= result.endIndex { - destination -= result.endIndex - } - } - } - } - - /// Performs a right rotation. - /// - /// - Parameters: - /// - major: `0 <= major < self.endIndex` - /// - @inlinable public mutating func bitrotateRight(major: Int) { - self = self.bitrotatedRight(major: major) - } - - /// Performs a right rotation. - /// - /// - Parameters: - /// - major: `0 <= major < self.endIndex` - /// - @inlinable public func bitrotatedRight(major: Int) -> Self { - precondition(0 ..< self.endIndex ~= major, NBK.callsiteOutOfBoundsInfo()) - //=--------------------------------------= - if major.isZero { return self } - //=--------------------------------------= - return Self.uninitialized(as: UInt.self) { - let result = NBK.TwinHeaded($0, reversed: NBK.isBigEndian) - var destination = result.index(result.endIndex, offsetBy: -major) - //=----------------------------------= - precondition(result.indices ~= destination) - for source in self.indices { - //=------------------------------= - result.base.baseAddress!.advanced(by: result.baseSubscriptIndex(destination)).initialize(to: self[source]) - //=------------------------------= - result.formIndex(after: &destination) - if destination >= result.endIndex { - destination -= result.endIndex - } - } - } - } -} diff --git a/Tests/NBKCoreKitBenchmarks/NBKCoreInteger+Rotations.swift b/Tests/NBKCoreKitBenchmarks/NBKCoreInteger+Rotations.swift deleted file mode 100644 index b3c6cf21..00000000 --- a/Tests/NBKCoreKitBenchmarks/NBKCoreInteger+Rotations.swift +++ /dev/null @@ -1,93 +0,0 @@ -//=----------------------------------------------------------------------------= -// This source file is part of the Numberick open source project. -// -// Copyright (c) 2023 Oscar Byström Ericsson -// Licensed under Apache License, Version 2.0 -// -// See http://www.apache.org/licenses/LICENSE-2.0 for license information. -//=----------------------------------------------------------------------------= - -#if !DEBUG - -import NBKCoreKit -import XCTest - -//*============================================================================* -// MARK: * NBK x Core Integer x Rotations x Int -//*============================================================================* - -final class NBKCoreIntegerBenchmarksOnRotationsAsInt: XCTestCase { - - typealias T = Int - - //=------------------------------------------------------------------------= - // MARK: Tests x Left - //=------------------------------------------------------------------------= - - func testBitrotatingLeft() { - var lhs = NBK.blackHoleIdentity(T(123)) - var rhs = NBK.blackHoleIdentity(T.bitWidth / 3) - - for _ in 0 ..< 5_000_000 { - NBK.blackHole(lhs.bitrotatedLeft(by: rhs)) - NBK.blackHoleInoutIdentity(&lhs) - NBK.blackHoleInoutIdentity(&rhs) - } - } - - //=------------------------------------------------------------------------= - // MARK: Tests x Right - //=------------------------------------------------------------------------= - - func testBitrotatingRight() { - var lhs = NBK.blackHoleIdentity(T(123)) - var rhs = NBK.blackHoleIdentity(T.bitWidth / 3) - - for _ in 0 ..< 5_000_000 { - NBK.blackHole(lhs.bitrotatedRight(by: rhs)) - NBK.blackHoleInoutIdentity(&lhs) - NBK.blackHoleInoutIdentity(&rhs) - } - } -} - -//*============================================================================* -// MARK: * NBK x Core Integer x Rotations x UInt -//*============================================================================* - -final class NBKCoreIntegerBenchmarksOnRotationsAsUInt: XCTestCase { - - typealias T = UInt - - //=------------------------------------------------------------------------= - // MARK: Tests x Left - //=------------------------------------------------------------------------= - - func testBitrotatingLeft() { - var lhs = NBK.blackHoleIdentity(T(123)) - var rhs = NBK.blackHoleIdentity(T.bitWidth / 3) - - for _ in 0 ..< 5_000_000 { - NBK.blackHole(lhs.bitrotatedLeft(by: rhs)) - NBK.blackHoleInoutIdentity(&lhs) - NBK.blackHoleInoutIdentity(&rhs) - } - } - - //=------------------------------------------------------------------------= - // MARK: Tests x Right - //=------------------------------------------------------------------------= - - func testBitrotatingRight() { - var lhs = NBK.blackHoleIdentity(T(123)) - var rhs = NBK.blackHoleIdentity(T.bitWidth / 3) - - for _ in 0 ..< 5_000_000 { - NBK.blackHole(lhs.bitrotatedRight(by: rhs)) - NBK.blackHoleInoutIdentity(&lhs) - NBK.blackHoleInoutIdentity(&rhs) - } - } -} - -#endif diff --git a/Tests/NBKCoreKitTests/NBKCoreInteger+Rotations.swift b/Tests/NBKCoreKitTests/NBKCoreInteger+Rotations.swift deleted file mode 100644 index 80daf92f..00000000 --- a/Tests/NBKCoreKitTests/NBKCoreInteger+Rotations.swift +++ /dev/null @@ -1,102 +0,0 @@ -//=----------------------------------------------------------------------------= -// This source file is part of the Numberick open source project. -// -// Copyright (c) 2022 Oscar Byström Ericsson -// Licensed under Apache License, Version 2.0 -// -// See http://www.apache.org/licenses/LICENSE-2.0 for license information. -//=----------------------------------------------------------------------------= - -#if DEBUG - -import NBKCoreKit -import XCTest - -//*============================================================================* -// MARK: * NBK x Core Integer x Rotations -//*============================================================================* - -final class NBKCoreIntegerTestsOnRotations: XCTestCase { - - typealias T = any NBKCoreInteger.Type - - //=------------------------------------------------------------------------= - // MARK: State - //=------------------------------------------------------------------------= - - let types: [T] = NBKCoreIntegerTests.types - - //=------------------------------------------------------------------------= - // MARK: Tests x Left - //=------------------------------------------------------------------------= - - func testBitrotatingLeftByBits() { - func whereIs(_ type: T.Type) where T: NBKCoreInteger { - NBKAssertRotateLeft( (T(7) << T(T.bitWidth - 3)), 0, (T(7) << T(T.bitWidth - 3)) | T(0)) - NBKAssertRotateLeft( (T(7) << T(T.bitWidth - 3)), 1, (T(3) << T(T.bitWidth - 2)) | T(1)) - NBKAssertRotateLeft( (T(7) << T(T.bitWidth - 3)), 2, (T(1) << T(T.bitWidth - 1)) | T(3)) - NBKAssertRotateLeft( (T(7) << T(T.bitWidth - 3)), 3, (T(0) << T(T.bitWidth - 0)) | T(7)) - - NBKAssertRotateLeft(~(T(7) << T(T.bitWidth - 3)), 0, ~(T(7) << T(T.bitWidth - 3)) & ~T(0)) - NBKAssertRotateLeft(~(T(7) << T(T.bitWidth - 3)), 1, ~(T(3) << T(T.bitWidth - 2)) & ~T(1)) - NBKAssertRotateLeft(~(T(7) << T(T.bitWidth - 3)), 2, ~(T(1) << T(T.bitWidth - 1)) & ~T(3)) - NBKAssertRotateLeft(~(T(7) << T(T.bitWidth - 3)), 3, ~(T(0) << T(T.bitWidth - 0)) & ~T(7)) - } - - for type: T in types { - whereIs(type) - } - } - - //=------------------------------------------------------------------------= - // MARK: Tests x Right - //=------------------------------------------------------------------------= - - func testBitrotatingRightByBits() { - func whereIs(_ type: T.Type) where T: NBKCoreInteger { - NBKAssertRotateRight( T(7), 0, (T(0) << T(T.bitWidth - 0)) | T(7)) - NBKAssertRotateRight( T(7), 1, (T(1) << T(T.bitWidth - 1)) | T(3)) - NBKAssertRotateRight( T(7), 2, (T(3) << T(T.bitWidth - 2)) | T(1)) - NBKAssertRotateRight( T(7), 3, (T(7) << T(T.bitWidth - 3)) | T(0)) - - NBKAssertRotateRight(~T(7), 0, ~(T(0) << T(T.bitWidth - 0)) & ~T(7)) - NBKAssertRotateRight(~T(7), 1, ~(T(1) << T(T.bitWidth - 1)) & ~T(3)) - NBKAssertRotateRight(~T(7), 2, ~(T(3) << T(T.bitWidth - 2)) & ~T(1)) - NBKAssertRotateRight(~T(7), 3, ~(T(7) << T(T.bitWidth - 3)) & ~T(0)) - } - - for type: T in types { - whereIs(type) - } - } -} - -//*============================================================================* -// MARK: * NBK x Core Integer x Rotations x Assertions -//*============================================================================* - -private func NBKAssertRotateLeft( -_ lhs: T, _ rhs: Int, _ result: T, -file: StaticString = #file, line: UInt = #line) { - //=------------------------------------------= - XCTAssert(0 ..< lhs.bitWidth ~= rhs, "no smart rotations", file: file, line: line) - //=------------------------------------------= - if 0 ..< lhs.bitWidth ~= rhs { - XCTAssertEqual(lhs.bitrotatedLeft(by: rhs), result, file: file, line: line) - XCTAssertEqual({ var lhs = lhs; lhs.bitrotateLeft(by: rhs); return lhs }(), result, file: file, line: line) - } -} - -private func NBKAssertRotateRight( -_ lhs: T, _ rhs: Int, _ result: T, -file: StaticString = #file, line: UInt = #line) { - //=------------------------------------------= - XCTAssert(0 ..< lhs.bitWidth ~= rhs, "no smart rotations", file: file, line: line) - //=------------------------------------------= - if 0 ..< lhs.bitWidth ~= rhs { - XCTAssertEqual(lhs.bitrotatedRight(by: rhs), result, file: file, line: line) - XCTAssertEqual({ var lhs = lhs; lhs.bitrotateRight(by: rhs); return lhs }(), result, file: file, line: line) - } -} - -#endif diff --git a/Tests/NBKDoubleWidthKitBenchmarks/NBKDoubleWidth+Rotations.swift b/Tests/NBKDoubleWidthKitBenchmarks/NBKDoubleWidth+Rotations.swift deleted file mode 100644 index 70c5324f..00000000 --- a/Tests/NBKDoubleWidthKitBenchmarks/NBKDoubleWidth+Rotations.swift +++ /dev/null @@ -1,185 +0,0 @@ -//=----------------------------------------------------------------------------= -// This source file is part of the Numberick open source project. -// -// Copyright (c) 2023 Oscar Byström Ericsson -// Licensed under Apache License, Version 2.0 -// -// See http://www.apache.org/licenses/LICENSE-2.0 for license information. -//=----------------------------------------------------------------------------= - -#if !DEBUG - -import NBKCoreKit -import NBKDoubleWidthKit -import XCTest - -private typealias X = NBK.U256X64 -private typealias Y = NBK.U256X32 - -//*============================================================================* -// MARK: * NBK x Double Width x Rotations x Int256 -//*============================================================================* - -final class NBKDoubleWidthBenchmarksOnRotationsAsInt256: XCTestCase { - - typealias T = Int256 - - //=------------------------------------------------------------------------= - // MARK: Tests x Left - //=------------------------------------------------------------------------= - - func testBitrotatingLeft() { - var lhs = NBK.blackHoleIdentity(T(x64: X(~0, ~1, ~2, ~3))) - var rhs = NBK.blackHoleIdentity(UInt.bitWidth * 3/2) - - for _ in 0 ..< 5_000_000 { - NBK.blackHole(lhs.bitrotatedLeft(by: rhs)) - NBK.blackHoleInoutIdentity(&lhs) - NBK.blackHoleInoutIdentity(&rhs) - } - } - - func testBitrotatingLeftByWords() { - var lhs = NBK.blackHoleIdentity(T(x64: X(~0, ~1, ~2, ~3))) - var rhs = NBK.blackHoleIdentity((major: 1, minor: UInt.bitWidth/2)) - - for _ in 0 ..< 5_000_000 { - NBK.blackHole(lhs.bitrotatedLeft(major: rhs.major)) - NBK.blackHoleInoutIdentity(&lhs) - NBK.blackHoleInoutIdentity(&rhs) - } - } - - func testBitrotatingLeftByWordsAndBits() { - var lhs = NBK.blackHoleIdentity(T(x64: X(~0, ~1, ~2, ~3))) - var rhs = NBK.blackHoleIdentity((major: 1, minor: UInt.bitWidth/2)) - - for _ in 0 ..< 5_000_000 { - NBK.blackHole(lhs.bitrotatedLeft(major: rhs.major, minor: rhs.minor)) - NBK.blackHoleInoutIdentity(&lhs) - NBK.blackHoleInoutIdentity(&rhs) - } - } - - //=------------------------------------------------------------------------= - // MARK: Tests x Right - //=------------------------------------------------------------------------= - - func testBitrotatingRight() { - var lhs = NBK.blackHoleIdentity(T(x64: X(~0, ~1, ~2, ~3))) - var rhs = NBK.blackHoleIdentity(UInt.bitWidth * 3/2) - - for _ in 0 ..< 5_000_000 { - NBK.blackHole(lhs.bitrotatedRight(by: rhs)) - NBK.blackHoleInoutIdentity(&lhs) - NBK.blackHoleInoutIdentity(&rhs) - } - } - - func testBitrotatingRightByWords() { - var lhs = NBK.blackHoleIdentity(T(x64: X(~0, ~1, ~2, ~3))) - var rhs = NBK.blackHoleIdentity((major: 1, minor: UInt.bitWidth/2)) - - for _ in 0 ..< 5_000_000 { - NBK.blackHole(lhs.bitrotatedRight(major: rhs.major)) - NBK.blackHoleInoutIdentity(&lhs) - NBK.blackHoleInoutIdentity(&rhs) - } - } - - func testBitrotatingRightByWordsAndBits() { - var lhs = NBK.blackHoleIdentity(T(x64: X(~0, ~1, ~2, ~3))) - var rhs = NBK.blackHoleIdentity((major: 1, minor: UInt.bitWidth/2)) - - for _ in 0 ..< 5_000_000 { - NBK.blackHole(lhs.bitrotatedRight(major: rhs.major, minor: rhs.minor)) - NBK.blackHoleInoutIdentity(&lhs) - NBK.blackHoleInoutIdentity(&rhs) - } - } -} - -//*============================================================================* -// MARK: * NBK x Double Width x Rotations x UInt256 -//*============================================================================* - -final class NBKDoubleWidthBenchmarksOnRotationsAsUInt256: XCTestCase { - - typealias T = UInt256 - - //=------------------------------------------------------------------------= - // MARK: Tests x Left - //=------------------------------------------------------------------------= - - func testBitrotatingLeft() { - var lhs = NBK.blackHoleIdentity(T(x64: X(~0, ~1, ~2, ~3))) - var rhs = NBK.blackHoleIdentity(UInt.bitWidth * 3/2) - - for _ in 0 ..< 5_000_000 { - NBK.blackHole(lhs.bitrotatedLeft(by: rhs)) - NBK.blackHoleInoutIdentity(&lhs) - NBK.blackHoleInoutIdentity(&rhs) - } - } - - func testBitrotatingLeftByWords() { - var lhs = NBK.blackHoleIdentity(T(x64: X(~0, ~1, ~2, ~3))) - var rhs = NBK.blackHoleIdentity((major: 1, minor: UInt.bitWidth/2)) - - for _ in 0 ..< 5_000_000 { - NBK.blackHole(lhs.bitrotatedLeft(major: rhs.major)) - NBK.blackHoleInoutIdentity(&lhs) - NBK.blackHoleInoutIdentity(&rhs) - } - } - - func testBitrotatingLeftByWordsAndBits() { - var lhs = NBK.blackHoleIdentity(T(x64: X(~0, ~1, ~2, ~3))) - var rhs = NBK.blackHoleIdentity((major: 1, minor: UInt.bitWidth/2)) - - for _ in 0 ..< 5_000_000 { - NBK.blackHole(lhs.bitrotatedLeft(major: rhs.major, minor: rhs.minor)) - NBK.blackHoleInoutIdentity(&lhs) - NBK.blackHoleInoutIdentity(&rhs) - } - } - - //=------------------------------------------------------------------------= - // MARK: Tests x Right - //=------------------------------------------------------------------------= - - func testBitrotatingRight() { - var lhs = NBK.blackHoleIdentity(T(x64: X(~0, ~1, ~2, ~3))) - var rhs = NBK.blackHoleIdentity(UInt.bitWidth * 3/2) - - for _ in 0 ..< 5_000_000 { - NBK.blackHole(lhs.bitrotatedRight(by: rhs)) - NBK.blackHoleInoutIdentity(&lhs) - NBK.blackHoleInoutIdentity(&rhs) - } - } - - func testBitrotatingRightByWords() { - var lhs = NBK.blackHoleIdentity(T(x64: X(~0, ~1, ~2, ~3))) - var rhs = NBK.blackHoleIdentity((major: 1, minor: UInt.bitWidth/2)) - - for _ in 0 ..< 5_000_000 { - NBK.blackHole(lhs.bitrotatedRight(major: rhs.major)) - NBK.blackHoleInoutIdentity(&lhs) - NBK.blackHoleInoutIdentity(&rhs) - } - } - - func testBitrotatingRightByWordsAndBits() { - var lhs = NBK.blackHoleIdentity(T(x64: X(~0, ~1, ~2, ~3))) - var rhs = NBK.blackHoleIdentity((major: 1, minor: UInt.bitWidth/2)) - - for _ in 0 ..< 5_000_000 { - NBK.blackHole(lhs.bitrotatedRight(major: rhs.major, minor: rhs.minor)) - NBK.blackHoleInoutIdentity(&lhs) - NBK.blackHoleInoutIdentity(&rhs) - } - } -} - -#endif diff --git a/Tests/NBKDoubleWidthKitTests/NBKDoubleWidth+Rotations.swift b/Tests/NBKDoubleWidthKitTests/NBKDoubleWidth+Rotations.swift deleted file mode 100644 index 90a10b97..00000000 --- a/Tests/NBKDoubleWidthKitTests/NBKDoubleWidth+Rotations.swift +++ /dev/null @@ -1,213 +0,0 @@ -//=----------------------------------------------------------------------------= -// This source file is part of the Numberick open source project. -// -// Copyright (c) 2023 Oscar Byström Ericsson -// Licensed under Apache License, Version 2.0 -// -// See http://www.apache.org/licenses/LICENSE-2.0 for license information. -//=----------------------------------------------------------------------------= - -#if DEBUG - -import NBKCoreKit -import NBKDoubleWidthKit -import XCTest - -private typealias X = NBK.U256X64 -private typealias Y = NBK.U256X32 - -//*============================================================================* -// MARK: * NBK x Double Width x Rotations x Int256 -//*============================================================================* - -final class NBKDoubleWidthTestsOnRotationsAsInt256: XCTestCase { - - typealias T = Int256 - - //=------------------------------------------------------------------------= - // MARK: Tests x Left - //=------------------------------------------------------------------------= - - func testBitrotatingLeftByBits() { - NBKAssertRotateLeft(T(x64: X( 1, 2, 3, 4)), 0, T(x64: X( 1, 2, 3, 4))) - NBKAssertRotateLeft(T(x64: X( 1, 2, 3, 4)), 1, T(x64: X( 2, 4, 6, 8))) - NBKAssertRotateLeft(T(x64: X( 1, 2, 3, 4)), 2, T(x64: X( 4, 8, 12, 16))) - NBKAssertRotateLeft(T(x64: X( 1, 2, 3, 4)), 3, T(x64: X( 8, 16, 24, 32))) - } - - func testBitrotatingLeftByWords() { - NBKAssertRotateLeft(T(x64: X( 1, 2, 3, 4)), 0, T(x64: X( 1, 2, 3, 4))) - NBKAssertRotateLeft(T(x64: X( 1, 2, 3, 4)), 64, T(x64: X( 4, 1, 2, 3))) - NBKAssertRotateLeft(T(x64: X( 1, 2, 3, 4)), 128, T(x64: X( 3, 4, 1, 2))) - NBKAssertRotateLeft(T(x64: X( 1, 2, 3, 4)), 192, T(x64: X( 2, 3, 4, 1))) - } - - func testBitrotatingLeftByWordsAndBits() { - NBKAssertRotateLeft(T(x64: X( 1, 2, 3, 4)), 3, T(x64: X( 8, 16, 24, 32))) - NBKAssertRotateLeft(T(x64: X( 1, 2, 3, 4)), 67, T(x64: X(32, 8, 16, 24))) - NBKAssertRotateLeft(T(x64: X( 1, 2, 3, 4)), 131, T(x64: X(24, 32, 8, 16))) - NBKAssertRotateLeft(T(x64: X( 1, 2, 3, 4)), 195, T(x64: X(16, 24, 32, 8))) - } - - func testBitrotatingLeftSuchThatWordsSplit() { - NBKAssertRotateLeft(T(x64: X(~0, 0, 0, 0)), 1, T(x64: X(~1, 1, 0, 0))) - NBKAssertRotateLeft(T(x64: X( 0, ~0, 0, 0)), 1, T(x64: X( 0, ~1, 1, 0))) - NBKAssertRotateLeft(T(x64: X( 0, 0, ~0, 0)), 1, T(x64: X( 0, 0, ~1, 1))) - NBKAssertRotateLeft(T(x64: X( 0, 0, 0, ~0)), 1, T(x64: X( 1, 0, 0, ~1))) - } - - //=------------------------------------------------------------------------= - // MARK: Tests x Right - //=------------------------------------------------------------------------= - - func testBitrotatingRightByBits() { - NBKAssertRotateRight(T(x64: X(8, 16, 24, 32)), 0, T(x64: X( 8, 16, 24, 32))) - NBKAssertRotateRight(T(x64: X(8, 16, 24, 32)), 1, T(x64: X( 4, 8, 12, 16))) - NBKAssertRotateRight(T(x64: X(8, 16, 24, 32)), 2, T(x64: X( 2, 4, 6, 8))) - NBKAssertRotateRight(T(x64: X(8, 16, 24, 32)), 3, T(x64: X( 1, 2, 3, 4))) - } - - func testBitrotatingRightByWords() { - NBKAssertRotateRight(T(x64: X( 1, 2, 3, 4)), 0, T(x64: X( 1, 2, 3, 4))) - NBKAssertRotateRight(T(x64: X( 1, 2, 3, 4)), 64, T(x64: X( 2, 3, 4, 1))) - NBKAssertRotateRight(T(x64: X( 1, 2, 3, 4)), 128, T(x64: X( 3, 4, 1, 2))) - NBKAssertRotateRight(T(x64: X( 1, 2, 3, 4)), 192, T(x64: X( 4, 1, 2, 3))) - } - - func testBitrotatingRightByWordsAndBits() { - NBKAssertRotateRight(T(x64: X(8, 16, 24, 32)), 3, T(x64: X( 1, 2, 3, 4))) - NBKAssertRotateRight(T(x64: X(8, 16, 24, 32)), 67, T(x64: X( 2, 3, 4, 1))) - NBKAssertRotateRight(T(x64: X(8, 16, 24, 32)), 131, T(x64: X( 3, 4, 1, 2))) - NBKAssertRotateRight(T(x64: X(8, 16, 24, 32)), 195, T(x64: X( 4, 1, 2, 3))) - } - - func testBitrotatingRightSuchThatWordsSplit() { - NBKAssertRotateRight(T(x64: X(0, 0, 0, 7)), 1, T(x64: X( 0, 0, 1 << 63, 3))) - NBKAssertRotateRight(T(x64: X(0, 0, 7, 0)), 1, T(x64: X( 0, 1 << 63, 3, 0))) - NBKAssertRotateRight(T(x64: X(0, 7, 0, 0)), 1, T(x64: X( 1 << 63, 3, 0, 0))) - NBKAssertRotateRight(T(x64: X(7, 0, 0, 0)), 1, T(x64: X( 3, 0, 0, 1 << 63))) - } -} - -//*============================================================================* -// MARK: * NBK x Double Width x Rotations x UInt256 -//*============================================================================* - -final class NBKDoubleWidthTestsOnRotationsAsUInt256: XCTestCase { - - typealias T = UInt256 - - //=------------------------------------------------------------------------= - // MARK: Tests x Left - //=------------------------------------------------------------------------= - - func testBitrotatingLeftByBits() { - NBKAssertRotateLeft(T(x64: X( 1, 2, 3, 4)), 0, T(x64: X( 1, 2, 3, 4))) - NBKAssertRotateLeft(T(x64: X( 1, 2, 3, 4)), 1, T(x64: X( 2, 4, 6, 8))) - NBKAssertRotateLeft(T(x64: X( 1, 2, 3, 4)), 2, T(x64: X( 4, 8, 12, 16))) - NBKAssertRotateLeft(T(x64: X( 1, 2, 3, 4)), 3, T(x64: X( 8, 16, 24, 32))) - } - - func testBitrotatingLeftByWords() { - NBKAssertRotateLeft(T(x64: X( 1, 2, 3, 4)), 0, T(x64: X( 1, 2, 3, 4))) - NBKAssertRotateLeft(T(x64: X( 1, 2, 3, 4)), 64, T(x64: X( 4, 1, 2, 3))) - NBKAssertRotateLeft(T(x64: X( 1, 2, 3, 4)), 128, T(x64: X( 3, 4, 1, 2))) - NBKAssertRotateLeft(T(x64: X( 1, 2, 3, 4)), 192, T(x64: X( 2, 3, 4, 1))) - } - - func testBitrotatingLeftByWordsAndBits() { - NBKAssertRotateLeft(T(x64: X( 1, 2, 3, 4)), 3, T(x64: X( 8, 16, 24, 32))) - NBKAssertRotateLeft(T(x64: X( 1, 2, 3, 4)), 67, T(x64: X(32, 8, 16, 24))) - NBKAssertRotateLeft(T(x64: X( 1, 2, 3, 4)), 131, T(x64: X(24, 32, 8, 16))) - NBKAssertRotateLeft(T(x64: X( 1, 2, 3, 4)), 195, T(x64: X(16, 24, 32, 8))) - } - - func testBitrotatingLeftSuchThatWordsSplit() { - NBKAssertRotateLeft(T(x64: X(~0, 0, 0, 0)), 1, T(x64: X(~1, 1, 0, 0))) - NBKAssertRotateLeft(T(x64: X( 0, ~0, 0, 0)), 1, T(x64: X( 0, ~1, 1, 0))) - NBKAssertRotateLeft(T(x64: X( 0, 0, ~0, 0)), 1, T(x64: X( 0, 0, ~1, 1))) - NBKAssertRotateLeft(T(x64: X( 0, 0, 0, ~0)), 1, T(x64: X( 1, 0, 0, ~1))) - } - - //=------------------------------------------------------------------------= - // MARK: Tests x Right - //=------------------------------------------------------------------------= - - func testBitrotatingRightByBits() { - NBKAssertRotateRight(T(x64: X(8, 16, 24, 32)), 0, T(x64: X( 8, 16, 24, 32))) - NBKAssertRotateRight(T(x64: X(8, 16, 24, 32)), 1, T(x64: X( 4, 8, 12, 16))) - NBKAssertRotateRight(T(x64: X(8, 16, 24, 32)), 2, T(x64: X( 2, 4, 6, 8))) - NBKAssertRotateRight(T(x64: X(8, 16, 24, 32)), 3, T(x64: X( 1, 2, 3, 4))) - } - - func testBitrotatingRightByWords() { - NBKAssertRotateRight(T(x64: X( 1, 2, 3, 4)), 0, T(x64: X( 1, 2, 3, 4))) - NBKAssertRotateRight(T(x64: X( 1, 2, 3, 4)), 64, T(x64: X( 2, 3, 4, 1))) - NBKAssertRotateRight(T(x64: X( 1, 2, 3, 4)), 128, T(x64: X( 3, 4, 1, 2))) - NBKAssertRotateRight(T(x64: X( 1, 2, 3, 4)), 192, T(x64: X( 4, 1, 2, 3))) - } - - func testBitrotatingRightByWordsAndBits() { - NBKAssertRotateRight(T(x64: X(8, 16, 24, 32)), 3, T(x64: X( 1, 2, 3, 4))) - NBKAssertRotateRight(T(x64: X(8, 16, 24, 32)), 67, T(x64: X( 2, 3, 4, 1))) - NBKAssertRotateRight(T(x64: X(8, 16, 24, 32)), 131, T(x64: X( 3, 4, 1, 2))) - NBKAssertRotateRight(T(x64: X(8, 16, 24, 32)), 195, T(x64: X( 4, 1, 2, 3))) - } - - func testBitrotatingRightSuchThatWordsSplit() { - NBKAssertRotateRight(T(x64: X(0, 0, 0, 7)), 1, T(x64: X( 0, 0, 1 << 63, 3))) - NBKAssertRotateRight(T(x64: X(0, 0, 7, 0)), 1, T(x64: X( 0, 1 << 63, 3, 0))) - NBKAssertRotateRight(T(x64: X(0, 7, 0, 0)), 1, T(x64: X( 1 << 63, 3, 0, 0))) - NBKAssertRotateRight(T(x64: X(7, 0, 0, 0)), 1, T(x64: X( 3, 0, 0, 1 << 63))) - } -} - -//*============================================================================* -// MARK: * NBK x Double Width x Rotations x Assertions -//*============================================================================* - -private func NBKAssertRotateLeft( -_ lhs: NBKDoubleWidth, _ rhs: Int, _ result: NBKDoubleWidth, -file: StaticString = #file, line: UInt = #line) { - //=------------------------------------------= - let (major, minor) = rhs.quotientAndRemainder(dividingBy: UInt.bitWidth) - //=------------------------------------------= - XCTAssert(0 ..< lhs.bitWidth ~= rhs, "no smart rotations", file: file, line: line) - //=------------------------------------------= - if 0 ..< lhs.bitWidth ~= rhs { - XCTAssertEqual(lhs.bitrotatedLeft(by: rhs), result, file: file, line: line) - XCTAssertEqual({ var lhs = lhs; lhs.bitrotateLeft(by: rhs); return lhs }(), result, file: file, line: line) - - XCTAssertEqual(lhs.bitrotatedLeft(major: major, minor: minor), result, file: file, line: line) - XCTAssertEqual({ var lhs = lhs; lhs.bitrotateLeft(major: major, minor: minor); return lhs }(), result, file: file, line: line) - } - //=------------------------------------------= - if 0 ..< lhs.bitWidth ~= rhs, minor.isZero { - XCTAssertEqual(lhs.bitrotatedLeft(major: major), result, file: file, line: line) - XCTAssertEqual({ var lhs = lhs; lhs.bitrotateLeft(major: major); return lhs }(), result, file: file, line: line) - } -} - -private func NBKAssertRotateRight( -_ lhs: NBKDoubleWidth, _ rhs: Int, _ result: NBKDoubleWidth, -file: StaticString = #file, line: UInt = #line) { - //=------------------------------------------= - let (major, minor) = rhs.quotientAndRemainder(dividingBy: UInt.bitWidth) - //=------------------------------------------= - XCTAssert(0 ..< lhs.bitWidth ~= rhs, "no smart rotations", file: file, line: line) - //=------------------------------------------= - if 0 ..< lhs.bitWidth ~= rhs { - XCTAssertEqual(lhs.bitrotatedRight(by: rhs), result, file: file, line: line) - XCTAssertEqual({ var lhs = lhs; lhs.bitrotateRight(by: rhs); return lhs }(), result, file: file, line: line) - - XCTAssertEqual(lhs.bitrotatedRight(major: major, minor: minor), result, file: file, line: line) - XCTAssertEqual({ var lhs = lhs; lhs.bitrotateRight(major: major, minor: minor); return lhs }(), result, file: file, line: line) - } - //=------------------------------------------= - if 0 ..< lhs.bitWidth ~= rhs, minor.isZero { - XCTAssertEqual(lhs.bitrotatedRight(major: major), result, file: file, line: line) - XCTAssertEqual({ var lhs = lhs; lhs.bitrotateRight(major: major); return lhs }(), result, file: file, line: line) - } -} - -#endif From 5f459caffcccbefdecfbae4424faa384140a9ce2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oscar=20Bystr=C3=B6m=20Ericsson?= Date: Mon, 23 Oct 2023 10:04:09 +0200 Subject: [PATCH 2/2] Camel case `bitShift` like `bitWidth` (#103). --- Sources/NBKCoreKit/NBKFixedWidthInteger.swift | 16 ++-- .../NBKStrictBinaryInteger+Shifts.swift | 16 ++-- .../NBKStrictUnsignedInteger+Shifts.swift | 44 +++++----- .../NBKDoubleWidth+Division.swift | 14 +-- .../NBKDoubleWidth+Shifts.swift | 80 ++++++++--------- .../NBKCoreInteger+Shifts.swift | 16 ++-- .../NBKCoreInteger+Shifts.swift | 20 ++--- .../NBKStrictBinaryInteger+Shifts.swift | 24 ++--- .../NBKStrictUnsignedInteger+Shifts.swift | 30 +++---- .../NBKDoubleWidth+Shifts.swift | 48 +++++----- .../NBKDoubleWidth+Shifts.swift | 88 +++++++++---------- 11 files changed, 198 insertions(+), 198 deletions(-) diff --git a/Sources/NBKCoreKit/NBKFixedWidthInteger.swift b/Sources/NBKCoreKit/NBKFixedWidthInteger.swift index 8ee30e9a..602ebf19 100644 --- a/Sources/NBKCoreKit/NBKFixedWidthInteger.swift +++ b/Sources/NBKCoreKit/NBKFixedWidthInteger.swift @@ -438,7 +438,7 @@ Digit: NBKFixedWidthInteger, Magnitude: NBKFixedWidthInteger, Magnitude.BitPatte /// - Parameters: /// - distance: `0 <= distance < Self.bitWidth` /// - @inlinable mutating func bitshiftLeft(by distance: Int) + @inlinable mutating func bitShiftLeft(by distance: Int) /// Performs a left shift. /// @@ -454,7 +454,7 @@ Digit: NBKFixedWidthInteger, Magnitude: NBKFixedWidthInteger, Magnitude.BitPatte /// - Parameters: /// - distance: `0 <= distance < Self.bitWidth` /// - @inlinable func bitshiftedLeft(by distance: Int) -> Self + @inlinable func bitShiftedLeft(by distance: Int) -> Self /// Performs an un/signed right shift. /// @@ -473,7 +473,7 @@ Digit: NBKFixedWidthInteger, Magnitude: NBKFixedWidthInteger, Magnitude.BitPatte /// - Parameters: /// - distance: `0 <= distance < Self.bitWidth` /// - @inlinable mutating func bitshiftRight(by distance: Int) + @inlinable mutating func bitShiftRight(by distance: Int) /// Performs an un/signed right shift. /// @@ -492,7 +492,7 @@ Digit: NBKFixedWidthInteger, Magnitude: NBKFixedWidthInteger, Magnitude.BitPatte /// - Parameters: /// - distance: `0 <= distance < Self.bitWidth` /// - @inlinable func bitshiftedRight(by distance: Int) -> Self + @inlinable func bitShiftedRight(by distance: Int) -> Self } //=----------------------------------------------------------------------------= @@ -671,22 +671,22 @@ extension NBKFixedWidthInteger { // MARK: Details x Shifts //=------------------------------------------------------------------------= - @inlinable public mutating func bitshiftLeft(by distance: Int) { + @inlinable public mutating func bitShiftLeft(by distance: Int) { precondition(0 ..< self.bitWidth ~= distance, NBK.callsiteOutOfBoundsInfo()) self &<<= distance } - @inlinable public func bitshiftedLeft(by distance: Int) -> Self { + @inlinable public func bitShiftedLeft(by distance: Int) -> Self { precondition(0 ..< self.bitWidth ~= distance, NBK.callsiteOutOfBoundsInfo()) return self &<< distance } - @inlinable public mutating func bitshiftRight(by distance: Int) { + @inlinable public mutating func bitShiftRight(by distance: Int) { precondition(0 ..< self.bitWidth ~= distance, NBK.callsiteOutOfBoundsInfo()) self &>>= distance } - @inlinable public func bitshiftedRight(by distance: Int) -> Self { + @inlinable public func bitShiftedRight(by distance: Int) -> Self { precondition(0 ..< self.bitWidth ~= distance, NBK.callsiteOutOfBoundsInfo()) return self &>> distance } diff --git a/Sources/NBKCoreKit/Private/NBKStrictBinaryInteger+Shifts.swift b/Sources/NBKCoreKit/Private/NBKStrictBinaryInteger+Shifts.swift index 1f0d1fe3..02c20967 100644 --- a/Sources/NBKCoreKit/Private/NBKStrictBinaryInteger+Shifts.swift +++ b/Sources/NBKCoreKit/Private/NBKStrictBinaryInteger+Shifts.swift @@ -27,7 +27,7 @@ extension NBK.StrictBinaryInteger where Base: MutableCollection { /// - environment: The element used to fill the void. /// - major: `1 <= major < base.count` /// - @inlinable public static func bitshiftLeft( + @inlinable public static func bitShiftLeft( _ base: inout Base, environment: Base.Element, majorAtLeastOne major: Int) { //=--------------------------------------= var destination = base.endIndex as Base.Index @@ -70,9 +70,9 @@ extension NBK.StrictBinaryInteger where Base: MutableCollection { /// - major: `0 <= major < base.count` /// - minor: `1 <= minor < Base.Element.bitWidth` /// - @inlinable public static func bitshiftLeft( + @inlinable public static func bitShiftLeft( _ base: inout Base, environment: Base.Element, major: Int, minorAtLeastOne minor: Int) { - self.bitshiftLeftCodeBlock(&base, environment: environment, major: major, minorAtLeastOne: minor) + self.bitShiftLeftCodeBlock(&base, environment: environment, major: major, minorAtLeastOne: minor) } /// Performs a left shift, assuming the `base` is ordered from least to most significant. @@ -87,7 +87,7 @@ extension NBK.StrictBinaryInteger where Base: MutableCollection { /// /// `@inline(always)` is required for `NBKDoubleWidth` performance reasons. /// - @inline(__always) @inlinable public static func bitshiftLeftCodeBlock( + @inline(__always) @inlinable public static func bitShiftLeftCodeBlock( _ base: inout Base, environment: Base.Element, major: Int, minorAtLeastOne minor: Int) { //=--------------------------------------= precondition(1 <= minor && minor < Base.Element.bitWidth, NBK.callsiteOutOfBoundsInfo()) @@ -139,7 +139,7 @@ extension NBK.StrictBinaryInteger where Base: MutableCollection { /// - environment: The element used to fill the void. /// - major: `1 <= major < base.count` /// - @inlinable public static func bitshiftRight( + @inlinable public static func bitShiftRight( _ base: inout Base, environment: Base.Element, majorAtLeastOne major: Int) { //=--------------------------------------= var destination = base.startIndex as Base.Index @@ -181,9 +181,9 @@ extension NBK.StrictBinaryInteger where Base: MutableCollection { /// - major: `0 <= major < base.count` /// - minor: `1 <= minor < Base.Element.bitWidth` /// - @inlinable public static func bitshiftRight( + @inlinable public static func bitShiftRight( _ base: inout Base, environment: Base.Element, major: Int, minorAtLeastOne minor: Int) { - Self.bitshiftRightCodeBlock(&base, environment: environment, major: major, minorAtLeastOne: minor) + Self.bitShiftRightCodeBlock(&base, environment: environment, major: major, minorAtLeastOne: minor) } /// Performs a right shift, assuming the `base` is ordered from least to most significant. @@ -198,7 +198,7 @@ extension NBK.StrictBinaryInteger where Base: MutableCollection { /// /// `@inline(always)` is required for `NBKDoubleWidth` performance reasons. /// - @inline(__always) @inlinable public static func bitshiftRightCodeBlock( + @inline(__always) @inlinable public static func bitShiftRightCodeBlock( _ base: inout Base, environment: Base.Element, major: Int, minorAtLeastOne minor: Int) { //=--------------------------------------= precondition(1 <= minor && minor < Base.Element.bitWidth, NBK.callsiteOutOfBoundsInfo()) diff --git a/Sources/NBKCoreKit/Private/NBKStrictUnsignedInteger+Shifts.swift b/Sources/NBKCoreKit/Private/NBKStrictUnsignedInteger+Shifts.swift index 639e4795..5c4ff188 100644 --- a/Sources/NBKCoreKit/Private/NBKStrictUnsignedInteger+Shifts.swift +++ b/Sources/NBKCoreKit/Private/NBKStrictUnsignedInteger+Shifts.swift @@ -25,9 +25,9 @@ extension NBK.StrictUnsignedInteger where Base: MutableCollection { /// - Parameters: /// - distance: `0 <= distance < base.bitWidth` /// - @inlinable public static func bitshiftLeft(_ base: inout Base, by distance: Int) { + @inlinable public static func bitShiftLeft(_ base: inout Base, by distance: Int) { let (major, minor) = distance.quotientAndRemainder(dividingBy: Base.Element.bitWidth) - return self.bitshiftLeft(&base, major: major, minor: minor) + return self.bitShiftLeft(&base, major: major, minor: minor) } /// Performs a left shift. @@ -36,13 +36,13 @@ extension NBK.StrictUnsignedInteger where Base: MutableCollection { /// - major: `0 <= major < base.endIndex` /// - minor: `0 <= minor < Base.Element.bitWidth` /// - @inlinable public static func bitshiftLeft(_ base: inout Base, major: Int, minor: Int) { + @inlinable public static func bitShiftLeft(_ base: inout Base, major: Int, minor: Int) { //=--------------------------------------= if minor.isZero { - return self.bitshiftLeft(&base, major: major) + return self.bitShiftLeft(&base, major: major) } //=--------------------------------------= - self.bitshiftLeft(&base, major: major, minorAtLeastOne: minor) + self.bitShiftLeft(&base, major: major, minorAtLeastOne: minor) } /// Performs a left shift. @@ -50,11 +50,11 @@ extension NBK.StrictUnsignedInteger where Base: MutableCollection { /// - Parameters: /// - major: `0 <= major < base.endIndex` /// - @inlinable public static func bitshiftLeft(_ base: inout Base, major: Int) { + @inlinable public static func bitShiftLeft(_ base: inout Base, major: Int) { //=--------------------------------------= if major.isZero { return } //=--------------------------------------= - self.bitshiftLeft(&base, majorAtLeastOne: major) + self.bitShiftLeft(&base, majorAtLeastOne: major) } //=------------------------------------------------------------------------= @@ -67,8 +67,8 @@ extension NBK.StrictUnsignedInteger where Base: MutableCollection { /// - major: `0 <= major < base.endIndex` /// - minor: `1 <= minor < Base.Element.bitWidth` /// - @inlinable public static func bitshiftLeft(_ base: inout Base, major: Int, minorAtLeastOne minor: Int) { - Binary.bitshiftLeft(&base, environment: 0 as Base.Element, major: major, minorAtLeastOne: minor) + @inlinable public static func bitShiftLeft(_ base: inout Base, major: Int, minorAtLeastOne minor: Int) { + Binary.bitShiftLeft(&base, environment: 0 as Base.Element, major: major, minorAtLeastOne: minor) } /// Performs a left shift. @@ -76,8 +76,8 @@ extension NBK.StrictUnsignedInteger where Base: MutableCollection { /// - Parameters: /// - major: `1 <= major < base.endIndex` /// - @inlinable public static func bitshiftLeft(_ base: inout Base, majorAtLeastOne major: Int) { - Binary.bitshiftLeft(&base, environment: 0 as Base.Element, majorAtLeastOne: major) + @inlinable public static func bitShiftLeft(_ base: inout Base, majorAtLeastOne major: Int) { + Binary.bitShiftLeft(&base, environment: 0 as Base.Element, majorAtLeastOne: major) } } @@ -96,9 +96,9 @@ extension NBK.StrictUnsignedInteger where Base: MutableCollection { /// - Parameters: /// - distance: `0 <= distance < base.bitWidth` /// - @inlinable public static func bitshiftRight(_ base: inout Base, by distance: Int) { + @inlinable public static func bitShiftRight(_ base: inout Base, by distance: Int) { let (major, minor) = distance.quotientAndRemainder(dividingBy: Base.Element.bitWidth) - return self.bitshiftRight(&base, major: major, minor: minor) + return self.bitShiftRight(&base, major: major, minor: minor) } /// Performs an unsigned right shift. @@ -107,13 +107,13 @@ extension NBK.StrictUnsignedInteger where Base: MutableCollection { /// - major: `0 <= major < base.endIndex` /// - bits: `0 <= minor < Base.Element.bitWidth` /// - @inlinable public static func bitshiftRight(_ base: inout Base, major: Int, minor: Int) { + @inlinable public static func bitShiftRight(_ base: inout Base, major: Int, minor: Int) { //=--------------------------------------= if minor.isZero { - return self.bitshiftRight(&base, major: major) + return self.bitShiftRight(&base, major: major) } //=--------------------------------------= - self.bitshiftRight(&base, major: major, minorAtLeastOne: minor) + self.bitShiftRight(&base, major: major, minorAtLeastOne: minor) } /// Performs an unsigned right shift. @@ -121,11 +121,11 @@ extension NBK.StrictUnsignedInteger where Base: MutableCollection { /// - Parameters: /// - major: `0 <= major < base.endIndex` /// - @inlinable public static func bitshiftRight(_ base: inout Base, major: Int) { + @inlinable public static func bitShiftRight(_ base: inout Base, major: Int) { //=--------------------------------------= if major.isZero { return } //=--------------------------------------= - self.bitshiftRight(&base, majorAtLeastOne: major) + self.bitShiftRight(&base, majorAtLeastOne: major) } //=------------------------------------------------------------------------= @@ -138,8 +138,8 @@ extension NBK.StrictUnsignedInteger where Base: MutableCollection { /// - major: `0 <= major < base.endIndex` /// - minor: `1 <= minor < Base.Element.bitWidth` /// - @inlinable public static func bitshiftRight(_ base: inout Base, major: Int, minorAtLeastOne minor: Int) { - Binary.bitshiftRight(&base, environment: 0 as Base.Element, major: major, minorAtLeastOne: minor) + @inlinable public static func bitShiftRight(_ base: inout Base, major: Int, minorAtLeastOne minor: Int) { + Binary.bitShiftRight(&base, environment: 0 as Base.Element, major: major, minorAtLeastOne: minor) } /// Performs an unsigned right shift. @@ -147,7 +147,7 @@ extension NBK.StrictUnsignedInteger where Base: MutableCollection { /// - Parameters: /// - major: `1 <= major < base.endIndex` /// - @inlinable public static func bitshiftRight(_ base: inout Base, majorAtLeastOne major: Int) { - Binary.bitshiftRight(&base, environment: 0 as Base.Element, majorAtLeastOne: major) + @inlinable public static func bitShiftRight(_ base: inout Base, majorAtLeastOne major: Int) { + Binary.bitShiftRight(&base, environment: 0 as Base.Element, majorAtLeastOne: major) } } diff --git a/Sources/NBKDoubleWidthKit/NBKDoubleWidth+Division.swift b/Sources/NBKDoubleWidthKit/NBKDoubleWidth+Division.swift index d742f6ca..1052a58c 100644 --- a/Sources/NBKDoubleWidthKit/NBKDoubleWidth+Division.swift +++ b/Sources/NBKDoubleWidthKit/NBKDoubleWidth+Division.swift @@ -166,13 +166,13 @@ extension NBKDoubleWidth where High == High.Magnitude { let minor = NBK.remainder(dividing: shift, by: NBK.PowerOf2(bitWidth: UInt.self)) let top = shift.value.isZero ? High.zero : lhs.high &>> (High.bitWidth &- shift.value) - let lhs = lhs.bitshiftedLeft(major: major, minor: minor) as Self - let rhs = rhs.bitshiftedLeft(major: major, minor: minor) as Self + let lhs = lhs.bitShiftedLeft(major: major, minor: minor) as Self + let rhs = rhs.bitShiftedLeft(major: major, minor: minor) as Self //=--------------------------------------= // division: 3212 (normalized) //=--------------------------------------= let (quotient, remainder) = Self.divide3212MSBUnchecked(NBK.Wide3(top, lhs.high, lhs.low), by: rhs) - return QR(Self(low: quotient), remainder.bitshiftedRight(major: major, minor: minor)) + return QR(Self(low: quotient), remainder.bitShiftedRight(major: major, minor: minor)) } //=------------------------------------------------------------------------= @@ -225,20 +225,20 @@ extension NBKDoubleWidth where High == High.Magnitude { let major = NBK .quotient(dividing: shift, by: NBK.PowerOf2(bitWidth: UInt.self)) let minor = NBK.remainder(dividing: shift, by: NBK.PowerOf2(bitWidth: UInt.self)) - let lhs = lhs.bitshiftedLeft(major: major, minor: minor) as NBKDoubleWidth - let rhs = rhs.bitshiftedLeft(major: major, minor: minor) as Self + let lhs = lhs.bitShiftedLeft(major: major, minor: minor) as NBKDoubleWidth + let rhs = rhs.bitShiftedLeft(major: major, minor: minor) as Self //=--------------------------------------= // division: 3212 (normalized) //=--------------------------------------= if lhs.high.high.isZero, rhs > Self(high: lhs.high.low, low: lhs.low.high) { let (quotient, remainder) = Self.divide3212MSBUnchecked(NBK.Wide3(lhs.high.low, lhs.low.high, lhs.low.low), by: rhs) - return QR(Self(low: quotient), remainder.bitshiftedRight(major: major, minor: minor)) + return QR(Self(low: quotient), remainder.bitShiftedRight(major: major, minor: minor)) } //=--------------------------------------= // division: 4222 (normalized) //=--------------------------------------= let (quotient, remainder) = Self.divide4222MSBUnchecked(lhs, by: rhs) - return QR(quotient, remainder.bitshiftedRight(major: major, minor: minor)) + return QR(quotient, remainder.bitShiftedRight(major: major, minor: minor)) } //=------------------------------------------------------------------------= diff --git a/Sources/NBKDoubleWidthKit/NBKDoubleWidth+Shifts.swift b/Sources/NBKDoubleWidthKit/NBKDoubleWidth+Shifts.swift index d0b79244..cd308574 100644 --- a/Sources/NBKDoubleWidthKit/NBKDoubleWidth+Shifts.swift +++ b/Sources/NBKDoubleWidthKit/NBKDoubleWidth+Shifts.swift @@ -20,7 +20,7 @@ extension NBKDoubleWidth { //=------------------------------------------------------------------------= @inlinable public static func <<=(lhs: inout Self, rhs: some BinaryInteger) { - lhs.bitshiftLeftSmart(by: NBK.initOrBitCast(clamping: rhs, as: Int.self)) + lhs.bitShiftLeftSmart(by: NBK.initOrBitCast(clamping: rhs, as: Int.self)) } @inlinable public static func <<(lhs: Self, rhs: some BinaryInteger) -> Self { @@ -28,7 +28,7 @@ extension NBKDoubleWidth { } @inlinable public static func &<<=(lhs: inout Self, rhs: some BinaryInteger) { - lhs.bitshiftLeft(by: NBK.leastPositiveResidue(dividing: rhs, by: NBK.NonZero(unchecked: Self.bitWidth))) + lhs.bitShiftLeft(by: NBK.leastPositiveResidue(dividing: rhs, by: NBK.NonZero(unchecked: Self.bitWidth))) } @inlinable public static func &<<(lhs: Self, rhs: some BinaryInteger) -> Self { @@ -44,12 +44,12 @@ extension NBKDoubleWidth { /// - Parameters: /// - distance: `Int.min <= distance <= Int.max` /// - @inlinable public mutating func bitshiftLeftSmart(by distance: Int) { + @inlinable public mutating func bitShiftLeftSmart(by distance: Int) { let size = distance.magnitude as UInt switch (distance >= 0, size < UInt(bitPattern: self.bitWidth)) { - case (true, true ): self.bitshiftLeft (by: Int(bitPattern: size)) + case (true, true ): self.bitShiftLeft (by: Int(bitPattern: size)) case (true, false): self = Self(repeating: false) - case (false, true ): self.bitshiftRight(by: Int(bitPattern: size)) + case (false, true ): self.bitShiftRight(by: Int(bitPattern: size)) case (false, false): self = Self(repeating: self.isLessThanZero) } } @@ -58,8 +58,8 @@ extension NBKDoubleWidth { /// - Parameters: /// - distance: `Int.min <= distance <= Int.max` /// - @inlinable public func bitshiftedLeftSmart(by distance: Int) -> Self { - var result = self; result.bitshiftLeftSmart(by: distance); return result + @inlinable public func bitShiftedLeftSmart(by distance: Int) -> Self { + var result = self; result.bitShiftLeftSmart(by: distance); return result } /// Performs a left shift. @@ -67,10 +67,10 @@ extension NBKDoubleWidth { /// - Parameters: /// - distance: `0 <= distance < self.bitWidth` /// - @inlinable public mutating func bitshiftLeft(@NBK.ZeroOrMore by distance: Int) { + @inlinable public mutating func bitShiftLeft(@NBK.ZeroOrMore by distance: Int) { let major = NBK .quotient(dividing: $distance, by: NBK.PowerOf2(bitWidth: UInt.self)) let minor = NBK.remainder(dividing: $distance, by: NBK.PowerOf2(bitWidth: UInt.self)) - return self.bitshiftLeft(major: major, minor: minor) + return self.bitShiftLeft(major: major, minor: minor) } /// Performs a left shift. @@ -78,8 +78,8 @@ extension NBKDoubleWidth { /// - Parameters: /// - distance: `0 <= distance < self.bitWidth` /// - @inlinable public func bitshiftedLeft(by distance: Int) -> Self { - var result = self; result.bitshiftLeft(by: distance); return result + @inlinable public func bitShiftedLeft(by distance: Int) -> Self { + var result = self; result.bitShiftLeft(by: distance); return result } /// Performs a left shift. @@ -88,13 +88,13 @@ extension NBKDoubleWidth { /// - major: `0 <= major < self.endIndex` /// - minor: `0 <= minor < UInt.bitWidth` /// - @inlinable public mutating func bitshiftLeft(major: Int, minor: Int) { + @inlinable public mutating func bitShiftLeft(major: Int, minor: Int) { //=--------------------------------------= if minor.isZero { - return self.bitshiftLeft(major: major) + return self.bitShiftLeft(major: major) } //=--------------------------------------= - NBK.SBI.bitshiftLeftCodeBlock(&self, environment: 0 as UInt, major: major, minorAtLeastOne: minor) + NBK.SBI.bitShiftLeftCodeBlock(&self, environment: 0 as UInt, major: major, minorAtLeastOne: minor) } /// Performs a left shift. @@ -103,8 +103,8 @@ extension NBKDoubleWidth { /// - major: `0 <= major < self.endIndex` /// - minor: `0 <= minor < UInt.bitWidth` /// - @inlinable public func bitshiftedLeft(major: Int, minor: Int) -> Self { - var result = self; result.bitshiftLeft(major: major, minor: minor); return result + @inlinable public func bitShiftedLeft(major: Int, minor: Int) -> Self { + var result = self; result.bitShiftLeft(major: major, minor: minor); return result } /// Performs a left shift. @@ -112,11 +112,11 @@ extension NBKDoubleWidth { /// - Parameters: /// - major: `0 <= major < self.endIndex` /// - @inlinable public mutating func bitshiftLeft(major: Int) { + @inlinable public mutating func bitShiftLeft(major: Int) { //=--------------------------------------= if major.isZero { return } //=--------------------------------------= - NBK.SBI.bitshiftLeft(&self, environment: 0 as UInt, majorAtLeastOne: major) + NBK.SBI.bitShiftLeft(&self, environment: 0 as UInt, majorAtLeastOne: major) } /// Performs a left shift. @@ -124,8 +124,8 @@ extension NBKDoubleWidth { /// - Parameters: /// - major: `0 <= major < self.endIndex` /// - @inlinable public func bitshiftedLeft(major: Int) -> Self { - var result = self; result.bitshiftLeft(major: major); return result + @inlinable public func bitShiftedLeft(major: Int) -> Self { + var result = self; result.bitShiftLeft(major: major); return result } } @@ -140,7 +140,7 @@ extension NBKDoubleWidth { //=------------------------------------------------------------------------= @inlinable public static func >>=(lhs: inout Self, rhs: some BinaryInteger) { - lhs.bitshiftRightSmart(by: NBK.initOrBitCast(clamping: rhs, as: Int.self)) + lhs.bitShiftRightSmart(by: NBK.initOrBitCast(clamping: rhs, as: Int.self)) } @inlinable public static func >>(lhs: Self, rhs: some BinaryInteger) -> Self { @@ -148,7 +148,7 @@ extension NBKDoubleWidth { } @inlinable public static func &>>=(lhs: inout Self, rhs: some BinaryInteger) { - lhs.bitshiftRight(by: NBK.leastPositiveResidue(dividing: rhs, by: NBK.NonZero(unchecked: Self.bitWidth))) + lhs.bitShiftRight(by: NBK.leastPositiveResidue(dividing: rhs, by: NBK.NonZero(unchecked: Self.bitWidth))) } @inlinable public static func &>>(lhs: Self, rhs: some BinaryInteger) -> Self { @@ -164,12 +164,12 @@ extension NBKDoubleWidth { /// - Parameters: /// - distance: `Int.min <= distance <= Int.max` /// - @inlinable public mutating func bitshiftRightSmart(by distance: Int) { + @inlinable public mutating func bitShiftRightSmart(by distance: Int) { let size = distance.magnitude as UInt switch (distance >= 0, size < UInt(bitPattern: self.bitWidth)) { - case (true, true ): self.bitshiftRight(by: Int(bitPattern: size)) + case (true, true ): self.bitShiftRight(by: Int(bitPattern: size)) case (true, false): self = Self(repeating: self.isLessThanZero) - case (false, true ): self.bitshiftLeft (by: Int(bitPattern: size)) + case (false, true ): self.bitShiftLeft (by: Int(bitPattern: size)) case (false, false): self = Self(repeating: false) } } @@ -178,8 +178,8 @@ extension NBKDoubleWidth { /// - Parameters: /// - distance: `Int.min <= distance <= Int.max` /// - @inlinable public func bitshiftedRightSmart(by distance: Int) -> Self { - var result = self; result.bitshiftRightSmart(by: distance); return result + @inlinable public func bitShiftedRightSmart(by distance: Int) -> Self { + var result = self; result.bitShiftRightSmart(by: distance); return result } /// Performs an un/signed right shift. @@ -187,10 +187,10 @@ extension NBKDoubleWidth { /// - Parameters: /// - distance: `0 <= distance < self.bitWidth` /// - @inlinable public mutating func bitshiftRight(@NBK.ZeroOrMore by distance: Int) { + @inlinable public mutating func bitShiftRight(@NBK.ZeroOrMore by distance: Int) { let major = NBK .quotient(dividing: $distance, by: NBK.PowerOf2(bitWidth: UInt.self)) let minor = NBK.remainder(dividing: $distance, by: NBK.PowerOf2(bitWidth: UInt.self)) - return self.bitshiftRight(major: major, minor: minor) + return self.bitShiftRight(major: major, minor: minor) } /// Performs an un/signed right shift. @@ -198,8 +198,8 @@ extension NBKDoubleWidth { /// - Parameters: /// - distance: `0 <= distance < self.bitWidth` /// - @inlinable public func bitshiftedRight(by distance: Int) -> Self { - var result = self; result.bitshiftRight(by: distance); return result + @inlinable public func bitShiftedRight(by distance: Int) -> Self { + var result = self; result.bitShiftRight(by: distance); return result } /// Performs an un/signed right shift. @@ -208,14 +208,14 @@ extension NBKDoubleWidth { /// - major: `0 <= major < self.endIndex` /// - minor: `0 <= minor < UInt.bitWidth` /// - @inlinable public mutating func bitshiftRight(major: Int, minor: Int) { + @inlinable public mutating func bitShiftRight(major: Int, minor: Int) { //=--------------------------------------= if minor.isZero { - return self.bitshiftRight(major: major) + return self.bitShiftRight(major: major) } //=--------------------------------------= let environment = UInt(repeating: self.isLessThanZero) - NBK.SBI.bitshiftRightCodeBlock(&self, environment: environment, major: major, minorAtLeastOne: minor) + NBK.SBI.bitShiftRightCodeBlock(&self, environment: environment, major: major, minorAtLeastOne: minor) } /// Performs an un/signed right shift. @@ -224,8 +224,8 @@ extension NBKDoubleWidth { /// - major: `0 <= major < self.endIndex` /// - minor: `0 <= minor < UInt.bitWidth` /// - @inlinable public func bitshiftedRight(major: Int, minor: Int) -> Self { - var result = self; result.bitshiftRight(major: major, minor: minor); return result + @inlinable public func bitShiftedRight(major: Int, minor: Int) -> Self { + var result = self; result.bitShiftRight(major: major, minor: minor); return result } /// Performs an un/signed right shift. @@ -233,12 +233,12 @@ extension NBKDoubleWidth { /// - Parameters: /// - major: `0 <= major < self.endIndex` /// - @inlinable public mutating func bitshiftRight(major: Int) { + @inlinable public mutating func bitShiftRight(major: Int) { //=--------------------------------------= if major.isZero { return } //=--------------------------------------= let environment = UInt(repeating: self.isLessThanZero) - NBK.SBI.bitshiftRight(&self, environment: environment, majorAtLeastOne: major) + NBK.SBI.bitShiftRight(&self, environment: environment, majorAtLeastOne: major) } /// Performs an un/signed right shift. @@ -246,7 +246,7 @@ extension NBKDoubleWidth { /// - Parameters: /// - major: `0 <= major < self.endIndex` /// - @inlinable public func bitshiftedRight(major: Int) -> Self { - var result = self; result.bitshiftRight(major: major); return result + @inlinable public func bitShiftedRight(major: Int) -> Self { + var result = self; result.bitShiftRight(major: major); return result } } diff --git a/Tests/NBKCoreKitBenchmarks/NBKCoreInteger+Shifts.swift b/Tests/NBKCoreKitBenchmarks/NBKCoreInteger+Shifts.swift index 05df4ce5..edf2d5be 100644 --- a/Tests/NBKCoreKitBenchmarks/NBKCoreInteger+Shifts.swift +++ b/Tests/NBKCoreKitBenchmarks/NBKCoreInteger+Shifts.swift @@ -24,12 +24,12 @@ final class NBKCoreIntegerBenchmarksOnShiftsAsInt: XCTestCase { // MARK: Tests x Left //=------------------------------------------------------------------------= - func testBitshiftingLeft() { + func testBitShiftingLeft() { var lhs = NBK.blackHoleIdentity(T(123)) var rhs = NBK.blackHoleIdentity(T.bitWidth / 3) for _ in 0 ..< 5_000_000 { - NBK.blackHole(lhs.bitshiftedLeft(by: rhs)) + NBK.blackHole(lhs.bitShiftedLeft(by: rhs)) NBK.blackHoleInoutIdentity(&lhs) NBK.blackHoleInoutIdentity(&rhs) } @@ -39,12 +39,12 @@ final class NBKCoreIntegerBenchmarksOnShiftsAsInt: XCTestCase { // MARK: Tests x Right //=------------------------------------------------------------------------= - func testBitshiftingRight() { + func testBitShiftingRight() { var lhs = NBK.blackHoleIdentity(T(123)) var rhs = NBK.blackHoleIdentity(T.bitWidth / 3) for _ in 0 ..< 5_000_000 { - NBK.blackHole(lhs.bitshiftedRight(by: rhs)) + NBK.blackHole(lhs.bitShiftedRight(by: rhs)) NBK.blackHoleInoutIdentity(&lhs) NBK.blackHoleInoutIdentity(&rhs) } @@ -63,12 +63,12 @@ final class NBKCoreIntegerBenchmarksOnShiftsAsUInt: XCTestCase { // MARK: Tests x Left //=------------------------------------------------------------------------= - func testBitshiftingLeft() { + func testBitShiftingLeft() { var lhs = NBK.blackHoleIdentity(T(123)) var rhs = NBK.blackHoleIdentity(T.bitWidth / 3) for _ in 0 ..< 5_000_000 { - NBK.blackHole(lhs.bitshiftedLeft(by: rhs)) + NBK.blackHole(lhs.bitShiftedLeft(by: rhs)) NBK.blackHoleInoutIdentity(&lhs) NBK.blackHoleInoutIdentity(&rhs) } @@ -78,12 +78,12 @@ final class NBKCoreIntegerBenchmarksOnShiftsAsUInt: XCTestCase { // MARK: Tests x Right //=------------------------------------------------------------------------= - func testBitshiftingRight() { + func testBitShiftingRight() { var lhs = NBK.blackHoleIdentity(T(123)) var rhs = NBK.blackHoleIdentity(T.bitWidth / 3) for _ in 0 ..< 5_000_000 { - NBK.blackHole(lhs.bitshiftedRight(by: rhs)) + NBK.blackHole(lhs.bitShiftedRight(by: rhs)) NBK.blackHoleInoutIdentity(&lhs) NBK.blackHoleInoutIdentity(&rhs) } diff --git a/Tests/NBKCoreKitTests/NBKCoreInteger+Shifts.swift b/Tests/NBKCoreKitTests/NBKCoreInteger+Shifts.swift index 6dbf34c6..022e48bb 100644 --- a/Tests/NBKCoreKitTests/NBKCoreInteger+Shifts.swift +++ b/Tests/NBKCoreKitTests/NBKCoreInteger+Shifts.swift @@ -30,7 +30,7 @@ final class NBKCoreIntegerTestsOnShifts: XCTestCase { // MARK: Tests x Left //=------------------------------------------------------------------------= - func testBitshiftingLeftByBits() { + func testBitShiftingLeftByBits() { func whereIs(_ type: T.Type) where T: NBKCoreInteger { NBKAssertShiftLeft(~T(0), 0, ~T(0)) NBKAssertShiftLeft(~T(0), 1, ~T(1)) @@ -47,7 +47,7 @@ final class NBKCoreIntegerTestsOnShifts: XCTestCase { // MARK: Tests x Right //=------------------------------------------------------------------------= - func testBitshiftingRightByBits() { + func testBitShiftingRightByBits() { func whereIs(_ type: T.Type) where T: NBKCoreInteger { NBKAssertShiftRight(T(7), 0, T(7)) NBKAssertShiftRight(T(7), 1, T(3)) @@ -60,7 +60,7 @@ final class NBKCoreIntegerTestsOnShifts: XCTestCase { } } - func testBitshiftingRightIsSignedOrUnsigned() { + func testBitShiftingRightIsSignedOrUnsigned() { func whereIs(_ type: T.Type) where T: NBKCoreInteger { NBKAssertShiftRight(T(repeating: true), T.bitWidth, T(repeating: T.isSigned)) } @@ -74,7 +74,7 @@ final class NBKCoreIntegerTestsOnShifts: XCTestCase { // MARK: Tests x Miscellaneous //=------------------------------------------------------------------------= - func testBitshiftingIsSmart() { + func testBitShiftingIsSmart() { func whereIs(_ type: T.Type) where T: NBKCoreInteger { XCTAssertEqual(T(4) << 1, T(8)) XCTAssertEqual(T(4) >> -1, T(8)) @@ -88,7 +88,7 @@ final class NBKCoreIntegerTestsOnShifts: XCTestCase { } } - func testBitshiftingByMinDistanceDoesNotTrap() { + func testBitShiftingByMinDistanceDoesNotTrap() { func whereIs(_ type: T.Type) where T: NBKCoreInteger { XCTAssertEqual(T(repeating: true) << Int.min, T(repeating: T.isSigned)) XCTAssertEqual(T(repeating: true) >> Int.min, T(repeating: false)) @@ -99,7 +99,7 @@ final class NBKCoreIntegerTestsOnShifts: XCTestCase { } } - func testBitshiftingByMaskingIsEquivalentToBitshiftingModuloBitWidth() { + func testBitShiftingByMaskingIsEquivalentToBitShiftingModuloBitWidth() { func whereIs(_ type: T.Type) where T: NBKCoreInteger { NBKAssertShiftLeftByMasking(~T(0), 0 + T.bitWidth, ~T(0)) NBKAssertShiftLeftByMasking(~T(0), 0 - T.bitWidth, ~T(0)) @@ -146,8 +146,8 @@ file: StaticString = #file, line: UInt = #line) { } //=------------------------------------------= if 0 ..< lhs.bitWidth ~= rhs { - XCTAssertEqual(lhs.bitshiftedLeft(by: rhs), result, file: file, line: line) - XCTAssertEqual({ var lhs = lhs; lhs.bitshiftLeft(by: rhs); return lhs }(), result, file: file, line: line) + XCTAssertEqual(lhs.bitShiftedLeft(by: rhs), result, file: file, line: line) + XCTAssertEqual({ var lhs = lhs; lhs.bitShiftLeft(by: rhs); return lhs }(), result, file: file, line: line) } } @@ -167,8 +167,8 @@ file: StaticString = #file, line: UInt = #line) { } //=------------------------------------------= if 0 ..< lhs.bitWidth ~= rhs { - XCTAssertEqual(lhs.bitshiftedRight(by: rhs), result, file: file, line: line) - XCTAssertEqual({ var lhs = lhs; lhs.bitshiftRight(by: rhs); return lhs }(), result, file: file, line: line) + XCTAssertEqual(lhs.bitShiftedRight(by: rhs), result, file: file, line: line) + XCTAssertEqual({ var lhs = lhs; lhs.bitShiftRight(by: rhs); return lhs }(), result, file: file, line: line) } } diff --git a/Tests/NBKCoreKitTests/Private/NBKStrictBinaryInteger+Shifts.swift b/Tests/NBKCoreKitTests/Private/NBKStrictBinaryInteger+Shifts.swift index 67d48a7c..1ef7d47d 100644 --- a/Tests/NBKCoreKitTests/Private/NBKStrictBinaryInteger+Shifts.swift +++ b/Tests/NBKCoreKitTests/Private/NBKStrictBinaryInteger+Shifts.swift @@ -28,7 +28,7 @@ final class NBKStrictBinaryIntegerTestsOnShifts: XCTestCase { // MARK: Tests x Left //=------------------------------------------------------------------------= - func testBitshiftingLeftByBits() { + func testBitShiftingLeftByBits() { NBKAssertShiftLeft([ 1, 2, 3, 4] as T8, 0 as UInt8, 0 as Int, [ 1, 2, 3, 4] as T8) NBKAssertShiftLeft([ 1, 2, 3, 4] as T8, 0 as UInt8, 1 as Int, [ 2, 4, 6, 8] as T8) NBKAssertShiftLeft([ 1, 2, 3, 4] as T8, 0 as UInt8, 2 as Int, [ 4, 8, 12, 16] as T8) @@ -40,7 +40,7 @@ final class NBKStrictBinaryIntegerTestsOnShifts: XCTestCase { NBKAssertShiftLeft([ 1, 2, 3, 4] as T8, ~0 as UInt8, 3 as Int, [15, 16, 24, 32] as T8) } - func testBitshiftingLeftByWords() { + func testBitShiftingLeftByWords() { NBKAssertShiftLeft([ 1, 2, 3, 4] as T8, 0 as UInt8, 0 as Int, [ 1, 2, 3, 4] as T8) NBKAssertShiftLeft([ 1, 2, 3, 4] as T8, 0 as UInt8, 8 as Int, [ 0, 1, 2, 3] as T8) NBKAssertShiftLeft([ 1, 2, 3, 4] as T8, 0 as UInt8, 16 as Int, [ 0, 0, 1, 2] as T8) @@ -52,7 +52,7 @@ final class NBKStrictBinaryIntegerTestsOnShifts: XCTestCase { NBKAssertShiftLeft([ 1, 2, 3, 4] as T8, ~0 as UInt8, 24 as Int, [~0, ~0, ~0, 1] as T8) } - func testBitshiftingLeftByWordsAndBits() { + func testBitShiftingLeftByWordsAndBits() { NBKAssertShiftLeft([ 1, 2, 3, 4] as T8, 0 as UInt8, 3 as Int, [ 8, 16, 24, 32] as T8) NBKAssertShiftLeft([ 1, 2, 3, 4] as T8, 0 as UInt8, 11 as Int, [ 0, 8, 16, 24] as T8) NBKAssertShiftLeft([ 1, 2, 3, 4] as T8, 0 as UInt8, 19 as Int, [ 0, 0, 8, 16] as T8) @@ -64,7 +64,7 @@ final class NBKStrictBinaryIntegerTestsOnShifts: XCTestCase { NBKAssertShiftLeft([ 1, 2, 3, 4] as T8, ~0 as UInt8, 27 as Int, [~0, ~0, ~0, 15] as T8) } - func testBitshiftingLeftSuchThatWordsSplit() { + func testBitShiftingLeftSuchThatWordsSplit() { NBKAssertShiftLeft([~0, 0, 0, 0] as T8, 0 as UInt8, 1 as Int, [~1, 1, 0, 0] as T8) NBKAssertShiftLeft([ 0, ~0, 0, 0] as T8, 0 as UInt8, 1 as Int, [ 0, ~1, 1, 0] as T8) NBKAssertShiftLeft([ 0, 0, ~0, 0] as T8, 0 as UInt8, 1 as Int, [ 0, 0, ~1, 1] as T8) @@ -80,7 +80,7 @@ final class NBKStrictBinaryIntegerTestsOnShifts: XCTestCase { // MARK: Tests x Right //=------------------------------------------------------------------------= - func testBitshiftingRightByBits() { + func testBitShiftingRightByBits() { NBKAssertShiftRight([8, 16, 24, 32] as T8, 0 as UInt8, 0 as Int, [ 8, 16, 24, 32] as T8) NBKAssertShiftRight([8, 16, 24, 32] as T8, 0 as UInt8, 1 as Int, [ 4, 8, 12, 16] as T8) NBKAssertShiftRight([8, 16, 24, 32] as T8, 0 as UInt8, 2 as Int, [ 2, 4, 6, 8] as T8) @@ -92,7 +92,7 @@ final class NBKStrictBinaryIntegerTestsOnShifts: XCTestCase { NBKAssertShiftRight([8, 16, 24, 32] as T8, ~0 as UInt8, 3 as Int, [ 1, 2, 3, 4 + ~0 << 5] as T8) } - func testBitshiftingRightByWords() { + func testBitShiftingRightByWords() { NBKAssertShiftRight([8, 16, 24, 32] as T8, 0 as UInt8, 0 as Int, [ 8, 16, 24, 32] as T8) NBKAssertShiftRight([8, 16, 24, 32] as T8, 0 as UInt8, 8 as Int, [16, 24, 32, 0] as T8) NBKAssertShiftRight([8, 16, 24, 32] as T8, 0 as UInt8, 16 as Int, [24, 32, 0, 0] as T8) @@ -104,7 +104,7 @@ final class NBKStrictBinaryIntegerTestsOnShifts: XCTestCase { NBKAssertShiftRight([8, 16, 24, 32] as T8, ~0 as UInt8, 24 as Int, [32, ~0, ~0, ~0] as T8) } - func testBitshiftingRightByWordsAndBits() { + func testBitShiftingRightByWordsAndBits() { NBKAssertShiftRight([8, 16, 24, 32] as T8, 0 as UInt8, 3 as Int, [ 1, 2, 3, 4] as T8) NBKAssertShiftRight([8, 16, 24, 32] as T8, 0 as UInt8, 11 as Int, [ 2, 3, 4, 0] as T8) NBKAssertShiftRight([8, 16, 24, 32] as T8, 0 as UInt8, 19 as Int, [ 3, 4, 0, 0] as T8) @@ -116,7 +116,7 @@ final class NBKStrictBinaryIntegerTestsOnShifts: XCTestCase { NBKAssertShiftRight([8, 16, 24, 32] as T8, ~0 as UInt8, 27 as Int, [ 4 + ~0 << 5, ~0, ~0, ~0] as T8) } - func testBitshiftingRightSuchThatWordsSplit() { + func testBitShiftingRightSuchThatWordsSplit() { NBKAssertShiftRight([0, 0, 0, 7] as T8, 0 as UInt8, 1 as Int, [ 0, 0, 1 << 7, 3] as T8) NBKAssertShiftRight([0, 0, 7, 0] as T8, 0 as UInt8, 1 as Int, [ 0, 1 << 7, 3, 0] as T8) NBKAssertShiftRight([0, 7, 0, 0] as T8, 0 as UInt8, 1 as Int, [ 1 << 7, 3, 0, 0] as T8) @@ -143,13 +143,13 @@ file: StaticString = #file, line: UInt = #line) { //=------------------------------------------= if major >= 1, minor == 0 { var base = base - SBI.bitshiftLeft(&base, environment: environment, majorAtLeastOne: major) + SBI.bitShiftLeft(&base, environment: environment, majorAtLeastOne: major) XCTAssertEqual(base, result, file: file, line: line) } if major >= 0, minor >= 1 { var base = base - SBI.bitshiftLeft(&base, environment: environment, major: major, minorAtLeastOne: minor) + SBI.bitShiftLeft(&base, environment: environment, major: major, minorAtLeastOne: minor) XCTAssertEqual(base, result, file: file, line: line) } } @@ -164,13 +164,13 @@ file: StaticString = #file, line: UInt = #line) { //=------------------------------------------= if major >= 1, minor == 0 { var base = base - SBI.bitshiftRight(&base, environment: environment, majorAtLeastOne: major) + SBI.bitShiftRight(&base, environment: environment, majorAtLeastOne: major) XCTAssertEqual(base, result, file: file, line: line) } if major >= 0, minor >= 1 { var base = base - SBI.bitshiftRight(&base, environment: environment, major: major, minorAtLeastOne: minor) + SBI.bitShiftRight(&base, environment: environment, major: major, minorAtLeastOne: minor) XCTAssertEqual(base, result, file: file, line: line) } } diff --git a/Tests/NBKCoreKitTests/Private/NBKStrictUnsignedInteger+Shifts.swift b/Tests/NBKCoreKitTests/Private/NBKStrictUnsignedInteger+Shifts.swift index 0a4217f1..c6151e3a 100644 --- a/Tests/NBKCoreKitTests/Private/NBKStrictUnsignedInteger+Shifts.swift +++ b/Tests/NBKCoreKitTests/Private/NBKStrictUnsignedInteger+Shifts.swift @@ -28,28 +28,28 @@ final class NBKStrictUnsignedIntegerTestsOnShifts: XCTestCase { // MARK: Tests x Left //=------------------------------------------------------------------------= - func testBitshiftingLeftByBits() { + func testBitShiftingLeftByBits() { NBKAssertShiftLeft([ 1, 2, 3, 4] as T8, 0 as Int, [ 1, 2, 3, 4] as T8) NBKAssertShiftLeft([ 1, 2, 3, 4] as T8, 1 as Int, [ 2, 4, 6, 8] as T8) NBKAssertShiftLeft([ 1, 2, 3, 4] as T8, 2 as Int, [ 4, 8, 12, 16] as T8) NBKAssertShiftLeft([ 1, 2, 3, 4] as T8, 3 as Int, [ 8, 16, 24, 32] as T8) } - func testBitshiftingLeftByWords() { + func testBitShiftingLeftByWords() { NBKAssertShiftLeft([ 1, 2, 3, 4] as T8, 0 as Int, [ 1, 2, 3, 4] as T8) NBKAssertShiftLeft([ 1, 2, 3, 4] as T8, 8 as Int, [ 0, 1, 2, 3] as T8) NBKAssertShiftLeft([ 1, 2, 3, 4] as T8, 16 as Int, [ 0, 0, 1, 2] as T8) NBKAssertShiftLeft([ 1, 2, 3, 4] as T8, 24 as Int, [ 0, 0, 0, 1] as T8) } - func testBitshiftingLeftByWordsAndBits() { + func testBitShiftingLeftByWordsAndBits() { NBKAssertShiftLeft([ 1, 2, 3, 4] as T8, 3 as Int, [ 8, 16, 24, 32] as T8) NBKAssertShiftLeft([ 1, 2, 3, 4] as T8, 11 as Int, [ 0, 8, 16, 24] as T8) NBKAssertShiftLeft([ 1, 2, 3, 4] as T8, 19 as Int, [ 0, 0, 8, 16] as T8) NBKAssertShiftLeft([ 1, 2, 3, 4] as T8, 27 as Int, [ 0, 0, 0, 8] as T8) } - func testBitshiftingLeftSuchThatWordsSplit() { + func testBitShiftingLeftSuchThatWordsSplit() { NBKAssertShiftLeft([~0, 0, 0, 0] as T8, 1 as Int, [~1, 1, 0, 0] as T8) NBKAssertShiftLeft([ 0, ~0, 0, 0] as T8, 1 as Int, [ 0, ~1, 1, 0] as T8) NBKAssertShiftLeft([ 0, 0, ~0, 0] as T8, 1 as Int, [ 0, 0, ~1, 1] as T8) @@ -60,35 +60,35 @@ final class NBKStrictUnsignedIntegerTestsOnShifts: XCTestCase { // MARK: Tests x Right //=------------------------------------------------------------------------= - func testBitshiftingRightByBits() { + func testBitShiftingRightByBits() { NBKAssertShiftRight([8, 16, 24, 32] as T8, 0 as Int, [ 8, 16, 24, 32] as T8) NBKAssertShiftRight([8, 16, 24, 32] as T8, 1 as Int, [ 4, 8, 12, 16] as T8) NBKAssertShiftRight([8, 16, 24, 32] as T8, 2 as Int, [ 2, 4, 6, 8] as T8) NBKAssertShiftRight([8, 16, 24, 32] as T8, 3 as Int, [ 1, 2, 3, 4] as T8) } - func testBitshiftingRightByWords() { + func testBitShiftingRightByWords() { NBKAssertShiftRight([8, 16, 24, 32] as T8, 0 as Int, [ 8, 16, 24, 32] as T8) NBKAssertShiftRight([8, 16, 24, 32] as T8, 8 as Int, [16, 24, 32, 0] as T8) NBKAssertShiftRight([8, 16, 24, 32] as T8, 16 as Int, [24, 32, 0, 0] as T8) NBKAssertShiftRight([8, 16, 24, 32] as T8, 24 as Int, [32, 0, 0, 0] as T8) } - func testBitshiftingRightByWordsAndBits() { + func testBitShiftingRightByWordsAndBits() { NBKAssertShiftRight([8, 16, 24, 32] as T8, 3 as Int, [ 1, 2, 3, 4] as T8) NBKAssertShiftRight([8, 16, 24, 32] as T8, 11 as Int, [ 2, 3, 4, 0] as T8) NBKAssertShiftRight([8, 16, 24, 32] as T8, 19 as Int, [ 3, 4, 0, 0] as T8) NBKAssertShiftRight([8, 16, 24, 32] as T8, 27 as Int, [ 4, 0, 0, 0] as T8) } - func testBitshiftingRightSuchThatWordsSplit() { + func testBitShiftingRightSuchThatWordsSplit() { NBKAssertShiftRight([0, 0, 0, 7] as T8, 1 as Int, [ 0, 0, 1 << 7, 3] as T8) NBKAssertShiftRight([0, 0, 7, 0] as T8, 1 as Int, [ 0, 1 << 7, 3, 0] as T8) NBKAssertShiftRight([0, 7, 0, 0] as T8, 1 as Int, [ 1 << 7, 3, 0, 0] as T8) NBKAssertShiftRight([7, 0, 0, 0] as T8, 1 as Int, [ 3, 0, 0, 0] as T8) } - func testBitshiftingRightIsUnsigned() { + func testBitShiftingRightIsUnsigned() { NBKAssertShiftRight([0, 0, 0, 1 << 7] as T8, 0 as Int, [0, 0, 0, 1 << 7] as T8) NBKAssertShiftRight([0, 0, 0, 1 << 7] as T8, 8 as Int, [0, 0, 1 << 7, 0] as T8) NBKAssertShiftRight([0, 0, 0, 1 << 7] as T8, 16 as Int, [0, 1 << 7, 0, 0] as T8) @@ -110,19 +110,19 @@ file: StaticString = #file, line: UInt = #line) { //=------------------------------------------= brr: do { var base = base - SBI.bitshiftLeft(&base, by: distance) + SBI.bitShiftLeft(&base, by: distance) XCTAssertEqual(base, result, file: file, line: line) } brr: do { var base = base - SBI.bitshiftLeft(&base, major: major, minor: minor) + SBI.bitShiftLeft(&base, major: major, minor: minor) XCTAssertEqual(base, result, file: file, line: line) } if minor.isZero { var base = base - SBI.bitshiftLeft(&base, major: major) + SBI.bitShiftLeft(&base, major: major) XCTAssertEqual(base, result, file: file, line: line) } } @@ -137,19 +137,19 @@ file: StaticString = #file, line: UInt = #line) { //=------------------------------------------= brr: do { var base = base - SBI.bitshiftRight(&base, by: distance) + SBI.bitShiftRight(&base, by: distance) XCTAssertEqual(base, result, file: file, line: line) } brr: do { var base = base - SBI.bitshiftRight(&base, major: major, minor: minor) + SBI.bitShiftRight(&base, major: major, minor: minor) XCTAssertEqual(base, result, file: file, line: line) } if minor.isZero { var base = base - SBI.bitshiftRight(&base, major: major) + SBI.bitShiftRight(&base, major: major) XCTAssertEqual(base, result, file: file, line: line) } } diff --git a/Tests/NBKDoubleWidthKitBenchmarks/NBKDoubleWidth+Shifts.swift b/Tests/NBKDoubleWidthKitBenchmarks/NBKDoubleWidth+Shifts.swift index 2efa7dc5..3e064b58 100644 --- a/Tests/NBKDoubleWidthKitBenchmarks/NBKDoubleWidth+Shifts.swift +++ b/Tests/NBKDoubleWidthKitBenchmarks/NBKDoubleWidth+Shifts.swift @@ -28,7 +28,7 @@ final class NBKDoubleWidthBenchmarksOnShiftsAsInt256: XCTestCase { // MARK: Tests x Left //=------------------------------------------------------------------------= - func testBitshiftingLeft() { + func testBitShiftingLeft() { var lhs = NBK.blackHoleIdentity(T(x64: X(~0, ~1, ~2, ~3))) var rhs = NBK.blackHoleIdentity(UInt.bitWidth * 3/2) @@ -39,7 +39,7 @@ final class NBKDoubleWidthBenchmarksOnShiftsAsInt256: XCTestCase { } } - func testBitshiftingLeftByMasking() { + func testBitShiftingLeftByMasking() { var lhs = NBK.blackHoleIdentity(T(x64: X(~0, ~1, ~2, ~3))) var rhs = NBK.blackHoleIdentity(UInt.bitWidth * 3/2) @@ -50,23 +50,23 @@ final class NBKDoubleWidthBenchmarksOnShiftsAsInt256: XCTestCase { } } - func testBitshiftingLeftByWords() { + func testBitShiftingLeftByWords() { var lhs = NBK.blackHoleIdentity(T(x64: X(~0, ~1, ~2, ~3))) var rhs = NBK.blackHoleIdentity((major: 1, minor: UInt.bitWidth/2)) for _ in 0 ..< 5_000_000 { - NBK.blackHole(lhs.bitshiftedLeft(major: rhs.major)) + NBK.blackHole(lhs.bitShiftedLeft(major: rhs.major)) NBK.blackHoleInoutIdentity(&lhs) NBK.blackHoleInoutIdentity(&rhs) } } - func testBitshiftingLeftByWordsAndBits() { + func testBitShiftingLeftByWordsAndBits() { var lhs = NBK.blackHoleIdentity(T(x64: X(~0, ~1, ~2, ~3))) var rhs = NBK.blackHoleIdentity((major: 1, minor: UInt.bitWidth/2)) for _ in 0 ..< 5_000_000 { - NBK.blackHole(lhs.bitshiftedLeft(major: rhs.major, minor: rhs.minor)) + NBK.blackHole(lhs.bitShiftedLeft(major: rhs.major, minor: rhs.minor)) NBK.blackHoleInoutIdentity(&lhs) NBK.blackHoleInoutIdentity(&rhs) } @@ -76,7 +76,7 @@ final class NBKDoubleWidthBenchmarksOnShiftsAsInt256: XCTestCase { // MARK: Tests x Right //=------------------------------------------------------------------------= - func testBitshiftingRight() { + func testBitShiftingRight() { var lhs = NBK.blackHoleIdentity(T(x64: X(~0, ~1, ~2, ~3))) var rhs = NBK.blackHoleIdentity(UInt.bitWidth * 3/2) @@ -87,7 +87,7 @@ final class NBKDoubleWidthBenchmarksOnShiftsAsInt256: XCTestCase { } } - func testBitshiftingRightByMasking() { + func testBitShiftingRightByMasking() { var lhs = NBK.blackHoleIdentity(T(x64: X(~0, ~1, ~2, ~3))) var rhs = NBK.blackHoleIdentity(UInt.bitWidth * 3/2) @@ -98,23 +98,23 @@ final class NBKDoubleWidthBenchmarksOnShiftsAsInt256: XCTestCase { } } - func testBitshiftingRightByWords() { + func testBitShiftingRightByWords() { var lhs = NBK.blackHoleIdentity(T(x64: X(~0, ~1, ~2, ~3))) var rhs = NBK.blackHoleIdentity((major: 1, minor: UInt.bitWidth/2)) for _ in 0 ..< 5_000_000 { - NBK.blackHole(lhs.bitshiftedRight(major: rhs.major)) + NBK.blackHole(lhs.bitShiftedRight(major: rhs.major)) NBK.blackHoleInoutIdentity(&lhs) NBK.blackHoleInoutIdentity(&rhs) } } - func testBitshiftingRightByWordsAndBits() { + func testBitShiftingRightByWordsAndBits() { var lhs = NBK.blackHoleIdentity(T(x64: X(~0, ~1, ~2, ~3))) var rhs = NBK.blackHoleIdentity((major: 1, minor: UInt.bitWidth/2)) for _ in 0 ..< 5_000_000 { - NBK.blackHole(lhs.bitshiftedRight(major: rhs.major, minor: rhs.minor)) + NBK.blackHole(lhs.bitShiftedRight(major: rhs.major, minor: rhs.minor)) NBK.blackHoleInoutIdentity(&lhs) NBK.blackHoleInoutIdentity(&rhs) } @@ -133,7 +133,7 @@ final class NBKDoubleWidthBenchmarksOnShiftsAsUInt256: XCTestCase { // MARK: Tests x Left //=------------------------------------------------------------------------= - func testBitshiftingLeft() { + func testBitShiftingLeft() { var lhs = NBK.blackHoleIdentity(T(x64: X(~0, ~1, ~2, ~3))) var rhs = NBK.blackHoleIdentity(UInt.bitWidth * 3/2) @@ -144,7 +144,7 @@ final class NBKDoubleWidthBenchmarksOnShiftsAsUInt256: XCTestCase { } } - func testBitshiftingLeftByMasking() { + func testBitShiftingLeftByMasking() { var lhs = NBK.blackHoleIdentity(T(x64: X(~0, ~1, ~2, ~3))) var rhs = NBK.blackHoleIdentity(UInt.bitWidth * 3/2) @@ -155,23 +155,23 @@ final class NBKDoubleWidthBenchmarksOnShiftsAsUInt256: XCTestCase { } } - func testBitshiftingLeftByWords() { + func testBitShiftingLeftByWords() { var lhs = NBK.blackHoleIdentity(T(x64: X(~0, ~1, ~2, ~3))) var rhs = NBK.blackHoleIdentity((major: 1, minor: UInt.bitWidth/2)) for _ in 0 ..< 5_000_000 { - NBK.blackHole(lhs.bitshiftedLeft(major: rhs.major)) + NBK.blackHole(lhs.bitShiftedLeft(major: rhs.major)) NBK.blackHoleInoutIdentity(&lhs) NBK.blackHoleInoutIdentity(&rhs) } } - func testBitshiftingLeftByWordsAndBits() { + func testBitShiftingLeftByWordsAndBits() { var lhs = NBK.blackHoleIdentity(T(x64: X(~0, ~1, ~2, ~3))) var rhs = NBK.blackHoleIdentity((major: 1, minor: UInt.bitWidth/2)) for _ in 0 ..< 5_000_000 { - NBK.blackHole(lhs.bitshiftedLeft(major: rhs.major, minor: rhs.minor)) + NBK.blackHole(lhs.bitShiftedLeft(major: rhs.major, minor: rhs.minor)) NBK.blackHoleInoutIdentity(&lhs) NBK.blackHoleInoutIdentity(&rhs) } @@ -181,7 +181,7 @@ final class NBKDoubleWidthBenchmarksOnShiftsAsUInt256: XCTestCase { // MARK: Tests x Right //=------------------------------------------------------------------------= - func testBitshiftingRight() { + func testBitShiftingRight() { var lhs = NBK.blackHoleIdentity(T(x64: X(~0, ~1, ~2, ~3))) var rhs = NBK.blackHoleIdentity(UInt.bitWidth * 3/2) @@ -192,7 +192,7 @@ final class NBKDoubleWidthBenchmarksOnShiftsAsUInt256: XCTestCase { } } - func testBitshiftingRightByMasking() { + func testBitShiftingRightByMasking() { var lhs = NBK.blackHoleIdentity(T(x64: X(~0, ~1, ~2, ~3))) var rhs = NBK.blackHoleIdentity(UInt.bitWidth * 3/2) @@ -203,23 +203,23 @@ final class NBKDoubleWidthBenchmarksOnShiftsAsUInt256: XCTestCase { } } - func testBitshiftingRightByWords() { + func testBitShiftingRightByWords() { var lhs = NBK.blackHoleIdentity(T(x64: X(~0, ~1, ~2, ~3))) var rhs = NBK.blackHoleIdentity((major: 1, minor: UInt.bitWidth/2)) for _ in 0 ..< 5_000_000 { - NBK.blackHole(lhs.bitshiftedRight(major: rhs.major)) + NBK.blackHole(lhs.bitShiftedRight(major: rhs.major)) NBK.blackHoleInoutIdentity(&lhs) NBK.blackHoleInoutIdentity(&rhs) } } - func testBitshiftingRightByWordsAndBits() { + func testBitShiftingRightByWordsAndBits() { var lhs = NBK.blackHoleIdentity(T(x64: X(~0, ~1, ~2, ~3))) var rhs = NBK.blackHoleIdentity((major: 1, minor: UInt.bitWidth/2)) for _ in 0 ..< 5_000_000 { - NBK.blackHole(lhs.bitshiftedRight(major: rhs.major, minor: rhs.minor)) + NBK.blackHole(lhs.bitShiftedRight(major: rhs.major, minor: rhs.minor)) NBK.blackHoleInoutIdentity(&lhs) NBK.blackHoleInoutIdentity(&rhs) } diff --git a/Tests/NBKDoubleWidthKitTests/NBKDoubleWidth+Shifts.swift b/Tests/NBKDoubleWidthKitTests/NBKDoubleWidth+Shifts.swift index e3993fde..6018de7d 100644 --- a/Tests/NBKDoubleWidthKitTests/NBKDoubleWidth+Shifts.swift +++ b/Tests/NBKDoubleWidthKitTests/NBKDoubleWidth+Shifts.swift @@ -29,14 +29,14 @@ final class NBKDoubleWidthTestsOnShiftsAsInt256: XCTestCase { // MARK: Tests x Left //=------------------------------------------------------------------------= - func testBitshiftingLeftByBits() { + func testBitShiftingLeftByBits() { NBKAssertShiftLeft(T(x64: X( 1, 2, 3, 4)), 0, T(x64: X( 1, 2, 3, 4))) NBKAssertShiftLeft(T(x64: X( 1, 2, 3, 4)), 1, T(x64: X( 2, 4, 6, 8))) NBKAssertShiftLeft(T(x64: X( 1, 2, 3, 4)), 2, T(x64: X( 4, 8, 12, 16))) NBKAssertShiftLeft(T(x64: X( 1, 2, 3, 4)), 3, T(x64: X( 8, 16, 24, 32))) } - func testBitshiftingLeftByWords() { + func testBitShiftingLeftByWords() { NBKAssertShiftLeft(T(x64: X( 1, 2, 3, 4)), 0, T(x64: X( 1, 2, 3, 4))) NBKAssertShiftLeft(T(x64: X( 1, 2, 3, 4)), 64, T(x64: X( 0, 1, 2, 3))) NBKAssertShiftLeft(T(x64: X( 1, 2, 3, 4)), 128, T(x64: X( 0, 0, 1, 2))) @@ -44,7 +44,7 @@ final class NBKDoubleWidthTestsOnShiftsAsInt256: XCTestCase { NBKAssertShiftLeft(T(x64: X( 1, 2, 3, 4)), 256, T(x64: X( 0, 0, 0, 0))) } - func testBitshiftingLeftByWordsAndBits() { + func testBitShiftingLeftByWordsAndBits() { NBKAssertShiftLeft(T(x64: X( 1, 2, 3, 4)), 3, T(x64: X( 8, 16, 24, 32))) NBKAssertShiftLeft(T(x64: X( 1, 2, 3, 4)), 67, T(x64: X( 0, 8, 16, 24))) NBKAssertShiftLeft(T(x64: X( 1, 2, 3, 4)), 131, T(x64: X( 0, 0, 8, 16))) @@ -52,7 +52,7 @@ final class NBKDoubleWidthTestsOnShiftsAsInt256: XCTestCase { NBKAssertShiftLeft(T(x64: X( 1, 2, 3, 4)), 259, T(x64: X( 0, 0, 0, 0))) } - func testBitshiftingLeftSuchThatWordsSplit() { + func testBitShiftingLeftSuchThatWordsSplit() { NBKAssertShiftLeft(T(x64: X(~0, 0, 0, 0)), 1, T(x64: X(~1, 1, 0, 0))) NBKAssertShiftLeft(T(x64: X( 0, ~0, 0, 0)), 1, T(x64: X( 0, ~1, 1, 0))) NBKAssertShiftLeft(T(x64: X( 0, 0, ~0, 0)), 1, T(x64: X( 0, 0, ~1, 1))) @@ -63,14 +63,14 @@ final class NBKDoubleWidthTestsOnShiftsAsInt256: XCTestCase { // MARK: Tests x Right //=------------------------------------------------------------------------= - func testBitshiftingRightByBits() { + func testBitShiftingRightByBits() { NBKAssertShiftRight(T(x64: X(8, 16, 24, 32)), 0, T(x64: X( 8, 16, 24, 32))) NBKAssertShiftRight(T(x64: X(8, 16, 24, 32)), 1, T(x64: X( 4, 8, 12, 16))) NBKAssertShiftRight(T(x64: X(8, 16, 24, 32)), 2, T(x64: X( 2, 4, 6, 8))) NBKAssertShiftRight(T(x64: X(8, 16, 24, 32)), 3, T(x64: X( 1, 2, 3, 4))) } - func testBitshiftingRightByWords() { + func testBitShiftingRightByWords() { NBKAssertShiftRight(T(x64: X(8, 16, 24, 32)), 0, T(x64: X( 8, 16, 24, 32))) NBKAssertShiftRight(T(x64: X(8, 16, 24, 32)), 64, T(x64: X(16, 24, 32, 0))) NBKAssertShiftRight(T(x64: X(8, 16, 24, 32)), 128, T(x64: X(24, 32, 0, 0))) @@ -78,7 +78,7 @@ final class NBKDoubleWidthTestsOnShiftsAsInt256: XCTestCase { NBKAssertShiftRight(T(x64: X(8, 16, 24, 32)), 256, T(x64: X( 0, 0, 0, 0))) } - func testBitshiftingRightByWordsAndBits() { + func testBitShiftingRightByWordsAndBits() { NBKAssertShiftRight(T(x64: X(8, 16, 24, 32)), 3, T(x64: X( 1, 2, 3, 4))) NBKAssertShiftRight(T(x64: X(8, 16, 24, 32)), 67, T(x64: X( 2, 3, 4, 0))) NBKAssertShiftRight(T(x64: X(8, 16, 24, 32)), 131, T(x64: X( 3, 4, 0, 0))) @@ -86,14 +86,14 @@ final class NBKDoubleWidthTestsOnShiftsAsInt256: XCTestCase { NBKAssertShiftRight(T(x64: X(8, 16, 24, 32)), 259, T(x64: X( 0, 0, 0, 0))) } - func testBitshiftingRightSuchThatWordsSplit() { + func testBitShiftingRightSuchThatWordsSplit() { NBKAssertShiftRight(T(x64: X(0, 0, 0, 7)), 1, T(x64: X( 0, 0, 1 << 63, 3))) NBKAssertShiftRight(T(x64: X(0, 0, 7, 0)), 1, T(x64: X( 0, 1 << 63, 3, 0))) NBKAssertShiftRight(T(x64: X(0, 7, 0, 0)), 1, T(x64: X( 1 << 63, 3, 0, 0))) NBKAssertShiftRight(T(x64: X(7, 0, 0, 0)), 1, T(x64: X( 3, 0, 0, 0))) } - func testBitshiftingRightIsSigned() { + func testBitShiftingRightIsSigned() { NBKAssertShiftRight(T(x64: X(0, 0, 0, 1 << 63)), 0, T(x64: X( 0, 0, 0, 1 << 63))) NBKAssertShiftRight(T(x64: X(0, 0, 0, 1 << 63)), 64, T(x64: X( 0, 0, 1 << 63, ~0))) NBKAssertShiftRight(T(x64: X(0, 0, 0, 1 << 63)), 128, T(x64: X( 0, 1 << 63, ~0, ~0))) @@ -105,7 +105,7 @@ final class NBKDoubleWidthTestsOnShiftsAsInt256: XCTestCase { // MARK: Tests x Miscellaneous //=------------------------------------------------------------------------= - func testBitshiftingIsSmart() { + func testBitShiftingIsSmart() { XCTAssertEqual(T(x64: X(1, 2, 3, 4)) << 1, T(x64: X(2, 4, 6, 8))) XCTAssertEqual(T(x64: X(1, 2, 3, 4)) >> -1, T(x64: X(2, 4, 6, 8))) @@ -113,12 +113,12 @@ final class NBKDoubleWidthTestsOnShiftsAsInt256: XCTestCase { XCTAssertEqual(T(x64: X(1, 2, 3, 4)) >> -64, T(x64: X(0, 1, 2, 3))) } - func testBitshiftingByMinDistanceDoesNotTrap() { + func testBitShiftingByMinDistanceDoesNotTrap() { XCTAssertEqual(T(repeating: true) << Int.min, T(repeating: true )) XCTAssertEqual(T(repeating: true) >> Int.min, T(repeating: false)) } - func testBitshiftingByMaskingIsEquivalentToBitshiftingModuloBitWidth() { + func testBitShiftingByMaskingIsEquivalentToBitShiftingModuloBitWidth() { NBKAssertShiftLeftByMasking (T(x64: X(1, 2, 3, 4)), 256, T(x64: X(1, 2, 3, 4)), signitude: S.self) NBKAssertShiftLeftByMasking (T(x64: X(1, 2, 3, 4)), -256, T(x64: X(1, 2, 3, 4)), signitude: S.self) @@ -152,14 +152,14 @@ final class NBKDoubleWidthTestsOnShiftsAsUInt256: XCTestCase { // MARK: Tests x Left //=------------------------------------------------------------------------= - func testBitshiftingLeftByBits() { + func testBitShiftingLeftByBits() { NBKAssertShiftLeft(T(x64: X( 1, 2, 3, 4)), 0, T(x64: X( 1, 2, 3, 4))) NBKAssertShiftLeft(T(x64: X( 1, 2, 3, 4)), 1, T(x64: X( 2, 4, 6, 8))) NBKAssertShiftLeft(T(x64: X( 1, 2, 3, 4)), 2, T(x64: X( 4, 8, 12, 16))) NBKAssertShiftLeft(T(x64: X( 1, 2, 3, 4)), 3, T(x64: X( 8, 16, 24, 32))) } - func testBitshiftingLeftByWords() { + func testBitShiftingLeftByWords() { NBKAssertShiftLeft(T(x64: X( 1, 2, 3, 4)), 0, T(x64: X( 1, 2, 3, 4))) NBKAssertShiftLeft(T(x64: X( 1, 2, 3, 4)), 64, T(x64: X( 0, 1, 2, 3))) NBKAssertShiftLeft(T(x64: X( 1, 2, 3, 4)), 128, T(x64: X( 0, 0, 1, 2))) @@ -167,7 +167,7 @@ final class NBKDoubleWidthTestsOnShiftsAsUInt256: XCTestCase { NBKAssertShiftLeft(T(x64: X( 1, 2, 3, 4)), 256, T(x64: X( 0, 0, 0, 0))) } - func testBitshiftingLeftByWordsAndBits() { + func testBitShiftingLeftByWordsAndBits() { NBKAssertShiftLeft(T(x64: X( 1, 2, 3, 4)), 3, T(x64: X( 8, 16, 24, 32))) NBKAssertShiftLeft(T(x64: X( 1, 2, 3, 4)), 67, T(x64: X( 0, 8, 16, 24))) NBKAssertShiftLeft(T(x64: X( 1, 2, 3, 4)), 131, T(x64: X( 0, 0, 8, 16))) @@ -175,7 +175,7 @@ final class NBKDoubleWidthTestsOnShiftsAsUInt256: XCTestCase { NBKAssertShiftLeft(T(x64: X( 1, 2, 3, 4)), 259, T(x64: X( 0, 0, 0, 0))) } - func testBitshiftingLeftSuchThatWordsSplit() { + func testBitShiftingLeftSuchThatWordsSplit() { NBKAssertShiftLeft(T(x64: X(~0, 0, 0, 0)), 1, T(x64: X(~1, 1, 0, 0))) NBKAssertShiftLeft(T(x64: X( 0, ~0, 0, 0)), 1, T(x64: X( 0, ~1, 1, 0))) NBKAssertShiftLeft(T(x64: X( 0, 0, ~0, 0)), 1, T(x64: X( 0, 0, ~1, 1))) @@ -186,14 +186,14 @@ final class NBKDoubleWidthTestsOnShiftsAsUInt256: XCTestCase { // MARK: Tests x Right //=------------------------------------------------------------------------= - func testBitshiftingRightByBits() { + func testBitShiftingRightByBits() { NBKAssertShiftRight(T(x64: X(8, 16, 24, 32)), 0, T(x64: X( 8, 16, 24, 32))) NBKAssertShiftRight(T(x64: X(8, 16, 24, 32)), 1, T(x64: X( 4, 8, 12, 16))) NBKAssertShiftRight(T(x64: X(8, 16, 24, 32)), 2, T(x64: X( 2, 4, 6, 8))) NBKAssertShiftRight(T(x64: X(8, 16, 24, 32)), 3, T(x64: X( 1, 2, 3, 4))) } - func testBitshiftingRightByWords() { + func testBitShiftingRightByWords() { NBKAssertShiftRight(T(x64: X(8, 16, 24, 32)), 0, T(x64: X( 8, 16, 24, 32))) NBKAssertShiftRight(T(x64: X(8, 16, 24, 32)), 64, T(x64: X(16, 24, 32, 0))) NBKAssertShiftRight(T(x64: X(8, 16, 24, 32)), 128, T(x64: X(24, 32, 0, 0))) @@ -201,7 +201,7 @@ final class NBKDoubleWidthTestsOnShiftsAsUInt256: XCTestCase { NBKAssertShiftRight(T(x64: X(8, 16, 24, 32)), 256, T(x64: X( 0, 0, 0, 0))) } - func testBitshiftingRightByWordsAndBits() { + func testBitShiftingRightByWordsAndBits() { NBKAssertShiftRight(T(x64: X(8, 16, 24, 32)), 3, T(x64: X( 1, 2, 3, 4))) NBKAssertShiftRight(T(x64: X(8, 16, 24, 32)), 67, T(x64: X( 2, 3, 4, 0))) NBKAssertShiftRight(T(x64: X(8, 16, 24, 32)), 131, T(x64: X( 3, 4, 0, 0))) @@ -209,14 +209,14 @@ final class NBKDoubleWidthTestsOnShiftsAsUInt256: XCTestCase { NBKAssertShiftRight(T(x64: X(8, 16, 24, 32)), 259, T(x64: X( 0, 0, 0, 0))) } - func testBitshiftingRightSuchThatWordsSplit() { + func testBitShiftingRightSuchThatWordsSplit() { NBKAssertShiftRight(T(x64: X(0, 0, 0, 7)), 1, T(x64: X( 0, 0, 1 << 63, 3))) NBKAssertShiftRight(T(x64: X(0, 0, 7, 0)), 1, T(x64: X( 0, 1 << 63, 3, 0))) NBKAssertShiftRight(T(x64: X(0, 7, 0, 0)), 1, T(x64: X( 1 << 63, 3, 0, 0))) NBKAssertShiftRight(T(x64: X(7, 0, 0, 0)), 1, T(x64: X( 3, 0, 0, 0))) } - func testBitshiftingRightIsUnsigned() { + func testBitShiftingRightIsUnsigned() { NBKAssertShiftRight(T(x64: X(0, 0, 0, 1 << 63)), 0, T(x64: X(0, 0, 0, 1 << 63))) NBKAssertShiftRight(T(x64: X(0, 0, 0, 1 << 63)), 64, T(x64: X(0, 0, 1 << 63, 0))) NBKAssertShiftRight(T(x64: X(0, 0, 0, 1 << 63)), 128, T(x64: X(0, 1 << 63, 0, 0))) @@ -228,7 +228,7 @@ final class NBKDoubleWidthTestsOnShiftsAsUInt256: XCTestCase { // MARK: Tests x Miscellaneous //=------------------------------------------------------------------------= - func testBitshiftingIsSmart() { + func testBitShiftingIsSmart() { XCTAssertEqual(T(x64: X(1, 2, 3, 4)) << 1, T(x64: X(2, 4, 6, 8))) XCTAssertEqual(T(x64: X(1, 2, 3, 4)) >> -1, T(x64: X(2, 4, 6, 8))) @@ -236,12 +236,12 @@ final class NBKDoubleWidthTestsOnShiftsAsUInt256: XCTestCase { XCTAssertEqual(T(x64: X(1, 2, 3, 4)) >> -64, T(x64: X(0, 1, 2, 3))) } - func testBitshiftingByMinDistanceDoesNotTrap() { + func testBitShiftingByMinDistanceDoesNotTrap() { XCTAssertEqual(T(repeating: true) << Int.min, T(repeating: false)) XCTAssertEqual(T(repeating: true) >> Int.min, T(repeating: false)) } - func testBitshiftingByMaskingIsEquivalentToBitshiftingModuloBitWidth() { + func testBitShiftingByMaskingIsEquivalentToBitShiftingModuloBitWidth() { NBKAssertShiftLeftByMasking (T(x64: X(1, 2, 3, 4)), 256, T(x64: X(1, 2, 3, 4)), signitude: S.self) NBKAssertShiftLeftByMasking (T(x64: X(1, 2, 3, 4)), -256, T(x64: X(1, 2, 3, 4)), signitude: S.self) @@ -278,11 +278,11 @@ file: StaticString = #file, line: UInt = #line) { XCTAssertEqual({ var lhs = lhs; lhs <<= rhs; return lhs }(), result, file: file, line: line) XCTAssertEqual({ var lhs = lhs; lhs >>= -rhs; return lhs }(), result, file: file, line: line) - XCTAssertEqual(lhs.bitshiftedLeftSmart(by: rhs), result, file: file, line: line) - XCTAssertEqual(lhs.bitshiftedRightSmart(by: -rhs), result, file: file, line: line) + XCTAssertEqual(lhs.bitShiftedLeftSmart(by: rhs), result, file: file, line: line) + XCTAssertEqual(lhs.bitShiftedRightSmart(by: -rhs), result, file: file, line: line) - XCTAssertEqual({ var lhs = lhs; lhs.bitshiftLeftSmart(by: rhs); return lhs }(), result, file: file, line: line) - XCTAssertEqual({ var lhs = lhs; lhs.bitshiftRightSmart(by: -rhs); return lhs }(), result, file: file, line: line) + XCTAssertEqual({ var lhs = lhs; lhs.bitShiftLeftSmart(by: rhs); return lhs }(), result, file: file, line: line) + XCTAssertEqual({ var lhs = lhs; lhs.bitShiftRightSmart(by: -rhs); return lhs }(), result, file: file, line: line) //=------------------------------------------= if 0 ..< lhs.bitWidth ~= rhs { XCTAssertEqual( lhs &<< rhs, result, file: file, line: line) @@ -290,16 +290,16 @@ file: StaticString = #file, line: UInt = #line) { } //=------------------------------------------= if 0 ..< lhs.bitWidth ~= rhs { - XCTAssertEqual(lhs.bitshiftedLeft(by: rhs), result, file: file, line: line) - XCTAssertEqual({ var lhs = lhs; lhs.bitshiftLeft(by: rhs); return lhs }(), result, file: file, line: line) + XCTAssertEqual(lhs.bitShiftedLeft(by: rhs), result, file: file, line: line) + XCTAssertEqual({ var lhs = lhs; lhs.bitShiftLeft(by: rhs); return lhs }(), result, file: file, line: line) - XCTAssertEqual(lhs.bitshiftedLeft(major: major, minor: minor), result, file: file, line: line) - XCTAssertEqual({ var lhs = lhs; lhs.bitshiftLeft(major: major, minor: minor); return lhs }(), result, file: file, line: line) + XCTAssertEqual(lhs.bitShiftedLeft(major: major, minor: minor), result, file: file, line: line) + XCTAssertEqual({ var lhs = lhs; lhs.bitShiftLeft(major: major, minor: minor); return lhs }(), result, file: file, line: line) } //=------------------------------------------= if 0 ..< lhs.bitWidth ~= rhs, minor.isZero { - XCTAssertEqual(lhs.bitshiftedLeft(major: major), result, file: file, line: line) - XCTAssertEqual({ var lhs = lhs; lhs.bitshiftLeft(major: major); return lhs }(), result, file: file, line: line) + XCTAssertEqual(lhs.bitShiftedLeft(major: major), result, file: file, line: line) + XCTAssertEqual({ var lhs = lhs; lhs.bitShiftLeft(major: major); return lhs }(), result, file: file, line: line) } } @@ -315,11 +315,11 @@ file: StaticString = #file, line: UInt = #line) { XCTAssertEqual({ var lhs = lhs; lhs >>= rhs; return lhs }(), result, file: file, line: line) XCTAssertEqual({ var lhs = lhs; lhs <<= -rhs; return lhs }(), result, file: file, line: line) - XCTAssertEqual(lhs.bitshiftedRightSmart(by: rhs), result, file: file, line: line) - XCTAssertEqual(lhs.bitshiftedLeftSmart(by: -rhs), result, file: file, line: line) + XCTAssertEqual(lhs.bitShiftedRightSmart(by: rhs), result, file: file, line: line) + XCTAssertEqual(lhs.bitShiftedLeftSmart(by: -rhs), result, file: file, line: line) - XCTAssertEqual({ var lhs = lhs; lhs.bitshiftRightSmart(by: rhs); return lhs }(), result, file: file, line: line) - XCTAssertEqual({ var lhs = lhs; lhs.bitshiftLeftSmart(by: -rhs); return lhs }(), result, file: file, line: line) + XCTAssertEqual({ var lhs = lhs; lhs.bitShiftRightSmart(by: rhs); return lhs }(), result, file: file, line: line) + XCTAssertEqual({ var lhs = lhs; lhs.bitShiftLeftSmart(by: -rhs); return lhs }(), result, file: file, line: line) //=------------------------------------------= if 0 ..< lhs.bitWidth ~= rhs { XCTAssertEqual( lhs &>> rhs, result, file: file, line: line) @@ -327,16 +327,16 @@ file: StaticString = #file, line: UInt = #line) { } //=------------------------------------------= if 0 ..< lhs.bitWidth ~= rhs { - XCTAssertEqual(lhs.bitshiftedRight(by: rhs), result, file: file, line: line) - XCTAssertEqual({ var lhs = lhs; lhs.bitshiftRight(by: rhs); return lhs }(), result, file: file, line: line) + XCTAssertEqual(lhs.bitShiftedRight(by: rhs), result, file: file, line: line) + XCTAssertEqual({ var lhs = lhs; lhs.bitShiftRight(by: rhs); return lhs }(), result, file: file, line: line) - XCTAssertEqual(lhs.bitshiftedRight(major: major, minor: minor), result, file: file, line: line) - XCTAssertEqual({ var lhs = lhs; lhs.bitshiftRight(major: major, minor: minor); return lhs }(), result, file: file, line: line) + XCTAssertEqual(lhs.bitShiftedRight(major: major, minor: minor), result, file: file, line: line) + XCTAssertEqual({ var lhs = lhs; lhs.bitShiftRight(major: major, minor: minor); return lhs }(), result, file: file, line: line) } //=------------------------------------------= if 0 ..< lhs.bitWidth ~= rhs, minor.isZero { - XCTAssertEqual(lhs.bitshiftedRight(major: major), result, file: file, line: line) - XCTAssertEqual({ var lhs = lhs; lhs.bitshiftRight(major: major); return lhs }(), result, file: file, line: line) + XCTAssertEqual(lhs.bitShiftedRight(major: major), result, file: file, line: line) + XCTAssertEqual({ var lhs = lhs; lhs.bitShiftRight(major: major); return lhs }(), result, file: file, line: line) } }