x64 Architecture

本文详细介绍了x64架构作为x86的后向兼容扩展,涵盖了其32位兼容模式及新的64位模式。文章深入探讨了x64架构下的寄存器扩展、操作数寻址方式、指令集特性以及调用约定等内容。

x64 Architecture

        3 out of 3 rated this helpful Rate this topic
The x64 architecture is a backwards-compatible extension of x86.  It provides a legacy 32-bit mode, which is identical to x86, and a new 64-bit mode.

The term "x64" includes both AMD 64 and Intel64. The instruction sets are close to identical.

Registers

x64 extends x64's 8 general-purpose registers to be 64-bit, and adds 8 new 64-bit registers.  The 64-bit registers have names beginning with "r", so for example the 64-bit extension of eax is called rax.  The new registers are named r8 through r15.

The lower 32 bits, 16 bits, and 8 bits of each register are directly addressable in operands.  This includes registers, like esi, whose lower 8 bits were not previously addressable.  The following table specifies the assembly-language names for the lower portions of 64-bit registers.

64-bit registerLower 32 bitsLower 16 bitsLower 8 bits

rax

eax

ax

al

rbx

ebx

bx

bl

rcx

ecx

cx

cl

rdx

edx

dx

dl

rsi

esi

si

sil

rdi

edi

di

dil

rbp

ebp

bp

bpl

rsp

esp

sp

spl

r8

r8d

r8w

r8b

r9

r9d

r9w

r9b

r10

r10d

r10w

r10b

r11

r11d

r11w

r11b

r12

r12d

r12w

r12b

r13

r13d

r13w

r13b

r14

r14d

r14w

r14b

r15

r15d

r15w

r15b

Operations that output to a 32-bit subregister are automatically zero-extended to the entire 64-bit register.  Operations that output to 8-bit or 16-bit subregisters are not zero-extended (this is compatible x86 behavior).

The high 8 bits of ax, bx, cx, and dx are still addressable as ah, bh, ch, dh, but cannot be used with all types of operands.  

The instruction pointer, eip, and flags register have been extended to 64 bits (rip and rflags, respectively) as well.

The x64 processor also provides several sets of floating-point registers:

  • Eight 80-bit x87 registers.

  • Eight 64-bit MMX registers.  (These overlap with the x87 registers.)

  • The original set of eight 128-bit SSE registers is increased to sixteen.

Calling Conventions

Unlike the x86, the C/C++ compiler only supports one calling convention on x64.  This calling convention takes advantage of the increased number of registers available on x64:

  • The first four integer or pointer parameters are passed in the rcx, rdx, r8, and r9 registers.

  • The first four floating-point parameters are passed in the first four SSE registers, xmm0-xmm3.

  • The caller reserves space on the stack for arguments passed in registers.  The called function can use this space to spill the contents of registers to the stack.

  • Any additional arguments are passed on the stack.

  • An integer or pointer return value is returned in the rax register, while a floating-point return value is returned in xmm0.

  • rax, rcx, rdx, r8-r11 are volatile.

  • rbx, rbp, rdi, rsi, r12-r15 are nonvolatile.

The calling convention for C++ is very similar: the this pointer is passed as an implicit first parameter.  The next three parameters are passed in registers, while the rest are passed on the stack.

Addressing Modes

The addressing modes in 64-bit mode are similar to, but not identical to, x86.

  • Instructions that refer to 64-bit registers are automatically performed with 64-bit precision.  (For example mov rax, [rbx] moves 8 bytes beginning at rbx into rax.)

  • A special form of the mov instruction has been added for 64-bit immediate constants or constant addresses.  For all other instructions, immediate constants or constant addresses are still 32 bits. 

  • x64 provides a new rip-relative addressing mode.  Instructions that refer to a single constant address are encoded as offsets from rip.  For example, the mov rax, [addr] instruction moves 8 bytes beginning at addr + rip to rax.

