Skip to content

Commit e48c92e

Browse files
authored
Merge pull request rust-lang#176 from rust-lang/feature/more-simd
Feature/more simd
2 parents e8dca3e + ee4755a commit e48c92e

File tree

5 files changed

+787
-326
lines changed

5 files changed

+787
-326
lines changed

Readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ To get the `rustc` command to run in `gdb`, add the `--verbose` flag to `cargo b
127127
* Build the stage2 compiler (`rustup toolchain link debug-current build/x86_64-unknown-linux-gnu/stage2`).
128128
* Clean and rebuild the codegen with `debug-current` in the file `rust-toolchain`.
129129

130+
### How to use [mem-trace](https://github.com/antoyo/mem-trace)
131+
132+
`rustc` needs to be built without `jemalloc` so that `mem-trace` can overload `malloc` since `jemalloc` is linked statically, so a `LD_PRELOAD`-ed library won't a chance to intercept the calls to `malloc`.
133+
130134
### How to build a cross-compiling libgccjit
131135

132136
#### Building libgccjit

src/base.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,17 @@ pub fn compile_codegen_unit<'tcx>(tcx: TyCtxt<'tcx>, cgu_name: Symbol, supports_
8181
// TODO(antoyo): only add the following cli argument if the feature is supported.
8282
context.add_command_line_option("-msse2");
8383
context.add_command_line_option("-mavx2");
84-
context.add_command_line_option("-msha");
85-
context.add_command_line_option("-mpclmul");
8684
// FIXME(antoyo): the following causes an illegal instruction on vmovdqu64 in std_example on my CPU.
8785
// Only add if the CPU supports it.
88-
//context.add_command_line_option("-mavx512f");
86+
/*context.add_command_line_option("-mavx512f");
87+
context.add_command_line_option("-msha");
88+
context.add_command_line_option("-mpclmul");
89+
context.add_command_line_option("-mfma");
90+
context.add_command_line_option("-mfma4");
91+
context.add_command_line_option("-mavx512vpopcntdq");
92+
context.add_command_line_option("-mavx512vl");
93+
context.add_command_line_option("-m64");
94+
context.add_command_line_option("-mbmi");*/
8995
for arg in &tcx.sess.opts.cg.llvm_args {
9096
context.add_command_line_option(arg);
9197
}

src/builder.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
213213

214214
let actual_ty = actual_val.get_type();
215215
if expected_ty != actual_ty {
216-
if !actual_ty.is_vector() && !expected_ty.is_vector() && actual_ty.is_integral() && expected_ty.is_integral() && actual_ty.get_size() != expected_ty.get_size() {
216+
if !actual_ty.is_vector() && !expected_ty.is_vector() && actual_ty.is_integral() && expected_ty.is_integral() {
217217
self.context.new_cast(None, actual_val, expected_ty)
218218
}
219219
else if on_stack_param_indices.contains(&index) {
@@ -275,21 +275,25 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
275275
}
276276

277277
fn function_ptr_call(&mut self, func_ptr: RValue<'gcc>, args: &[RValue<'gcc>], _funclet: Option<&Funclet>) -> RValue<'gcc> {
278-
let args = self.check_ptr_call("call", func_ptr, args);
278+
let gcc_func = func_ptr.get_type().dyncast_function_ptr_type().expect("function ptr");
279+
let func_name = format!("{:?}", func_ptr);
280+
let previous_arg_count = args.len();
281+
let args = llvm::adjust_intrinsic_arguments(&self, gcc_func, args.into(), &func_name);
282+
let args_adjusted = args.len() != previous_arg_count;
283+
let args = self.check_ptr_call("call", func_ptr, &*args);
279284

280285
// gccjit requires to use the result of functions, even when it's not used.
281286
// That's why we assign the result to a local or call add_eval().
282-
let gcc_func = func_ptr.get_type().dyncast_function_ptr_type().expect("function ptr");
283287
let return_type = gcc_func.get_return_type();
284288
let void_type = self.context.new_type::<()>();
285289
let current_func = self.block.get_function();
286290

287291
if return_type != void_type {
288292
unsafe { RETURN_VALUE_COUNT += 1 };
289-
let result = current_func.new_local(None, return_type, &format!("ptrReturnValue{}", unsafe { RETURN_VALUE_COUNT }));
290-
let func_name = format!("{:?}", func_ptr);
291-
let args = llvm::adjust_intrinsic_arguments(&self, gcc_func, args, &func_name);
292-
self.block.add_assignment(None, result, self.cx.context.new_call_through_ptr(None, func_ptr, &args));
293+
let return_value = self.cx.context.new_call_through_ptr(None, func_ptr, &args);
294+
let return_value = llvm::adjust_intrinsic_return_value(&self, return_value, &func_name, &args, args_adjusted);
295+
let result = current_func.new_local(None, return_value.get_type(), &format!("ptrReturnValue{}", unsafe { RETURN_VALUE_COUNT }));
296+
self.block.add_assignment(None, result, return_value);
293297
result.to_rvalue()
294298
}
295299
else {
@@ -1386,18 +1390,20 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
13861390
where F: Fn(RValue<'gcc>, RValue<'gcc>, &'gcc Context<'gcc>) -> RValue<'gcc>
13871391
{
13881392
let vector_type = src.get_type().unqualified().dyncast_vector().expect("vector type");
1393+
let element_type = vector_type.get_element_type();
1394+
let mask_element_type = self.type_ix(element_type.get_size() as u64 * 8);
13891395
let element_count = vector_type.get_num_units();
13901396
let mut vector_elements = vec![];
13911397
for i in 0..element_count {
13921398
vector_elements.push(i);
13931399
}
1394-
let mask_type = self.context.new_vector_type(self.int_type, element_count as u64);
1400+
let mask_type = self.context.new_vector_type(mask_element_type, element_count as u64);
13951401
let mut shift = 1;
13961402
let mut res = src;
13971403
while shift < element_count {
13981404
let vector_elements: Vec<_> =
13991405
vector_elements.iter()
1400-
.map(|i| self.context.new_rvalue_from_int(self.int_type, ((i + shift) % element_count) as i32))
1406+
.map(|i| self.context.new_rvalue_from_int(mask_element_type, ((i + shift) % element_count) as i32))
14011407
.collect();
14021408
let mask = self.context.new_rvalue_from_vector(None, mask_type, &vector_elements);
14031409
let shifted = self.context.new_rvalue_vector_perm(None, res, res, mask);
@@ -1409,7 +1415,7 @@ impl<'a, 'gcc, 'tcx> Builder<'a, 'gcc, 'tcx> {
14091415
}
14101416

14111417
#[cfg(not(feature="master"))]
1412-
pub fn vector_reduce<F>(&mut self, src: RValue<'gcc>, op: F) -> RValue<'gcc>
1418+
pub fn vector_reduce<F>(&mut self, _src: RValue<'gcc>, _op: F) -> RValue<'gcc>
14131419
where F: Fn(RValue<'gcc>, RValue<'gcc>, &'gcc Context<'gcc>) -> RValue<'gcc>
14141420
{
14151421
unimplemented!();

0 commit comments

Comments
 (0)