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

std.time.milliTimestamp doesn't work with x86 backend #19807

Open
rupakhetibinit opened this issue Apr 29, 2024 · 1 comment
Open

std.time.milliTimestamp doesn't work with x86 backend #19807

rupakhetibinit opened this issue Apr 29, 2024 · 1 comment
Labels
arch-x86_64 backend-self-hosted bug Observed behavior contradicts documented or intended behavior
Milestone

Comments

@rupakhetibinit
Copy link

rupakhetibinit commented Apr 29, 2024

Zig Version

0.13.0-dev.46+3648d7df1

Steps to Reproduce and Observed Behavior

Given a simple program where you try to print the current milliseconds unix timestamp.

//src/timestamp.zig
const std = @import("std");
pub fn main() !void {
    const time = std.time.milliTimestamp();
    std.debug.print("{}", .{time});
}

When running with x86 backend zig run src/timestamp.zig -fno-llvm -fno-lld gives error

❯ zig run .\src\timestamp.zig -fno-llvm -fno-lld
error(x86_64_encoder): no encoding found for: none or xmm0 rax none none
user_path\zig\0.13.0-dev.46+3648d7df1\files\lib\std\time.zig:74:5: error: CodeGen failed to find a viable instruction. This is a bug in the Zig compiler.
pub fn milliTimestamp() i64 {
~~~~^~~~~~~~~~~~~~~~~~~~~~~

Expected Behavior

Expected to print timestamp, similar to the llvm backend.

❯ zig run .\src\timestamp.zig
1714405874063
@rupakhetibinit rupakhetibinit added the bug Observed behavior contradicts documented or intended behavior label Apr 29, 2024
@Vexu Vexu added this to the 0.13.0 milestone Apr 29, 2024
@rupakhetibinit
Copy link
Author

So I did some more digging. And I found that std.time.timestamp() , std.time.microTimestamp() and std.time.milliTimestamp() directly or indirectly call std.time.nanoTimestamp() when calculating timestamp and when trying to directly call std.time.nanoTimestamp() it silently fails without an error message. Reproduction steps below

//src/timestamp.zig
const std = @import("std");
pub fn main() !void {
    const time = std.time.nanoTimestamp();
    std.debug.print("{}", .{time});
}

when ran with zig run src/timestamp.zig -fno-llvm -fno-lld silently fails

❯ zig run .\src\timestamp.zig -fno-llvm -fno-lld

which gives no output, without any error. Hope this helps to narrow down the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arch-x86_64 backend-self-hosted bug Observed behavior contradicts documented or intended behavior
Projects
None yet
Development

No branches or pull requests

2 participants