-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Add experimental _Volatile module providing low-level primitives for MMIO #70944
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great start, we will obviously update this to match wherever the pitch ends up
@swift-ci please test |
public struct UnsafeVolatilePointer<Pointee> { | ||
public var _rawPointer: Builtin.RawPointer | ||
public init(bitPattern: UInt) { | ||
_rawPointer = UnsafeRawPointer(bitPattern: bitPattern)!._rawValue |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens when someone passes 0? this will assert - are there ever memory mapped registers at 0x0?
Should this not use self.init(Builtin.inttoptr_Word(bitPattern._builtinWordValue))
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should now handle 0 correctly.
|
||
|
||
|
||
extension UnsafeMutablePointer where Pointee == UInt8 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would say drop these extensions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dropped
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To land this we should definitely do the following
- gate it by a flag
- After consideration this should not conform to
_Pointer
- permit this for all build types not just embedded - I could see the use for more than just embedded.
- the initializer should mention unsafe in it since that is the only spot that truly is unsafe; the type and the load/store are perfectly safe to hold
- it should probably be named
VolatileRegister
or something like that (orVolatileMappedRegister
) to avoid confusion about general volatile things that are NOT register bound - after validating this is the design we want we should then move it from a module down into the stdlib asap
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it might be good to add functional tests to verify the initialization of values etc (and maybe even a test store/load on a heap region initialized unsafely)
The rest of the changes other than the tests and restriction to embedded seem on point.
@@ -397,6 +397,15 @@ ImportResolver::getModule(ImportPath::Module modulePath) { | |||
} | |||
} | |||
|
|||
// Only allow importing "Volatile" with Feature::Volatile or Feature::Embedded |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should allow this in non-embedded no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes -- it's allowed in the current implementation in this PR
INSTALL_IN_COMPONENT stdlib | ||
) | ||
|
||
if(SWIFT_SHOULD_BUILD_EMBEDDED_STDLIB) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what if I want to try out volatile thingies in regular desktop swift?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the small block above, that's defining and building Volatile for regular platforms.
…e 'unsafe' name in initializer
…allow NULL pointer
Added! Any more ideas what to try to cover? (The tests btw show that the Volatile module is available outside of embedded.) |
@swift-ci please test |
@swift-ci please test |
See the full pitch at https://forums.swift.org/t/pitch-low-level-operations-for-volatile-memory-accesses/69483. Summary:
Added APIs in a new "Volatile" module (underscored name,
_Volatile
, for now):