OpCodes.Unaligned 字段

定义

指示当前位于计算堆栈上的地址可能没有与紧接的 ldindstindldfldstfldldobjstobjinitblkcpblk 指令的自然大小对齐。Indicates that an address currently atop the evaluation stack might not be aligned to the natural size of the immediately following ldind, stind, ldfld, stfld, ldobj, stobj, initblk, or cpblk instruction.

public: static initonly System::Reflection::Emit::OpCode Unaligned;
public static readonly System.Reflection.Emit.OpCode Unaligned;
 staticval mutable Unaligned : System.Reflection.Emit.OpCode
Public Shared ReadOnly Unaligned As OpCode 

字段值

注解

下表列出了指令的十六进制和 Microsoft 中间语言(MSIL)程序集格式以及简短的参考摘要:The following table lists the instruction's hexadecimal and Microsoft Intermediate Language (MSIL) assembly format, along with a brief reference summary:

格式Format 程序集格式Assembly Format 说明Description
FE 12 < unsigned int8 @ NO__T-1FE 12 < unsigned int8 > 未对齐.unaligned. alignment 指示后面的指针指令可能是不对齐的。Indicates that the subsequent pointer instruction may be unaligned.

堆栈转换行为顺序如下:The stack transitional behavior, in sequential order, is:

  1. 地址被推送到堆栈上。An address is pushed onto the stack.

@no__t 指定,则不会将堆栈上的地址(非托管指针,native int)与紧随其后 ldindstindldfldstfldldobjstobj,@no__t 或 @no__t 说明的自然大小对齐。Unaligned specifies that the address (an unmanaged pointer, native int) on the stack might not be aligned to the natural size of the immediately following ldind, stind, ldfld, stfld, ldobj, stobj, initblk, or cpblk instruction. 也就是说,对于 Ldind_I4 指令,地址的对齐可能不是4字节边界。That is, for a Ldind_I4 instruction the alignment of the address may not be to a 4-byte boundary. 对于 initblkcpblk,默认对齐方式取决于体系结构依赖(32位 Cpu 上的4个字节,64位 Cpu 上的8个字节)。For initblk and cpblk the default alignment is architecture dependent (4-byte on 32-bit CPUs, 8-byte on 64-bit CPUs). 如果在编译时不知道对齐方式为8字节,则不会将其输出限制为32位字的代码生成器必须使用 unalignedCode generators that do not restrict their output to a 32-bit word size must use unaligned if the alignment is not known at compile time to be 8-byte.

"对齐" 的值必须是1、2或4,这意味着生成的代码应分别假定地址是字节、双字节或4字节对齐。The value of alignment must be 1, 2, or 4 and means that the generated code should assume that the address is byte, double-byte, or quad-byte aligned, respectively. 请注意,临时指针(类型 *)始终对齐。Note that transient pointers (type *) are always aligned.

尽管 cpblk 指令的对齐在逻辑上需要两个数字(一个用于源,另一个用于目标),但如果只指定了较小的数字,则不会对性能产生显著影响。While the alignment for a cpblk instruction would logically require two numbers (one for the source and one for the destination), there is no noticeable impact on performance if only the lower number is specified.

可以按任意顺序组合 @no__t 0 和 @no__t 前缀。The unaligned and volatile prefixes can be combined in either order. 它们必须紧跟在 ldindstindldfldstfldldobjstobjinitblk 或 @no__t 7 指令之前。They must immediately precede a ldind, stind, ldfld, stfld, ldobj, stobj, initblk, or cpblk instruction. 对于 Ldsfld 和 @no__t 2 说明,只允许 @no__t 0 前缀。Only the Volatile prefix is allowed for the Ldsfld and Stsfld instructions.

以下 Emit 方法重载可以使用 @no__t 操作码:The following Emit method overloads can use the unaligned opcode:

  • ILGenerator (操作码、标签)ILGenerator.Emit(OpCode, Label)

  • ILGenerator (Opcode,Byte)ILGenerator.Emit(Opcode, Byte)

适用于