Skip to content

Commit 57fef28

Browse files
committed
kernels: decorate the global_asm symbols for Mach-O
Mach-O prefixes every C-visible symbol with an underscore, so a block that defines the bare name links everywhere except Darwin, where the extern "C" declaration resolves to _name and the three int8 kernels came out undefined. The .S kernels already get this from CNAME in src/asm/asm_common.h; these blocks are not preprocessed, so they carry the same rule in Rust.
1 parent 87cf08a commit 57fef28

1 file changed

Lines changed: 31 additions & 12 deletions

File tree

‎crates/yscv-kernels/src/ops/int8_matmul.rs‎

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -495,13 +495,32 @@ unsafe fn widen_dot_1col(ap: *const i8, bp: *const i8, k: usize) -> i32 {
495495
// Branch targets in all three blocks below are numeric locals: Mach-O does not
496496
// treat a `.L` name as assembler-local, so a conditional branch to one is
497497
// rejected outright when the same source is assembled for Darwin.
498+
/// The C-visible spelling of an assembly symbol. Mach-O decorates every such
499+
/// symbol with a leading underscore, so a `global_asm!` block that defines the
500+
/// bare name links everywhere except Darwin, where the `extern "C"` declaration
501+
/// looks for `_name`. The `.S` kernels get this from `CNAME` in
502+
/// `src/asm/asm_common.h`; these blocks are not preprocessed, so they need it
503+
/// here.
504+
#[cfg(target_vendor = "apple")]
505+
macro_rules! cname {
506+
($name:literal) => {
507+
concat!("_", $name)
508+
};
509+
}
510+
#[cfg(not(target_vendor = "apple"))]
511+
macro_rules! cname {
512+
($name:literal) => {
513+
$name
514+
};
515+
}
516+
498517
#[cfg(target_arch = "aarch64")]
499518
core::arch::global_asm!(
519+
".text",
520+
".align 4",
521+
concat!(".global ", cname!("yscv_mlal4x8_kernel")),
522+
concat!(cname!("yscv_mlal4x8_kernel"), ":"),
500523
r#"
501-
.text
502-
.align 4
503-
.global yscv_mlal4x8_kernel
504-
yscv_mlal4x8_kernel:
505524
movi v16.4s, #0
506525
movi v17.4s, #0
507526
movi v18.4s, #0
@@ -636,11 +655,11 @@ unsafe extern "C" {
636655
// scheduling, not a copy of their assembly.
637656
#[cfg(target_arch = "aarch64")]
638657
core::arch::global_asm!(
658+
".text",
659+
".align 4",
660+
concat!(".global ", cname!("yscv_gemm4x4_i8")),
661+
concat!(cname!("yscv_gemm4x4_i8"), ":"),
639662
r#"
640-
.text
641-
.align 4
642-
.global yscv_gemm4x4_i8
643-
yscv_gemm4x4_i8:
644663
stp d8, d9, [sp, #-32]!
645664
stp d10, d11, [sp, #16]
646665
add x7, x0, x1
@@ -941,11 +960,11 @@ unsafe fn neon_mlal_lane_gemm(a: &[i8], b: &[i8], m: usize, k: usize, n: usize,
941960
// j), x3=n (elems, B k-stride), x4=kp, x5=out (i32 row0), x6=ldo (bytes).
942961
#[cfg(target_arch = "aarch64")]
943962
core::arch::global_asm!(
963+
".text",
964+
".align 4",
965+
concat!(".global ", cname!("yscv_mlal4x16")),
966+
concat!(cname!("yscv_mlal4x16"), ":"),
944967
r#"
945-
.text
946-
.align 4
947-
.global yscv_mlal4x16
948-
yscv_mlal4x16:
949968
add x7, x0, x1
950969
add x8, x7, x1
951970
add x9, x8, x1

0 commit comments

Comments
 (0)