Skip to content

Commit 4ad128b

Browse files
committed
Auto merge of #28136 - huonw:simd, r=alexcrichton
I believe everything that doesn't take a constant integer up to SSE4.2 should now be correct (I don't have any reason to believe that those that do take constant integers are wrong; they're just more complicated and I just haven't tested them in detail). (Also, takes out two unused code paths from trans.)
2 parents 4da6c7e + 787a21f commit 4ad128b

File tree

6 files changed

+35
-64
lines changed

6 files changed

+35
-64
lines changed

src/etc/platform-intrinsics/x86/sse2.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
"intrinsic": "_madd_epi16",
2020
"width": [128],
2121
"llvm": "pmadd.wd",
22-
"ret": "s16",
23-
"args": ["0", "0"]
22+
"ret": "s32",
23+
"args": ["s16", "s16"]
2424
},
2525
{
2626
"intrinsic": "_max_{0.data_type}",
@@ -68,11 +68,11 @@
6868
"intrinsic": "_mul_epu32",
6969
"width": [128],
7070
"llvm": "pmulu.dq",
71-
"ret": "s64",
71+
"ret": "u64",
7272
"args": ["0dn", "0dn"]
7373
},
7474
{
75-
"intrinsic": "_mulhi_ep{0.kind}16",
75+
"intrinsic": "_mulhi_{0.data_type}",
7676
"width": [128],
7777
"llvm": "pmulh{0.kind_short}.w",
7878
"ret": "i16",

src/etc/platform-intrinsics/x86/sse41.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
{
4040
"intrinsic": "_mul_epi32",
4141
"width": [128],
42-
"llvm": "muldq",
42+
"llvm": "pmuldq",
4343
"ret": "s64",
4444
"args": ["s32", "s32"]
4545
},
@@ -58,9 +58,9 @@
5858
"args": ["u64", "u64"]
5959
},
6060
{
61-
"intrinsic": "_testncz_si128",
61+
"intrinsic": "_testnzc_si128",
6262
"width": [128],
63-
"llvm": "ptest.nzc",
63+
"llvm": "ptestnzc",
6464
"ret": "S32",
6565
"args": ["u64", "u64"]
6666
},

src/etc/platform-intrinsics/x86/ssse3.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
{
55
"intrinsic": "_abs_{0.data_type}",
66
"width": [128],
7-
"llvm": "pabs.{0.data_type_short}",
7+
"llvm": "pabs.{0.data_type_short}.128",
88
"ret": "s(8-32)",
99
"args": ["0"]
1010
},
@@ -41,7 +41,7 @@
4141
"width": [128],
4242
"llvm": "pmadd.ub.sw.128",
4343
"ret": "s16",
44-
"args": ["s8", "s8"]
44+
"args": ["u8", "s8"]
4545
},
4646
{
4747
"intrinsic": "_mulhrs_epi16",
@@ -61,7 +61,7 @@
6161
"intrinsic": "_sign_{0.data_type}",
6262
"width": [128],
6363
"llvm": "psign.{0.data_type_short}.128",
64-
"ret": "s(8-16)",
64+
"ret": "s(8-32)",
6565
"args": ["0", "0"]
6666
}
6767
]

