Skip to content

libc: implement common abs for various integer sizes #23893

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/c.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ else
std.debug.no_panic;

comptime {
_ = @import("c/inttypes.zig");
_ = @import("c/stdlib.zig");

if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {
// Files specific to musl and wasi-libc.
_ = @import("c/string.zig");
Expand Down
27 changes: 27 additions & 0 deletions lib/c/inttypes.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const std = @import("std");
const common = @import("common.zig");
const builtin = @import("builtin");
const intmax_t = std.c.intmax_t;

comptime {
if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {
// Functions specific to musl and wasi-libc.
@export(&imaxabs, .{ .name = "imaxabs", .linkage = common.linkage, .visibility = common.visibility });
}

if (builtin.target.isMuslLibC()) {
// Functions specific to musl.
}

if (builtin.target.isWasiLibC()) {
// Functions specific to wasi-libc.
}

if (builtin.target.isMinGW()) {
// Functions specific to MinGW-w64.
}
}

fn imaxabs(a: intmax_t) callconv(.c) intmax_t {
return if (a > 0) a else -a;
}
36 changes: 36 additions & 0 deletions lib/c/stdlib.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
const std = @import("std");
const common = @import("common.zig");
const builtin = @import("builtin");

comptime {
if (builtin.target.isMuslLibC() or builtin.target.isWasiLibC()) {
// Functions specific to musl and wasi-libc.
@export(&abs, .{ .name = "abs", .linkage = common.linkage, .visibility = common.visibility });
@export(&labs, .{ .name = "labs", .linkage = common.linkage, .visibility = common.visibility });
@export(&llabs, .{ .name = "llabs", .linkage = common.linkage, .visibility = common.visibility });
}

if (builtin.target.isMuslLibC()) {
// Functions specific to musl.
}

if (builtin.target.isWasiLibC()) {
// Functions specific to wasi-libc.
}

if (builtin.target.isMinGW()) {
// Functions specific to MinGW-w64.
}
}

fn abs(a: c_int) callconv(.c) c_int {
return if (a > 0) a else -a;
}

fn labs(a: c_long) callconv(.c) c_long {
return if (a > 0) a else -a;
}

fn llabs(a: c_longlong) callconv(.c) c_longlong {
return if (a > 0) a else -a;
}
18 changes: 0 additions & 18 deletions lib/libc/mingw/math/fabsf.c

This file was deleted.

18 changes: 0 additions & 18 deletions lib/libc/mingw/math/fabsl.c

This file was deleted.

7 changes: 0 additions & 7 deletions lib/libc/musl/src/math/aarch64/fabs.c

This file was deleted.

7 changes: 0 additions & 7 deletions lib/libc/musl/src/math/aarch64/fabsf.c

This file was deleted.

15 changes: 0 additions & 15 deletions lib/libc/musl/src/math/arm/fabs.c

This file was deleted.

15 changes: 0 additions & 15 deletions lib/libc/musl/src/math/arm/fabsf.c

This file was deleted.

9 changes: 0 additions & 9 deletions lib/libc/musl/src/math/fabs.c

This file was deleted.

9 changes: 0 additions & 9 deletions lib/libc/musl/src/math/fabsf.c

This file was deleted.

15 changes: 0 additions & 15 deletions lib/libc/musl/src/math/fabsl.c

This file was deleted.

7 changes: 0 additions & 7 deletions lib/libc/musl/src/math/i386/fabs.c

This file was deleted.

7 changes: 0 additions & 7 deletions lib/libc/musl/src/math/i386/fabsf.c

This file was deleted.

7 changes: 0 additions & 7 deletions lib/libc/musl/src/math/i386/fabsl.c

This file was deleted.

16 changes: 0 additions & 16 deletions lib/libc/musl/src/math/mips/fabs.c

This file was deleted.

16 changes: 0 additions & 16 deletions lib/libc/musl/src/math/mips/fabsf.c

This file was deleted.

15 changes: 0 additions & 15 deletions lib/libc/musl/src/math/powerpc/fabs.c

This file was deleted.

15 changes: 0 additions & 15 deletions lib/libc/musl/src/math/powerpc/fabsf.c

This file was deleted.

7 changes: 0 additions & 7 deletions lib/libc/musl/src/math/powerpc64/fabs.c

This file was deleted.

7 changes: 0 additions & 7 deletions lib/libc/musl/src/math/powerpc64/fabsf.c

This file was deleted.

15 changes: 0 additions & 15 deletions lib/libc/musl/src/math/riscv32/fabs.c

This file was deleted.

15 changes: 0 additions & 15 deletions lib/libc/musl/src/math/riscv32/fabsf.c

This file was deleted.

15 changes: 0 additions & 15 deletions lib/libc/musl/src/math/riscv64/fabs.c

This file was deleted.

15 changes: 0 additions & 15 deletions lib/libc/musl/src/math/riscv64/fabsf.c

This file was deleted.

15 changes: 0 additions & 15 deletions lib/libc/musl/src/math/s390x/fabs.c

This file was deleted.

15 changes: 0 additions & 15 deletions lib/libc/musl/src/math/s390x/fabsf.c

This file was deleted.

Loading
Loading