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

u128 is largest unsigned type? #1485

Closed
catb0t opened this issue Sep 7, 2018 · 7 comments
Closed

u128 is largest unsigned type? #1485

catb0t opened this issue Sep 7, 2018 · 7 comments
Labels
contributor friendly This issue is limited in scope and/or knowledge of Zig internals. upstream An issue with a third party project that Zig uses.
Milestone

Comments

@catb0t
Copy link

catb0t commented Sep 7, 2018

const debug = @import("std").debug;

const uType = u128;

pub fn main () void {
  debug.warn("{} {}", @intCast(uType, @maxValue(uType)), @intCast(uType, r()) * 2);
}

pub fn r () uType {
  return @intCast(uType, 1844674407370955161611); // higher than 2 ** 64
}

-> 340282366920938463463374607431768211455 3689348814741910323222

if you change uType to anything higher than u128 compiling fails with LLVM ERROR: Unsupported library call operation! (lower works fine though)

Maximum width for unsigned types isn't mentioned in the docs (anyway there is no explicit list of unsigned types).

Is 128 as max intentional? I might like a u256...

@andrewrk andrewrk added this to the 0.4.0 milestone Sep 8, 2018
@andrewrk andrewrk added contributor friendly This issue is limited in scope and/or knowledge of Zig internals. upstream An issue with a third party project that Zig uses. labels Sep 17, 2018
@andrewrk
Copy link
Member

The short answer to this and #1534 is that we need to send a patch to LLVM to make it emit library calls for this even though the scope of those library calls is outside of the standardized compiler-rt.

@catb0t
Copy link
Author

catb0t commented Sep 27, 2018

Would a zig fork of LLVM with upstream merging be a solution?

@andrewrk
Copy link
Member

It would be a solution, but ideally we could use upstream without any patches. I think the feature is not so critical that we can't wait for one llvm release cycle (after getting the patch into llvm)

@data-man
Copy link
Contributor

Inefficient workaround

const std = @import("std");
const Int = std.math.big.Int;
const warn = std.debug.warn;

pub fn main() void {
  var alloc = std.heap.direct_allocator;

  const a: u1024 = 1234;
  const b: u1024 = 5678;
  const c = a + b;

  const i = Int.initSet(alloc, c);

  warn("{}\n", i);
}

@mikdusan
Copy link
Member

mikdusan commented Oct 1, 2021

an upstream bug report looking like there is no planned LLVM solution: https://bugs.llvm.org/show_bug.cgi?id=45649

@andrewrk
Copy link
Member

andrewrk commented Oct 1, 2021

We can and should lower to our own lib calls instead of LLVM arithmetic for cases where we know LLVM cannot lower them.

@Vexu
Copy link
Member

Vexu commented Oct 24, 2022

LLVM15 is able to correctly lower addition, substraction, multiplication, all bitwise operations and comparisions for all integer types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor friendly This issue is limited in scope and/or knowledge of Zig internals. upstream An issue with a third party project that Zig uses.
Projects
None yet
Development

No branches or pull requests

5 participants