src/librustc_platform_intrinsics/x86.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub fn find<'tcx>(_tcx: &ty::ctxt<'tcx>, name: &str) -> Option<Intrinsic> {
8282
},
8383
"_madd_epi16" => Intrinsic {
8484
inputs: vec![v(i(16), 8), v(i(16), 8)],
85-
output: v(i(16), 8),
85+
output: v(i(32), 4),
8686
definition: Named("llvm.x86.sse2.pmadd.wd")
8787
},
8888
"_max_epi16" => Intrinsic {
@@ -126,11 +126,11 @@ pub fn find<'tcx>(_tcx: &ty::ctxt<'tcx>, name: &str) -> Option<Intrinsic> {
126126
definition: Named("llvm.x86.sse2.pmovmskb.128")
127127
},
128128
"_mul_epu32" => Intrinsic {
129-
inputs: vec![v(i(32), 4), v(i(32), 4)],
130-
output: v(i(64), 2),
129+
inputs: vec![v(u(32), 4), v(u(32), 4)],
130+
output: v(u(64), 2),
131131
definition: Named("llvm.x86.sse2.pmulu.dq")
132132
},
133-
"_mulhi_eps16" => Intrinsic {
133+
"_mulhi_epi16" => Intrinsic {
134134
inputs: vec![v(i(16), 8), v(i(16), 8)],
135135
output: v(i(16), 8),
136136
definition: Named("llvm.x86.sse2.pmulh.w")
@@ -218,17 +218,17 @@ pub fn find<'tcx>(_tcx: &ty::ctxt<'tcx>, name: &str) -> Option<Intrinsic> {
218218
"_abs_epi8" => Intrinsic {
219219
inputs: vec![v(i(8), 16)],
220220
output: v(i(8), 16),
221-
definition: Named("llvm.x86.ssse3.pabs.b")
221+
definition: Named("llvm.x86.ssse3.pabs.b.128")
222222
},
223223
"_abs_epi16" => Intrinsic {
224224
inputs: vec![v(i(16), 8)],
225225
output: v(i(16), 8),
226-
definition: Named("llvm.x86.ssse3.pabs.w")
226+
definition: Named("llvm.x86.ssse3.pabs.w.128")
227227
},
228228
"_abs_epi32" => Intrinsic {
229229
inputs: vec![v(i(32), 4)],
230230
output: v(i(32), 4),
231-
definition: Named("llvm.x86.ssse3.pabs.d")
231+
definition: Named("llvm.x86.ssse3.pabs.d.128")
232232
},
233233
"_hadd_epi16" => Intrinsic {
234234
inputs: vec![v(i(16), 8), v(i(16), 8)],
@@ -261,7 +261,7 @@ pub fn find<'tcx>(_tcx: &ty::ctxt<'tcx>, name: &str) -> Option<Intrinsic> {
261261
definition: Named("llvm.x86.ssse3.phsub.sw.128")
262262
},
263263
"_maddubs_epi16" => Intrinsic {
264-
inputs: vec![v(i(8), 16), v(i(8), 16)],
264+
inputs: vec![v(u(8), 16), v(i(8), 16)],
265265
output: v(i(16), 8),
266266
definition: Named("llvm.x86.ssse3.pmadd.ub.sw.128")
267267
},
@@ -285,6 +285,11 @@ pub fn find<'tcx>(_tcx: &ty::ctxt<'tcx>, name: &str) -> Option<Intrinsic> {
285285
output: v(i(16), 8),
286286
definition: Named("llvm.x86.ssse3.psign.w.128")
287287
},
288+
"_sign_epi32" => Intrinsic {
289+
inputs: vec![v(i(32), 4), v(i(32), 4)],
290+
output: v(i(32), 4),
291+
definition: Named("llvm.x86.ssse3.psign.d.128")
292+
},
288293
"_dp_ps" => Intrinsic {
289294
inputs: vec![v(f(32), 4), v(f(32), 4), i_(32, 8)],
290295
output: v(f(32), 4),
@@ -348,7 +353,7 @@ pub fn find<'tcx>(_tcx: &ty::ctxt<'tcx>, name: &str) -> Option<Intrinsic> {
348353
"_mul_epi32" => Intrinsic {
349354
inputs: vec![v(i(32), 4), v(i(32), 4)],
350355
output: v(i(64), 2),
351-
definition: Named("llvm.x86.sse41.muldq")
356+
definition: Named("llvm.x86.sse41.pmuldq")
352357
},
353358
"_packus_epi32" => Intrinsic {
354359
inputs: vec![v(i(32), 4), v(i(32), 4)],
@@ -360,10 +365,10 @@ pub fn find<'tcx>(_tcx: &ty::ctxt<'tcx>, name: &str) -> Option<Intrinsic> {
360365
output: i(32),
361366
definition: Named("llvm.x86.sse41.ptestc")
362367
},
363-
"_testncz_si128" => Intrinsic {
368+
"_testnzc_si128" => Intrinsic {
364369
inputs: vec![v(u(64), 2), v(u(64), 2)],
365370
output: i(32),
366-
definition: Named("llvm.x86.sse41.ptest.nzc")
371+
definition: Named("llvm.x86.sse41.ptestnzc")
367372
},
368373
"_testz_si128" => Intrinsic {
369374
inputs: vec![v(u(64), 2), v(u(64), 2)],

src/librustc_trans/trans/consts.rs

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -501,14 +501,9 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
501501
debug!("const_expr_unadjusted: te1={}, ty={:?}",
502502
cx.tn().val_to_string(te1),
503503
ty);
504-
let is_simd = ty.is_simd();
505-
let intype = if is_simd {
506-
ty.simd_type(cx.tcx())
507-
} else {
508-
ty
509-
};
510-
let is_float = intype.is_fp();
511-
let signed = intype.is_signed();
504+
assert!(!ty.is_simd());
505+
let is_float = ty.is_fp();
506+
let signed = ty.is_signed();
512507

513508
let (te2, _) = const_expr(cx, &**e2, param_substs, fn_args);
514509

@@ -552,14 +547,7 @@ fn const_expr_unadjusted<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
552547
ConstFCmp(cmp, te1, te2)
553548
} else {
554549
let cmp = base::bin_op_to_icmp_predicate(cx, b.node, signed);
555-
let bool_val = ConstICmp(cmp, te1, te2);
556-
if is_simd {
557-
// LLVM outputs an `< size x i1 >`, so we need to perform
558-
// a sign extension to get the correctly sized type.
559-
llvm::LLVMConstIntCast(bool_val, val_ty(te1).to_ref(), True)
560-
} else {
561-
bool_val
562-
}
550+
ConstICmp(cmp, te1, te2)
563551
}
564552
},
565553
} } // unsafe { match b.node {

