Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
8003b043
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,发现更多精彩内容 >>
提交
8003b043
编写于
12月 01, 2021
作者:
J
Jubilee Young
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
impl Op<&'_ RHS> for &'_ LHS
上级
257fa7aa
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
106 addition
and
30 deletion
+106
-30
crates/core_simd/src/ops/deref.rs
crates/core_simd/src/ops/deref.rs
+84
-30
crates/core_simd/tests/autoderef.rs
crates/core_simd/tests/autoderef.rs
+22
-0
未找到文件。
crates/core_simd/src/ops/deref.rs
浏览文件 @
8003b043
//! This module hacks in "implicit deref" for Simd's operators.
//! Ideally, Rust would take care of this itself,
//! and method calls usually handle the LHS implicitly.
//!
So, we'll manually deref the RHS
.
//!
But this is not the case with arithmetic ops
.
use
super
::
*
;
macro_rules!
deref_ops
{
(
$
(
impl
<
T
,
const
LANES
:
usize
>
$trait:ident
<&
Self
>
for
Simd
<
T
,
LANES
>
{
fn
$call:ident
(
rhs
:
&
Self
)
})
*
)
=>
{
$
(
impl
<
T
,
const
LANES
:
usize
>
$trait
<&
Self
>
for
Simd
<
T
,
LANES
>
macro_rules!
deref_lhs
{
(
impl
<
T
,
const
LANES
:
usize
>
$trait:ident
for
$simd:ty
{
fn
$call:ident
})
=>
{
impl
<
T
,
const
LANES
:
usize
>
$trait
<
$simd
>
for
&
$simd
where
T
:
SimdElement
,
$simd
:
$trait
<
$simd
,
Output
=
$simd
>
,
LaneCount
<
LANES
>
:
SupportedLaneCount
,
{
type
Output
=
Simd
<
T
,
LANES
>
;
#[inline]
#[must_use
=
"operator returns a new vector without mutating the inputs"
]
fn
$call
(
self
,
rhs
:
$simd
)
->
Self
::
Output
{
(
*
self
)
.
$call
(
rhs
)
}
}
};
}
macro_rules!
deref_rhs
{
(
impl
<
T
,
const
LANES
:
usize
>
$trait:ident
for
$simd:ty
{
fn
$call:ident
})
=>
{
impl
<
T
,
const
LANES
:
usize
>
$trait
<&
$simd
>
for
$simd
where
Self
:
$trait
<
Self
,
Output
=
Self
>
,
T
:
SimdElement
,
$simd
:
$trait
<
$simd
,
Output
=
$simd
>
,
LaneCount
<
LANES
>
:
SupportedLaneCount
,
{
type
Output
=
S
elf
;
type
Output
=
S
imd
<
T
,
LANES
>
;
#[inline]
#[must_use
=
"operator returns a new vector without mutating the inputs"
]
fn
$call
(
self
,
rhs
:
&
Self
)
->
Self
::
Output
{
fn
$call
(
self
,
rhs
:
&
$simd
)
->
Self
::
Output
{
self
.
$call
(
*
rhs
)
}
})
*
}
};
}
macro_rules!
deref_ops
{
(
$
(
impl
<
T
,
const
LANES
:
usize
>
$trait:ident
for
$simd:ty
{
fn
$call:ident
})
*
)
=>
{
$
(
deref_rhs!
{
impl
<
T
,
const
LANES
:
usize
>
$trait
for
$simd
{
fn
$call
}
}
deref_lhs!
{
impl
<
T
,
const
LANES
:
usize
>
$trait
for
$simd
{
fn
$call
}
}
impl
<
'lhs
,
'rhs
,
T
,
const
LANES
:
usize
>
$trait
<&
'rhs
$simd
>
for
&
'lhs
$simd
where
T
:
SimdElement
,
$simd
:
$trait
<
$simd
,
Output
=
$simd
>
,
LaneCount
<
LANES
>
:
SupportedLaneCount
,
{
type
Output
=
$simd
;
#[inline]
#[must_use
=
"operator returns a new vector without mutating the inputs"
]
fn
$call
(
self
,
rhs
:
&
$simd
)
->
Self
::
Output
{
(
*
self
)
.
$call
(
*
rhs
)
}
}
)
*
}
}
deref_ops!
{
// Arithmetic
impl
<
T
,
const
LANES
:
usize
>
Add
<&
Self
>
for
Simd
<
T
,
LANES
>
{
fn
add
(
rhs
:
&
Self
)
impl
<
T
,
const
LANES
:
usize
>
Add
for
Simd
<
T
,
LANES
>
{
fn
add
}
impl
<
T
,
const
LANES
:
usize
>
Mul
<&
Self
>
for
Simd
<
T
,
LANES
>
{
fn
mul
(
rhs
:
&
Self
)
impl
<
T
,
const
LANES
:
usize
>
Mul
for
Simd
<
T
,
LANES
>
{
fn
mul
}
impl
<
T
,
const
LANES
:
usize
>
Sub
<&
Self
>
for
Simd
<
T
,
LANES
>
{
fn
sub
(
rhs
:
&
Self
)
impl
<
T
,
const
LANES
:
usize
>
Sub
for
Simd
<
T
,
LANES
>
{
fn
sub
}
impl
<
T
,
const
LANES
:
usize
>
Div
<&
Self
>
for
Simd
<
T
,
LANES
>
{
fn
div
(
rhs
:
&
Self
)
impl
<
T
,
const
LANES
:
usize
>
Div
for
Simd
<
T
,
LANES
>
{
fn
div
}
impl
<
T
,
const
LANES
:
usize
>
Rem
<&
Self
>
for
Simd
<
T
,
LANES
>
{
fn
rem
(
rhs
:
&
Self
)
impl
<
T
,
const
LANES
:
usize
>
Rem
for
Simd
<
T
,
LANES
>
{
fn
rem
}
// Bitops
impl
<
T
,
const
LANES
:
usize
>
BitAnd
<&
Self
>
for
Simd
<
T
,
LANES
>
{
fn
bitand
(
rhs
:
&
Self
)
impl
<
T
,
const
LANES
:
usize
>
BitAnd
for
Simd
<
T
,
LANES
>
{
fn
bitand
}
impl
<
T
,
const
LANES
:
usize
>
BitOr
<&
Self
>
for
Simd
<
T
,
LANES
>
{
fn
bitor
(
rhs
:
&
Self
)
impl
<
T
,
const
LANES
:
usize
>
BitOr
for
Simd
<
T
,
LANES
>
{
fn
bitor
}
impl
<
T
,
const
LANES
:
usize
>
BitXor
<&
Self
>
for
Simd
<
T
,
LANES
>
{
fn
bitxor
(
rhs
:
&
Self
)
impl
<
T
,
const
LANES
:
usize
>
BitXor
for
Simd
<
T
,
LANES
>
{
fn
bitxor
}
impl
<
T
,
const
LANES
:
usize
>
Shl
<&
Self
>
for
Simd
<
T
,
LANES
>
{
fn
shl
(
rhs
:
&
Self
)
impl
<
T
,
const
LANES
:
usize
>
Shl
for
Simd
<
T
,
LANES
>
{
fn
shl
}
impl
<
T
,
const
LANES
:
usize
>
Shr
<&
Self
>
for
Simd
<
T
,
LANES
>
{
fn
shr
(
rhs
:
&
Self
)
impl
<
T
,
const
LANES
:
usize
>
Shr
for
Simd
<
T
,
LANES
>
{
fn
shr
}
}
crates/core_simd/tests/autoderef.rs
0 → 100644
浏览文件 @
8003b043
// Test that we handle all our "auto-deref" cases correctly.
#![feature(portable_simd)]
use
core_simd
::
f32x4
;
#[cfg(target_arch
=
"wasm32"
)]
use
wasm_bindgen_test
::
*
;
#[cfg(target_arch
=
"wasm32"
)]
wasm_bindgen_test_configure!
(
run_in_browser
);
#[test]
#[cfg_attr(target_arch
=
"wasm32"
,
wasm_bindgen_test)]
fn
deref
()
{
let
x
=
f32x4
::
splat
(
1.0
);
let
y
=
f32x4
::
splat
(
2.0
);
let
a
=
&
x
;
let
b
=
&
y
;
assert_eq!
(
f32x4
::
splat
(
3.0
),
x
+
y
);
assert_eq!
(
f32x4
::
splat
(
3.0
),
x
+
b
);
assert_eq!
(
f32x4
::
splat
(
3.0
),
a
+
y
);
assert_eq!
(
f32x4
::
splat
(
3.0
),
a
+
b
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录