Instructions, such as jmp, call, push, and pop, that implicitly refer to the instruction pointer and the stack pointer treat them as 64 bits registers on x64.

 Send comments about this topic to Microsoft

Build date: 2/14/2012

http://msdn.microsoft.com/en-us/library/ff561499(v=vs.85).aspx

译文:

http://blog.youkuaiyun.com/herx1/article/details/3134889

【轴承故障诊断】加权多尺度字典学习模型(WMSDL)及其在轴承故障诊断上的应用(Matlab代码实现)内容概要:本文介绍了加权多尺度字典学习模型(WMSDL)在轴承故障诊断中的应用,并提供了基于Matlab的代码实现。该模型结合多尺度分析与字典学习技术,能够有效提取轴承振动信号中的故障特征,提升故障识别精度。文档重点阐述了WMSDL模型的理论基础、算法流程及其在实际故障诊断中的实施步骤,展示了其相较于传统方法在特征表达能力和诊断准确性方面的优势。同时,文中还提及该资源属于一个涵盖多个科研方向的技术合集,包括智能优化算法、机器学习、信号处理、电力系统等多个领域的Matlab仿真案例。; 适合人群:具备一定信号处理和机器学习基础,从事机械故障诊断、工业自动化、智能制造等相关领域的研究生、科研人员及工程技术人员。; 使用场景及目标:①学习并掌握加权多尺度字典学习模型的基本原理与实现方法;②将其应用于旋转机械的轴承故障特征提取与智能诊断;③结合实际工程数据复现算法,提升故障诊断系统的准确性和鲁棒性。; 阅读建议:建议读者结合提供的Matlab代码进行实践操作,重点关注字典学习的训练过程与多尺度分解的实现细节,同时可参考文中提到的其他相关技术(如VMD、CNN、BILSTM等)进行对比实验与算法优化。
<think>我们正在解决Unity中DLL文件的架构不匹配问题(x86与x64)。用户遇到错误,需要重新编译插件以匹配目标平台。根据用户问题,错误信息通常为:“DllNotFoundException”或“BadImageFormatException”,这通常是因为DLL的架构与Unity项目的目标平台不匹配(例如,在64位环境中使用了32位的DLL,反之亦然)。解决方案的核心是重新编译DLL以匹配目标平台。以下是具体步骤:1.**确认Unity项目的目标平台**:在Unity编辑器中,打开“File>BuildSettings”,查看当前选择的平台(例如,PC平台下是x86还是x64)。2.**获取DLL的源代码**:由于需要重新编译,我们必须有DLL的源代码。如果没有,可能需要联系DLL的提供者获取对应架构的版本。3.**使用匹配的架构重新编译DLL**:-如果目标平台是64位(x64),则编译64位的DLL。-如果目标平台是32位(x86),则编译32位的DLL。4.**在VisualStudio中设置目标平台**:打开DLL的源代码项目,在解决方案配置管理器中,选择对应的平台(如x64或x86)进行编译。5.**替换Unity项目中的DLL**:将新编译的DLL文件(通常为`.dll`文件)放入Unity项目的`Assets`文件夹下的`Plugins`文件夹中(如果没有则创建)。注意:根据平台可能需要放在`Plugins/x86`或`Plugins/x86_64`子文件夹中。6.**设置Unity中DLL的平台兼容性**:在Unity编辑器中,选中DLL文件,在Inspector窗口中设置平台兼容性(例如,勾选对应的平台,并选择CPU架构)。7.**重新加载并测试**:重新启动Unity并运行项目,检查错误是否解决。注意:如果DLL是第三方提供的,且没有源代码,则需要联系供应商获取匹配架构的DLL版本。另外,有时在Unity中,我们也可以尝试通过设置PlayerSettings中的目标架构来匹配现有的DLL。例如,如果DLL是32位的,那么将PlayerSettings中的目标架构设置为x86(32位)可能可以解决问题。但这种方法不适用于64位系统上运行64位程序的情况,因此重新编译为正确架构是更彻底的解决方案。引用说明:虽然提供的引用内容是关于Unreal引擎的修复和优化(如枚举编译问题、蓝图崩溃修复、内部数据重构等),但这些引用与当前问题无关。因此,我们忽略这些引用,专注于UnityDLL架构问题的解决方案。生成相关问题:1.如何检查一个DLL文件是32位还是64位?2.在Unity中如何为不同平台(如Android、iOS)编译原生插件?3.当无法获取DLL源代码时,如何解决架构不匹配问题?</think>### 解决Unity中DLL的x86/x64架构不匹配问题 当Unity项目中遇到`DllNotFoundException`或`BadImageFormatException`错误时,通常是由于原生插件DLL的架构(x86/x64)与Unity构建目标不匹配导致。以下是系统化的解决方案: #### 🔧 核心解决步骤 1. **确认DLL架构** 使用工具检查DLL的架构类型: - Windows:通过 **Dependency Walker** 或 `dumpbin /headers YourDLL.dll | findstr "machine"` - `x86`输出:`8664 machine (x64)` - `x64`输出:`14C machine (x86)` - macOS:`lipo -info YourDLL.bundle` - Unity编辑器日志会明确显示加载失败的原因 2. **统一构建目标** - **Unity设置**: ```text File > Build Settings > Player Settings > - PC端:Target Architecture 勾选 x86 或 x64 - Android:Target Architectures 选择 ARMv7 或 ARM64 ``` - **DLL放置路径**: ```text Assets/ └── Plugins/ ├── x86/ → 32位DLL ├── x86_64/ → 64位DLL └── Android/ ├── armv7/ → ARMv7 DLL └── arm64/ → ARM64 DLL ``` 3. **重新编译DLL(必要操作)** - **Visual Studio 设置**: ```csharp 解决方案资源管理器 > 右键项目 > 属性 → 配置管理器:新建 x86 或 x64 平台 → C/C++ > 代码生成:Runtime Library 必须匹配Unity(通常为 /MD) ``` - **关键编译参数**: - Windows x86:`/platform:x86` - Windows x64:`/platform:x64` - Android ARMv7:`-march=armv7-a` - Android ARM64:`-march=armv8-a` 4. **Unity编辑器特殊处理** - 如果编辑器是64位(默认)但DLL是32位: - 临时方案:启动Unity时添加命令行参数`-force-glcore` - 永久方案:重新编译DLL为x64版本[^3] #### ⚠️ 常见陷阱 1. **混合架构依赖链** - 当主DLL依赖其他x86库时,整个链需统一架构 - 解决方案:用`dumpbin /dependents YourDLL.dll`检查依赖 2. **.NET版本冲突** - Unity 2020+默认使用`.NET Standard 2.1` - 编译DLL时需指定:`<TargetFramework>netstandard2.1</TargetFramework>` 3. **托管桥接层错误** ```csharp // C#声明必须完全匹配DLL导出 [DllImport("YourPlugin")] private static extern int Init(IntPtr config); // 参数类型需精确匹配 ``` #### ✅ 验证流程 1. 在Unity编辑器日志中搜索`Plugin loaded`确认加载成功 2. 空场景调用`DLL`基础函数测试 3. 构建最小可执行程序测试目标平台 > 对于第三方闭源DLL:联系供应商索要多架构版本,或使用进程间通信(如gRPC)隔离架构差异[^2]。 --- ### 📚 相关问题 1. **如何为Android/iOS交叉编译Unity原生插件?** 2. **Unity中如何处理不同平台(Windows/macOS/Linux)的DLL兼容性?** 3. **当DLL依赖特定运行时库(如VC++ Redist)时如何打包部署?** 4. **如何调试Unity中崩溃的原生插件?** [^1]: 编译过程需严格匹配目标平台架构 [^2]: 架构隔离方案可避免重新编译闭源组件 [^3]: Unity编辑器架构需与插件一致
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值