Rollup merge of #114382 - scottmcm:compare-bytes-intrinsic, r=cjgillot
Add a new `compare_bytes` intrinsic instead of calling `memcmp` directly As discussed in #113435, this lets the backends be the place that can have the "don't call the function if n == 0" logic, if it's needed for the target. (I didn't actually *add* those checks, though, since as I understood it we didn't actually need them on known targets?) Doing this also let me make it `const` (unstable), which I don't think `extern "C" fn memcmp` can be. cc `@RalfJung` `@Amanieu`
This commit is contained in:
commit
8a160d6fcd
@ -302,6 +302,21 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
sym::compare_bytes => {
|
||||
let a = args[0].immediate();
|
||||
let b = args[1].immediate();
|
||||
let n = args[2].immediate();
|
||||
|
||||
let void_ptr_type = self.context.new_type::<*const ()>();
|
||||
let a_ptr = self.bitcast(a, void_ptr_type);
|
||||
let b_ptr = self.bitcast(b, void_ptr_type);
|
||||
|
||||
// Here we assume that the `memcmp` provided by the target is a NOP for size 0.
|
||||
let builtin = self.context.get_builtin_function("memcmp");
|
||||
let cmp = self.context.new_call(None, builtin, &[a_ptr, b_ptr, n]);
|
||||
self.sext(cmp, self.type_ix(32))
|
||||
}
|
||||
|
||||
sym::black_box => {
|
||||
args[0].val.store(self, result);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user