Skip to content

Commit f1784d2

Browse files
committed
Inline codegen_xgetbv into llvm_x86.rs
1 parent f86f9a4 commit f1784d2

File tree

2 files changed

+34
-44
lines changed

2 files changed

+34
-44
lines changed

src/inline_asm.rs

+2-43
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use target_lexicon::BinaryFormat;
1010

1111
use crate::prelude::*;
1212

13-
enum CInlineAsmOperand<'tcx> {
13+
pub(crate) enum CInlineAsmOperand<'tcx> {
1414
In {
1515
reg: InlineAsmRegOrRegClass,
1616
value: Value,
@@ -146,7 +146,7 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>(
146146
}
147147
}
148148

149-
fn codegen_inline_asm_inner<'tcx>(
149+
pub(crate) fn codegen_inline_asm_inner<'tcx>(
150150
fx: &mut FunctionCx<'_, '_, 'tcx>,
151151
template: &[InlineAsmTemplatePiece],
152152
operands: &[CInlineAsmOperand<'tcx>],
@@ -737,44 +737,3 @@ fn call_inline_asm<'tcx>(
737737
place.write_cvalue(fx, CValue::by_val(value, place.layout()));
738738
}
739739
}
740-
741-
pub(crate) fn codegen_xgetbv<'tcx>(
742-
fx: &mut FunctionCx<'_, '_, 'tcx>,
743-
xcr_no: Value,
744-
ret: CPlace<'tcx>,
745-
) {
746-
// FIXME add .eh_frame unwind info directives
747-
748-
let operands = vec![
749-
CInlineAsmOperand::In {
750-
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::cx)),
751-
value: xcr_no,
752-
},
753-
CInlineAsmOperand::Out {
754-
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::ax)),
755-
late: true,
756-
place: Some(ret),
757-
},
758-
CInlineAsmOperand::Out {
759-
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::dx)),
760-
late: true,
761-
place: None,
762-
},
763-
];
764-
let options = InlineAsmOptions::NOSTACK | InlineAsmOptions::PURE | InlineAsmOptions::NOMEM;
765-
766-
codegen_inline_asm_inner(
767-
fx,
768-
&[InlineAsmTemplatePiece::String(
769-
"
770-
xgetbv
771-
// out = rdx << 32 | rax
772-
shl rdx, 32
773-
or rax, rdx
774-
"
775-
.to_string(),
776-
)],
777-
&operands,
778-
options,
779-
);
780-
}

src/intrinsics/llvm_x86.rs

+32-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
//! Emulate x86 LLVM intrinsics
22
3+
use rustc_ast::ast::{InlineAsmOptions, InlineAsmTemplatePiece};
34
use rustc_middle::ty::GenericArgsRef;
5+
use rustc_target::asm::*;
46

7+
use crate::inline_asm::{codegen_inline_asm_inner, CInlineAsmOperand};
58
use crate::intrinsics::*;
69
use crate::prelude::*;
710

@@ -24,7 +27,35 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
2427

2528
let xcr_no = xcr_no.load_scalar(fx);
2629

27-
crate::inline_asm::codegen_xgetbv(fx, xcr_no, ret);
30+
codegen_inline_asm_inner(
31+
fx,
32+
&[InlineAsmTemplatePiece::String(
33+
"
34+
xgetbv
35+
// out = rdx << 32 | rax
36+
shl rdx, 32
37+
or rax, rdx
38+
"
39+
.to_string(),
40+
)],
41+
&[
42+
CInlineAsmOperand::In {
43+
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::cx)),
44+
value: xcr_no,
45+
},
46+
CInlineAsmOperand::Out {
47+
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::ax)),
48+
late: true,
49+
place: Some(ret),
50+
},
51+
CInlineAsmOperand::Out {
52+
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::dx)),
53+
late: true,
54+
place: None,
55+
},
56+
],
57+
InlineAsmOptions::NOSTACK | InlineAsmOptions::PURE | InlineAsmOptions::NOMEM,
58+
);
2859
}
2960

3061
"llvm.x86.sse3.ldu.dq" | "llvm.x86.avx.ldu.dq.256" => {

0 commit comments

Comments
 (0)