Skip to content

Commit c803ee4

Browse files
committed
refactor
1 parent 3b28ad6 commit c803ee4

File tree

2 files changed

+30
-61
lines changed

2 files changed

+30
-61
lines changed

src/librustc_codegen_llvm/intrinsic.rs

+30-60
Original file line numberDiff line numberDiff line change
@@ -1260,6 +1260,36 @@ fn generic_simd_intrinsic<'a, 'tcx>(
12601260
return simd_simple_float_intrinsic("fma", in_elem, in_ty, in_len, bx, span, args);
12611261
}
12621262

1263+
// FIXME: use:
1264+
// https://github.com/llvm-mirror/llvm/blob/master/include/llvm/IR/Function.h#L182
1265+
// https://github.com/llvm-mirror/llvm/blob/master/include/llvm/IR/Intrinsics.h#L81
1266+
fn llvm_vector_str(elem_ty: ty::Ty, vec_len: usize, no_pointers: usize) -> String {
1267+
let p0s: String = "p0".repeat(no_pointers);
1268+
match elem_ty.sty {
1269+
ty::TyInt(v) => format!("v{}{}i{}", vec_len, p0s, v.bit_width().unwrap()),
1270+
ty::TyUint(v) => format!("v{}{}i{}", vec_len, p0s, v.bit_width().unwrap()),
1271+
ty::TyFloat(v) => format!("v{}{}f{}", vec_len, p0s, v.bit_width()),
1272+
_ => unreachable!(),
1273+
}
1274+
}
1275+
1276+
fn llvm_vector_ty(cx: &CodegenCx, elem_ty: ty::Ty, vec_len: usize,
1277+
mut no_pointers: usize) -> Type {
1278+
// FIXME: use cx.layout_of(ty).llvm_type() ?
1279+
let mut elem_ty = match elem_ty.sty {
1280+
ty::TyInt(v) => Type::int_from_ty(cx, v),
1281+
ty::TyUint(v) => Type::uint_from_ty(cx, v),
1282+
ty::TyFloat(v) => Type::float_from_ty(cx, v),
1283+
_ => unreachable!(),
1284+
};
1285+
while no_pointers > 0 {
1286+
elem_ty = elem_ty.ptr_to();
1287+
no_pointers -= 1;
1288+
}
1289+
Type::vector(&elem_ty, vec_len as u64)
1290+
}
1291+
1292+
12631293
if name == "simd_gather" {
12641294
// simd_gather(values: <N x T>, pointers: <N x *_ T>,
12651295
// mask: <N x i{M}>) -> <N x T>
@@ -1343,36 +1373,6 @@ fn generic_simd_intrinsic<'a, 'tcx>(
13431373
(bx.trunc(args[2].immediate(), i1xn), i1xn)
13441374
};
13451375

1346-
// FIXME: use:
1347-
// https://github.com/llvm-mirror/llvm/blob/master/include/llvm/IR/Function.h#L182
1348-
// https://github.com/llvm-mirror/llvm/blob/master/include/llvm/IR/Intrinsics.h#L81
1349-
fn llvm_vector_str(elem_ty: ty::Ty, vec_len: usize, no_pointers: usize) -> String {
1350-
let p0s: String = "p0".repeat(no_pointers);
1351-
match elem_ty.sty {
1352-
ty::TyInt(v) => format!("v{}{}i{}", vec_len, p0s, v.bit_width().unwrap()),
1353-
ty::TyUint(v) => format!("v{}{}i{}", vec_len, p0s, v.bit_width().unwrap()),
1354-
ty::TyFloat(v) => format!("v{}{}f{}", vec_len, p0s, v.bit_width()),
1355-
_ => unreachable!(),
1356-
}
1357-
}
1358-
1359-
fn llvm_vector_ty(cx: &CodegenCx, elem_ty: ty::Ty, vec_len: usize,
1360-
mut no_pointers: usize) -> Type {
1361-
// FIXME: use cx.layout_of(ty).llvm_type() ?
1362-
let mut elem_ty = match elem_ty.sty {
1363-
ty::TyInt(v) => Type::int_from_ty(cx, v),
1364-
ty::TyUint(v) => Type::uint_from_ty(cx, v),
1365-
ty::TyFloat(v) => Type::float_from_ty(cx, v),
1366-
_ => unreachable!(),
1367-
};
1368-
while no_pointers > 0 {
1369-
elem_ty = elem_ty.ptr_to();
1370-
no_pointers -= 1;
1371-
}
1372-
Type::vector(&elem_ty, vec_len as u64)
1373-
}
1374-
1375-
13761376
// Type of the vector of pointers:
13771377
let llvm_pointer_vec_ty = llvm_vector_ty(bx.cx, underlying_ty, in_len, pointer_count);
13781378
let llvm_pointer_vec_str = llvm_vector_str(underlying_ty, in_len, pointer_count);
@@ -1472,36 +1472,6 @@ fn generic_simd_intrinsic<'a, 'tcx>(
14721472

14731473
let ret_t = Type::void(bx.cx);
14741474

1475-
// FIXME: use:
1476-
// https://github.com/llvm-mirror/llvm/blob/master/include/llvm/IR/Function.h#L182
1477-
// https://github.com/llvm-mirror/llvm/blob/master/include/llvm/IR/Intrinsics.h#L81
1478-
fn llvm_vector_str(elem_ty: ty::Ty, vec_len: usize, no_pointers: usize) -> String {
1479-
let p0s: String = "p0".repeat(no_pointers);
1480-
match elem_ty.sty {
1481-
ty::TyInt(v) => format!("v{}{}i{}", vec_len, p0s, v.bit_width().unwrap()),
1482-
ty::TyUint(v) => format!("v{}{}i{}", vec_len, p0s, v.bit_width().unwrap()),
1483-
ty::TyFloat(v) => format!("v{}{}f{}", vec_len, p0s, v.bit_width()),
1484-
_ => unreachable!(),
1485-
}
1486-
}
1487-
1488-
fn llvm_vector_ty(cx: &CodegenCx, elem_ty: ty::Ty, vec_len: usize,
1489-
mut no_pointers: usize) -> Type {
1490-
// FIXME: use cx.layout_of(ty).llvm_type() ?
1491-
let mut elem_ty = match elem_ty.sty {
1492-
ty::TyInt(v) => Type::int_from_ty(cx, v),
1493-
ty::TyUint(v) => Type::uint_from_ty(cx, v),
1494-
ty::TyFloat(v) => Type::float_from_ty(cx, v),
1495-
_ => unreachable!(),
1496-
};
1497-
while no_pointers > 0 {
1498-
elem_ty = elem_ty.ptr_to();
1499-
no_pointers -= 1;
1500-
}
1501-
Type::vector(&elem_ty, vec_len as u64)
1502-
}
1503-
1504-
15051475
// Type of the vector of pointers:
15061476
let llvm_pointer_vec_ty = llvm_vector_ty(bx.cx, underlying_ty, in_len, pointer_count);
15071477
let llvm_pointer_vec_str = llvm_vector_str(underlying_ty, in_len, pointer_count);

src/test/run-pass/simd-intrinsic-float-math.rs

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
// ignore-emscripten
12-
// error-pattern: panicked
1312

1413
// Test that the simd floating-point math intrinsics produce correct results.
1514

0 commit comments

Comments
 (0)