Skip to content

Commit 1e6ee7c

Browse files
heiherAmanieu
authored andcommitted
stdarch-gen: Add LoongArch frecipe intrinsics
1 parent 21a2557 commit 1e6ee7c

File tree

6 files changed

+135
-17
lines changed

6 files changed

+135
-17
lines changed

crates/stdarch-gen-loongarch/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ LSX:
1111
# Generate bindings
1212
OUT_DIR=`pwd`/crates/stdarch-gen-loongarch cargo run -p stdarch-gen-loongarch -- crates/stdarch-gen-loongarch/lsxintrin.h
1313
OUT_DIR=`pwd`/crates/core_arch cargo run -p stdarch-gen-loongarch -- crates/stdarch-gen-loongarch/lsx.spec
14+
rustfmt crates/core_arch/src/loongarch64/lsx/generated.rs
1415
1516
# Generate tests
1617
OUT_DIR=`pwd`/crates/stdarch-gen-loongarch cargo run -p stdarch-gen-loongarch -- crates/stdarch-gen-loongarch/lsx.spec test
17-
loongarch64-unknown-linux-gnu-gcc -static -o lsx crates/stdarch-gen-loongarch/lsx.c -mlasx
18+
loongarch64-unknown-linux-gnu-gcc -static -o lsx crates/stdarch-gen-loongarch/lsx.c -mlasx -mfrecipe
1819
qemu-loongarch64 ./lsx > crates/core_arch/src/loongarch64/lsx/tests.rs
1920
rustfmt crates/core_arch/src/loongarch64/lsx/tests.rs
2021
```
@@ -24,10 +25,11 @@ LASX:
2425
# Generate bindings
2526
OUT_DIR=`pwd`/crates/stdarch-gen-loongarch cargo run -p stdarch-gen-loongarch -- crates/stdarch-gen-loongarch/lasxintrin.h
2627
OUT_DIR=`pwd`/crates/core_arch cargo run -p stdarch-gen-loongarch -- crates/stdarch-gen-loongarch/lasx.spec
28+
rustfmt crates/core_arch/src/loongarch64/lasx/generated.rs
2729
2830
# Generate tests
2931
OUT_DIR=`pwd`/crates/stdarch-gen-loongarch cargo run -p stdarch-gen-loongarch -- crates/stdarch-gen-loongarch/lasx.spec test
30-
loongarch64-unknown-linux-gnu-gcc -static -o lasx crates/stdarch-gen-loongarch/lasx.c -mlasx
32+
loongarch64-unknown-linux-gnu-gcc -static -o lasx crates/stdarch-gen-loongarch/lasx.c -mlasx -mfrecipe
3133
qemu-loongarch64 ./lasx > crates/core_arch/src/loongarch64/lasx/tests.rs
3234
rustfmt crates/core_arch/src/loongarch64/lasx/tests.rs
3335
```

crates/stdarch-gen-loongarch/lasx.spec

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1648,6 +1648,26 @@ name = lasx_xvfrecip_d
16481648
asm-fmts = xd, xj
16491649
data-types = V4DF, V4DF
16501650

1651+
/// lasx_xvfrecipe_s
1652+
name = lasx_xvfrecipe_s
1653+
asm-fmts = xd, xj
1654+
data-types = V8SF, V8SF
1655+
1656+
/// lasx_xvfrecipe_d
1657+
name = lasx_xvfrecipe_d
1658+
asm-fmts = xd, xj
1659+
data-types = V4DF, V4DF
1660+
1661+
/// lasx_xvfrsqrte_s
1662+
name = lasx_xvfrsqrte_s
1663+
asm-fmts = xd, xj
1664+
data-types = V8SF, V8SF
1665+
1666+
/// lasx_xvfrsqrte_d
1667+
name = lasx_xvfrsqrte_d
1668+
asm-fmts = xd, xj
1669+
data-types = V4DF, V4DF
1670+
16511671
/// lasx_xvfrint_s
16521672
name = lasx_xvfrint_s
16531673
asm-fmts = xd, xj

crates/stdarch-gen-loongarch/lasxintrin.h

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*
2-
* https://gcc.gnu.org/git/?p=gcc.git;a=blob_plain;f=gcc/config/loongarch/lasxintrin.h;hb=4912418dc1b51d49aca5982c6a2061bb912b92b7
2+
* https://gcc.gnu.org/git/?p=gcc.git;a=blob_plain;f=gcc/config/loongarch/lasxintrin.h;hb=61f1001f2f4ab9128e5eb6e9a4adbbb0f9f0bc75
33
*/
44

