Skip to content

Commit b81c7f8

Browse files
committed
use Crypto feature
1 parent f706f56 commit b81c7f8

File tree

4 files changed

+97
-65
lines changed

4 files changed

+97
-65
lines changed

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4094,6 +4094,19 @@ pub unsafe fn vmull_high_u32(a: uint32x4_t, b: uint32x4_t) -> uint64x2_t {
40944094
vmull_u32(a, b)
40954095
}
40964096

4097+
/// Polynomial multiply long
4098+
#[inline]
4099+
#[target_feature(enable = "neon,crypto")]
4100+
#[cfg_attr(test, assert_instr(pmull))]
4101+
pub unsafe fn vmull_p64(a: p64, b: p64) -> p128 {
4102+
#[allow(improper_ctypes)]
4103+
extern "C" {
4104+
#[cfg_attr(target_arch = "aarch64", link_name = "llvm.aarch64.neon.pmull64")]
4105+
fn vmull_p64_(a: p64, b: p64) -> int8x16_t;
4106+
}
4107+
transmute(vmull_p64_(a, b))
4108+
}
4109+
40974110
/// Polynomial multiply long
40984111
#[inline]
40994112
#[target_feature(enable = "neon")]
@@ -4106,7 +4119,7 @@ pub unsafe fn vmull_high_p8(a: poly8x16_t, b: poly8x16_t) -> poly16x8_t {
41064119

41074120
/// Polynomial multiply long
41084121
#[inline]
4109-
#[target_feature(enable = "neon")]
4122+
#[target_feature(enable = "neon,crypto")]
41104123
#[cfg_attr(test, assert_instr(pmull2))]
41114124
pub unsafe fn vmull_high_p64(a: poly64x2_t, b: poly64x2_t) -> p128 {
41124125
vmull_p64(simd_extract(a, 1), simd_extract(b, 1))
@@ -11376,6 +11389,15 @@ mod test {
1137611389
assert_eq!(r, e);
1137711390
}
1137811391

11392+
#[simd_test(enable = "neon")]
11393+
unsafe fn test_vmull_p64() {
11394+
let a: p64 = 15;
11395+
let b: p64 = 3;
11396+
let e: p128 = 17;
11397+
let r: p128 = transmute(vmull_p64(transmute(a), transmute(b)));
11398+
assert_eq!(r, e);
11399+
}
11400+
1137911401
#[simd_test(enable = "neon")]
1138011402
unsafe fn test_vmull_high_p8() {
1138111403
let a: i8x16 = i8x16::new(1, 2, 9, 10, 9, 10, 11, 12, 9, 10, 11, 12, 13, 14, 15, 16);

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

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,6 @@ extern "C" {
108108
#[link_name = "llvm.aarch64.neon.usqadd.v2i64"]
109109
fn vsqaddq_u64_(a: uint64x2_t, b: int64x2_t) -> uint64x2_t;
110110

111-
#[link_name = "llvm.aarch64.neon.pmull64"]
112-
fn vmull_p64_(a: i64, b: i64) -> int8x16_t;
113-
114111
#[link_name = "llvm.aarch64.neon.addp.v8i16"]
115112
fn vpaddq_s16_(a: int16x8_t, b: int16x8_t) -> int16x8_t;
116113
#[link_name = "llvm.aarch64.neon.addp.v4i32"]
@@ -1150,14 +1147,6 @@ pub unsafe fn vaddlvq_u8(a: uint8x16_t) -> u16 {
11501147
vaddlvq_u8_(a) as u16
11511148
}
11521149

1153-
/// Polynomial multiply long
1154-
#[inline]
1155-
#[target_feature(enable = "neon")]
1156-
#[cfg_attr(test, assert_instr(pmull))]
1157-
pub unsafe fn vmull_p64(a: p64, b: p64) -> p128 {
1158-
transmute(vmull_p64_(transmute(a), transmute(b)))
1159-
}
1160-
11611150
/// Vector add.
11621151
#[inline]
11631152
#[target_feature(enable = "neon")]
@@ -3260,36 +3249,6 @@ mod tests {
32603249
assert_eq!(r, e);
32613250
}
32623251

3263-
#[simd_test(enable = "neon")]
3264-
unsafe fn test_vmull_p64() {
3265-
// FIXME: I've a hard time writing a test for this as the documentation
3266-
// from arm is a bit thin as to waht exactly it does
3267-
let a: i64 = 8;
3268-
let b: i64 = 7;
3269-
let e: i128 = 56;
3270-
let r: i128 = transmute(vmull_p64(transmute(a), transmute(b)));
3271-
assert_eq!(r, e);
3272-
3273-
/*
3274-
let a: i64 = 5;
3275-
let b: i64 = 5;
3276-
let e: i128 = 25;
3277-
let r: i128 = transmute(vmull_p64(a, b));
3278-
3279-
assert_eq!(r, e);
3280-
let a: i64 = 6;
3281-
let b: i64 = 6;
3282-
let e: i128 = 36;
3283-
let r: i128 = transmute(vmull_p64(a, b));
3284-
assert_eq!(r, e);
3285-
3286-
let a: i64 = 7;
3287-
let b: i64 = 6;
3288-
let e: i128 = 42;
3289-
let r: i128 = transmute(vmull_p64(a, b));
3290-
assert_eq!(r, e);
3291-
*/
3292-
}
32933252
#[simd_test(enable = "neon")]
32943253
unsafe fn test_vadd_f64() {
32953254
let a = 1.;

crates/stdarch-gen/neon.spec

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2055,6 +2055,18 @@ link-arm = vmullp._EXT_
20552055
link-aarch64 = pmull._EXT_
20562056
generate poly8x8_t:poly8x8_t:poly16x8_t
20572057

2058+
/// Polynomial multiply long
2059+
name = vmull
2060+
no-q
2061+
a = 15
2062+
b = 3
2063+
validate 17
2064+
target = crypto
2065+
2066+
aarch64 = pmull
2067+
link-aarch64 = pmull64:p64:p64:p64:int8x16_t
2068+
generate p64:p64:p128
2069+
20582070
/// Polynomial multiply long
20592071
name = vmull_high
20602072
no-q
@@ -2076,6 +2088,7 @@ multi_fn = vmull-noqself-noext, {simd_extract, a, 1}, {simd_extract, b, 1}
20762088
a = 1, 15
20772089
b = 1, 3
20782090
validate 17
2091+
target = crypto
20792092

20802093
aarch64 = pmull2
20812094
generate poly64x2_t:poly64x2_t:p128

crates/stdarch-gen/src/main.rs

Lines changed: 61 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ fn type_len(t: &str) -> usize {
8181
"poly64x1_t" => 1,
8282
"poly64x2_t" => 2,
8383
"i8" | "i16" | "i32" | "i64" | "u8" | "u16" | "u32" | "u64" | "f32" | "f64" | "p8"
84-
| "p16" | "p128" => 1,
84+
| "p16" | "p64" | "p128" => 1,
8585
_ => panic!("unknown type: {}", t),
8686
}
8787
}
@@ -333,7 +333,7 @@ fn type_to_noq_suffix(t: &str) -> &str {
333333
"float64x1_t" | "float64x2_t" => "_f64",
334334
"poly8x8_t" | "poly8x16_t" => "_p8",
335335
"poly16x4_t" | "poly16x8_t" => "_p16",
336-
"poly64x1_t" | "poly64x2_t" => "_p64",
336+
"poly64x1_t" | "poly64x2_t" | "p64" => "_p64",
337337
_ => panic!("unknown type: {}", t),
338338
}
339339
}
@@ -355,8 +355,10 @@ enum Suffix {
355355

356356
#[derive(Clone, Copy)]
357357
enum TargetFeature {
358+
Default,
358359
ArmV7,
359360
FPArmV8,
361+
Crypto,
360362
}
361363

362364
fn type_to_global_type(t: &str) -> &str {
@@ -401,6 +403,7 @@ fn type_to_global_type(t: &str) -> &str {
401403
"f64" => "f64",
402404
"p8" => "p8",
403405
"p16" => "p16",
406+
"p64" => "p64",
404407
"p128" => "p128",
405408
_ => panic!("unknown type: {}", t),
406409
}
@@ -496,6 +499,8 @@ fn type_to_ext(t: &str) -> &str {
496499
"u64" => "v1i64",
497500
"f32" => "f32",
498501
"f64" => "f64",
502+
"p64" => "p64",
503+
"p128" => "p128",
499504
/*
500505
"poly64x1_t" => "i64x1",
501506
"poly64x2_t" => "i64x2",
@@ -829,6 +834,7 @@ fn gen_aarch64(
829834
)],
830835
suffix: Suffix,
831836
para_num: i32,
837+
target: TargetFeature,
832838
fixed: &Vec<String>,
833839
multi_fn: &Vec<String>,
834840
) -> (String, String) {
@@ -855,12 +861,15 @@ fn gen_aarch64(
855861
In2 => format!("{}{}", current_name, type_to_suffix(in_t[2])),
856862
In2Lane => format!("{}{}", current_name, type_to_lane_suffixes(out_t, in_t[2])),
857863
};
864+
let current_target = match target {
865+
Default => "neon",
866+
ArmV7 => "v7",
867+
FPArmV8 => "fp-armv8,v8",
868+
Crypto => "neon,crypto",
869+
};
858870
let current_fn = if let Some(current_fn) = current_fn.clone() {
859871
if link_aarch64.is_some() {
860-
panic!(
861-
"[{}] Can't specify link and (multi) fn at the same time.",
862-
name
863-
)
872+
panic!("[{}] Can't specify link and fn at the same time.", name)
864873
}
865874
current_fn
866875
} else if link_aarch64.is_some() {
@@ -877,7 +886,24 @@ fn gen_aarch64(
877886
let current_aarch64 = current_aarch64.clone().unwrap();
878887
let mut ext_c = String::new();
879888
let mut ext_c_const = String::new();
880-
if let Some(link_aarch64) = link_aarch64.clone() {
889+
let mut link_t: Vec<String> = vec![
890+
in_t[0].to_string(),
891+
in_t[1].to_string(),
892+
in_t[2].to_string(),
893+
out_t.to_string(),
894+
];
895+
if let Some(mut link_aarch64) = link_aarch64.clone() {
896+
if link_aarch64.contains(":") {
897+
let links: Vec<_> = link_aarch64.split(':').map(|v| v.to_string()).collect();
898+
assert_eq!(links.len(), 5);
899+
link_aarch64 = links[0].to_string();
900+
link_t = vec![
901+
links[1].clone(),
902+
links[2].clone(),
903+
links[3].clone(),
904+
links[4].clone(),
905+
];
906+
}
881907
let ext = type_to_ext(in_t[0]);
882908
let ext2 = type_to_ext(out_t);
883909
let link_aarch64 = if link_aarch64.starts_with("llvm") {
@@ -898,17 +924,17 @@ fn gen_aarch64(
898924
current_fn,
899925
match para_num {
900926
1 => {
901-
format!("a: {}", in_t[0])
927+
format!("a: {}", link_t[0])
902928
}
903929
2 => {
904-
format!("a: {}, b: {}", in_t[0], in_t[1])
930+
format!("a: {}, b: {}", link_t[0], link_t[1])
905931
}
906932
3 => {
907-
format!("a: {}, b: {}, c: {}", in_t[0], in_t[1], in_t[2])
933+
format!("a: {}, b: {}, c: {}", link_t[0], link_t[1], link_t[2])
908934
}
909935
_ => unimplemented!("unknown para_num"),
910936
},
911-
out_t
937+
link_t[3]
912938
);
913939
if const_aarch64.is_some() {
914940
ext_c_const = format!(
@@ -1003,6 +1029,11 @@ fn gen_aarch64(
10031029
} else {
10041030
String::new()
10051031
};
1032+
let trans: [&str; 2] = if link_t[3] != out_t {
1033+
["transmute(", ")"]
1034+
} else {
1035+
["", ""]
1036+
};
10061037
let call = if let Some(const_aarch64) = const_aarch64 {
10071038
match para_num {
10081039
1 => format!(
@@ -1038,31 +1069,33 @@ fn gen_aarch64(
10381069
match (multi_calls.len(), para_num, fixed.len()) {
10391070
(0, 1, 0) => format!(
10401071
r#"pub unsafe fn {}{}(a: {}) -> {} {{
1041-
{}{}(a)
1072+
{}{}{}(a){}
10421073
}}"#,
1043-
name, const_declare, in_t[0], out_t, ext_c, current_fn,
1074+
name, const_declare, in_t[0], out_t, ext_c, trans[0], current_fn, trans[1]
10441075
),
10451076
(0, 1, _) => {
10461077
let fixed: Vec<String> = fixed.iter().take(type_len(in_t[0])).cloned().collect();
10471078
format!(
10481079
r#"pub unsafe fn {}{}(a: {}) -> {} {{
10491080
let b{};
1050-
{}{}(a, transmute(b))
1081+
{}{}{}(a, transmute(b)){}
10511082
}}"#,
10521083
name,
10531084
const_declare,
10541085
in_t[0],
10551086
out_t,
10561087
values(in_t[0], &fixed),
10571088
ext_c,
1089+
trans[0],
10581090
current_fn,
1091+
trans[1],
10591092
)
10601093
}
10611094
(0, 2, _) => format!(
10621095
r#"pub unsafe fn {}{}(a: {}, b: {}) -> {} {{
1063-
{}{}(a, b)
1096+
{}{}{}(a, b){}
10641097
}}"#,
1065-
name, const_declare, in_t[0], in_t[1], out_t, ext_c, current_fn,
1098+
name, const_declare, in_t[0], in_t[1], out_t, ext_c, trans[0], current_fn, trans[1],
10661099
),
10671100
(0, 3, _) => format!(
10681101
r#"pub unsafe fn {}{}(a: {}, b: {}, c: {}) -> {} {{
@@ -1095,11 +1128,11 @@ fn gen_aarch64(
10951128
r#"
10961129
{}
10971130
#[inline]
1098-
#[target_feature(enable = "neon")]
1131+
#[target_feature(enable = "{}")]
10991132
#[cfg_attr(test, assert_instr({}{}))]{}
11001133
{}
11011134
"#,
1102-
current_comment, current_aarch64, const_assert, const_legacy, call
1135+
current_comment, current_target, current_aarch64, const_assert, const_legacy, call
11031136
);
11041137

11051138
let test = gen_test(
@@ -1274,8 +1307,10 @@ fn gen_arm(
12741307
.unwrap_or_else(|| current_arm.to_string());
12751308

12761309
let current_target = match target {
1310+
Default => "v7",
12771311
ArmV7 => "v7",
12781312
FPArmV8 => "fp-armv8,v8",
1313+
Crypto => "crypto",
12791314
};
12801315

12811316
let current_fn = if let Some(current_fn) = current_fn.clone() {
@@ -2074,7 +2109,7 @@ fn get_call(
20742109
}
20752110
}
20762111
if param_str.is_empty() {
2077-
return fn_name
2112+
return fn_name;
20782113
}
20792114
let fn_str = if let Some((re_name, re_type)) = re.clone() {
20802115
format!(
@@ -2119,7 +2154,7 @@ fn main() -> io::Result<()> {
21192154
Vec<String>,
21202155
)> = Vec::new();
21212156
let mut multi_fn: Vec<String> = Vec::new();
2122-
let mut target: TargetFeature = ArmV7;
2157+
let mut target: TargetFeature = Default;
21232158

21242159
//
21252160
// THIS FILE IS GENERATED FORM neon.spec DO NOT CHANGE IT MANUALLY
@@ -2200,7 +2235,7 @@ mod test {
22002235
fixed = Vec::new();
22012236
n = None;
22022237
multi_fn = Vec::new();
2203-
target = ArmV7;
2238+
target = Default;
22042239
} else if line.starts_with("//") {
22052240
} else if line.starts_with("name = ") {
22062241
current_name = Some(String::from(&line[7..]));
@@ -2258,10 +2293,12 @@ mod test {
22582293
} else if line.starts_with("target = ") {
22592294
target = match Some(String::from(&line[9..])) {
22602295
Some(input) => match input.as_str() {
2296+
"v7" => ArmV7,
22612297
"fp-armv8" => FPArmV8,
2262-
_ => ArmV7,
2298+
"crypto" => Crypto,
2299+
_ => Default,
22632300
},
2264-
_ => ArmV7,
2301+
_ => Default,
22652302
}
22662303
} else if line.starts_with("generate ") {
22672304
let line = &line[9..];
@@ -2341,6 +2378,7 @@ mod test {
23412378
&current_tests,
23422379
suffix,
23432380
para_num,
2381+
target,
23442382
&fixed,
23452383
&multi_fn,
23462384
);

0 commit comments

Comments
 (0)