]> git.lizzy.rs Git - rust.git/blob - src/intrinsics.rs
Fix type in load_scalar
[rust.git] / src / intrinsics.rs
1 use crate::prelude::*;
2
3 use rustc::ty::subst::SubstsRef;
4
5 macro_rules! intrinsic_pat {
6     (_) => {
7         _
8     };
9     ($name:ident) => {
10         stringify!($name)
11     }
12 }
13
14 macro_rules! intrinsic_arg {
15     (c $fx:expr, $arg:ident) => {
16         $arg
17     };
18     (v $fx:expr, $arg:ident) => {
19         $arg.load_scalar($fx)
20     };
21 }
22
23 macro_rules! intrinsic_substs {
24     ($substs:expr, $index:expr,) => {};
25     ($substs:expr, $index:expr, $first:ident $(,$rest:ident)*) => {
26         let $first = $substs.type_at($index);
27         intrinsic_substs!($substs, $index+1, $($rest),*);
28     };
29 }
30
31 macro_rules! intrinsic_match {
32     ($fx:expr, $intrinsic:expr, $substs:expr, $args:expr, $(
33         $($name:tt)|+ $(if $cond:expr)?, $(<$($subst:ident),*>)? ($($a:ident $arg:ident),*) $content:block;
34     )*) => {
35         match $intrinsic {
36             $(
37                 $(intrinsic_pat!($name))|* $(if $cond)? => {
38                     #[allow(unused_parens, non_snake_case)]
39                     {
40                         $(
41                             intrinsic_substs!($substs, 0, $($subst),*);
42                         )?
43                         if let [$($arg),*] = *$args {
44                             let ($($arg),*) = (
45                                 $(intrinsic_arg!($a $fx, $arg)),*
46                             );
47                             #[warn(unused_parens, non_snake_case)]
48                             {
49                                 $content
50                             }
51                         } else {
52                             bug!("wrong number of args for intrinsic {:?}", $intrinsic);
53                         }
54                     }
55                 }
56             )*
57             _ => unimpl!("unsupported intrinsic {}", $intrinsic),
58         }
59     };
60 }
61
62 macro_rules! atomic_binop_return_old {
63     ($fx:expr, $op:ident<$T:ident>($ptr:ident, $src:ident) -> $ret:ident) => {
64         let clif_ty = $fx.clif_type($T).unwrap();
65         let old = $fx.bcx.ins().load(clif_ty, MemFlags::new(), $ptr, 0);
66         let new = $fx.bcx.ins().$op(old, $src);
67         $fx.bcx.ins().store(MemFlags::new(), new, $ptr, 0);
68         $ret.write_cvalue($fx, CValue::by_val(old, $fx.layout_of($T)));
69     };
70 }
71
72 macro_rules! atomic_minmax {
73     ($fx:expr, $cc:expr, <$T:ident> ($ptr:ident, $src:ident) -> $ret:ident) => {
74         // Read old
75         let clif_ty = $fx.clif_type($T).unwrap();
76         let old = $fx.bcx.ins().load(clif_ty, MemFlags::new(), $ptr, 0);
77
78         // Compare
79         let is_eq = $fx.bcx.ins().icmp(IntCC::SignedGreaterThan, old, $src);
80         let new = crate::common::codegen_select(&mut $fx.bcx, is_eq, old, $src);
81
82         // Write new
83         $fx.bcx.ins().store(MemFlags::new(), new, $ptr, 0);
84
85         let ret_val = CValue::by_val(old, $ret.layout());
86         $ret.write_cvalue($fx, ret_val);
87     };
88 }
89
90 pub fn codegen_intrinsic_call<'a, 'tcx: 'a>(
91     fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
92     def_id: DefId,
93     substs: SubstsRef<'tcx>,
94     args: Vec<CValue<'tcx>>,
95     destination: Option<(CPlace<'tcx>, BasicBlock)>,
96 ) {
97     let intrinsic = fx.tcx.item_name(def_id).as_str();
98     let intrinsic = &intrinsic[..];
99
100     let ret = match destination {
101         Some((place, _)) => place,
102         None => {
103             // Insert non returning intrinsics here
104             match intrinsic {
105                 "abort" => {
106                     trap_panic(fx, "Called intrinsic::abort.");
107                 }
108                 "unreachable" => {
109                     trap_unreachable(fx, "[corruption] Called intrinsic::unreachable.");
110                 }
111                 _ => unimplemented!("unsupported instrinsic {}", intrinsic),
112             }
113             return;
114         }
115     };
116
117     let u64_layout = fx.layout_of(fx.tcx.types.u64);
118     let usize_layout = fx.layout_of(fx.tcx.types.usize);
119
120     intrinsic_match! {
121         fx, intrinsic, substs, args,
122
123         assume, (c _a) {};
124         likely | unlikely, (c a) {
125             ret.write_cvalue(fx, a);
126         };
127         breakpoint, () {
128             fx.bcx.ins().debugtrap();
129         };
130         copy | copy_nonoverlapping, <elem_ty> (v src, v dst, v count) {
131             let elem_size: u64 = fx.layout_of(elem_ty).size.bytes();
132             let elem_size = fx
133                 .bcx
134                 .ins()
135                 .iconst(fx.pointer_type, elem_size as i64);
136             assert_eq!(args.len(), 3);
137             let byte_amount = fx.bcx.ins().imul(count, elem_size);
138
139             if intrinsic.ends_with("_nonoverlapping") {
140                 fx.bcx.call_memcpy(fx.module.target_config(), dst, src, byte_amount);
141             } else {
142                 fx.bcx.call_memmove(fx.module.target_config(), dst, src, byte_amount);
143             }
144         };
145         discriminant_value, (c val) {
146             let pointee_layout = fx.layout_of(val.layout().ty.builtin_deref(true).unwrap().ty);
147             let place = CPlace::for_addr(val.load_scalar(fx), pointee_layout);
148             let discr = crate::base::trans_get_discriminant(fx, place, ret.layout());
149             ret.write_cvalue(fx, discr);
150         };
151         size_of, <T> () {
152             let size_of = fx.layout_of(T).size.bytes();
153             let size_of = CValue::const_val(fx, usize_layout.ty, size_of as i64);
154             ret.write_cvalue(fx, size_of);
155         };
156         size_of_val, <T> (c ptr) {
157             let layout = fx.layout_of(T);
158             let size = if layout.is_unsized() {
159                 let (_ptr, info) = ptr.load_scalar_pair(fx);
160                 let (size, _align) = crate::unsize::size_and_align_of_dst(fx, layout.ty, info);
161                 size
162             } else {
163                 fx
164                     .bcx
165                     .ins()
166                     .iconst(fx.pointer_type, layout.size.bytes() as i64)
167             };
168             ret.write_cvalue(fx, CValue::by_val(size, usize_layout));
169         };
170         min_align_of, <T> () {
171             let min_align = fx.layout_of(T).align.abi.bytes();
172             let min_align = CValue::const_val(fx, usize_layout.ty, min_align as i64);
173             ret.write_cvalue(fx, min_align);
174         };
175         min_align_of_val, <T> (c ptr) {
176             let layout = fx.layout_of(T);
177             let align = if layout.is_unsized() {
178                 let (_ptr, info) = ptr.load_scalar_pair(fx);
179                 let (_size, align) = crate::unsize::size_and_align_of_dst(fx, layout.ty, info);
180                 align
181             } else {
182                 fx
183                     .bcx
184                     .ins()
185                     .iconst(fx.pointer_type, layout.align.abi.bytes() as i64)
186             };
187             ret.write_cvalue(fx, CValue::by_val(align, usize_layout));
188         };
189         pref_align_of, <T> () {
190             let pref_align = fx.layout_of(T).align.pref.bytes();
191             let pref_align = CValue::const_val(fx, usize_layout.ty, pref_align as i64);
192             ret.write_cvalue(fx, pref_align);
193         };
194
195
196         type_id, <T> () {
197             let type_id = fx.tcx.type_id_hash(T);
198             let type_id = CValue::const_val(fx, u64_layout.ty, type_id as i64);
199             ret.write_cvalue(fx, type_id);
200         };
201         type_name, <T> () {
202             let type_name = fx.tcx.type_name(T);
203             let type_name = crate::constant::trans_const_value(fx, type_name);
204             ret.write_cvalue(fx, type_name);
205         };
206
207         _ if intrinsic.starts_with("unchecked_") || intrinsic == "exact_div", (c x, c y) {
208             // FIXME trap on overflow
209             let bin_op = match intrinsic {
210                 "unchecked_sub" => BinOp::Sub,
211                 "unchecked_div" | "exact_div" => BinOp::Div,
212                 "unchecked_rem" => BinOp::Rem,
213                 "unchecked_shl" => BinOp::Shl,
214                 "unchecked_shr" => BinOp::Shr,
215                 _ => unimplemented!("intrinsic {}", intrinsic),
216             };
217             let res = match ret.layout().ty.sty {
218                 ty::Uint(_) => crate::base::trans_int_binop(
219                     fx,
220                     bin_op,
221                     x,
222                     y,
223                     ret.layout().ty,
224                     false,
225                 ),
226                 ty::Int(_) => crate::base::trans_int_binop(
227                     fx,
228                     bin_op,
229                     x,
230                     y,
231                     ret.layout().ty,
232                     true,
233                 ),
234                 _ => panic!(),
235             };
236             ret.write_cvalue(fx, res);
237         };
238         _ if intrinsic.ends_with("_with_overflow"), <T> (c x, c y) {
239             assert_eq!(x.layout().ty, y.layout().ty);
240             let bin_op = match intrinsic {
241                 "add_with_overflow" => BinOp::Add,
242                 "sub_with_overflow" => BinOp::Sub,
243                 "mul_with_overflow" => BinOp::Mul,
244                 _ => unimplemented!("intrinsic {}", intrinsic),
245             };
246             let res = match T.sty {
247                 ty::Uint(_) => crate::base::trans_checked_int_binop(
248                     fx,
249                     bin_op,
250                     x,
251                     y,
252                     ret.layout().ty,
253                     false,
254                 ),
255                 ty::Int(_) => crate::base::trans_checked_int_binop(
256                     fx,
257                     bin_op,
258                     x,
259                     y,
260                     ret.layout().ty,
261                     true,
262                 ),
263                 _ => panic!(),
264             };
265             ret.write_cvalue(fx, res);
266         };
267         _ if intrinsic.starts_with("overflowing_"), <T> (c x, c y) {
268             assert_eq!(x.layout().ty, y.layout().ty);
269             let bin_op = match intrinsic {
270                 "overflowing_add" => BinOp::Add,
271                 "overflowing_sub" => BinOp::Sub,
272                 "overflowing_mul" => BinOp::Mul,
273                 _ => unimplemented!("intrinsic {}", intrinsic),
274             };
275             let res = match T.sty {
276                 ty::Uint(_) => crate::base::trans_int_binop(
277                     fx,
278                     bin_op,
279                     x,
280                     y,
281                     ret.layout().ty,
282                     false,
283                 ),
284                 ty::Int(_) => crate::base::trans_int_binop(
285                     fx,
286                     bin_op,
287                     x,
288                     y,
289                     ret.layout().ty,
290                     true,
291                 ),
292                 _ => panic!(),
293             };
294             ret.write_cvalue(fx, res);
295         };
296         _ if intrinsic.starts_with("saturating_"), <T> (c x, c y) {
297             // FIXME implement saturating behavior
298             assert_eq!(x.layout().ty, y.layout().ty);
299             let bin_op = match intrinsic {
300                 "saturating_add" => BinOp::Add,
301                 "saturating_sub" => BinOp::Sub,
302                 "saturating_mul" => BinOp::Mul,
303                 _ => unimplemented!("intrinsic {}", intrinsic),
304             };
305             let res = match T.sty {
306                 ty::Uint(_) => crate::base::trans_int_binop(
307                     fx,
308                     bin_op,
309                     x,
310                     y,
311                     ret.layout().ty,
312                     false,
313                 ),
314                 ty::Int(_) => crate::base::trans_int_binop(
315                     fx,
316                     bin_op,
317                     x,
318                     y,
319                     ret.layout().ty,
320                     true,
321                 ),
322                 _ => panic!(),
323             };
324             ret.write_cvalue(fx, res);
325         };
326         rotate_left, <T>(v x, v y) {
327             let layout = fx.layout_of(T);
328             let res = fx.bcx.ins().rotl(x, y);
329             ret.write_cvalue(fx, CValue::by_val(res, layout));
330         };
331         rotate_right, <T>(v x, v y) {
332             let layout = fx.layout_of(T);
333             let res = fx.bcx.ins().rotr(x, y);
334             ret.write_cvalue(fx, CValue::by_val(res, layout));
335         };
336
337         // The only difference between offset and arith_offset is regarding UB. Because Cranelift
338         // doesn't have UB both are codegen'ed the same way
339         offset | arith_offset, (c base, v offset) {
340             let pointee_ty = base.layout().ty.builtin_deref(true).unwrap().ty;
341             let pointee_size = fx.layout_of(pointee_ty).size.bytes();
342             let ptr_diff = fx.bcx.ins().imul_imm(offset, pointee_size as i64);
343             let base_val = base.load_scalar(fx);
344             let res = fx.bcx.ins().iadd(base_val, ptr_diff);
345             ret.write_cvalue(fx, CValue::by_val(res, args[0].layout()));
346         };
347
348         transmute, <src_ty, dst_ty> (c from) {
349             assert_eq!(from.layout().ty, src_ty);
350             let addr = from.force_stack(fx);
351             let dst_layout = fx.layout_of(dst_ty);
352             ret.write_cvalue(fx, CValue::by_ref(addr, dst_layout))
353         };
354         init, () {
355             if ret.layout().abi == Abi::Uninhabited {
356                 crate::trap::trap_panic(fx, "[panic] Called intrinsic::init for uninhabited type.");
357                 return;
358             }
359
360             match ret {
361                 CPlace::NoPlace(_layout) => {}
362                 CPlace::Var(var, layout) => {
363                     let clif_ty = fx.clif_type(layout.ty).unwrap();
364                     let val = match clif_ty {
365                         types::I8 | types::I16 | types::I32 | types::I64 => fx.bcx.ins().iconst(clif_ty, 0),
366                         types::F32 => {
367                             let zero = fx.bcx.ins().iconst(types::I32, 0);
368                             fx.bcx.ins().bitcast(types::F32, zero)
369                         }
370                         types::F64 => {
371                             let zero = fx.bcx.ins().iconst(types::I64, 0);
372                             fx.bcx.ins().bitcast(types::F64, zero)
373                         }
374                         _ => panic!("clif_type returned {}", clif_ty),
375                     };
376                     fx.bcx.def_var(mir_var(var), val);
377                 }
378                 _ => {
379                     let addr = ret.to_addr(fx);
380                     let layout = ret.layout();
381                     fx.bcx.emit_small_memset(fx.module.target_config(), addr, 0, layout.size.bytes(), 1);
382                 }
383             }
384         };
385         write_bytes, (c dst, v val, v count) {
386             let pointee_ty = dst.layout().ty.builtin_deref(true).unwrap().ty;
387             let pointee_size = fx.layout_of(pointee_ty).size.bytes();
388             let count = fx.bcx.ins().imul_imm(count, pointee_size as i64);
389             let dst_ptr = dst.load_scalar(fx);
390             fx.bcx.call_memset(fx.module.target_config(), dst_ptr, val, count);
391         };
392         ctlz | ctlz_nonzero, <T> (v arg) {
393             let res = CValue::by_val(fx.bcx.ins().clz(arg), fx.layout_of(T));
394             ret.write_cvalue(fx, res);
395         };
396         cttz | cttz_nonzero, <T> (v arg) {
397             let res = CValue::by_val(fx.bcx.ins().ctz(arg), fx.layout_of(T));
398             ret.write_cvalue(fx, res);
399         };
400         ctpop, <T> (v arg) {
401             let res = CValue::by_val(fx.bcx.ins().popcnt(arg), fx.layout_of(T));
402             ret.write_cvalue(fx, res);
403         };
404         bitreverse, <T> (v arg) {
405             let res = CValue::by_val(fx.bcx.ins().bitrev(arg), fx.layout_of(T));
406             ret.write_cvalue(fx, res);
407         };
408         bswap, <T> (v arg) {
409             // FIXME(CraneStation/cranelift#794) add bswap instruction to cranelift
410             fn swap(bcx: &mut FunctionBuilder, v: Value) -> Value {
411                 match bcx.func.dfg.value_type(v) {
412                     types::I8 => v,
413
414                     // https://code.woboq.org/gcc/include/bits/byteswap.h.html
415                     types::I16 => {
416                         let tmp1 = bcx.ins().ishl_imm(v, 8);
417                         let n1 = bcx.ins().band_imm(tmp1, 0xFF00);
418
419                         let tmp2 = bcx.ins().ushr_imm(v, 8);
420                         let n2 = bcx.ins().band_imm(tmp2, 0x00FF);
421
422                         bcx.ins().bor(n1, n2)
423                     }
424                     types::I32 => {
425                         let tmp1 = bcx.ins().ishl_imm(v, 24);
426                         let n1 = bcx.ins().band_imm(tmp1, 0xFF00_0000);
427
428                         let tmp2 = bcx.ins().ishl_imm(v, 8);
429                         let n2 = bcx.ins().band_imm(tmp2, 0x00FF_0000);
430
431                         let tmp3 = bcx.ins().ushr_imm(v, 8);
432                         let n3 = bcx.ins().band_imm(tmp3, 0x0000_FF00);
433
434                         let tmp4 = bcx.ins().ushr_imm(v, 24);
435                         let n4 = bcx.ins().band_imm(tmp4, 0x0000_00FF);
436
437                         let or_tmp1 = bcx.ins().bor(n1, n2);
438                         let or_tmp2 = bcx.ins().bor(n3, n4);
439                         bcx.ins().bor(or_tmp1, or_tmp2)
440                     }
441                     types::I64 => {
442                         let tmp1 = bcx.ins().ishl_imm(v, 56);
443                         let n1 = bcx.ins().band_imm(tmp1, 0xFF00_0000_0000_0000u64 as i64);
444
445                         let tmp2 = bcx.ins().ishl_imm(v, 40);
446                         let n2 = bcx.ins().band_imm(tmp2, 0x00FF_0000_0000_0000u64 as i64);
447
448                         let tmp3 = bcx.ins().ishl_imm(v, 24);
449                         let n3 = bcx.ins().band_imm(tmp3, 0x0000_FF00_0000_0000u64 as i64);
450
451                         let tmp4 = bcx.ins().ishl_imm(v, 8);
452                         let n4 = bcx.ins().band_imm(tmp4, 0x0000_00FF_0000_0000u64 as i64);
453
454                         let tmp5 = bcx.ins().ushr_imm(v, 8);
455                         let n5 = bcx.ins().band_imm(tmp5, 0x0000_0000_FF00_0000u64 as i64);
456
457                         let tmp6 = bcx.ins().ushr_imm(v, 24);
458                         let n6 = bcx.ins().band_imm(tmp6, 0x0000_0000_00FF_0000u64 as i64);
459
460                         let tmp7 = bcx.ins().ushr_imm(v, 40);
461                         let n7 = bcx.ins().band_imm(tmp7, 0x0000_0000_0000_FF00u64 as i64);
462
463                         let tmp8 = bcx.ins().ushr_imm(v, 56);
464                         let n8 = bcx.ins().band_imm(tmp8, 0x0000_0000_0000_00FFu64 as i64);
465
466                         let or_tmp1 = bcx.ins().bor(n1, n2);
467                         let or_tmp2 = bcx.ins().bor(n3, n4);
468                         let or_tmp3 = bcx.ins().bor(n5, n6);
469                         let or_tmp4 = bcx.ins().bor(n7, n8);
470
471                         let or_tmp5 = bcx.ins().bor(or_tmp1, or_tmp2);
472                         let or_tmp6 = bcx.ins().bor(or_tmp3, or_tmp4);
473                         bcx.ins().bor(or_tmp5, or_tmp6)
474                     }
475                     ty => unimplemented!("bwap {}", ty),
476                 }
477             };
478             let res = CValue::by_val(swap(&mut fx.bcx, arg), fx.layout_of(T));
479             ret.write_cvalue(fx, res);
480         };
481         needs_drop, <T> () {
482             let needs_drop = if T.needs_drop(fx.tcx, ParamEnv::reveal_all()) {
483                 1
484             } else {
485                 0
486             };
487             let needs_drop = CValue::const_val(fx, fx.tcx.types.bool, needs_drop);
488             ret.write_cvalue(fx, needs_drop);
489         };
490         panic_if_uninhabited, <T> () {
491             if fx.layout_of(T).abi.is_uninhabited() {
492                 crate::trap::trap_panic(fx, "[panic] Called intrinsic::panic_if_uninhabited for uninhabited type.");
493                 return;
494             }
495         };
496
497         volatile_load, (c ptr) {
498             // Cranelift treats loads as volatile by default
499             let inner_layout =
500                 fx.layout_of(ptr.layout().ty.builtin_deref(true).unwrap().ty);
501             let val = CValue::by_ref(ptr.load_scalar(fx), inner_layout);
502             ret.write_cvalue(fx, val);
503         };
504         volatile_store, (v ptr, c val) {
505             // Cranelift treats stores as volatile by default
506             let dest = CPlace::for_addr(ptr, val.layout());
507             dest.write_cvalue(fx, val);
508         };
509
510         _ if intrinsic.starts_with("atomic_fence"), () {};
511         _ if intrinsic.starts_with("atomic_singlethreadfence"), () {};
512         _ if intrinsic.starts_with("atomic_load"), (c ptr) {
513             let inner_layout =
514                 fx.layout_of(ptr.layout().ty.builtin_deref(true).unwrap().ty);
515             let val = CValue::by_ref(ptr.load_scalar(fx), inner_layout);
516             ret.write_cvalue(fx, val);
517         };
518         _ if intrinsic.starts_with("atomic_store"), (v ptr, c val) {
519             let dest = CPlace::for_addr(ptr, val.layout());
520             dest.write_cvalue(fx, val);
521         };
522         _ if intrinsic.starts_with("atomic_xchg"), <T> (v ptr, c src) {
523             // Read old
524             let clif_ty = fx.clif_type(T).unwrap();
525             let old = fx.bcx.ins().load(clif_ty, MemFlags::new(), ptr, 0);
526             ret.write_cvalue(fx, CValue::by_val(old, fx.layout_of(T)));
527
528             // Write new
529             let dest = CPlace::for_addr(ptr, src.layout());
530             dest.write_cvalue(fx, src);
531         };
532         _ if intrinsic.starts_with("atomic_cxchg"), <T> (v ptr, v test_old, v new) { // both atomic_cxchg_* and atomic_cxchgweak_*
533             // Read old
534             let clif_ty = fx.clif_type(T).unwrap();
535             let old = fx.bcx.ins().load(clif_ty, MemFlags::new(), ptr, 0);
536
537             // Compare
538             let is_eq = fx.bcx.ins().icmp(IntCC::Equal, old, test_old);
539             let new = crate::common::codegen_select(&mut fx.bcx, is_eq, new, old); // Keep old if not equal to test_old
540
541             // Write new
542             fx.bcx.ins().store(MemFlags::new(), new, ptr, 0);
543
544             let ret_val = CValue::by_val_pair(old, fx.bcx.ins().bint(types::I8, is_eq), ret.layout());
545             ret.write_cvalue(fx, ret_val);
546         };
547
548         _ if intrinsic.starts_with("atomic_xadd"), <T> (v ptr, v amount) {
549             atomic_binop_return_old! (fx, iadd<T>(ptr, amount) -> ret);
550         };
551         _ if intrinsic.starts_with("atomic_xsub"), <T> (v ptr, v amount) {
552             atomic_binop_return_old! (fx, isub<T>(ptr, amount) -> ret);
553         };
554         _ if intrinsic.starts_with("atomic_and"), <T> (v ptr, v src) {
555             atomic_binop_return_old! (fx, band<T>(ptr, src) -> ret);
556         };
557         _ if intrinsic.starts_with("atomic_nand"), <T> (v ptr, v src) {
558             atomic_binop_return_old! (fx, band_not<T>(ptr, src) -> ret);
559         };
560         _ if intrinsic.starts_with("atomic_or"), <T> (v ptr, v src) {
561             atomic_binop_return_old! (fx, bor<T>(ptr, src) -> ret);
562         };
563         _ if intrinsic.starts_with("atomic_xor"), <T> (v ptr, v src) {
564             atomic_binop_return_old! (fx, bxor<T>(ptr, src) -> ret);
565         };
566
567         _ if intrinsic.starts_with("atomic_max"), <T> (v ptr, v src) {
568             atomic_minmax!(fx, IntCC::SignedGreaterThan, <T> (ptr, src) -> ret);
569         };
570         _ if intrinsic.starts_with("atomic_umax"), <T> (v ptr, v src) {
571             atomic_minmax!(fx, IntCC::UnsignedGreaterThan, <T> (ptr, src) -> ret);
572         };
573         _ if intrinsic.starts_with("atomic_min"), <T> (v ptr, v src) {
574             atomic_minmax!(fx, IntCC::SignedLessThan, <T> (ptr, src) -> ret);
575         };
576         _ if intrinsic.starts_with("atomic_umin"), <T> (v ptr, v src) {
577             atomic_minmax!(fx, IntCC::UnsignedLessThan, <T> (ptr, src) -> ret);
578         };
579
580         expf32, (c flt) {
581             let res = fx.easy_call("expf", &[flt], fx.tcx.types.f32);
582             ret.write_cvalue(fx, res);
583         };
584         expf64, (c flt) {
585             let res = fx.easy_call("exp", &[flt], fx.tcx.types.f64);
586             ret.write_cvalue(fx, res);
587         };
588         exp2f32, (c flt) {
589             let res = fx.easy_call("exp2f", &[flt], fx.tcx.types.f32);
590             ret.write_cvalue(fx, res);
591         };
592         exp2f64, (c flt) {
593             let res = fx.easy_call("exp2", &[flt], fx.tcx.types.f64);
594             ret.write_cvalue(fx, res);
595         };
596         fabsf32, (c flt) {
597             let res = fx.easy_call("fabsf", &[flt], fx.tcx.types.f32);
598             ret.write_cvalue(fx, res);
599         };
600         fabsf64, (c flt) {
601             let res = fx.easy_call("fabs", &[flt], fx.tcx.types.f64);
602             ret.write_cvalue(fx, res);
603         };
604         sqrtf32, (c flt) {
605             let res = fx.easy_call("sqrtf", &[flt], fx.tcx.types.f32);
606             ret.write_cvalue(fx, res);
607         };
608         sqrtf64, (c flt) {
609             let res = fx.easy_call("sqrt", &[flt], fx.tcx.types.f64);
610             ret.write_cvalue(fx, res);
611         };
612         floorf32, (c flt) {
613             let res = fx.easy_call("floorf", &[flt], fx.tcx.types.f32);
614             ret.write_cvalue(fx, res);
615         };
616         floorf64, (c flt) {
617             let res = fx.easy_call("floor", &[flt], fx.tcx.types.f64);
618             ret.write_cvalue(fx, res);
619         };
620         ceilf32, (c flt) {
621             let res = fx.easy_call("ceilf", &[flt], fx.tcx.types.f32);
622             ret.write_cvalue(fx, res);
623         };
624         ceilf64, (c flt) {
625             let res = fx.easy_call("ceil", &[flt], fx.tcx.types.f64);
626             ret.write_cvalue(fx, res);
627         };
628
629         minnumf32, (c a, c b) {
630             let res = fx.easy_call("fminf", &[a, b], fx.tcx.types.f32);
631             ret.write_cvalue(fx, res);
632         };
633         minnumf64, (c a, c b) {
634             let res = fx.easy_call("fmin", &[a, b], fx.tcx.types.f64);
635             ret.write_cvalue(fx, res);
636         };
637         maxnumf32, (c a, c b) {
638             let res = fx.easy_call("fmaxf", &[a, b], fx.tcx.types.f32);
639             ret.write_cvalue(fx, res);
640         };
641         maxnumf64, (c a, c b) {
642             let res = fx.easy_call("fmax", &[a, b], fx.tcx.types.f64);
643             ret.write_cvalue(fx, res);
644         };
645
646     }
647
648     if let Some((_, dest)) = destination {
649         let ret_ebb = fx.get_ebb(dest);
650         fx.bcx.ins().jump(ret_ebb, &[]);
651     } else {
652         trap_unreachable(fx, "[corruption] Diverging intrinsic returned.");
653     }
654 }