55
/* LARCH Loongson ASX intrinsics include file.
66
7-
Copyright (C) 2018 Free Software Foundation, Inc.
7+
Copyright (C) 2018-2024 Free Software Foundation, Inc.
88
99
This file is part of GCC.
1010
@@ -2403,6 +2403,40 @@ __m256d __lasx_xvfrecip_d (__m256d _1)
24032403
return (__m256d)__builtin_lasx_xvfrecip_d ((v4f64)_1);
24042404
}
24052405

2406+
#if defined(__loongarch_frecipe)
2407+
/* Assembly instruction format: xd, xj. */
2408+
/* Data types in instruction templates: V8SF, V8SF. */
2409+
extern __inline __attribute__((__gnu_inline__, __always_inline__, __artificial__))
2410+
__m256 __lasx_xvfrecipe_s (__m256 _1)
2411+
{
2412+
return (__m256)__builtin_lasx_xvfrecipe_s ((v8f32)_1);
2413+
}
2414+
2415+
/* Assembly instruction format: xd, xj. */
2416+
/* Data types in instruction templates: V4DF, V4DF. */
2417+
extern __inline __attribute__((__gnu_inline__, __always_inline__, __artificial__))
2418+
__m256d __lasx_xvfrecipe_d (__m256d _1)
2419+
{
2420+
return (__m256d)__builtin_lasx_xvfrecipe_d ((v4f64)_1);
2421+
}
2422+
2423+
/* Assembly instruction format: xd, xj. */
2424+
/* Data types in instruction templates: V8SF, V8SF. */
2425+
extern __inline __attribute__((__gnu_inline__, __always_inline__, __artificial__))
2426+
__m256 __lasx_xvfrsqrte_s (__m256 _1)
2427+
{
2428+
return (__m256)__builtin_lasx_xvfrsqrte_s ((v8f32)_1);
2429+
}
2430+
2431+
/* Assembly instruction format: xd, xj. */
2432+
/* Data types in instruction templates: V4DF, V4DF. */
2433+
extern __inline __attribute__((__gnu_inline__, __always_inline__, __artificial__))
2434+
__m256d __lasx_xvfrsqrte_d (__m256d _1)
2435+
{
2436+
return (__m256d)__builtin_lasx_xvfrsqrte_d ((v4f64)_1);
2437+
}
2438+
#endif
2439+
24062440
/* Assembly instruction format: xd, xj. */
24072441
/* Data types in instruction templates: V8SF, V8SF. */
24082442
extern __inline __attribute__((__gnu_inline__, __always_inline__, __artificial__))

crates/stdarch-gen-loongarch/lsx.spec

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1723,6 +1723,26 @@ name = lsx_vfrecip_d
17231723
asm-fmts = vd, vj
17241724
data-types = V2DF, V2DF
17251725

1726+
/// lsx_vfrecipe_s
1727+
name = lsx_vfrecipe_s
1728+
asm-fmts = vd, vj
1729+
data-types = V4SF, V4SF
1730+
1731+
/// lsx_vfrecipe_d
1732+
name = lsx_vfrecipe_d
1733+
asm-fmts = vd, vj
1734+
data-types = V2DF, V2DF
1735+
1736+
/// lsx_vfrsqrte_s
1737+
name = lsx_vfrsqrte_s
1738+
asm-fmts = vd, vj
1739+
data-types = V4SF, V4SF
1740+
1741+
/// lsx_vfrsqrte_d
1742+
name = lsx_vfrsqrte_d
1743+
asm-fmts = vd, vj
1744+
data-types = V2DF, V2DF
1745+
17261746
/// lsx_vfrint_s
17271747
name = lsx_vfrint_s
17281748
asm-fmts = vd, vj

crates/stdarch-gen-loongarch/lsxintrin.h

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/*
2-
* https://gcc.gnu.org/git/?p=gcc.git;a=blob_plain;f=gcc/config/loongarch/lsxintrin.h;hb=4912418dc1b51d49aca5982c6a2061bb912b92b7
2+
* https://gcc.gnu.org/git/?p=gcc.git;a=blob_plain;f=gcc/config/loongarch/lsxintrin.h;hb=61f1001f2f4ab9128e5eb6e9a4adbbb0f9f0bc75
33
*/
44

