Skip to content

Commit 2ae377f

Browse files
committed
Auto merge of #3747 - RalfJung:sse-cleanup, r=RalfJung
remove some SSE/SSE2 intrinsics that are no longer used by stdarch Fixes #3691
2 parents e80c7c2 + 3e79bb4 commit 2ae377f

File tree

5 files changed

+11
-77
lines changed

5 files changed

+11
-77
lines changed

src/shims/x86/avx.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,12 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
7373

7474
round_all::<rustc_apfloat::ieee::Double>(this, op, rounding, dest)?;
7575
}
76-
// Used to implement _mm256_{sqrt,rcp,rsqrt}_ps functions.
76+
// Used to implement _mm256_{rcp,rsqrt}_ps functions.
7777
// Performs the operations on all components of `op`.
78-
"sqrt.ps.256" | "rcp.ps.256" | "rsqrt.ps.256" => {
78+
"rcp.ps.256" | "rsqrt.ps.256" => {
7979
let [op] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
8080

8181
let which = match unprefixed_name {
82-
"sqrt.ps.256" => FloatUnaryOp::Sqrt,
8382
"rcp.ps.256" => FloatUnaryOp::Rcp,
8483
"rsqrt.ps.256" => FloatUnaryOp::Rsqrt,
8584
_ => unreachable!(),

src/shims/x86/mod.rs

+1-19
Original file line numberDiff line numberDiff line change
@@ -159,8 +159,6 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
159159

160160
#[derive(Copy, Clone)]
161161
enum FloatBinOp {
162-
/// Arithmetic operation
163-
Arith(mir::BinOp),
164162
/// Comparison
165163
///
166164
/// The semantics of this operator is a case distinction: we compare the two operands,
@@ -247,16 +245,11 @@ impl FloatBinOp {
247245
/// Performs `which` scalar operation on `left` and `right` and returns
248246
/// the result.
249247
fn bin_op_float<'tcx, F: rustc_apfloat::Float>(
250-
this: &crate::MiriInterpCx<'tcx>,
251248
which: FloatBinOp,
252249
left: &ImmTy<'tcx>,
253250
right: &ImmTy<'tcx>,
254251
) -> InterpResult<'tcx, Scalar> {
255252
match which {
256-
FloatBinOp::Arith(which) => {
257-
let res = this.binary_op(which, left, right)?;
258-
Ok(res.to_scalar())
259-
}
260253
FloatBinOp::Cmp { gt, lt, eq, unord } => {
261254
let left = left.to_scalar().to_float::<F>()?;
262255
let right = right.to_scalar().to_float::<F>()?;
@@ -323,7 +316,6 @@ fn bin_op_simd_float_first<'tcx, F: rustc_apfloat::Float>(
323316
assert_eq!(dest_len, right_len);
324317

325318
let res0 = bin_op_float::<F>(
326-
this,
327319
which,
328320
&this.read_immediate(&this.project_index(&left, 0)?)?,
329321
&this.read_immediate(&this.project_index(&right, 0)?)?,
@@ -358,7 +350,7 @@ fn bin_op_simd_float_all<'tcx, F: rustc_apfloat::Float>(
358350
let right = this.read_immediate(&this.project_index(&right, i)?)?;
359351
let dest = this.project_index(&dest, i)?;
360352

361-
let res = bin_op_float::<F>(this, which, &left, &right)?;
353+
let res = bin_op_float::<F>(which, &left, &right)?;
362354
this.write_scalar(res, &dest)?;
363355
}
364356

@@ -367,11 +359,6 @@ fn bin_op_simd_float_all<'tcx, F: rustc_apfloat::Float>(
367359

368360
#[derive(Copy, Clone)]
369361
enum FloatUnaryOp {
370-
/// sqrt(x)
371-
///
372-
/// <https://www.felixcloutier.com/x86/sqrtss>
373-
/// <https://www.felixcloutier.com/x86/sqrtps>
374-
Sqrt,
375362
/// Approximation of 1/x
376363
///
377364
/// <https://www.felixcloutier.com/x86/rcpss>
@@ -392,11 +379,6 @@ fn unary_op_f32<'tcx>(
392379
op: &ImmTy<'tcx>,
393380
) -> InterpResult<'tcx, Scalar> {
394381
match which {
395-
FloatUnaryOp::Sqrt => {
396-
let op = op.to_scalar();
397-
// FIXME using host floats
398-
Ok(Scalar::from_u32(f32::from_bits(op.to_u32()?).sqrt().to_bits()))
399-
}
400382
FloatUnaryOp::Rcp => {
401383
let op = op.to_scalar().to_f32()?;
402384
let div = (Single::from_u128(1).value / op).value;

src/shims/x86/sse.rs

+5-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use rustc_apfloat::ieee::Single;
2-
use rustc_middle::mir;
32
use rustc_span::Symbol;
43
use rustc_target::spec::abi::Abi;
54

@@ -29,18 +28,14 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
2928
// performed only on the first element, copying the remaining elements from the input
3029
// vector (for binary operations, from the left-hand side).
3130
match unprefixed_name {
32-
// Used to implement _mm_{add,sub,mul,div,min,max}_ss functions.
31+
// Used to implement _mm_{min,max}_ss functions.
3332
// Performs the operations on the first component of `left` and
3433
// `right` and copies the remaining components from `left`.
35-
"add.ss" | "sub.ss" | "mul.ss" | "div.ss" | "min.ss" | "max.ss" => {
34+
"min.ss" | "max.ss" => {
3635
let [left, right] =
3736
this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
3837

3938
let which = match unprefixed_name {
40-
"add.ss" => FloatBinOp::Arith(mir::BinOp::Add),
41-
"sub.ss" => FloatBinOp::Arith(mir::BinOp::Sub),
42-
"mul.ss" => FloatBinOp::Arith(mir::BinOp::Mul),
43-
"div.ss" => FloatBinOp::Arith(mir::BinOp::Div),
4439
"min.ss" => FloatBinOp::Min,
4540
"max.ss" => FloatBinOp::Max,
4641
_ => unreachable!(),
@@ -65,14 +60,13 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
6560

6661
bin_op_simd_float_all::<Single>(this, which, left, right, dest)?;
6762
}
68-
// Used to implement _mm_{sqrt,rcp,rsqrt}_ss functions.
63+
// Used to implement _mm_{rcp,rsqrt}_ss functions.
6964
// Performs the operations on the first component of `op` and
7065
// copies the remaining components from `op`.
71-
"sqrt.ss" | "rcp.ss" | "rsqrt.ss" => {
66+
"rcp.ss" | "rsqrt.ss" => {
7267
let [op] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
7368

7469
let which = match unprefixed_name {
75-
"sqrt.ss" => FloatUnaryOp::Sqrt,
7670
"rcp.ss" => FloatUnaryOp::Rcp,
7771
"rsqrt.ss" => FloatUnaryOp::Rsqrt,
7872
_ => unreachable!(),
@@ -82,11 +76,10 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
8276
}
8377
// Used to implement _mm_{sqrt,rcp,rsqrt}_ps functions.
8478
// Performs the operations on all components of `op`.
85-
"sqrt.ps" | "rcp.ps" | "rsqrt.ps" => {
79+
"rcp.ps" | "rsqrt.ps" => {
8680
let [op] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
8781

8882
let which = match unprefixed_name {
89-
"sqrt.ps" => FloatUnaryOp::Sqrt,
9083
"rcp.ps" => FloatUnaryOp::Rcp,
9184
"rsqrt.ps" => FloatUnaryOp::Rsqrt,
9285
_ => unreachable!(),

src/shims/x86/sse2.rs

-40
Original file line numberDiff line numberDiff line change
@@ -227,46 +227,6 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
227227

228228
bin_op_simd_float_all::<Double>(this, which, left, right, dest)?;
229229
}
230-
// Used to implement _mm_sqrt_sd functions.
231-
// Performs the operations on the first component of `op` and
232-
// copies the remaining components from `op`.
233-
"sqrt.sd" => {
234-
let [op] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
235-
236-
let (op, op_len) = this.operand_to_simd(op)?;
237-
let (dest, dest_len) = this.mplace_to_simd(dest)?;
238-
239-
assert_eq!(dest_len, op_len);
240-
241-
let op0 = this.read_scalar(&this.project_index(&op, 0)?)?.to_u64()?;
242-
// FIXME using host floats
243-
let res0 = Scalar::from_u64(f64::from_bits(op0).sqrt().to_bits());
244-
this.write_scalar(res0, &this.project_index(&dest, 0)?)?;
245-
246-
for i in 1..dest_len {
247-
this.copy_op(&this.project_index(&op, i)?, &this.project_index(&dest, i)?)?;
248-
}
249-
}
250-
// Used to implement _mm_sqrt_pd functions.
251-
// Performs the operations on all components of `op`.
252-
"sqrt.pd" => {
253-
let [op] = this.check_shim(abi, Abi::C { unwind: false }, link_name, args)?;
254-
255-
let (op, op_len) = this.operand_to_simd(op)?;
256-
let (dest, dest_len) = this.mplace_to_simd(dest)?;
257-
258-
assert_eq!(dest_len, op_len);
259-
260-
for i in 0..dest_len {
261-
let op = this.read_scalar(&this.project_index(&op, i)?)?.to_u64()?;
262-
let dest = this.project_index(&dest, i)?;
263-
264-
// FIXME using host floats
265-
let res = Scalar::from_u64(f64::from_bits(op).sqrt().to_bits());
266-
267-
this.write_scalar(res, &dest)?;
268-
}
269-
}
270230
// Used to implement the _mm_cmp*_sd functions.
271231
// Performs a comparison operation on the first component of `left`
272232
// and `right`, returning 0 if false or `u64::MAX` if true. The remaining

tests/fail/intrinsics/intrinsic_target_feature.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ fn main() {
2424

2525
unsafe {
2626
// Pass, since SSE is enabled
27-
addss(_mm_setzero_ps(), _mm_setzero_ps());
27+
minss(_mm_setzero_ps(), _mm_setzero_ps());
2828

2929
// Fail, since SSE4.1 is not enabled
3030
dpps(_mm_setzero_ps(), _mm_setzero_ps(), 0);
@@ -34,8 +34,8 @@ fn main() {
3434

3535
#[allow(improper_ctypes)]
3636
extern "C" {
37-
#[link_name = "llvm.x86.sse.add.ss"]
38-
fn addss(a: __m128, b: __m128) -> __m128;
37+
#[link_name = "llvm.x86.sse.min.ss"]
38+
fn minss(a: __m128, b: __m128) -> __m128;
3939

4040
#[link_name = "llvm.x86.sse41.dpps"]
4141
fn dpps(a: __m128, b: __m128, imm8: u8) -> __m128;

0 commit comments

Comments
 (0)