diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-08-07 05:29:12 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-08-07 05:29:12 +0200 |
| commit | cbe25226525ac010295c666c05fef7a81e99984c (patch) | |
| tree | 6688fd8ce90bf73370c71d077d76e32d502766ec /compiler/rustc_codegen_gcc | |
| parent | f5df519fe7da5fc62656e9a4c46ed7f6b9742def (diff) | |
| parent | 75277a6606e8c7443ccd3fd1a2562c166fed7298 (diff) | |
| download | rust-cbe25226525ac010295c666c05fef7a81e99984c.tar.gz rust-cbe25226525ac010295c666c05fef7a81e99984c.zip | |
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`
Diffstat (limited to 'compiler/rustc_codegen_gcc')
| -rw-r--r-- | compiler/rustc_codegen_gcc/src/intrinsic/mod.rs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs b/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs index 68edde13829..f8c32c6dbbb 100644 --- a/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs +++ b/compiler/rustc_codegen_gcc/src/intrinsic/mod.rs @@ -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); |
