MCPcopy Create free account
hub / github.com/Rust-GPU/rust-cuda / checked_binop

Method checked_binop

crates/rustc_codegen_nvvm/src/builder.rs:355–431  ·  view source on GitHub ↗
(
        &mut self,
        oop: OverflowOp,
        ty: Ty<'_>,
        lhs: Self::Value,
        rhs: Self::Value,
    )

Source from the content-addressed store, hash-verified

353 }
354
355 fn checked_binop(
356 &mut self,
357 oop: OverflowOp,
358 ty: Ty<'_>,
359 lhs: Self::Value,
360 rhs: Self::Value,
361 ) -> (Self::Value, Self::Value) {
362 trace!(
363 "Checked binop `{:?}`, lhs: `{:?}`, rhs: `{:?}`",
364 ty,
365 lhs,
366 rhs
367 );
368 use rustc_middle::ty::IntTy::*;
369 use rustc_middle::ty::UintTy::*;
370 use rustc_middle::ty::{Int, Uint};
371
372 let new_kind = match ty.kind() {
373 Int(t @ Isize) => Int(t.normalize(self.tcx.sess.target.pointer_width)),
374 Uint(t @ Usize) => Uint(t.normalize(self.tcx.sess.target.pointer_width)),
375 t @ (Uint(_) | Int(_)) => t.clone(),
376 _ => panic!("tried to get overflow intrinsic for op applied to non-int type"),
377 };
378
379 let name = match oop {
380 OverflowOp::Add => match new_kind {
381 Int(I8) => "__nvvm_i8_addo",
382 Int(I16) => "llvm.sadd.with.overflow.i16",
383 Int(I32) => "llvm.sadd.with.overflow.i32",
384 Int(I64) => "llvm.sadd.with.overflow.i64",
385 Int(I128) => "__nvvm_i128_addo",
386
387 Uint(U8) => "__nvvm_u8_addo",
388 Uint(U16) => "llvm.uadd.with.overflow.i16",
389 Uint(U32) => "llvm.uadd.with.overflow.i32",
390 Uint(U64) => "llvm.uadd.with.overflow.i64",
391 Uint(U128) => "__nvvm_u128_addo",
392 _ => unreachable!(),
393 },
394 OverflowOp::Sub => match new_kind {
395 Int(I8) => "__nvvm_i8_subo",
396 Int(I16) => "llvm.ssub.with.overflow.i16",
397 Int(I32) => "llvm.ssub.with.overflow.i32",
398 Int(I64) => "llvm.ssub.with.overflow.i64",
399 Int(I128) => "__nvvm_i128_subo",
400
401 Uint(U8) => "__nvvm_u8_subo",
402 Uint(U16) => "llvm.usub.with.overflow.i16",
403 Uint(U32) => "llvm.usub.with.overflow.i32",
404 Uint(U64) => "llvm.usub.with.overflow.i64",
405 Uint(U128) => "__nvvm_u128_subo",
406
407 _ => unreachable!(),
408 },
409 OverflowOp::Mul => match new_kind {
410 Int(I8) => "__nvvm_i8_mulo",
411 Int(I16) => "llvm.smul.with.overflow.i16",
412 Int(I32) => "llvm.smul.with.overflow.i32",

Callers 1

Calls 5

get_intrinsicMethod · 0.80
callMethod · 0.80
type_i1Method · 0.80
extract_valueMethod · 0.80
cloneMethod · 0.45

Tested by

no test coverage detected