Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
9de60089
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,发现更多精彩内容 >>
提交
9de60089
编写于
3月 21, 2020
作者:
R
Ralf Jung
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
make bit_width return u64, consistently with other sizes in the compiler
上级
1ddbdc62
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
25 addition
and
28 deletion
+25
-28
src/librustc_ast/ast.rs
src/librustc_ast/ast.rs
+3
-3
src/librustc_codegen_llvm/intrinsic.rs
src/librustc_codegen_llvm/intrinsic.rs
+16
-18
src/librustc_mir/interpret/cast.rs
src/librustc_mir/interpret/cast.rs
+6
-7
未找到文件。
src/librustc_ast/ast.rs
浏览文件 @
9de60089
...
...
@@ -1614,7 +1614,7 @@ pub fn name(self) -> Symbol {
}
}
pub
fn
bit_width
(
self
)
->
u
size
{
pub
fn
bit_width
(
self
)
->
u
64
{
match
self
{
FloatTy
::
F32
=>
32
,
FloatTy
::
F64
=>
64
,
...
...
@@ -1663,7 +1663,7 @@ pub fn val_to_string(&self, val: i128) -> String {
format!
(
"{}{}"
,
val
as
u128
,
self
.name_str
())
}
pub
fn
bit_width
(
&
self
)
->
Option
<
u
size
>
{
pub
fn
bit_width
(
&
self
)
->
Option
<
u
64
>
{
Some
(
match
*
self
{
IntTy
::
Isize
=>
return
None
,
IntTy
::
I8
=>
8
,
...
...
@@ -1725,7 +1725,7 @@ pub fn val_to_string(&self, val: u128) -> String {
format!
(
"{}{}"
,
val
,
self
.name_str
())
}
pub
fn
bit_width
(
&
self
)
->
Option
<
u
size
>
{
pub
fn
bit_width
(
&
self
)
->
Option
<
u
64
>
{
Some
(
match
*
self
{
UintTy
::
Usize
=>
return
None
,
UintTy
::
U8
=>
8
,
...
...
src/librustc_codegen_llvm/intrinsic.rs
浏览文件 @
9de60089
...
...
@@ -1172,8 +1172,8 @@ fn generic_simd_intrinsic(
let
m_len
=
match
in_ty
.kind
{
// Note that this `.unwrap()` crashes for isize/usize, that's sort
// of intentional as there's not currently a use case for that.
ty
::
Int
(
i
)
=>
i
.bit_width
()
.unwrap
()
as
u64
,
ty
::
Uint
(
i
)
=>
i
.bit_width
()
.unwrap
()
as
u64
,
ty
::
Int
(
i
)
=>
i
.bit_width
()
.unwrap
(),
ty
::
Uint
(
i
)
=>
i
.bit_width
()
.unwrap
(),
_
=>
return_error!
(
"`{}` is not an integral type"
,
in_ty
),
};
require_simd!
(
arg_tys
[
1
],
"argument"
);
...
...
@@ -1354,20 +1354,18 @@ fn generic_simd_intrinsic(
// trailing bits.
let
expected_int_bits
=
in_len
.max
(
8
);
match
ret_ty
.kind
{
ty
::
Uint
(
i
)
if
i
.bit_width
()
==
Some
(
expected_int_bits
as
usize
)
=>
(),
ty
::
Uint
(
i
)
if
i
.bit_width
()
==
Some
(
expected_int_bits
)
=>
(),
_
=>
return_error!
(
"bitmask `{}`, expected `u{}`"
,
ret_ty
,
expected_int_bits
),
}
// Integer vector <i{in_bitwidth} x in_len>:
let
(
i_xn
,
in_elem_bitwidth
)
=
match
in_elem
.kind
{
ty
::
Int
(
i
)
=>
(
args
[
0
]
.immediate
(),
i
.bit_width
()
.unwrap_or
(
bx
.data_layout
()
.pointer_size
.bits
()
as
_
),
),
ty
::
Uint
(
i
)
=>
(
args
[
0
]
.immediate
(),
i
.bit_width
()
.unwrap_or
(
bx
.data_layout
()
.pointer_size
.bits
()
as
_
),
),
ty
::
Int
(
i
)
=>
{
(
args
[
0
]
.immediate
(),
i
.bit_width
()
.unwrap_or
(
bx
.data_layout
()
.pointer_size
.bits
()))
}
ty
::
Uint
(
i
)
=>
{
(
args
[
0
]
.immediate
(),
i
.bit_width
()
.unwrap_or
(
bx
.data_layout
()
.pointer_size
.bits
()))
}
_
=>
return_error!
(
"vector argument `{}`'s element type `{}`, expected integer element type"
,
in_ty
,
...
...
@@ -1378,16 +1376,16 @@ fn generic_simd_intrinsic(
// Shift the MSB to the right by "in_elem_bitwidth - 1" into the first bit position.
let
shift_indices
=
vec!
[
bx
.cx
.const_int
(
bx
.type_ix
(
in_elem_bitwidth
as
_
),
(
in_elem_bitwidth
-
1
)
as
_
);
bx
.cx
.const_int
(
bx
.type_ix
(
in_elem_bitwidth
),
(
in_elem_bitwidth
-
1
)
as
_
);
in_len
as
_
];
let
i_xn_msb
=
bx
.lshr
(
i_xn
,
bx
.const_vector
(
shift_indices
.as_slice
()));
// Truncate vector to an <i1 x N>
let
i1xn
=
bx
.trunc
(
i_xn_msb
,
bx
.type_vector
(
bx
.type_i1
(),
in_len
as
_
));
let
i1xn
=
bx
.trunc
(
i_xn_msb
,
bx
.type_vector
(
bx
.type_i1
(),
in_len
));
// Bitcast <i1 x N> to iN:
let
i_
=
bx
.bitcast
(
i1xn
,
bx
.type_ix
(
in_len
as
_
));
let
i_
=
bx
.bitcast
(
i1xn
,
bx
.type_ix
(
in_len
));
// Zero-extend iN to the bitmask type:
return
Ok
(
bx
.zext
(
i_
,
bx
.type_ix
(
expected_int_bits
as
_
)));
return
Ok
(
bx
.zext
(
i_
,
bx
.type_ix
(
expected_int_bits
)));
}
fn
simd_simple_float_intrinsic
(
...
...
@@ -2099,7 +2097,7 @@ fn int_type_width_signed(ty: Ty<'_>, cx: &CodegenCx<'_, '_>) -> Option<(u64, boo
match
ty
.kind
{
ty
::
Int
(
t
)
=>
Some
((
match
t
{
ast
::
IntTy
::
Isize
=>
cx
.tcx.sess.target.ptr_width
as
u64
,
ast
::
IntTy
::
Isize
=>
u64
::
from
(
cx
.tcx.sess.target.ptr_width
)
,
ast
::
IntTy
::
I8
=>
8
,
ast
::
IntTy
::
I16
=>
16
,
ast
::
IntTy
::
I32
=>
32
,
...
...
@@ -2110,7 +2108,7 @@ fn int_type_width_signed(ty: Ty<'_>, cx: &CodegenCx<'_, '_>) -> Option<(u64, boo
)),
ty
::
Uint
(
t
)
=>
Some
((
match
t
{
ast
::
UintTy
::
Usize
=>
cx
.tcx.sess.target.ptr_width
as
u64
,
ast
::
UintTy
::
Usize
=>
u64
::
from
(
cx
.tcx.sess.target.ptr_width
)
,
ast
::
UintTy
::
U8
=>
8
,
ast
::
UintTy
::
U16
=>
16
,
ast
::
UintTy
::
U32
=>
32
,
...
...
@@ -2127,7 +2125,7 @@ fn int_type_width_signed(ty: Ty<'_>, cx: &CodegenCx<'_, '_>) -> Option<(u64, boo
// Returns None if the type is not a float
fn
float_type_width
(
ty
:
Ty
<
'_
>
)
->
Option
<
u64
>
{
match
ty
.kind
{
ty
::
Float
(
t
)
=>
Some
(
t
.bit_width
()
as
u64
),
ty
::
Float
(
t
)
=>
Some
(
t
.bit_width
()),
_
=>
None
,
}
}
src/librustc_mir/interpret/cast.rs
浏览文件 @
9de60089
...
...
@@ -228,17 +228,16 @@ fn cast_from_float<F>(
match
dest_ty
.kind
{
// float -> uint
Uint
(
t
)
=>
{
// FIXME: can we make `bit_width` return a type more compatible with `Size::bits`?
let
width
=
t
.bit_width
()
.unwrap_or_else
(||
self
.pointer_size
()
.bits
()
as
usize
);
let
v
=
f
.to_u128
(
width
)
.value
;
let
width
=
t
.bit_width
()
.unwrap_or_else
(||
self
.pointer_size
()
.bits
());
let
v
=
f
.to_u128
(
usize
::
try_from
(
width
)
.unwrap
())
.value
;
// This should already fit the bit width
Ok
(
Scalar
::
from_uint
(
v
,
Size
::
from_bits
(
width
as
u64
)))
Ok
(
Scalar
::
from_uint
(
v
,
Size
::
from_bits
(
width
)))
}
// float -> int
Int
(
t
)
=>
{
let
width
=
t
.bit_width
()
.unwrap_or_else
(||
self
.pointer_size
()
.bits
()
as
usize
);
let
v
=
f
.to_i128
(
width
)
.value
;
Ok
(
Scalar
::
from_int
(
v
,
Size
::
from_bits
(
width
as
u64
)))
let
width
=
t
.bit_width
()
.unwrap_or_else
(||
self
.pointer_size
()
.bits
());
let
v
=
f
.to_i128
(
usize
::
try_from
(
width
)
.unwrap
()
)
.value
;
Ok
(
Scalar
::
from_int
(
v
,
Size
::
from_bits
(
width
)))
}
// float -> f32
Float
(
FloatTy
::
F32
)
=>
Ok
(
Scalar
::
from_f32
(
f
.convert
(
&
mut
false
)
.value
)),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录