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

[stdlib] Implement difference between pointers #3508

Open
wants to merge 8 commits into
base: nightly
Choose a base branch
from

Conversation

msaelices
Copy link
Contributor

@msaelices msaelices commented Sep 19, 2024

  • [stdlib] Implement difference between pointers, so we have completed the pointers arithmetic we can do in C
  • [docs] Document pointer arithmetic in pointers document

To complete the pointers arithmetic that we can do it in C

❯ mojo
  1> s = 100 
  2.  
(Int) s = 100
  2> p = UnsafePointer.address_of(s) 
  3.  
(UnsafePointer[Int, 0, 0, alignof[::AnyType,__mlir_type.!kgen.target]() if triple_is_nvidia_cuda() else 1]) p = {
  (pointer<_stdlib::_builtin::_int::_Int>) address = 0x000071858be84008
}
  3> p2 = p + 1 
  4.  
(UnsafePointer[Int, 0, 0, alignof[::AnyType,__mlir_type.!kgen.target]() if triple_is_nvidia_cuda() else 1]) p2 = {
  (pointer<_stdlib::_builtin::_int::_Int>) address = 0x000071858be84010
}
  4> offset = p2 - p 
  5.  
(Int) offset = 1  

To complete the pointers arithmetics we can do in C

Signed-off-by: Manuel Saelices <msaelices@gmail.com>
@msaelices msaelices requested a review from a team as a code owner September 19, 2024 21:20
Signed-off-by: Manuel Saelices <msaelices@gmail.com>
Signed-off-by: Manuel Saelices <msaelices@gmail.com>
@msaelices msaelices requested a review from a team as a code owner September 19, 2024 21:56
Signed-off-by: Manuel Saelices <msaelices@gmail.com>
Signed-off-by: Manuel Saelices <msaelices@gmail.com>
Copy link
Collaborator

@JoeLoser JoeLoser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a unit test, please?

@JoeLoser JoeLoser self-assigned this Sep 19, 2024
@msaelices
Copy link
Contributor Author

Can you add a unit test, please?

Sure. Done: msaelices@19830ec

@JoeLoser
Copy link
Collaborator

!sync

@modularbot modularbot added the imported-internally Signals that a given pull request has been imported internally. label Sep 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
imported-internally Signals that a given pull request has been imported internally.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants