在c++代码中使用嵌入式汇编语言进行错误分析

Error profiling with embedded assembly language in C++ code

本文关键字:汇编语言 错误分析 嵌入式 c++ 代码      更新时间:2023-10-16

我找到了这篇关于std::vector::push_back效率的文章,相关代码可以在这里找到。我自己尝试了一下,我得到了一个illegal instruction (core dumped), gdb指示错误发生在第37行。

我使用gcc 4.7.2进行编译,在计算机上使用:

$ sudo dmidecode -t processor
# dmidecode 2.11
SMBIOS 2.5 present.
Handle 0x0400, DMI type 4, 40 bytes
Processor Information
    Socket Designation: CPU
    Type: Central Processor
    Family: Core 2 Duo
    Manufacturer: Intel
    ID: 7A 06 01 00 FF FB EB BF
    Signature: Type 0, Family 6, Model 23, Stepping 10
    Flags:
        FPU (Floating-point unit on-chip)
        VME (Virtual mode extension)
        DE (Debugging extension)
        PSE (Page size extension)
        TSC (Time stamp counter)
        MSR (Model specific registers)
        PAE (Physical address extension)
        MCE (Machine check exception)
        CX8 (CMPXCHG8 instruction supported)
        APIC (On-chip APIC hardware supported)
        SEP (Fast system call)
        MTRR (Memory type range registers)
        PGE (Page global enable)
        MCA (Machine check architecture)
        CMOV (Conditional move instruction supported)
        PAT (Page attribute table)
        PSE-36 (36-bit page size extension)
        CLFSH (CLFLUSH instruction supported)
        DS (Debug store)
        ACPI (ACPI supported)
        MMX (MMX technology supported)
        FXSR (FXSAVE and FXSTOR instructions supported)
        SSE (Streaming SIMD extensions)
        SSE2 (Streaming SIMD extensions 2)
        SS (Self-snoop)
        HTT (Multi-threading)
        TM (Thermal monitor supported)
        PBE (Pending break enabled)
    Version: Not Specified
    Voltage: 1.2 V
    External Clock: 1333 MHz
    Max Speed: 5200 MHz
    Current Speed: 3000 MHz
    Status: Populated, Enabled
    Upgrade: Socket LGA775
    L1 Cache Handle: 0x0700
    L2 Cache Handle: 0x0701
    L3 Cache Handle: Not Provided
    Serial Number: Not Specified
    Asset Tag: Not Specified
    Part Number: Not Specified
    Core Count: 2
    Core Enabled: 2
    Thread Count: 2
    Characteristics:
        64-bit capable

这里有什么问题?我怎样才能使这个代码工作?我也尝试了icpc 13.1.0,但这也失败了。

编辑:我使用Ubuntu 12.10 64位。

您的CPU不支持RDTSCP指令。这是一条酷睿i7指令,而你的处理器是较早一代的(Merom-L)。

您应该能够使用RDTSC代替。例如,参见"rdtscp, rdtsc: memory和cpuid/rdtsc之间的差异?"