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

Printing unsigned 64-bit integers #492

Merged
merged 1 commit into from
Nov 14, 2024
Merged

Printing unsigned 64-bit integers #492

merged 1 commit into from
Nov 14, 2024

Conversation

kengorab
Copy link
Owner

@kengorab kengorab commented Nov 14, 2024

Ints in abra are 64-bit signed values, but it's also useful to treat
those 64 bits as an unsigned value. There's currently no UInt type,
because that would require a lot more logic with arithmetic and casting
and dealing with overflows, but as a temporary stopgap, this introduces
the Int#unsignedToString method (which uses "%llu" under the hood as
the print formatter). This also updates the existing Int#toString
implementation to use "%lld" (it had previously been using "%d"...).

This also adds the -fcall-saved-x18 flag to the flags passed to clang
when compiling the assembly output of qbe. This is the clang version of
the -ffixed-x18 flag from the arm compiler, which ensures that x18 is preserved.
Without this flag, this register can potentially be overwritten by the
platform (in this case, macos) even though qbe treats it as a
general-purpose register. This was the source of an extremely mysterious
and frustrating bug.

@kengorab kengorab added bug Something isn't working standard library labels Nov 14, 2024
Ints in abra are 64-bit signed values, but it's also useful to treat
those 64 bits as an unsigned value. There's currently no `UInt` type,
because that would require a lot more logic with arithmetic and casting
and dealing with overflows, but as a temporary stopgap, this introduces
the `Int#unsignedToString` method (which uses `"%llu"` under the hood as
the print formatter). This also updates the existing `Int#toString`
implementation to use `"%lld"` (it had previously been using `"%d"`...).

This also adds the `-fcall-saved-x18` flag to the flags passed to `clang`
when compiling the assembly output of qbe. This is the clang version of
the [`-ffixed-x18`](https://developer.arm.com/documentation/101754/0623/armclang-Reference/armclang-Command-line-Options/-ffixed-x18)
flag from the arm compiler, which ensures that `x18` is preserved.
Without this flag, this register can potentially be overwritten by the
platform (in this case, macos) even though qbe treats it as a
general-purpose register. This was the source of an extremely mysterious
and frustrating bug.
@kengorab kengorab force-pushed the printing-unsigned-int branch from 4b8cf46 to dcc0129 Compare November 14, 2024 02:13
@kengorab kengorab merged commit 6282840 into master Nov 14, 2024
1 check passed
@kengorab kengorab deleted the printing-unsigned-int branch November 14, 2024 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working standard library
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant