From f9fd6a23e5c3a39f54b9afd29e6e3f59dfbd5965 Mon Sep 17 00:00:00 2001 From: Nicholas Thompson Date: Mon, 29 Jan 2024 14:51:58 -0500 Subject: [PATCH] Implement prefetch data intrinsics --- src/context.rs | 2 +- src/intrinsic/mod.rs | 20 +++++++++++++++++--- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/context.rs b/src/context.rs index a043660ea63..728a5e9c070 100644 --- a/src/context.rs +++ b/src/context.rs @@ -209,7 +209,7 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> { "__builtin_usub_overflow", "sqrtf", "sqrt", "__builtin_powif", "__builtin_powi", "sinf", "sin", "cosf", "cos", "powf", "pow", "expf", "exp", "exp2f", "exp2", "logf", "log", "log10f", "log10", "log2f", "log2", "fmaf", "fma", "fabsf", "fabs", "fminf", "fmin", "fmaxf", "fmax", "copysignf", "copysign", "floorf", "floor", "ceilf", - "ceil", "truncf", "trunc", "rintf", "rint", "nearbyintf", "nearbyint", "roundf", "round", + "ceil", "truncf", "trunc", "rintf", "rint", "nearbyintf", "nearbyint", "roundf", "round", "__builtin_prefetch", "__builtin_expect_with_probability", ]; diff --git a/src/intrinsic/mod.rs b/src/intrinsic/mod.rs index ba1cae03f3e..cf30b4ff9e6 100644 --- a/src/intrinsic/mod.rs +++ b/src/intrinsic/mod.rs @@ -168,10 +168,24 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> { return; } sym::prefetch_read_data - | sym::prefetch_write_data - | sym::prefetch_read_instruction + | sym::prefetch_write_data => { + let a = args[0].immediate(); + let void_ptr_type = self.context.new_type::<*const ()>(); + let a_ptr = self.bitcast(a, void_ptr_type); + + let b = match name { + sym::prefetch_read_data => self.const_i32(0), + sym::prefetch_write_data => self.const_i32(1), + _ => bug!(), + }; + + let builtin = self.context.get_builtin_function("__builtin_prefetch"); + self.context.new_call(None, builtin, &[a_ptr, b]); + return; + } + sym::prefetch_read_instruction | sym::prefetch_write_instruction => { - unimplemented!(); + return; } sym::ctlz | sym::ctlz_nonzero