Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit d425116

Browse files
committed
Implement some intrinsics
1 parent d7274ac commit d425116

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ pub fn force_eval_const<'a, 'tcx: 'a>(
106106
}
107107
}
108108

109-
fn trans_const_value<'a, 'tcx: 'a>(
109+
pub fn trans_const_value<'a, 'tcx: 'a>(
110110
fx: &mut FunctionCx<'a, 'tcx, impl Backend>,
111111
const_: Const<'tcx>,
112112
) -> CValue<'tcx> {

src/intrinsics.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,24 @@ pub fn codegen_intrinsic_call<'a, 'tcx: 'a>(
186186
};
187187
ret.write_cvalue(fx, CValue::by_val(align, usize_layout));
188188
};
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+
189196
type_id, <T> () {
190197
let type_id = fx.tcx.type_id_hash(T);
191198
let type_id = CValue::const_val(fx, u64_layout.ty, type_id as i64);
192199
ret.write_cvalue(fx, type_id);
193200
};
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+
194207
_ if intrinsic.starts_with("unchecked_") || intrinsic == "exact_div", (c x, c y) {
195208
// FIXME trap on overflow
196209
let bin_op = match intrinsic {
@@ -418,6 +431,19 @@ pub fn codegen_intrinsic_call<'a, 'tcx: 'a>(
418431
}
419432
};
420433

434+
volatile_load, (c ptr) {
435+
// Cranelift treats loads as volatile by default
436+
let inner_layout =
437+
fx.layout_of(ptr.layout().ty.builtin_deref(true).unwrap().ty);
438+
let val = CValue::by_ref(ptr.load_scalar(fx), inner_layout);
439+
ret.write_cvalue(fx, val);
440+
};
441+
volatile_store, (v ptr, c val) {
442+
// Cranelift treats stores as volatile by default
443+
let dest = CPlace::for_addr(ptr, val.layout());
444+
dest.write_cvalue(fx, val);
445+
};
446+
421447
_ if intrinsic.starts_with("atomic_fence"), () {};
422448
_ if intrinsic.starts_with("atomic_singlethreadfence"), () {};
423449
_ if intrinsic.starts_with("atomic_load"), (c ptr) {

0 commit comments

Comments
 (0)