]> git.lizzy.rs Git - rust.git/blob - src/intrinsics.rs
Implement some float intrinsics
[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 intrinisc::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         uninit, <T> () {
393             if ret.layout().abi == Abi::Uninhabited {
394                 crate::trap::trap_panic(fx, "[panic] Called intrinsic::uninit for uninhabited type.");
395                 return;
396             }
397
398             let uninit_place = CPlace::new_stack_slot(fx, T);
399             let uninit_val = uninit_place.to_cvalue(fx);
400             ret.write_cvalue(fx, uninit_val);
401         };
402         ctlz | ctlz_nonzero, <T> (v arg) {
403             let res = CValue::by_val(fx.bcx.ins().clz(arg), fx.layout_of(T));
404             ret.write_cvalue(fx, res);
405         };
406         cttz | cttz_nonzero, <T> (v arg) {
407             let res = CValue::by_val(fx.bcx.ins().ctz(arg), fx.layout_of(T));
408             ret.write_cvalue(fx, res);
409         };
410         ctpop, <T> (v arg) {
411             let res = CValue::by_val(fx.bcx.ins().popcnt(arg), fx.layout_of(T));
412             ret.write_cvalue(fx, res);
413         };
414         bitreverse, <T> (v arg) {
415             let res = CValue::by_val(fx.bcx.ins().bitrev(arg), fx.layout_of(T));
416             ret.write_cvalue(fx, res);
417         };
418         bswap, <T> (v arg) {
419             // FIXME(CraneStation/cranelift#794) add bswap instruction to cranelift
420             fn swap(bcx: &mut FunctionBuilder, v: Value) -> Value {
421                 match bcx.func.dfg.value_type(v) {
422                     types::I8 => v,
423
424                     // https://code.woboq.org/gcc/include/bits/byteswap.h.html
425                     types::I16 => {
426                         let tmp1 = bcx.ins().ishl_imm(v, 8);
427                         let n1 = bcx.ins().band_imm(tmp1, 0xFF00);
428
429                         let tmp2 = bcx.ins().ushr_imm(v, 8);
430                         let n2 = bcx.ins().band_imm(tmp2, 0x00FF);
431
432                         bcx.ins().bor(n1, n2)
433                     }
434                     types::I32 => {
435                         let tmp1 = bcx.ins().ishl_imm(v, 24);
436                         let n1 = bcx.ins().band_imm(tmp1, 0xFF00_0000);
437
438                         let tmp2 = bcx.ins().ishl_imm(v, 8);
439                         let n2 = bcx.ins().band_imm(tmp2, 0x00FF_0000);
440
441                         let tmp3 = bcx.ins().ushr_imm(v, 8);
442                         let n3 = bcx.ins().band_imm(tmp3, 0x0000_FF00);
443
444                         let tmp4 = bcx.ins().ushr_imm(v, 24);
445                         let n4 = bcx.ins().band_imm(tmp4, 0x0000_00FF);
446
447                         let or_tmp1 = bcx.ins().bor(n1, n2);
448                         let or_tmp2 = bcx.ins().bor(n3, n4);
449                         bcx.ins().bor(or_tmp1, or_tmp2)
450                     }
451                     types::I64 => {
452                         let tmp1 = bcx.ins().ishl_imm(v, 56);
453                         let n1 = bcx.ins().band_imm(tmp1, 0xFF00_0000_0000_0000u64 as i64);
454
455                         let tmp2 = bcx.ins().ishl_imm(v, 40);
456                         let n2 = bcx.ins().band_imm(tmp2, 0x00FF_0000_0000_0000u64 as i64);
457
458                         let tmp3 = bcx.ins().ishl_imm(v, 24);
459                         let n3 = bcx.ins().band_imm(tmp3, 0x0000_FF00_0000_0000u64 as i64);
460
461                         let tmp4 = bcx.ins().ishl_imm(v, 8);
462                         let n4 = bcx.ins().band_imm(tmp4, 0x0000_00FF_0000_0000u64 as i64);
463
464                         let tmp5 = bcx.ins().ushr_imm(v, 8);
465                         let n5 = bcx.ins().band_imm(tmp5, 0x0000_0000_FF00_0000u64 as i64);
466
467                         let tmp6 = bcx.ins().ushr_imm(v, 24);
468                         let n6 = bcx.ins().band_imm(tmp6, 0x0000_0000_00FF_0000u64 as i64);
469
470                         let tmp7 = bcx.ins().ushr_imm(v, 40);
471                         let n7 = bcx.ins().band_imm(tmp7, 0x0000_0000_0000_FF00u64 as i64);
472
473                         let tmp8 = bcx.ins().ushr_imm(v, 56);
474                         let n8 = bcx.ins().band_imm(tmp8, 0x0000_0000_0000_00FFu64 as i64);
475
476                         let or_tmp1 = bcx.ins().bor(n1, n2);
477                         let or_tmp2 = bcx.ins().bor(n3, n4);
478                         let or_tmp3 = bcx.ins().bor(n5, n6);
479                         let or_tmp4 = bcx.ins().bor(n7, n8);
480
481                         let or_tmp5 = bcx.ins().bor(or_tmp1, or_tmp2);
482                         let or_tmp6 = bcx.ins().bor(or_tmp3, or_tmp4);
483                         bcx.ins().bor(or_tmp5, or_tmp6)
484                     }
485                     ty => unimplemented!("bwap {}", ty),
486                 }
487             };
488             let res = CValue::by_val(swap(&mut fx.bcx, arg), fx.layout_of(T));
489             ret.write_cvalue(fx, res);
490         };
491         needs_drop, <T> () {
492             let needs_drop = if T.needs_drop(fx.tcx, ParamEnv::reveal_all()) {
493                 1
494             } else {
495                 0
496             };
497             let needs_drop = CValue::const_val(fx, fx.tcx.types.bool, needs_drop);
498             ret.write_cvalue(fx, needs_drop);
499         };
500         panic_if_uninhabited, <T> () {
501             if fx.layout_of(T).abi.is_uninhabited() {
502                 crate::trap::trap_panic(fx, "[panic] Called intrinsic::panic_if_uninhabited for uninhabited type.");
503                 return;
504             }
505         };
506
507         volatile_load, (c ptr) {
508             // Cranelift treats loads as volatile by default
509             let inner_layout =
510                 fx.layout_of(ptr.layout().ty.builtin_deref(true).unwrap().ty);
511             let val = CValue::by_ref(ptr.load_scalar(fx), inner_layout);
512             ret.write_cvalue(fx, val);
513         };
514         volatile_store, (v ptr, c val) {
515             // Cranelift treats stores as volatile by default
516             let dest = CPlace::for_addr(ptr, val.layout());
517             dest.write_cvalue(fx, val);
518         };
519
520         _ if intrinsic.starts_with("atomic_fence"), () {};
521         _ if intrinsic.starts_with("atomic_singlethreadfence"), () {};
522         _ if intrinsic.starts_with("atomic_load"), (c ptr) {
523             let inner_layout =
524                 fx.layout_of(ptr.layout().ty.builtin_deref(true).unwrap().ty);
525             let val = CValue::by_ref(ptr.load_scalar(fx), inner_layout);
526             ret.write_cvalue(fx, val);
527         };
528         _ if intrinsic.starts_with("atomic_store"), (v ptr, c val) {
529             let dest = CPlace::for_addr(ptr, val.layout());
530             dest.write_cvalue(fx, val);
531         };
532         _ if intrinsic.starts_with("atomic_xchg"), <T> (v ptr, c src) {
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             ret.write_cvalue(fx, CValue::by_val(old, fx.layout_of(T)));
537
538             // Write new
539             let dest = CPlace::for_addr(ptr, src.layout());
540             dest.write_cvalue(fx, src);
541         };
542         _ if intrinsic.starts_with("atomic_cxchg"), <T> (v ptr, v test_old, v new) { // both atomic_cxchg_* and atomic_cxchgweak_*
543             // Read old
544             let clif_ty = fx.clif_type(T).unwrap();
545             let old = fx.bcx.ins().load(clif_ty, MemFlags::new(), ptr, 0);
546
547             // Compare
548             let is_eq = fx.bcx.ins().icmp(IntCC::Equal, old, test_old);
549             let new = crate::common::codegen_select(&mut fx.bcx, is_eq, new, old); // Keep old if not equal to test_old
550
551             // Write new
552             fx.bcx.ins().store(MemFlags::new(), new, ptr, 0);
553
554             let ret_val = CValue::by_val_pair(old, fx.bcx.ins().bint(types::I8, is_eq), ret.layout());
555             ret.write_cvalue(fx, ret_val);
556         };
557
558         _ if intrinsic.starts_with("atomic_xadd"), <T> (v ptr, v amount) {
559             atomic_binop_return_old! (fx, iadd<T>(ptr, amount) -> ret);
560         };
561         _ if intrinsic.starts_with("atomic_xsub"), <T> (v ptr, v amount) {
562             atomic_binop_return_old! (fx, isub<T>(ptr, amount) -> ret);
563         };
564         _ if intrinsic.starts_with("atomic_and"), <T> (v ptr, v src) {
565             atomic_binop_return_old! (fx, band<T>(ptr, src) -> ret);
566         };
567         _ if intrinsic.starts_with("atomic_nand"), <T> (v ptr, v src) {
568             atomic_binop_return_old! (fx, band_not<T>(ptr, src) -> ret);
569         };
570         _ if intrinsic.starts_with("atomic_or"), <T> (v ptr, v src) {
571             atomic_binop_return_old! (fx, bor<T>(ptr, src) -> ret);
572         };
573         _ if intrinsic.starts_with("atomic_xor"), <T> (v ptr, v src) {
574             atomic_binop_return_old! (fx, bxor<T>(ptr, src) -> ret);
575         };
576
577         _ if intrinsic.starts_with("atomic_max"), <T> (v ptr, v src) {
578             atomic_minmax!(fx, IntCC::SignedGreaterThan, <T> (ptr, src) -> ret);
579         };
580         _ if intrinsic.starts_with("atomic_umax"), <T> (v ptr, v src) {
581             atomic_minmax!(fx, IntCC::UnsignedGreaterThan, <T> (ptr, src) -> ret);
582         };
583         _ if intrinsic.starts_with("atomic_min"), <T> (v ptr, v src) {
584             atomic_minmax!(fx, IntCC::SignedLessThan, <T> (ptr, src) -> ret);
585         };
586         _ if intrinsic.starts_with("atomic_umin"), <T> (v ptr, v src) {
587             atomic_minmax!(fx, IntCC::UnsignedLessThan, <T> (ptr, src) -> ret);
588         };
589
590         expf32, (c flt) {
591             let res = fx.easy_call("expf", &[flt], fx.tcx.types.f32);
592             ret.write_cvalue(fx, res);
593         };
594         expf64, (c flt) {
595             let res = fx.easy_call("exp", &[flt], fx.tcx.types.f64);
596             ret.write_cvalue(fx, res);
597         };
598         exp2f32, (c flt) {
599             let res = fx.easy_call("exp2f", &[flt], fx.tcx.types.f32);
600             ret.write_cvalue(fx, res);
601         };
602         exp2f64, (c flt) {
603             let res = fx.easy_call("exp2", &[flt], fx.tcx.types.f64);
604             ret.write_cvalue(fx, res);
605         };
606         fabsf32, (c flt) {
607             let res = fx.easy_call("fabsf", &[flt], fx.tcx.types.f32);
608             ret.write_cvalue(fx, res);
609         };
610         fabsf64, (c flt) {
611             let res = fx.easy_call("fabs", &[flt], fx.tcx.types.f64);
612             ret.write_cvalue(fx, res);
613         };
614         sqrtf32, (c flt) {
615             let res = fx.easy_call("sqrtf", &[flt], fx.tcx.types.f32);
616             ret.write_cvalue(fx, res);
617         };
618         sqrtf64, (c flt) {
619             let res = fx.easy_call("sqrt", &[flt], fx.tcx.types.f64);
620             ret.write_cvalue(fx, res);
621         };
622         floorf32, (c flt) {
623             let res = fx.easy_call("floorf", &[flt], fx.tcx.types.f32);
624             ret.write_cvalue(fx, res);
625         };
626         floorf64, (c flt) {
627             let res = fx.easy_call("floor", &[flt], fx.tcx.types.f64);
628             ret.write_cvalue(fx, res);
629         };
630         ceilf32, (c flt) {
631             let res = fx.easy_call("ceilf", &[flt], fx.tcx.types.f32);
632             ret.write_cvalue(fx, res);
633         };
634         ceilf64, (c flt) {
635             let res = fx.easy_call("ceil", &[flt], fx.tcx.types.f64);
636             ret.write_cvalue(fx, res);
637         };
638
639         minnumf32, (c a, c b) {
640             let res = fx.easy_call("fminf", &[a, b], fx.tcx.types.f32);
641             ret.write_cvalue(fx, res);
642         };
643         minnumf64, (c a, c b) {
644             let res = fx.easy_call("fmin", &[a, b], fx.tcx.types.f64);
645             ret.write_cvalue(fx, res);
646         };
647         maxnumf32, (c a, c b) {
648             let res = fx.easy_call("fmaxf", &[a, b], fx.tcx.types.f32);
649             ret.write_cvalue(fx, res);
650         };
651         maxnumf64, (c a, c b) {
652             let res = fx.easy_call("fmax", &[a, b], fx.tcx.types.f64);
653             ret.write_cvalue(fx, res);
654         };
655
656     }
657
658     if let Some((_, dest)) = destination {
659         let ret_ebb = fx.get_ebb(dest);
660         fx.bcx.ins().jump(ret_ebb, &[]);
661     } else {
662         trap_unreachable(fx, "[corruption] Diverging intrinsic returned.");
663     }
664 }