55
/* LARCH Loongson SX intrinsics include file.
66
7-
Copyright (C) 2018 Free Software Foundation, Inc.
7+
Copyright (C) 2018-2024 Free Software Foundation, Inc.
88
99
This file is part of GCC.
1010
@@ -2484,6 +2484,40 @@ __m128d __lsx_vfrecip_d (__m128d _1)
24842484
return (__m128d)__builtin_lsx_vfrecip_d ((v2f64)_1);
24852485
}
24862486

2487+
#if defined(__loongarch_frecipe)
2488+
/* Assembly instruction format: vd, vj. */
2489+
/* Data types in instruction templates: V4SF, V4SF. */
2490+
extern __inline __attribute__((__gnu_inline__, __always_inline__, __artificial__))
2491+
__m128 __lsx_vfrecipe_s (__m128 _1)
2492+
{
2493+
return (__m128)__builtin_lsx_vfrecipe_s ((v4f32)_1);
2494+
}
2495+
2496+
/* Assembly instruction format: vd, vj. */
2497+
/* Data types in instruction templates: V2DF, V2DF. */
2498+
extern __inline __attribute__((__gnu_inline__, __always_inline__, __artificial__))
2499+
__m128d __lsx_vfrecipe_d (__m128d _1)
2500+
{
2501+
return (__m128d)__builtin_lsx_vfrecipe_d ((v2f64)_1);
2502+
}
2503+
2504+
/* Assembly instruction format: vd, vj. */
2505+
/* Data types in instruction templates: V4SF, V4SF. */
2506+
extern __inline __attribute__((__gnu_inline__, __always_inline__, __artificial__))
2507+
__m128 __lsx_vfrsqrte_s (__m128 _1)
2508+
{
2509+
return (__m128)__builtin_lsx_vfrsqrte_s ((v4f32)_1);
2510+
}
2511+
2512+
/* Assembly instruction format: vd, vj. */
2513+
/* Data types in instruction templates: V2DF, V2DF. */
2514+
extern __inline __attribute__((__gnu_inline__, __always_inline__, __artificial__))
2515+
__m128d __lsx_vfrsqrte_d (__m128d _1)
2516+
{
2517+
return (__m128d)__builtin_lsx_vfrsqrte_d ((v2f64)_1);
2518+
}
2519+
#endif
2520+
24872521
/* Assembly instruction format: vd, vj. */
24882522
/* Data types in instruction templates: V4SF, V4SF. */
24892523
extern __inline __attribute__((__gnu_inline__, __always_inline__, __artificial__))

crates/stdarch-gen-loongarch/src/main.rs

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,36 @@ impl TargetFeature {
5353
}
5454

5555
/// A string for use with `#[target_feature(...)]`.
56-
fn as_target_feature_arg_loongarch64(&self) -> &str {
57-
match *self {
56+
fn as_target_feature_arg(&self, ins: &str) -> String {
57+
let vec = match *self {
5858
// Features included with LoongArch64 LSX and LASX.
5959
Self::Lsx => "lsx",
6060
Self::Lasx => "lasx",
61-
}
61+
};
62+
let frecipe = match ins {
63+
"lsx_vfrecipe_s" | "lsx_vfrecipe_d" | "lsx_vfrsqrte_s" | "lsx_vfrsqrte_d"
64+
| "lasx_xvfrecipe_s" | "lasx_xvfrecipe_d" | "lasx_xvfrsqrte_s" | "lasx_xvfrsqrte_d" => {
65+
",frecipe"
66+
}
67+
_ => "",
68+
};
69+
format!("{vec}{frecipe}")
6270
}
6371

6472
fn attr(name: &str, value: impl fmt::Display) -> String {
6573
format!(r#"#[{name}(enable = "{value}")]"#)
6674
}
6775

68-
/// Generate a target_feature attribute for a test that will compile only for "loongarch64".
69-
fn to_target_feature_attr_loongarch64(self) -> Lines {
76+
/// Generate a target_feature attribute
77+
fn to_target_feature_attr(&self, ins: &str) -> Lines {
7078
Lines::single(Self::attr(
7179
"target_feature",
72-
self.as_target_feature_arg_loongarch64(),
80+
self.as_target_feature_arg(ins),
7381
))
7482
}
7583

76-
fn bytes(self) -> u8 {
77-
match self {
84+
fn bytes(&self) -> u8 {
85+
match *self {
7886
// Features included with LoongArch64 LSX and LASX.
7987
Self::Lsx => 16,
8088
Self::Lasx => 32,
@@ -531,7 +539,7 @@ fn gen_bind_body(
531539
{call_params}
532540
}}
533541
"#,
534-
target_feature = target.to_target_feature_attr_loongarch64()
542+
target_feature = target.to_target_feature_attr(current_name)
535543
)
536544
} else {
537545
format!(
@@ -542,7 +550,7 @@ fn gen_bind_body(
542550
{call_params}
543551
}}
544552
"#,
545-
target_feature = target.to_target_feature_attr_loongarch64()
553+
target_feature = target.to_target_feature_attr(current_name)
546554
)
547555
};
548556
(link_function, function)
@@ -1491,7 +1499,7 @@ static void {current_name}(void)
14911499
printf("}}\n");
14921500
}}
14931501
"#,
1494-
target.as_target_feature_arg_loongarch64()
1502+
target.as_target_feature_arg(current_name)
14951503
)
14961504
};
14971505
let call_function = format!(" {current_name}();\n");

0 commit comments

Comments
 (0)