Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Word-based pointer APIs #68

Closed
oscbyspro opened this issue Aug 24, 2023 · 4 comments
Closed

Word-based pointer APIs #68

oscbyspro opened this issue Aug 24, 2023 · 4 comments
Labels
addition oh, so shiny! no don't even think about it
Milestone

Comments

@oscbyspro
Copy link
Owner

oscbyspro commented Aug 24, 2023

The following APIs circumnavigate uninitialized NBKDoubleWidth pointee access (#67).

New UnsafePointer APIs

public func load <H>(_ word: UInt.Type, at index: Int) -> UInt where Pointee == NBKDoubleWidth<H>

New UnsafeMutablePointer APIs

public func store<H>(_ word: UInt,      at index: Int)         where Pointee == NBKDoubleWidth<H>
public func load <H>(_ type: UInt.Type, at index: Int) -> UInt where Pointee == NBKDoubleWidth<H>
@oscbyspro oscbyspro added the addition oh, so shiny! label Aug 24, 2023
@oscbyspro oscbyspro added this to the v0.10.0 milestone Aug 24, 2023
@oscbyspro
Copy link
Owner Author

oscbyspro commented Aug 24, 2023

Hm. I do wonder, however, if the following is allowed. In that case, the above is not required.

let value = Int256.uninitialized { pointer in
    for index in  Int256.indices {
        pointer.pointee[index] = UInt.zero // subscript calls UnsafeMutableRawPointer/storeBytes(of:toByteOffset:as:)
    }
}

Edit: I suppose the subscript access needs to be set rather than _modify, if it is allowed.

@oscbyspro oscbyspro added the maybe to do, or not to do? label Aug 24, 2023
@oscbyspro
Copy link
Owner Author

oscbyspro commented Aug 24, 2023

Hm. I suppose the following might count as a pointee read:

// pointer.pointee[index] = UInt.zero

set {
    let byteOffset = BitPattern.endiannessSensitiveByteOffset(unchecked: index)
    Swift.withUnsafeMutablePointer(to: &self) { pointer in // ⚠️ inout pointee
        UnsafeMutableRawPointer(pointer).storeBytes(of: newValue, toByteOffset: byteOffset, as: T.self)
    }
}

@oscbyspro
Copy link
Owner Author

I just want an initialized junk allocation 😣

@oscbyspro
Copy link
Owner Author

These APIs are (or would be) made obsolete by (#71).

@oscbyspro oscbyspro closed this as not planned Won't fix, can't repro, duplicate, stale Aug 25, 2023
@oscbyspro oscbyspro added no don't even think about it and removed maybe to do, or not to do? labels Aug 25, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition oh, so shiny! no don't even think about it
Projects
None yet
Development

No branches or pull requests

1 participant