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

Unavailable I128 and U128 models #152

Merged
merged 5 commits into from
Dec 17, 2024
Merged

Conversation

oscbyspro
Copy link
Owner

@oscbyspro oscbyspro commented Dec 17, 2024

This patch adds unavailable I128 and U128 models (#143).

The underlying Swift.Int128 and Swift.UInt128 models fail some tests. I have submitted some fixes that got merged into the Swift 6.1 branch. I'll try again later and make the I128 and U128 available when all tests pass successfully.

The underlying `Swift.Int128` and `Swift.UInt128` models fail some tests (crash). I have submitted some fixes that got merged into the `Swift 6.1` branch. I'll try again later and make the `I128` and `U128` available when all tests pass successfully.
@oscbyspro oscbyspro added the addition oh, so shiny! label Dec 17, 2024
@oscbyspro oscbyspro added this to the Ultimathnum 0.13.0 milestone Dec 17, 2024
@oscbyspro
Copy link
Owner Author

oscbyspro commented Dec 17, 2024

Hm. I suppose it as to be 128-bit aligned for Element to equal Self.

Quoting the SE-0425 proposal:

The [U]Int128 types are 16B aligned on 64b targets¹ and have the same alignment as [U]Int64 on 32b targets.

64-bit alignment works for some purposes, but I'm not sure if it works for all purposes. Hm.

@oscbyspro oscbyspro marked this pull request as draft December 17, 2024 05:25
@oscbyspro oscbyspro changed the title Unavailable I128 and U128 models I128 and U128 models Dec 17, 2024
@oscbyspro
Copy link
Owner Author

oscbyspro commented Dec 17, 2024

Hm. I believe the actual requirement is something like this:

// where A: SystemsInteger & A.Element == A
// where B: SystemsInteger & B.Element == B

if A.size > B.size {
   MemoryLayout<A>.alignment >= MemoryLayout<B>.alignment
}  else if A.size < B.size {
   MemoryLayout<A>.alignment <= MemoryLayout<B>.alignment
}  else {
   MemoryLayout<A>.alignment == MemoryLayout<B>.alignment
}

Imagine U128 is 32-bit aligned, but U64 is 64-bit aligned:

// where  U64 is 64-bit aligned
// where U128 is 32-bit aligned

| 32 | 32 | 32 | 32 | 32 | 32 | 32 | 32 | 32 | 32 |
|--  64 --|--  64 --|--  64 --|--  64 --|
          |--  64 --|--  64 --|--  64 --|--  64 --|

| 32 | 32 | 32 | 32 | 32 | 32 | 32 | 32 | 32 | 32 |
|------- 128 -------|------- 128 -------|
     |------- 128 -------|------- 128 -------|
     |    |------- 128 -------|------- 128 -------|
     |
     └ U128 is NOT a [U64, U64]

It should be fine for U128 and U64 to both be 64-bit aligned, however:

// where  U64 is 64-bit aligned
// where U128 is 64-bit aligned

| 32 | 32 | 32 | 32 | 32 | 32 |
|--  64 --|--  64 --|
          |--  64 --|--  64 --|
          
| 32 | 32 | 32 | 32 | 32 | 32 |
|------- 128 -------|
          |------- 128 -------|
          |
          └ U128 is [U64, U64]

If same-size types have different alignment, then size is not enough info to reinterpret them:

// where U64_64 is 64-bit aligned
// where U64_32 is 32-bit aligned

| 32 | 32 | 32 | 32 |
|--  64 --|
          |--  64 --|
          
| 32 | 32 | 32 | 32 |
|--  64 --|
     |--  64 --|
     |    |--  64 --|
     |
     └ U64_32 is NOT a U64_64

@oscbyspro oscbyspro changed the title I128 and U128 models Unavailable I128 and U128 models Dec 17, 2024
@oscbyspro oscbyspro marked this pull request as ready for review December 17, 2024 07:27
@oscbyspro oscbyspro merged commit 76d83e7 into main Dec 17, 2024
@oscbyspro oscbyspro deleted the features/unavailable-int128-models branch December 17, 2024 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition oh, so shiny!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant