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

undefined symbol: ___floatunoitf #22667

Open
scheibo opened this issue Jan 29, 2025 · 3 comments
Open

undefined symbol: ___floatunoitf #22667

scheibo opened this issue Jan 29, 2025 · 3 comments
Labels
backend-llvm The LLVM backend outputs an LLVM IR Module. bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@scheibo
Copy link
Contributor

scheibo commented Jan 29, 2025

Zig Version

0.14.0-dev.2987+183bb8b08

Steps to Reproduce and Observed Behavior

const std = @import("std");

test "___floatunoitf" {
    var p: u256 = 20;
    p = 21;
    var q: u256 = 41;
    q = 42;
    try std.testing.expectEqual(@as(f128, 50.0), 100 * @as(f128, @floatFromInt(p)) / @as(f128, @floatFromInt(q)));
}
error: undefined symbol: ___floatunoitf
    note: referenced by /Users/kjs/Downloads/.zig-cache/o/734b3cba46dae3cc305996316ca9f311/test.o:_main.test.___floatunoitf
    note: referenced by /Users/kjs/Downloads/.zig-cache/o/734b3cba46dae3cc305996316ca9f311/test.o:_main.test.___floatunoitf

Expected Behavior

Passing test. Switching from u256 -> u128 works.

#15057 appears to be the same issue that was closed for not being able to reproduce, but it definitely reproduces on 0.11.0, 0.12.0, 0.13.0, and master for me.

@scheibo scheibo added the bug Observed behavior contradicts documented or intended behavior label Jan 29, 2025
@Rexicon226
Copy link
Contributor

Here's a bit of a cleaner reproduction that makes the issue more obvious:

test "___floatunoitf" {
    _ = foo(20);
}

fn foo(p: u256) f128 {
    return @floatFromInt(p);
}

@Rexicon226
Copy link
Contributor

The strange o is coming from this code here:

zig/src/target.zig

Lines 677 to 685 in 7d699be

pub fn compilerRtIntAbbrev(bits: u16) []const u8 {
return switch (bits) {
16 => "h",
32 => "s",
64 => "d",
128 => "t",
else => "o", // Non-standard
};
}

LLVM doesn't implement anything with __floatuno* nor do we. I'm not exactly sure where the o comes from.

scheibo added a commit to pkmn/engine that referenced this issue Jan 29, 2025
switching to BigRational in 26a79a0 resulted in a fairly large
performance regression, using a Rational(u256) mitigates most of
this (6-7x faster).

Unfortunately, the u256 field trips an issue with Zig's compiler_rt
support: ziglang/zig#22667. Not the end of the world given its only
in the debugging code so it can just be commented out temporarily
@Rexicon226
Copy link
Contributor

Some more info:

@floatFromInt with a source integer type above 128 bits in size (unsigned or signed) and with a destination type that's not f128 (so f16, f32, f64) will fail with:

test "bar" {
    _ = foo(20);
}

fn foo(p: u256) f64 {
    return @floatFromInt(p);
}
$ zig test empty.zig -target aarch64-macos
Assertion failed: (LC != RTLIB::UNKNOWN_LIBCALL && "Don't know how to expand this XINT_TO_FP!"), function ExpandIntOp_XINT_TO_FP, file LegalizeIntegerTypes.cpp, line 5574.

@jacobly0 jacobly0 added the backend-llvm The LLVM backend outputs an LLVM IR Module. label Feb 9, 2025
@jacobly0 jacobly0 added this to the 0.15.0 milestone Feb 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend-llvm The LLVM backend outputs an LLVM IR Module. bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

3 participants