src/librustc_trans/trans/expr.rs

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,14 +1693,9 @@ fn trans_eager_binop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
16931693
let _icx = push_ctxt("trans_eager_binop");
16941694

16951695
let tcx = bcx.tcx();
1696-
let is_simd = lhs_t.is_simd();
1697-
let intype = if is_simd {
1698-
lhs_t.simd_type(tcx)
1699-
} else {
1700-
lhs_t
1701-
};
1702-
let is_float = intype.is_fp();
1703-
let is_signed = intype.is_signed();
1696+
assert!(!lhs_t.is_simd());
1697+
let is_float = lhs_t.is_fp();
1698+
let is_signed = lhs_t.is_signed();
17041699
let info = expr_info(binop_expr);
17051700

17061701
let binop_debug_loc = binop_expr.debug_loc();
@@ -1710,8 +1705,6 @@ fn trans_eager_binop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
17101705
ast::BiAdd => {
17111706
if is_float {
17121707
FAdd(bcx, lhs, rhs, binop_debug_loc)
1713-
} else if is_simd {
1714-
Add(bcx, lhs, rhs, binop_debug_loc)
17151708
} else {
17161709
let (newbcx, res) = with_overflow_check(
17171710
bcx, OverflowOp::Add, info, lhs_t, lhs, rhs, binop_debug_loc);
@@ -1722,8 +1715,6 @@ fn trans_eager_binop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
17221715
ast::BiSub => {
17231716
if is_float {
17241717
FSub(bcx, lhs, rhs, binop_debug_loc)
1725-
} else if is_simd {
1726-
Sub(bcx, lhs, rhs, binop_debug_loc)
17271718
} else {
17281719
let (newbcx, res) = with_overflow_check(
17291720
bcx, OverflowOp::Sub, info, lhs_t, lhs, rhs, binop_debug_loc);
@@ -1734,8 +1725,6 @@ fn trans_eager_binop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
17341725
ast::BiMul => {
17351726
if is_float {
17361727
FMul(bcx, lhs, rhs, binop_debug_loc)
1737-
} else if is_simd {
1738-
Mul(bcx, lhs, rhs, binop_debug_loc)
17391728
} else {
17401729
let (newbcx, res) = with_overflow_check(
17411730
bcx, OverflowOp::Mul, info, lhs_t, lhs, rhs, binop_debug_loc);
@@ -1828,11 +1817,7 @@ fn trans_eager_binop<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
18281817
res
18291818
}
18301819
ast::BiEq | ast::BiNe | ast::BiLt | ast::BiGe | ast::BiLe | ast::BiGt => {
1831-
if is_simd {
1832-
base::compare_simd_types(bcx, lhs, rhs, intype, val_ty(lhs), op.node, binop_debug_loc)
1833-
} else {
1834-
base::compare_scalar_types(bcx, lhs, rhs, intype, op.node, binop_debug_loc)
1835-
}
1820+
base::compare_scalar_types(bcx, lhs, rhs, lhs_t, op.node, binop_debug_loc)
18361821
}
18371822
_ => {
18381823
bcx.tcx().sess.span_bug(binop_expr.span, "unexpected binop");
@@ -2533,14 +2518,7 @@ fn build_unchecked_rshift<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
25332518
let rhs = base::cast_shift_expr_rhs(bcx, ast::BinOp_::BiShr, lhs, rhs);
25342519
// #1877, #10183: Ensure that input is always valid
25352520
let rhs = shift_mask_rhs(bcx, rhs, binop_debug_loc);
2536-
let tcx = bcx.tcx();
2537-
let is_simd = lhs_t.is_simd();
2538-
let intype = if is_simd {
2539-
lhs_t.simd_type(tcx)
2540-
} else {
2541-
lhs_t
2542-
};
2543-
let is_signed = intype.is_signed();
2521+
let is_signed = lhs_t.is_signed();
25442522
if is_signed {
25452523
AShr(bcx, lhs, rhs, binop_debug_loc)
25462524
} else {

0 commit comments

Comments
 (0)