Skip to content

Commit 9e33ce7

Browse files
committed
Fix arm vfma inlining by using special _vfp4 dup fns.
Some VFMA functions have `target_feature(enable = "vfp4")` while the called functions `vdup_n_f32` and `vdupq_n_f32` are `target_feature(enable = "v7")`. LLVM does not inline the functions due to the different feature flags. Using private _vfp4 variants of those functions allows them to be inlined.
1 parent 3944043 commit 9e33ce7

File tree

4 files changed

+43
-7
lines changed

4 files changed

+43
-7
lines changed

crates/core_arch/src/arm_shared/neon/generated.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -8757,7 +8757,7 @@ vfmaq_f32_(b, c, a)
87578757
#[cfg_attr(all(test, target_arch = "arm"), assert_instr(vfma))]
87588758
#[cfg_attr(all(test, target_arch = "aarch64"), assert_instr(fmla))]
87598759
pub unsafe fn vfma_n_f32(a: float32x2_t, b: float32x2_t, c: f32) -> float32x2_t {
8760-
vfma_f32(a, b, vdup_n_f32(c))
8760+
vfma_f32(a, b, vdup_n_f32_vfp4(c))
87618761
}
87628762

87638763
/// Floating-point fused Multiply-Add to accumulator(vector)
@@ -8767,7 +8767,7 @@ pub unsafe fn vfma_n_f32(a: float32x2_t, b: float32x2_t, c: f32) -> float32x2_t
87678767
#[cfg_attr(all(test, target_arch = "arm"), assert_instr(vfma))]
87688768
#[cfg_attr(all(test, target_arch = "aarch64"), assert_instr(fmla))]
87698769
pub unsafe fn vfmaq_n_f32(a: float32x4_t, b: float32x4_t, c: f32) -> float32x4_t {
8770-
vfmaq_f32(a, b, vdupq_n_f32(c))
8770+
vfmaq_f32(a, b, vdupq_n_f32_vfp4(c))
87718771
}
87728772

87738773
/// Floating-point fused multiply-subtract from accumulator
@@ -8799,7 +8799,7 @@ pub unsafe fn vfmsq_f32(a: float32x4_t, b: float32x4_t, c: float32x4_t) -> float
87998799
#[cfg_attr(all(test, target_arch = "arm"), assert_instr(vfms))]
88008800
#[cfg_attr(all(test, target_arch = "aarch64"), assert_instr(fmls))]
88018801
pub unsafe fn vfms_n_f32(a: float32x2_t, b: float32x2_t, c: f32) -> float32x2_t {
8802-
vfms_f32(a, b, vdup_n_f32(c))
8802+
vfms_f32(a, b, vdup_n_f32_vfp4(c))
88038803
}
88048804

88058805
/// Floating-point fused Multiply-subtract to accumulator(vector)
@@ -8809,7 +8809,7 @@ pub unsafe fn vfms_n_f32(a: float32x2_t, b: float32x2_t, c: f32) -> float32x2_t
88098809
#[cfg_attr(all(test, target_arch = "arm"), assert_instr(vfms))]
88108810
#[cfg_attr(all(test, target_arch = "aarch64"), assert_instr(fmls))]
88118811
pub unsafe fn vfmsq_n_f32(a: float32x4_t, b: float32x4_t, c: f32) -> float32x4_t {
8812-
vfmsq_f32(a, b, vdupq_n_f32(c))
8812+
vfmsq_f32(a, b, vdupq_n_f32_vfp4(c))
88138813
}
88148814

88158815
/// Subtract

crates/core_arch/src/arm_shared/neon/mod.rs

+26
Original file line numberDiff line numberDiff line change
@@ -3786,6 +3786,19 @@ pub unsafe fn vdupq_n_f32(value: f32) -> float32x4_t {
37863786
float32x4_t(value, value, value, value)
37873787
}
37883788

3789+
/// Duplicate vector element to vector or scalar
3790+
///
3791+
/// Private vfp4 version used by FMA intriniscs because LLVM does
3792+
/// not inline the non-vfp4 version in vfp4 functions.
3793+
#[inline]
3794+
#[target_feature(enable = "neon")]
3795+
#[cfg_attr(target_arch = "arm", target_feature(enable = "vfp4"))]
3796+
#[cfg_attr(all(test, target_arch = "arm"), assert_instr("vdup.32"))]
3797+
#[cfg_attr(all(test, target_arch = "aarch64"), assert_instr(dup))]
3798+
unsafe fn vdupq_n_f32_vfp4(value: f32) -> float32x4_t {
3799+
float32x4_t(value, value, value, value)
3800+
}
3801+
37893802
/// Duplicate vector element to vector or scalar
37903803
#[inline]
37913804
#[target_feature(enable = "neon")]
@@ -3896,6 +3909,19 @@ pub unsafe fn vdup_n_f32(value: f32) -> float32x2_t {
38963909
float32x2_t(value, value)
38973910
}
38983911

