1 //! Emulation of a subset of the cpuid x86 instruction.
5 /// Emulates a subset of the cpuid x86 instruction.
7 /// This emulates an intel cpu with sse and sse2 support, but which doesn't support anything else.
8 pub(crate) fn codegen_cpuid_call<'tcx>(
9 fx: &mut FunctionCx<'_, 'tcx, impl Module>,
12 ) -> (Value, Value, Value, Value) {
13 let leaf_0 = fx.bcx.create_block();
14 let leaf_1 = fx.bcx.create_block();
15 let leaf_8000_0000 = fx.bcx.create_block();
16 let leaf_8000_0001 = fx.bcx.create_block();
17 let unsupported_leaf = fx.bcx.create_block();
19 let dest = fx.bcx.create_block();
20 let eax = fx.bcx.append_block_param(dest, types::I32);
21 let ebx = fx.bcx.append_block_param(dest, types::I32);
22 let ecx = fx.bcx.append_block_param(dest, types::I32);
23 let edx = fx.bcx.append_block_param(dest, types::I32);
25 let mut switch = cranelift_frontend::Switch::new();
26 switch.set_entry(0, leaf_0);
27 switch.set_entry(1, leaf_1);
28 switch.set_entry(0x8000_0000, leaf_8000_0000);
29 switch.set_entry(0x8000_0001, leaf_8000_0001);
30 switch.emit(&mut fx.bcx, leaf, unsupported_leaf);
32 fx.bcx.switch_to_block(leaf_0);
33 let max_basic_leaf = fx.bcx.ins().iconst(types::I32, 1);
37 .iconst(types::I32, i64::from(u32::from_le_bytes(*b"Genu")));
41 .iconst(types::I32, i64::from(u32::from_le_bytes(*b"ineI")));
45 .iconst(types::I32, i64::from(u32::from_le_bytes(*b"ntel")));
48 .jump(dest, &[max_basic_leaf, vend0, vend1, vend2]);
50 fx.bcx.switch_to_block(leaf_1);
51 let cpu_signature = fx.bcx.ins().iconst(types::I32, 0);
52 let additional_information = fx.bcx.ins().iconst(types::I32, 0);
53 let ecx_features = fx.bcx.ins().iconst(types::I32, 0);
57 .iconst(types::I32, 1 << 25 /* sse */ | 1 << 26 /* sse2 */);
62 additional_information,
68 fx.bcx.switch_to_block(leaf_8000_0000);
69 let extended_max_basic_leaf = fx.bcx.ins().iconst(types::I32, 0);
70 let zero = fx.bcx.ins().iconst(types::I32, 0);
73 .jump(dest, &[extended_max_basic_leaf, zero, zero, zero]);
75 fx.bcx.switch_to_block(leaf_8000_0001);
76 let zero = fx.bcx.ins().iconst(types::I32, 0);
77 let proc_info_ecx = fx.bcx.ins().iconst(types::I32, 0);
78 let proc_info_edx = fx.bcx.ins().iconst(types::I32, 0);
81 .jump(dest, &[zero, zero, proc_info_ecx, proc_info_edx]);
83 fx.bcx.switch_to_block(unsupported_leaf);
84 crate::trap::trap_unreachable(
86 "__cpuid_count arch intrinsic doesn't yet support specified leaf",
89 fx.bcx.switch_to_block(dest);