Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
49043f44
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
49043f44
编写于
3月 12, 2022
作者:
R
Ralf Jung
提交者:
GitHub
3月 12, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rust-lang/portable-simd#262: also implement clamp for integer vectors
* add test from issue rust-lang/portable-simd#253
上级
b6ee5293
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
55 addition
and
13 deletion
+55
-13
crates/core_simd/src/comparisons.rs
crates/core_simd/src/comparisons.rs
+31
-13
crates/core_simd/tests/i16_ops.rs
crates/core_simd/tests/i16_ops.rs
+12
-0
crates/core_simd/tests/ops_macros.rs
crates/core_simd/tests/ops_macros.rs
+12
-0
未找到文件。
crates/core_simd/src/comparisons.rs
浏览文件 @
49043f44
...
...
@@ -67,36 +67,54 @@ pub fn lanes_ge(self, other: Self) -> Mask<T::Mask, LANES> {
}
}
macro_rules!
impl_
min_max
_vector
{
macro_rules!
impl_
ord_methods
_vector
{
{
$type:ty
}
=>
{
impl
<
const
LANES
:
usize
>
Simd
<
$type
,
LANES
>
where
LaneCount
<
LANES
>
:
SupportedLaneCount
,
{
/// Returns the lane-wise minimum with
other
/// Returns the lane-wise minimum with
`other`.
#[must_use
=
"method returns a new vector and does not mutate the original value"
]
#[inline]
pub
fn
min
(
self
,
other
:
Self
)
->
Self
{
self
.lanes_gt
(
other
)
.select
(
other
,
self
)
}
/// Returns the lane-wise maximum with
other
/// Returns the lane-wise maximum with
`other`.
#[must_use
=
"method returns a new vector and does not mutate the original value"
]
#[inline]
pub
fn
max
(
self
,
other
:
Self
)
->
Self
{
self
.lanes_lt
(
other
)
.select
(
other
,
self
)
}
/// Restrict each lane to a certain interval.
///
/// For each lane, returns `max` if `self` is greater than `max`, and `min` if `self` is
/// less than `min`. Otherwise returns `self`.
///
/// # Panics
///
/// Panics if `min > max` on any lane.
#[must_use
=
"method returns a new vector and does not mutate the original value"
]
#[inline]
pub
fn
clamp
(
self
,
min
:
Self
,
max
:
Self
)
->
Self
{
assert!
(
min
.lanes_le
(
max
)
.all
(),
"each lane in `min` must be less than or equal to the corresponding lane in `max`"
,
);
self
.max
(
min
)
.min
(
max
)
}
}
}
}
impl_
min_max
_vector!
(
i8
);
impl_
min_max
_vector!
(
i16
);
impl_
min_max
_vector!
(
i32
);
impl_
min_max
_vector!
(
i64
);
impl_
min_max
_vector!
(
isize
);
impl_
min_max
_vector!
(
u8
);
impl_
min_max
_vector!
(
u16
);
impl_
min_max
_vector!
(
u32
);
impl_
min_max
_vector!
(
u64
);
impl_
min_max
_vector!
(
usize
);
impl_
ord_methods
_vector!
(
i8
);
impl_
ord_methods
_vector!
(
i16
);
impl_
ord_methods
_vector!
(
i32
);
impl_
ord_methods
_vector!
(
i64
);
impl_
ord_methods
_vector!
(
isize
);
impl_
ord_methods
_vector!
(
u8
);
impl_
ord_methods
_vector!
(
u16
);
impl_
ord_methods
_vector!
(
u32
);
impl_
ord_methods
_vector!
(
u64
);
impl_
ord_methods
_vector!
(
usize
);
crates/core_simd/tests/i16_ops.rs
浏览文件 @
49043f44
...
...
@@ -18,3 +18,15 @@ fn min_is_not_lexicographic() {
let
b
=
i16x2
::
from_array
([
12
,
-
4
]);
assert_eq!
(
a
.min
(
b
),
i16x2
::
from_array
([
10
,
-
4
]));
}
#[test]
fn
clamp_is_not_lexicographic
()
{
let
a
=
i16x2
::
splat
(
10
);
let
lo
=
i16x2
::
from_array
([
-
12
,
-
4
]);
let
up
=
i16x2
::
from_array
([
-
4
,
12
]);
assert_eq!
(
a
.clamp
(
lo
,
up
),
i16x2
::
from_array
([
-
4
,
10
]));
let
x
=
i16x2
::
from_array
([
1
,
10
]);
let
y
=
x
.clamp
(
i16x2
::
splat
(
0
),
i16x2
::
splat
(
9
));
assert_eq!
(
y
,
i16x2
::
from_array
([
1
,
9
]));
}
crates/core_simd/tests/ops_macros.rs
浏览文件 @
49043f44
...
...
@@ -239,6 +239,18 @@ fn max<const LANES: usize>() {
let
b
=
Vector
::
<
LANES
>
::
splat
(
0
);
assert_eq!
(
a
.max
(
b
),
a
);
}
fn
clamp
<
const
LANES
:
usize
>
()
{
let
min
=
Vector
::
<
LANES
>
::
splat
(
Scalar
::
MIN
);
let
max
=
Vector
::
<
LANES
>
::
splat
(
Scalar
::
MAX
);
let
zero
=
Vector
::
<
LANES
>
::
splat
(
0
);
let
one
=
Vector
::
<
LANES
>
::
splat
(
1
);
let
negone
=
Vector
::
<
LANES
>
::
splat
(
-
1
);
assert_eq!
(
zero
.clamp
(
min
,
max
),
zero
);
assert_eq!
(
zero
.clamp
(
min
,
one
),
zero
);
assert_eq!
(
zero
.clamp
(
one
,
max
),
one
);
assert_eq!
(
zero
.clamp
(
min
,
negone
),
negone
);
}
}
test_helpers
::
test_lanes_panic!
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录