Merge pull request #358 from sahib453/task/199-fences

loader: accept MFENCE, LFENCE and SFENCE and document guest memory ordering (#199)
This commit is contained in:
Zach Doxsee authored and GitHub committed 2026-11-24 21:14:51 +01:00
commit a7e3e1e42c
10 files changed
+193 -78

No files matched your search

+1
View File
@@ -29,6 +29,7 @@ remains unsupported.
- Added a documented independent acceptance rule for promoting AMD RDNA2 desktop GPU (gfx1030) forms from local CPU and Metal results to `fixture verified`, including clean-commit evidence, reviewer independence, raw-log location, review-log summary, failure handling and status regeneration (#302).
- Added the VOP3A (`_e64`) encodings of eleven gfx1030 VOP2 integer forms (`v_mul_{i32_i24,hi_i32_i24,u32_u24,hi_u32_u24}`, `v_{min,max}_{i32,u32}`, `v_xnor_b32`, `v_sub_nc_u32`, `v_subrev_nc_u32`) and of the sixteen Wave32 integer compares (explicit SGPR mask destination, `s_cbranch_vccz` through `vcc_lo`, a translation error for reads of runtime-only SGPR results) as semantic-registry encoding variants, with VGPR sources only. New fixtures `vop3-integer` and `vop3-compare` with IR and MSL goldens, and an independent guide-derived oracle (`tests/validation/tests/vop3_{integer,compare}.rs`) that agrees on both reference interpreters and on native Metal. Part of #215.
- Added guest texture binding through D3D12-style descriptor tables (#303): shader-visible CBV_SRV_UAV and sampler heaps, `CreateShaderResourceView` for one-level RGBA8 and BC1 2D textures, a point/clamp `CreateSampler`, a root signature with one pixel-stage SRV table and one sampler table, and `SetDescriptorHeaps`/`SetGraphicsRootDescriptorTable` in `crates/loader/src/graphics.rs`, plus `NativeCompute::render_rgba8_sampled_bc1`. Verified locally on an Apple M5 Pro under Metal validation: a guest draw with the translated `image_sample_lz` pixel stage matches the software reference and hand-derived images on 16 of 16 pixels for two RGBA8 textures and 64 of 64 for an 8×8 BC1 texture. A wrong descriptor slot changes the image, off-centre and out-of-range coordinates point-sample with clamping, and a rejected binding, draw shape or resource state never reaches the backend. The software reference samples BC1 with the spec-exact decoder, while Apple's hardware rounds BC1's interpolated palette entries differently (171/84 against 170/85), so the BC1 fixtures use only endpoint colours. Not yet reachable from guest imports. Not yet independently accepted.
- Added MFENCE, LFENCE and SFENCE and documented the ordering of guest memory accesses (part of #199). Both engines used to stop on a fence with an illegal-instruction exit. Each engine runs one guest instruction at a time on one host thread and completes its loads and stores before the next, so accesses are already totally ordered and the fences change nothing; `docs/cpu/instruction-registry.md` states this and that it holds only while guest threads do not run on several host threads. Five single-thread cases in `cpu_known_answers.rs` and three assembled fixtures cover them, and the memory forms that share the opcode stay rejected. SSE2 is still not reported by CPUID because other SSE2 instructions are rejected; the refused SSE2 instruction that `cpu_features.rs` holds is now MASKMOVDQU. No multi-thread behaviour is established, and nothing was compared with x86 hardware; awaiting independent review.
- Added the accumulator short form of XCHG, opcodes 91 to 97 and 90 with REX.B, at 16, 32 and 64 bits (part of #118). Assemblers choose this form whenever one operand is the accumulator, and both engines used to stop on it with an illegal-instruction exit. A 16-bit exchange keeps the upper 48 bits of both registers, a 32-bit one clears both upper halves, and `49 90` exchanges RAX with R8 while plain `90` stays NOP. Both engines run the shared semantics; nothing is lowered to ARM64. Three SDM-derived cases already in `cpu_known_answers.rs` moved from refused to verified, and `tests/x86/integer.txt` gains 20 assembled instructions checked by the text-only reference in `x86_integer.rs`. F3 before this form, 16-bit PUSH and POP and LODSW stay rejected. Not compared with x86 hardware; awaiting independent review.
- Added RCL and RCR, the rotates through the carry flag, for 8-, 16-, 32- and 64-bit register and memory operands with a count of one, CL or an immediate (part of #121). The count is masked to five bits (six for 64-bit operands) and then reduced modulo 9 or 17 for 8- and 16-bit operands; a masked count of zero changes nothing, CF receives the last bit rotated out, and OF is set only for a count of one. Both engines run the shared semantics; nothing is lowered to ARM64. Fourteen SDM-derived cases already in `cpu_known_answers.rs` moved from refused to verified, and its shift sweep now runs both instructions at every width, count and carry against its bit-loop model. `tests/x86/integer.txt` gains 80 assembled RCL and RCR instructions, checked by the single-step reference in `x86_integer.rs`. SHLD and SHRD stay rejected. Not compared with x86 hardware; awaiting independent review.
- Added four Wave32 gfx1030 VOP2 select and carry forms through the semantic registry. Conditional select, add with carry and both subtract orders with borrow use a per-lane VCC bit and have a guide-derived oracle that passes on both CPU interpreters and on native Metal (local Apple M5, API and shader validation); independent acceptance is pending. Part of #215.
+4
View File
@@ -603,6 +603,10 @@ pub fn execute(
cpu.gpr[RSP] = sp.wrapping_add(8).wrapping_add(insn.imm);
}
Op::Nop => {}
// Every load and store of an instruction completes before the next
// instruction starts, on one host thread, so guest accesses are already
// totally ordered and a fence has nothing further to enforce.
Op::Lfence | Op::Mfence | Op::Sfence => {}
Op::Cpuid => {
// The leaf is EAX and the subleaf ECX. Each result is a 32-bit
// register write, so the upper halves are cleared.
+88 -58
View File
@@ -155,6 +155,9 @@ pub enum Op {
Pinsrw,
Pextrw,
Ldmxcsr,
Lfence,
Mfence,
Sfence,
Stmxcsr,
Sqrtps,
Sqrtpd,
@@ -211,7 +214,7 @@ pub enum Op {
}
impl Op {
pub const ALL: &[Op] = &[Op::Add, Op::Or, Op::Adc, Op::Sbb, Op::And, Op::Sub, Op::Xor, Op::Cmp, Op::Test, Op::Inc, Op::Dec, Op::Neg, Op::Not, Op::Mov, Op::Movzx, Op::Movsx, Op::Movsxd, Op::Lea, Op::Xchg, Op::Xadd, Op::Cmpxchg, Op::Bswap, Op::Cwde, Op::Cdq, Op::Rol, Op::Ror, Op::Rcl, Op::Rcr, Op::Shl, Op::Shr, Op::Sar, Op::Mul, Op::Imul, Op::Imul2, Op::Div, Op::Idiv, Op::Cmov, Op::Setcc, Op::Bt, Op::Bts, Op::Btr, Op::Btc, Op::Bsf, Op::Bsr, Op::Popcnt, Op::Tzcnt, Op::Lzcnt, Op::Push, Op::Pop, Op::Leave, Op::Call, Op::Jmp, Op::Jcc, Op::Ret, Op::Nop, Op::Hlt, Op::Syscall, Op::Clc, Op::Stc, Op::Cmc, Op::Cpuid, Op::Cld, Op::Std, Op::Movs, Op::Stos, Op::Movaps, Op::Movups, Op::Movdqa, Op::Movdqu, Op::Movntdq, Op::Movntps, Op::Movss, Op::Movsd, Op::Movq, Op::Movd, Op::Movlps, Op::Movhps, Op::Movmskps, Op::Movmskpd, Op::Pmovmskb, Op::Pand, Op::Pandn, Op::Por, Op::Pxor, Op::Punpcklbw, Op::Punpcklwd, Op::Punpckldq, Op::Packsswb, Op::Pcmpgtb, Op::Pcmpgtw, Op::Pcmpgtd, Op::Packuswb, Op::Punpckhbw, Op::Punpckhwd, Op::Punpckhdq, Op::Packssdw, Op::Punpcklqdq, Op::Punpckhqdq, Op::Pcmpeqb, Op::Pcmpeqw, Op::Pcmpeqd, Op::Paddq, Op::Pmullw, Op::Psubusb, Op::Psubusw, Op::Pminub, Op::Paddusb, Op::Paddusw, Op::Pmaxub, Op::Pavgb, Op::Pavgw, Op::Pmulhuw, Op::Pmulhw, Op::Psubsb, Op::Psubsw, Op::Pminsw, Op::Paddsb, Op::Paddsw, Op::Pmaxsw, Op::Pmuludq, Op::Pmaddwd, Op::Psadbw, Op::Psubb, Op::Psubw, Op::Psubd, Op::Psubq, Op::Paddb, Op::Paddw, Op::Paddd, Op::Psrlw, Op::Psraw, Op::Psllw, Op::Psrld, Op::Psrad, Op::Pslld, Op::Psrlq, Op::Psllq, Op::Psrldq, Op::Pslldq, Op::Pshufd, Op::Pshufhw, Op::Pshuflw, Op::Shufps, Op::Shufpd, Op::Pinsrw, Op::Pextrw, Op::Ldmxcsr, Op::Stmxcsr, Op::Sqrtps, Op::Sqrtpd, Op::Sqrtss, Op::Sqrtsd, Op::Addps, Op::Addpd, Op::Addss, Op::Addsd, Op::Mulps, Op::Mulpd, Op::Mulss, Op::Mulsd, Op::Subps, Op::Subpd, Op::Subss, Op::Subsd, Op::Minps, Op::Minpd, Op::Minss, Op::Minsd, Op::Divps, Op::Divpd, Op::Divss, Op::Divsd, Op::Maxps, Op::Maxpd, Op::Maxss, Op::Maxsd, Op::Cmpps, Op::Cmppd, Op::Cmpss, Op::Cmpsd, Op::Ucomiss, Op::Comiss, Op::Ucomisd, Op::Comisd, Op::Cvtps2pd, Op::Cvtpd2ps, Op::Cvtss2sd, Op::Cvtsd2ss, Op::Cvtdq2ps, Op::Cvtps2dq, Op::Cvttps2dq, Op::Cvttpd2dq, Op::Cvtdq2pd, Op::Cvtpd2dq, Op::Cvtsi2ss, Op::Cvttss2si, Op::Cvtss2si, Op::Cvtsi2sd, Op::Cvttsd2si, Op::Cvtsd2si];
pub const ALL: &[Op] = &[Op::Add, Op::Or, Op::Adc, Op::Sbb, Op::And, Op::Sub, Op::Xor, Op::Cmp, Op::Test, Op::Inc, Op::Dec, Op::Neg, Op::Not, Op::Mov, Op::Movzx, Op::Movsx, Op::Movsxd, Op::Lea, Op::Xchg, Op::Xadd, Op::Cmpxchg, Op::Bswap, Op::Cwde, Op::Cdq, Op::Rol, Op::Ror, Op::Rcl, Op::Rcr, Op::Shl, Op::Shr, Op::Sar, Op::Mul, Op::Imul, Op::Imul2, Op::Div, Op::Idiv, Op::Cmov, Op::Setcc, Op::Bt, Op::Bts, Op::Btr, Op::Btc, Op::Bsf, Op::Bsr, Op::Popcnt, Op::Tzcnt, Op::Lzcnt, Op::Push, Op::Pop, Op::Leave, Op::Call, Op::Jmp, Op::Jcc, Op::Ret, Op::Nop, Op::Hlt, Op::Syscall, Op::Clc, Op::Stc, Op::Cmc, Op::Cpuid, Op::Cld, Op::Std, Op::Movs, Op::Stos, Op::Movaps, Op::Movups, Op::Movdqa, Op::Movdqu, Op::Movntdq, Op::Movntps, Op::Movss, Op::Movsd, Op::Movq, Op::Movd, Op::Movlps, Op::Movhps, Op::Movmskps, Op::Movmskpd, Op::Pmovmskb, Op::Pand, Op::Pandn, Op::Por, Op::Pxor, Op::Punpcklbw, Op::Punpcklwd, Op::Punpckldq, Op::Packsswb, Op::Pcmpgtb, Op::Pcmpgtw, Op::Pcmpgtd, Op::Packuswb, Op::Punpckhbw, Op::Punpckhwd, Op::Punpckhdq, Op::Packssdw, Op::Punpcklqdq, Op::Punpckhqdq, Op::Pcmpeqb, Op::Pcmpeqw, Op::Pcmpeqd, Op::Paddq, Op::Pmullw, Op::Psubusb, Op::Psubusw, Op::Pminub, Op::Paddusb, Op::Paddusw, Op::Pmaxub, Op::Pavgb, Op::Pavgw, Op::Pmulhuw, Op::Pmulhw, Op::Psubsb, Op::Psubsw, Op::Pminsw, Op::Paddsb, Op::Paddsw, Op::Pmaxsw, Op::Pmuludq, Op::Pmaddwd, Op::Psadbw, Op::Psubb, Op::Psubw, Op::Psubd, Op::Psubq, Op::Paddb, Op::Paddw, Op::Paddd, Op::Psrlw, Op::Psraw, Op::Psllw, Op::Psrld, Op::Psrad, Op::Pslld, Op::Psrlq, Op::Psllq, Op::Psrldq, Op::Pslldq, Op::Pshufd, Op::Pshufhw, Op::Pshuflw, Op::Shufps, Op::Shufpd, Op::Pinsrw, Op::Pextrw, Op::Ldmxcsr, Op::Lfence, Op::Mfence, Op::Sfence, Op::Stmxcsr, Op::Sqrtps, Op::Sqrtpd, Op::Sqrtss, Op::Sqrtsd, Op::Addps, Op::Addpd, Op::Addss, Op::Addsd, Op::Mulps, Op::Mulpd, Op::Mulss, Op::Mulsd, Op::Subps, Op::Subpd, Op::Subss, Op::Subsd, Op::Minps, Op::Minpd, Op::Minss, Op::Minsd, Op::Divps, Op::Divpd, Op::Divss, Op::Divsd, Op::Maxps, Op::Maxpd, Op::Maxss, Op::Maxsd, Op::Cmpps, Op::Cmppd, Op::Cmpss, Op::Cmpsd, Op::Ucomiss, Op::Comiss, Op::Ucomisd, Op::Comisd, Op::Cvtps2pd, Op::Cvtpd2ps, Op::Cvtss2sd, Op::Cvtsd2ss, Op::Cvtdq2ps, Op::Cvtps2dq, Op::Cvttps2dq, Op::Cvttpd2dq, Op::Cvtdq2pd, Op::Cvtpd2dq, Op::Cvtsi2ss, Op::Cvttss2si, Op::Cvtss2si, Op::Cvtsi2sd, Op::Cvttsd2si, Op::Cvtsd2si];
/// Lower-case mnemonic stem.
pub const fn name(self) -> &'static str {
@@ -363,6 +366,9 @@ impl Op {
Op::Pinsrw => "pinsrw",
Op::Pextrw => "pextrw",
Op::Ldmxcsr => "ldmxcsr",
Op::Lfence => "lfence",
Op::Mfence => "mfence",
Op::Sfence => "sfence",
Op::Stmxcsr => "stmxcsr",
Op::Sqrtps => "sqrtps",
Op::Sqrtpd => "sqrtpd",
@@ -569,6 +575,9 @@ impl Op {
Op::Pinsrw => 0,
Op::Pextrw => 0,
Op::Ldmxcsr => 0,
Op::Lfence => 0,
Op::Mfence => 0,
Op::Sfence => 0,
Op::Stmxcsr => 0,
Op::Sqrtps => 0,
Op::Sqrtpd => 0,
@@ -775,6 +784,9 @@ impl Op {
Op::Pinsrw => 0,
Op::Pextrw => 0,
Op::Ldmxcsr => 0,
Op::Lfence => 0,
Op::Mfence => 0,
Op::Sfence => 0,
Op::Stmxcsr => 0,
Op::Sqrtps => 0,
Op::Sqrtpd => 0,
@@ -981,6 +993,9 @@ impl Op {
Op::Pinsrw => 0,
Op::Pextrw => 0,
Op::Ldmxcsr => 0,
Op::Lfence => 0,
Op::Mfence => 0,
Op::Sfence => 0,
Op::Stmxcsr => 0,
Op::Sqrtps => 0,
Op::Sqrtpd => 0,
@@ -1187,6 +1202,9 @@ impl Op {
Op::Pinsrw => 0,
Op::Pextrw => 0,
Op::Ldmxcsr => 0,
Op::Lfence => 0,
Op::Mfence => 0,
Op::Sfence => 0,
Op::Stmxcsr => 0,
Op::Sqrtps => 0,
Op::Sqrtpd => 0,
@@ -1393,6 +1411,9 @@ impl Op {
Op::Pinsrw => false,
Op::Pextrw => false,
Op::Ldmxcsr => false,
Op::Lfence => false,
Op::Mfence => false,
Op::Sfence => false,
Op::Stmxcsr => false,
Op::Sqrtps => false,
Op::Sqrtpd => false,
@@ -1599,6 +1620,9 @@ impl Op {
Op::Pinsrw => false,
Op::Pextrw => false,
Op::Ldmxcsr => false,
Op::Lfence => false,
Op::Mfence => false,
Op::Sfence => false,
Op::Stmxcsr => false,
Op::Sqrtps => true,
Op::Sqrtpd => true,
@@ -1805,6 +1829,9 @@ impl Op {
Op::Pinsrw => true,
Op::Pextrw => true,
Op::Ldmxcsr => false,
Op::Lfence => false,
Op::Mfence => false,
Op::Sfence => false,
Op::Stmxcsr => false,
Op::Sqrtps => true,
Op::Sqrtpd => true,
@@ -1862,7 +1889,7 @@ impl Op {
}
}
pub static FORMS: [Form; 388] = [
pub static FORMS: [Form; 391] = [
Form { op: Op::Movsxd, encoding: Encoding::RegRm, size: OperandSize::Wide, immediate: Immediate::None, source: 4, has_modrm: true, memory_only: false, register_only: false, no_rex_b: false, unaligned: false, lockable: false },
Form { op: Op::Push, encoding: Encoding::OpReg, size: OperandSize::Quad, immediate: Immediate::None, source: 0, has_modrm: false, memory_only: false, register_only: false, no_rex_b: false, unaligned: false, lockable: false },
Form { op: Op::Pop, encoding: Encoding::OpReg, size: OperandSize::Quad, immediate: Immediate::None, source: 0, has_modrm: false, memory_only: false, register_only: false, no_rex_b: false, unaligned: false, lockable: false },
@@ -2065,6 +2092,9 @@ pub static FORMS: [Form; 388] = [
Form { op: Op::Pextrw, encoding: Encoding::RegXmmImm, size: OperandSize::Wide, immediate: Immediate::Byte, source: 16, has_modrm: true, memory_only: false, register_only: true, no_rex_b: false, unaligned: false, lockable: false },
Form { op: Op::Ldmxcsr, encoding: Encoding::Rm, size: OperandSize::None, immediate: Immediate::None, source: 4, has_modrm: true, memory_only: true, register_only: false, no_rex_b: false, unaligned: false, lockable: false },
Form { op: Op::Stmxcsr, encoding: Encoding::Rm, size: OperandSize::None, immediate: Immediate::None, source: 4, has_modrm: true, memory_only: true, register_only: false, no_rex_b: false, unaligned: false, lockable: false },
Form { op: Op::Lfence, encoding: Encoding::RmUnread, size: OperandSize::None, immediate: Immediate::None, source: 0, has_modrm: true, memory_only: false, register_only: true, no_rex_b: false, unaligned: false, lockable: false },
Form { op: Op::Mfence, encoding: Encoding::RmUnread, size: OperandSize::None, immediate: Immediate::None, source: 0, has_modrm: true, memory_only: false, register_only: true, no_rex_b: false, unaligned: false, lockable: false },
Form { op: Op::Sfence, encoding: Encoding::RmUnread, size: OperandSize::None, immediate: Immediate::None, source: 0, has_modrm: true, memory_only: false, register_only: true, no_rex_b: false, unaligned: false, lockable: false },
Form { op: Op::Sqrtps, encoding: Encoding::XmmRm, size: OperandSize::Xmm, immediate: Immediate::None, source: 16, has_modrm: true, memory_only: false, register_only: false, no_rex_b: false, unaligned: false, lockable: false },
Form { op: Op::Sqrtpd, encoding: Encoding::XmmRm, size: OperandSize::Xmm, immediate: Immediate::None, source: 16, has_modrm: true, memory_only: false, register_only: false, no_rex_b: false, unaligned: false, lockable: false },
Form { op: Op::Sqrtss, encoding: Encoding::XmmRm, size: OperandSize::Xmm, immediate: Immediate::None, source: 4, has_modrm: true, memory_only: false, register_only: false, no_rex_b: false, unaligned: false, lockable: false },
@@ -2255,47 +2285,47 @@ pub static FORMS: [Form; 388] = [
/// Form per ModRM digit; 65535 marks an unsupported digit.
pub static GROUPS: [[u16; 8]; 22] = [
[260, 269, 278, 287, 296, 305, 314, 323],
[261, 270, 279, 288, 297, 306, 315, 324],
[262, 271, 280, 289, 298, 307, 316, 325],
[263, 272, 281, 290, 299, 308, 317, 326],
[264, 273, 282, 291, 300, 309, 318, 327],
[265, 274, 283, 292, 301, 310, 319, 328],
[6, 65535, 65535, 65535, 65535, 65535, 65535, 65535],
[346, 347, 348, 349, 350, 351, 65535, 352],
[353, 354, 355, 356, 357, 358, 65535, 359],
[349, 350, 351, 352, 353, 354, 65535, 355],
[356, 357, 358, 359, 360, 361, 65535, 362],
[40, 65535, 65535, 65535, 65535, 65535, 65535, 65535],
[41, 65535, 65535, 65535, 65535, 65535, 65535, 65535],
[360, 361, 362, 363, 364, 365, 65535, 366],
[367, 368, 369, 370, 371, 372, 65535, 373],
[374, 375, 376, 377, 378, 379, 65535, 380],
[381, 382, 383, 384, 385, 386, 65535, 387],
[18, 65535, 330, 331, 332, 333, 334, 335],
[19, 65535, 336, 337, 338, 339, 340, 341],
[342, 343, 65535, 65535, 65535, 65535, 65535, 65535],
[344, 345, 48, 65535, 49, 65535, 5, 65535],
[363, 364, 365, 366, 367, 368, 65535, 369],
[370, 371, 372, 373, 374, 375, 65535, 376],
[377, 378, 379, 380, 381, 382, 65535, 383],
[384, 385, 386, 387, 388, 389, 65535, 390],
[18, 65535, 333, 334, 335, 336, 337, 338],
[19, 65535, 339, 340, 341, 342, 343, 344],
[345, 346, 65535, 65535, 65535, 65535, 65535, 65535],
[347, 348, 48, 65535, 49, 65535, 5, 65535],
[35, 65535, 65535, 65535, 65535, 65535, 65535, 65535],
[65535, 65535, 200, 201, 65535, 65535, 65535, 65535],
[65535, 65535, 65535, 65535, 326, 327, 328, 329],
[65535, 65535, 200, 201, 65535, 202, 203, 204],
[65535, 65535, 65535, 65535, 329, 330, 331, 332],
[65535, 65535, 172, 65535, 174, 65535, 176, 65535],
[65535, 65535, 178, 65535, 180, 65535, 182, 65535],
[65535, 65535, 184, 187, 65535, 65535, 186, 188],
];
pub static ONE_BYTE: [Entry; 256] = [
Entry::Form(254), Entry::Form(255), Entry::Form(256), Entry::Form(257),
Entry::Form(258), Entry::Form(259), Entry::Unsupported, Entry::Unsupported,
Entry::Form(263), Entry::Form(264), Entry::Form(265), Entry::Form(266),
Entry::Form(267), Entry::Form(268), Entry::Unsupported, Entry::Unsupported,
Entry::Form(272), Entry::Form(273), Entry::Form(274), Entry::Form(275),
Entry::Form(276), Entry::Form(277), Entry::Unsupported, Entry::Unsupported,
Entry::Form(281), Entry::Form(282), Entry::Form(283), Entry::Form(284),
Entry::Form(285), Entry::Form(286), Entry::Unsupported, Entry::Unsupported,
Entry::Form(290), Entry::Form(291), Entry::Form(292), Entry::Form(293),
Entry::Form(294), Entry::Form(295), Entry::Unsupported, Entry::Unsupported,
Entry::Form(299), Entry::Form(300), Entry::Form(301), Entry::Form(302),
Entry::Form(303), Entry::Form(304), Entry::Unsupported, Entry::Unsupported,
Entry::Form(308), Entry::Form(309), Entry::Form(310), Entry::Form(311),
Entry::Form(312), Entry::Form(313), Entry::Unsupported, Entry::Unsupported,
Entry::Form(317), Entry::Form(318), Entry::Form(319), Entry::Form(320),
Entry::Form(321), Entry::Form(322), Entry::Unsupported, Entry::Unsupported,
Entry::Form(257), Entry::Form(258), Entry::Form(259), Entry::Form(260),
Entry::Form(261), Entry::Form(262), Entry::Unsupported, Entry::Unsupported,
Entry::Form(266), Entry::Form(267), Entry::Form(268), Entry::Form(269),
Entry::Form(270), Entry::Form(271), Entry::Unsupported, Entry::Unsupported,
Entry::Form(275), Entry::Form(276), Entry::Form(277), Entry::Form(278),
Entry::Form(279), Entry::Form(280), Entry::Unsupported, Entry::Unsupported,
Entry::Form(284), Entry::Form(285), Entry::Form(286), Entry::Form(287),
Entry::Form(288), Entry::Form(289), Entry::Unsupported, Entry::Unsupported,
Entry::Form(293), Entry::Form(294), Entry::Form(295), Entry::Form(296),
Entry::Form(297), Entry::Form(298), Entry::Unsupported, Entry::Unsupported,
Entry::Form(302), Entry::Form(303), Entry::Form(304), Entry::Form(305),
Entry::Form(306), Entry::Form(307), Entry::Unsupported, Entry::Unsupported,
Entry::Form(311), Entry::Form(312), Entry::Form(313), Entry::Form(314),
Entry::Form(315), Entry::Form(316), Entry::Unsupported, Entry::Unsupported,
Entry::Form(320), Entry::Form(321), Entry::Form(322), Entry::Form(323),
Entry::Form(324), Entry::Form(325), Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
@@ -2358,7 +2388,7 @@ pub static TWO_BYTE: [Entry; 256] = [
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Form(80), Entry::Form(81), Entry::Unsupported, Entry::Form(93),
Entry::Unsupported, Entry::Unsupported, Entry::Form(234), Entry::Form(235),
Entry::Unsupported, Entry::Unsupported, Entry::Form(237), Entry::Form(238),
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
@@ -2367,10 +2397,10 @@ pub static TWO_BYTE: [Entry; 256] = [
Entry::Form(12), Entry::Form(12), Entry::Form(12), Entry::Form(12),
Entry::Form(12), Entry::Form(12), Entry::Form(12), Entry::Form(12),
Entry::Form(12), Entry::Form(12), Entry::Form(12), Entry::Form(12),
Entry::Form(111), Entry::Form(202), Entry::Unsupported, Entry::Unsupported,
Entry::Form(111), Entry::Form(205), Entry::Unsupported, Entry::Unsupported,
Entry::Form(115), Entry::Form(118), Entry::Form(121), Entry::Form(124),
Entry::Form(206), Entry::Form(210), Entry::Form(238), Entry::Form(242),
Entry::Form(214), Entry::Form(218), Entry::Form(222), Entry::Form(226),
Entry::Form(209), Entry::Form(213), Entry::Form(241), Entry::Form(245),
Entry::Form(217), Entry::Form(221), Entry::Form(225), Entry::Form(229),
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
@@ -2395,7 +2425,7 @@ pub static TWO_BYTE: [Entry; 256] = [
Entry::Unsupported, Entry::Unsupported, Entry::Form(62), Entry::Form(63),
Entry::Unsupported, Entry::Unsupported, Entry::Group(18), Entry::Form(75),
Entry::Form(67), Entry::Form(68), Entry::Form(64), Entry::Form(65),
Entry::Form(78), Entry::Form(79), Entry::Form(230), Entry::Unsupported,
Entry::Form(78), Entry::Form(79), Entry::Form(233), Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Form(192), Entry::Unsupported,
Entry::Form(66), Entry::Form(66), Entry::Form(66), Entry::Form(66),
Entry::Form(66), Entry::Form(66), Entry::Form(66), Entry::Form(66),
@@ -2425,7 +2455,7 @@ pub static TWO_BYTE_66: [Entry; 256] = [
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Form(82), Entry::Form(83), Entry::Unsupported, Entry::Form(94),
Entry::Unsupported, Entry::Unsupported, Entry::Form(236), Entry::Form(237),
Entry::Unsupported, Entry::Unsupported, Entry::Form(239), Entry::Form(240),
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
@@ -2434,10 +2464,10 @@ pub static TWO_BYTE_66: [Entry; 256] = [
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Form(112), Entry::Form(203), Entry::Unsupported, Entry::Unsupported,
Entry::Form(112), Entry::Form(206), Entry::Unsupported, Entry::Unsupported,
Entry::Form(116), Entry::Form(119), Entry::Form(122), Entry::Form(125),
Entry::Form(207), Entry::Form(211), Entry::Form(239), Entry::Form(243),
Entry::Form(215), Entry::Form(219), Entry::Form(223), Entry::Form(227),
Entry::Form(210), Entry::Form(214), Entry::Form(242), Entry::Form(246),
Entry::Form(218), Entry::Form(222), Entry::Form(226), Entry::Form(230),
Entry::Form(126), Entry::Form(127), Entry::Form(128), Entry::Form(129),
Entry::Form(130), Entry::Form(131), Entry::Form(132), Entry::Form(133),
Entry::Form(134), Entry::Form(135), Entry::Form(136), Entry::Form(137),
@@ -2462,7 +2492,7 @@ pub static TWO_BYTE_66: [Entry; 256] = [
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Form(231), Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Form(234), Entry::Unsupported,
Entry::Form(198), Entry::Form(199), Entry::Form(193), Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
@@ -2471,7 +2501,7 @@ pub static TWO_BYTE_66: [Entry; 256] = [
Entry::Form(145), Entry::Form(146), Entry::Form(147), Entry::Form(114),
Entry::Form(148), Entry::Form(149), Entry::Form(150), Entry::Form(117),
Entry::Form(151), Entry::Form(173), Entry::Form(179), Entry::Form(152),
Entry::Form(153), Entry::Form(154), Entry::Form(245), Entry::Form(92),
Entry::Form(153), Entry::Form(154), Entry::Form(248), Entry::Form(92),
Entry::Form(155), Entry::Form(156), Entry::Form(157), Entry::Form(120),
Entry::Form(158), Entry::Form(159), Entry::Form(160), Entry::Form(123),
Entry::Unsupported, Entry::Form(175), Entry::Form(181), Entry::Form(185),
@@ -2491,8 +2521,8 @@ pub static TWO_BYTE_F3: [Entry; 256] = [
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Form(248), Entry::Unsupported,
Entry::Form(249), Entry::Form(250), Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Form(251), Entry::Unsupported,
Entry::Form(252), Entry::Form(253), Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
@@ -2501,10 +2531,10 @@ pub static TWO_BYTE_F3: [Entry; 256] = [
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Form(204), Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Form(207), Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Form(208), Entry::Form(212), Entry::Form(240), Entry::Form(244),
Entry::Form(216), Entry::Form(220), Entry::Form(224), Entry::Form(228),
Entry::Form(211), Entry::Form(215), Entry::Form(243), Entry::Form(247),
Entry::Form(219), Entry::Form(223), Entry::Form(227), Entry::Form(231),
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
@@ -2529,7 +2559,7 @@ pub static TWO_BYTE_F3: [Entry; 256] = [
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Form(69), Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Form(70), Entry::Form(71), Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Form(232), Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Form(235), Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
@@ -2538,7 +2568,7 @@ pub static TWO_BYTE_F3: [Entry; 256] = [
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Form(246), Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Form(249), Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
@@ -2558,8 +2588,8 @@ pub static TWO_BYTE_F2: [Entry; 256] = [
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Form(251), Entry::Unsupported,
Entry::Form(252), Entry::Form(253), Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Form(254), Entry::Unsupported,
Entry::Form(255), Entry::Form(256), Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
@@ -2568,10 +2598,10 @@ pub static TWO_BYTE_F2: [Entry; 256] = [
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Form(205), Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Form(208), Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Form(209), Entry::Form(213), Entry::Form(241), Entry::Unsupported,
Entry::Form(217), Entry::Form(221), Entry::Form(225), Entry::Form(229),
Entry::Form(212), Entry::Form(216), Entry::Form(244), Entry::Unsupported,
Entry::Form(220), Entry::Form(224), Entry::Form(228), Entry::Form(232),
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
@@ -2596,7 +2626,7 @@ pub static TWO_BYTE_F2: [Entry; 256] = [
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Form(233), Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Form(236), Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
@@ -2605,7 +2635,7 @@ pub static TWO_BYTE_F2: [Entry; 256] = [
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Form(247), Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Form(250), Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
Entry::Unsupported, Entry::Unsupported, Entry::Unsupported, Entry::Unsupported,
+16 -16
View File
@@ -199,15 +199,15 @@ fn reported_features_have_all_their_instructions_in_the_fixtures() {
fn unreported_features_each_have_an_instruction_that_is_refused() {
// (feature, leaf, result register, bit, an instruction of that feature)
let witnesses: &[(&str, u32, usize, u32, &[u8])] = &[
("FPU", 1, EDX, 0, &[0xD9, 0xE8]), // fld1
("TSC", 1, EDX, 4, &[0x0F, 0x31]), // rdtsc
("CX8", 1, EDX, 8, &[0x0F, 0xC7, 0x0E]), // cmpxchg8b [rsi]
("CLFSH", 1, EDX, 19, &[0x0F, 0xAE, 0x3E]), // clflush [rsi]
("MMX", 1, EDX, 23, &[0x0F, 0x77]), // emms
("FXSR", 1, EDX, 24, &[0x0F, 0xAE, 0x06]), // fxsave [rsi]
("SSE", 1, EDX, 25, &[0x0F, 0x52, 0xC1]), // rsqrtps xmm0, xmm1
("SSE2", 1, EDX, 26, &[0x0F, 0xAE, 0xF0]), // mfence
("SSE3", 1, ECX, 0, &[0xF2, 0x0F, 0x7C, 0xC1]), // haddps xmm0, xmm1
("FPU", 1, EDX, 0, &[0xD9, 0xE8]), // fld1
("TSC", 1, EDX, 4, &[0x0F, 0x31]), // rdtsc
("CX8", 1, EDX, 8, &[0x0F, 0xC7, 0x0E]), // cmpxchg8b [rsi]
("CLFSH", 1, EDX, 19, &[0x0F, 0xAE, 0x3E]), // clflush [rsi]
("MMX", 1, EDX, 23, &[0x0F, 0x77]), // emms
("FXSR", 1, EDX, 24, &[0x0F, 0xAE, 0x06]), // fxsave [rsi]
("SSE", 1, EDX, 25, &[0x0F, 0x52, 0xC1]), // rsqrtps xmm0, xmm1
("SSE2", 1, EDX, 26, &[0x66, 0x0F, 0xF7, 0xC1]), // maskmovdqu xmm0, xmm1
("SSE3", 1, ECX, 0, &[0xF2, 0x0F, 0x7C, 0xC1]), // haddps xmm0, xmm1
(
"PCLMULQDQ",
1,
@@ -222,17 +222,17 @@ fn unreported_features_each_have_an_instruction_that_is_refused() {
("SSE4.2", 1, ECX, 20, &[0xF2, 0x0F, 0x38, 0xF1, 0xC1]), // crc32 eax, ecx
("MOVBE", 1, ECX, 22, &[0x0F, 0x38, 0xF0, 0x06]), // movbe eax, [rsi]
("AESNI", 1, ECX, 25, &[0x66, 0x0F, 0x38, 0xDC, 0xC1]), // aesenc xmm0, xmm1
("XSAVE", 1, ECX, 26, &[0x0F, 0x01, 0xD0]), // xgetbv
("AVX", 1, ECX, 28, &[0xC5, 0xF4, 0x58, 0xC2]), // vaddps ymm0, ymm1, ymm2
("XSAVE", 1, ECX, 26, &[0x0F, 0x01, 0xD0]), // xgetbv
("AVX", 1, ECX, 28, &[0xC5, 0xF4, 0x58, 0xC2]), // vaddps ymm0, ymm1, ymm2
("F16C", 1, ECX, 29, &[0xC4, 0xE2, 0x79, 0x13, 0xC1]), // vcvtph2ps xmm0, xmm1
("RDRAND", 1, ECX, 30, &[0x0F, 0xC7, 0xF0]), // rdrand eax
("RDRAND", 1, ECX, 30, &[0x0F, 0xC7, 0xF0]), // rdrand eax
("BMI1", 7, EBX, 3, &[0xC4, 0xE2, 0x70, 0xF2, 0xC2]), // andn eax, ecx, edx
("AVX2", 7, EBX, 5, &[0xC5, 0xF5, 0xFE, 0xC2]), // vpaddd ymm0, ymm1, ymm2
("AVX2", 7, EBX, 5, &[0xC5, 0xF5, 0xFE, 0xC2]), // vpaddd ymm0, ymm1, ymm2
("BMI2", 7, EBX, 8, &[0xC4, 0xE2, 0x73, 0xF6, 0xC2]), // mulx eax, ecx, edx
("RDSEED", 7, EBX, 18, &[0x0F, 0xC7, 0xF8]), // rdseed eax
("RDSEED", 7, EBX, 18, &[0x0F, 0xC7, 0xF8]), // rdseed eax
("ADX", 7, EBX, 19, &[0x66, 0x0F, 0x38, 0xF6, 0xC1]), // adcx eax, ecx
("SHA", 7, EBX, 29, &[0x0F, 0x38, 0xC9, 0xC1]), // sha1msg1 xmm0, xmm1
("LAHF/SAHF", 0x8000_0001, ECX, 0, &[0x9F]), // lahf
("SHA", 7, EBX, 29, &[0x0F, 0x38, 0xC9, 0xC1]), // sha1msg1 xmm0, xmm1
("LAHF/SAHF", 0x8000_0001, ECX, 0, &[0x9F]), // lahf
("PREFETCHW", 0x8000_0001, ECX, 8, &[0x0F, 0x0D, 0x0E]), // prefetchw [rsi]
("SYSCALL/SYSRET", 0x8000_0001, EDX, 11, &[0x48, 0x0F, 0x07]), // sysretq
("RDTSCP", 0x8000_0001, EDX, 27, &[0x0F, 0x01, 0xF9]), // rdtscp
+33
View File
@@ -1365,6 +1365,33 @@ mov_moffs8_store: rax=77 m0=00000000 => m0=00000077 f=*
thirteen_byte_fs_add_imm32: rax=10 rbx=8 fs120=0000000000000000 => fs120=4433221100000000 f=cPazso
";
/// Single-thread baseline for the fences (#199). Each engine completes every
/// load and store of an instruction before the next instruction starts, so the
/// cases only require that a fence changes nothing and that accesses on either
/// side of it happen in program order. Nothing here involves a second thread.
const FENCES: &str = r"
@ mov [rdi], rax; mfence; mov rbx, [rdi]
488907 0faef0 488b1f
SDM 2B MFENCE
mfence_store_is_visible_to_a_later_load: rdi=D rax=1122334455667788 m0=0000000000000000 => rbx=1122334455667788 m0=8877665544332211 f=*
@ mov [rdi], rax; sfence; mov rbx, [rdi+8]
488907 0faef8 488b5f08
SDM 2B SFENCE
sfence_after_a_store_keeps_other_memory: rdi=D rax=1 m0=0000000000000000 m8=aabbccddeeff0011 => rbx=1100ffeeddccbbaa m0=0100000000000000 f=*
@ mov rbx, [rdi]; lfence; mov [rdi], rax
488b1f 0faee8 488907
SDM 2B LFENCE
lfence_load_precedes_a_later_store: rdi=D rax=5 m0=0200000000000000 => rbx=2 m0=0500000000000000 f=*
@ mfence; lfence; sfence
0faef0 0faee8 0faef8
SDM 2B MFENCE; 2B LFENCE; 2B SFENCE
fences_change_no_register_or_flag: rax=1122334455667788 rbx=99aabbccddeeff00 => f=*
@ .byte 0x0f,0xae,0xf5; .byte 0x0f,0xae,0xeb; .byte 0x0f,0xae,0xff
0faef5 0faeeb 0faeff
SDM 2B MFENCE; 2B LFENCE; 2B SFENCE (the r/m field is ignored)
fences_ignore_the_rm_field: rax=1122334455667788 => f=*
";
const MEMORY_FAULTS: &str = r"
@ mov r8d, 1; add al, bl; mov rcx, [rsi]; mov r9d, 2
41b801000000 00d8 !488b0e 41b902000000
@@ -2646,6 +2673,7 @@ const GROUPS: &[(&str, &str)] = &[
("strings", STRINGS),
("fs_gs", FS_GS),
("decoding", DECODING),
("fences", FENCES),
("memory_faults", MEMORY_FAULTS),
(
"defect_straddling_fault_address",
@@ -3428,6 +3456,11 @@ fn decoding() {
check_group(DECODING);
}
#[test]
fn fences() {
check_group(FENCES);
}
#[test]
fn memory_faults() {
check_group(MEMORY_FAULTS);
+1 -1
View File
@@ -96,7 +96,7 @@ def cases():
out += ["mov ah, bl", "mov dl, ch", "mov bh, 0x21", "xchg ah, bl", "mov sil, dil",
"movabs r15, 0x8877665544332211", "mov rcx, -2", "bswap ebx", "bswap r9",
"cbw", "cwde", "cdqe", "cwd", "cdq", "cqo", "clc", "stc", "cmc", "nop", "cpuid",
"nop dword ptr [rax + 8]", "pause", "push r9", "push rbx", "push -5", "push 0x12345678",
"nop dword ptr [rax + 8]", "pause", "lfence", "mfence", "sfence", "push r9", "push rbx", "push -5", "push 0x12345678",
f"push {mem(64)}", "pop rbx", "pop r12", f"pop {mem(64)}", "leave"]
# The accumulator short form of XCHG: 91..97, and 90 with REX.B.
for index in range(1, 16):
+3
View File
@@ -1117,6 +1117,9 @@ f5 | cmc
0f a2 | cpuid
0f 1f 40 08 | nop dword ptr [rax + 8]
f3 90 | pause
0f ae e8 | lfence
0f ae f0 | mfence
0f ae f8 | sfence
41 51 | push r9
53 | push rbx
6a fb | push -5
+4 -1
View File
@@ -738,7 +738,8 @@ fn reference(m: &mut Machine, text: &str) -> Outcome {
m.flags.cf = !m.flags.cf;
Outcome::Done(none)
}
"nop" | "pause" => Outcome::Done(none),
// The fences order memory accesses and compute nothing.
"nop" | "pause" | "lfence" | "mfence" | "sfence" => Outcome::Done(none),
"cpuid" => {
// Xenora's guest CPUID contract, restated: the vendor "Xenora guest"
// and the four features whose every instruction exists, CMOV and
@@ -1234,6 +1235,8 @@ fn undeclared_and_ambiguous_encodings_are_rejected() {
&[0x66, 0x63, 0xC1], // 16-bit movsxd
&[0xF3, 0x41, 0x90], // F3 on xchg r8, rax
&[0x8D, 0xC0], // lea with a register operand
&[0x0F, 0xAE, 0x2E], // 0F AE /5 with a memory operand
&[0x0F, 0xAE, 0x36], // 0F AE /6 with a memory operand
&[0x0F, 0xA3, 0x06], // bt [rsi], eax
&[0xC6, 0xC8, 0x01], // C6 /1
&[0xFF, 0xF8], // FF /7
+33
View File
@@ -185,6 +185,9 @@ shufpd = { ref = "sdm SHUFPD" }
pinsrw = { ref = "sdm PINSRW" }
pextrw = { ref = "sdm PEXTRW" }
ldmxcsr = { ref = "sdm LDMXCSR" }
lfence = { ref = "sdm LFENCE" }
mfence = { ref = "sdm MFENCE" }
sfence = { ref = "sdm SFENCE" }
stmxcsr = { ref = "sdm STMXCSR" }
# Floating point. Every form can raise a SIMD floating-point exception.
@@ -1967,6 +1970,36 @@ size = "n"
src = "d"
memory_only = true
# The fences are the register forms of digits 5 to 7; the r/m field is ignored.
# The memory forms of those digits (the XSAVE family and CLFLUSH) are not
# declared.
[[form]]
op = "lfence"
map = "0f"
opcode = 0xAE
digit = 5
enc = "rm_unread"
size = "n"
register_only = true
[[form]]
op = "mfence"
map = "0f"
opcode = 0xAE
digit = 6
enc = "rm_unread"
size = "n"
register_only = true
[[form]]
op = "sfence"
map = "0f"
opcode = 0xAE
digit = 7
enc = "rm_unread"
size = "n"
register_only = true
# SSE and SSE2 floating-point forms. RCP and RSQRT approximations are not
# architecturally exact and are left out.
+10 -2
View File
@@ -60,6 +60,14 @@ These rules hold for both engines and are what a guest scheduler has to preserve
The SDM cases for these forms in `tests/cpu_known_answers.rs` were written before this implementation, by another contributor. `tests/x86_atomic.rs` adds the LOCK rules, both compare outcomes at every width, unaligned operands and faults. None of it has been compared with x86 hardware, and nothing here establishes multi-thread behaviour.
## Memory ordering and fences
Guest memory accesses are totally ordered today. Each engine runs one guest instruction at a time on one host thread, and every load and store of an instruction completes before the next instruction starts. There is no store buffer and nothing is reordered, so a load always sees the latest earlier store. That is stronger than the ordering the Intel SDM (Vol. 3A, "Memory Ordering") gives a real processor, where a store may sit in a buffer while later loads from other locations run.
MFENCE, LFENCE and SFENCE (`0F AE` with a register ModRM byte and digit 6, 5 or 7; the SDM states that the r/m field is ignored) are therefore accepted and change no register, flag or memory. They have nothing left to enforce. Non-temporal stores are ordinary stores, so SFENCE has no weakly ordered store to wait for either. The memory forms that share those digits, the XSAVE family and CLFLUSH, stay rejected.
This holds only while guest threads do not run on several host threads. ARM64 orders memory more weakly than x86, so an engine that ran guest threads in parallel would have to restore x86's ordering for ordinary accesses and give the fences a real effect. Nothing here provides or tests that. `tests/cpu_known_answers.rs` holds the single-thread cases: a store, a fence and a later load in program order, and no change to any other state. None of it has been compared with x86 hardware.
## String instructions
MOVS and STOS exist for 8-, 16-, 32- and 64-bit elements, alone and with REP (F3), together with the direction flag and CLD and STD. `CpuState::df` holds the flag. It is not one of the six status flags the registry tracks.
@@ -86,7 +94,7 @@ CPUID (`0F A2`) returns a fixed table that never reads the host. It describes a
A feature bit is set only when every instruction of that feature is implemented. That is stricter than "some of it works", and it has consequences:
- SSE and SSE2 are not reported, although most of their instructions exist, because parts are still rejected: RSQRTPS and MFENCE, for example. BMI1 is not reported although TZCNT exists, because ANDN does not. The x87 FPU, MMX, FXSAVE, CMPXCHG8B, the time-stamp counter, LAHF and SYSRET are absent too.
- SSE and SSE2 are not reported, although most of their instructions exist, because parts are still rejected: RSQRTPS and MASKMOVDQU, for example. BMI1 is not reported although TZCNT exists, because ANDN does not. The x87 FPU, MMX, FXSAVE, CMPXCHG8B, the time-stamp counter, LAHF and SYSRET are absent too.
- The table is therefore truthful about Xenora, not plausible as hardware: every real 64-bit processor reports the FPU and SSE2. A guest that tests a bit before using a feature avoids it; a guest that assumes SSE2 because it runs in 64-bit mode still gets every form that exists and an illegal-instruction exit for one that does not.
- A leaf that is not listed returns zeros, whatever the subleaf. Intel processors answer a leaf above the highest basic one with that leaf's data instead; software is expected to read the highest leaf first.
@@ -96,4 +104,4 @@ A feature bit is set only when every instruction of that feature is implemented.
## Rejected on purpose
LOCK except as described above, F2 or F3 where it is neither PAUSE nor part of a declared form, F2 combined with F3, address-size overrides, an ignored segment override after FS or GS, 16-bit stack and branch forms, 16-bit BSWAP and MOVSXD, bit tests of memory by a register index, SHLD, SHRD, LODS, CMPS, SCAS, REPE and REPNE, MMX, the RCP and RSQRT approximations, SSE3 and later, VEX, CMPXCHG8B, CMPXCHG16B and fences. The DBT also refuses raw SYSCALL.
LOCK except as described above, F2 or F3 where it is neither PAUSE nor part of a declared form, F2 combined with F3, address-size overrides, an ignored segment override after FS or GS, 16-bit stack and branch forms, 16-bit BSWAP and MOVSXD, bit tests of memory by a register index, SHLD, SHRD, LODS, CMPS, SCAS, REPE and REPNE, MMX, the RCP and RSQRT approximations, SSE3 and later, VEX, CMPXCHG8B and CMPXCHG16B. The DBT also refuses raw SYSCALL.