3912+
/// Duplicate vector element to vector or scalar
3913+
///
3914+
/// Private vfp4 version used by FMA intriniscs because LLVM does
3915+
/// not inline the non-vfp4 version in vfp4 functions.
3916+
#[inline]
3917+
#[target_feature(enable = "neon")]
3918+
#[cfg_attr(target_arch = "arm", target_feature(enable = "vfp4"))]
3919+
#[cfg_attr(all(test, target_arch = "arm"), assert_instr("vdup.32"))]
3920+
#[cfg_attr(all(test, target_arch = "aarch64"), assert_instr(dup))]
3921+
unsafe fn vdup_n_f32_vfp4(value: f32) -> float32x2_t {
3922+
float32x2_t(value, value)
3923+
}
3924+
38993925
/// Duplicate vector element to vector or scalar
39003926
#[inline]
39013927
#[target_feature(enable = "neon")]

crates/stdarch-gen/neon.spec

+2-2
Original file line numberDiff line numberDiff line change
@@ -2741,7 +2741,7 @@ generate float*_t
27412741
/// Floating-point fused Multiply-Add to accumulator(vector)
27422742
name = vfma
27432743
n-suffix
2744-
multi_fn = vfma-self-noext, a, b, {vdup-nself-noext, c}
2744+
multi_fn = vfma-self-noext, a, b, {vdup-nselfvfp4-noext, c}
27452745
a = 2.0, 3.0, 4.0, 5.0
27462746
b = 6.0, 4.0, 7.0, 8.0
27472747
c = 8.0
@@ -2818,7 +2818,7 @@ generate float*_t
28182818
/// Floating-point fused Multiply-subtract to accumulator(vector)
28192819
name = vfms
28202820
n-suffix
2821-
multi_fn = vfms-self-noext, a, b, {vdup-nself-noext, c}
2821+
multi_fn = vfms-self-noext, a, b, {vdup-nselfvfp4-noext, c}
28222822
a = 50.0, 35.0, 60.0, 69.0
28232823
b = 6.0, 4.0, 7.0, 8.0
28242824
c = 8.0

crates/stdarch-gen/src/main.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -1122,6 +1122,7 @@ fn gen_aarch64(
11221122
out_t,
11231123
fixed,
11241124
None,
1125+
true,
11251126
));
11261127
}
11271128
calls
@@ -1920,6 +1921,7 @@ fn gen_arm(
19201921
out_t,
19211922
fixed,
19221923
None,
1924+
false,
19231925
));
19241926
}
19251927
calls
@@ -2287,6 +2289,7 @@ fn get_call(
22872289
out_t: &str,
22882290
fixed: &Vec<String>,
22892291
n: Option<i32>,
2292+
aarch64: bool,
22902293
) -> String {
22912294
let params: Vec<_> = in_str.split(',').map(|v| v.trim().to_string()).collect();
22922295
assert!(params.len() > 0);
@@ -2454,7 +2457,8 @@ fn get_call(
24542457
in_t,
24552458
out_t,
24562459
fixed,
2457-
Some(i as i32)
2460+
Some(i as i32),
2461+
aarch64
24582462
)
24592463
);
24602464
call.push_str(&sub_match);
@@ -2503,6 +2507,7 @@ fn get_call(
25032507
out_t,
25042508
fixed,
25052509
n.clone(),
2510+
aarch64,
25062511
);
25072512
if !param_str.is_empty() {
25082513
param_str.push_str(", ");
@@ -2573,6 +2578,11 @@ fn get_call(
25732578
fn_name.push_str(type_to_suffix(in_t[1]));
25742579
} else if fn_format[1] == "nself" {
25752580
fn_name.push_str(type_to_n_suffix(in_t[1]));
2581+
} else if fn_format[1] == "nselfvfp4" {
2582+
fn_name.push_str(type_to_n_suffix(in_t[1]));
2583+
if !aarch64 {
2584+
fn_name.push_str("_vfp4");
2585+
}
25762586
} else if fn_format[1] == "out" {
25772587
fn_name.push_str(type_to_suffix(out_t));
25782588
} else if fn_format[1] == "in0" {

0 commit comments

Comments
 (0)