PPC 的 rdtsc 操作码相当于什么?

发布于 2024-11-04 17:15:35 字数 307 浏览 1 评论 0原文

我有一个包含以下代码的汇编程序。 这段代码对于英特尔处理器来说编译得很好。但是,当我使用 PPC(交叉)编译器时,出现操作码无法识别的错误。我正在尝试查找 PPC 架构是否有等效的操作码。

.file   "assembly.s"
.text
.globl func64
.type   func64,@function
func64:
    rdtsc
    ret

.size   func64,.Lfe1-func64
.globl func
.type   func,@function
func:
    rdtsc
    ret

I have an assembly program that has the following code.
This code compiles fine for a intel processor. But, when I use a PPC (cross)compiler, I get an error that the opcode is not recognized. I am trying to find if there is an equivalent opcode for PPC architecture.

.file   "assembly.s"
.text
.globl func64
.type   func64,@function
func64:
    rdtsc
    ret

.size   func64,.Lfe1-func64
.globl func
.type   func,@function
func:
    rdtsc
    ret

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

倾城月光淡如水﹏ 2024-11-11 17:15:35

PowerPC 包括一个“时基”寄存器,该寄存器会定期递增(尽管可能不是在每个时钟上递增——这取决于实际的硬件和操作系统)。 TB 寄存器是一个 64 位值,读取为两个 32 位半部,其中 mftb(低半部)和 mftbu(高半部)。 TB 的四个最低有效位有些不可靠(它们单调递增,但不一定以固定速率)。

一些较旧的 PowerPC 处理器没有 TB 寄存器(但操作系统可能会模拟它,其准确性可能值得怀疑);然而,603e 已经具备了它,因此可以肯定的是,大多数(如果不是全部)实际生产的 PowerPC 系统都拥有它。还有一个“备用时基寄存器”。

有关详细信息,请参阅 Power ISA 规范,可从 power.org 网站 获取。在撰写该答案时,当前版本为 2.06B,TB 寄存器和操作码记录在第 703 至 706 页。

PowerPC includes a "time base" register which is incremented regularly (although perhaps not at each clock -- it depends on the actual hardware and the operating system). The TB register is a 64-bit value, read as two 32-bit halves with mftb (low half) and mftbu (high half). The four least significant bits of TB are somewhat unreliable (they increment monotonically, but not necessarily with a fixed rate).

Some of the older PowerPC processors do not have the TB register (but the OS might emulate it, probably with questionable accuracy); however, the 603e already has it, so it is a fair bet that most if not all PowerPC systems actually in production have it. There is also an "aternate time base register".

For details, see the Power ISA specification, available from the power.org Web site. At the time of writing that answer, the current version was 2.06B, and the TB register and opcodes were documented at pages 703 to 706.

眼泪都笑了 2024-11-11 17:15:35

当您在 32 位架构上需要 64 位值(不确定它在 64 位上如何工作)并且读取 TB 寄存器时,您可能会遇到下半部分从 0xffffffff 到 0 的问题 - 当然这不会这种情况不会经常发生,但您可以确定它会在造成最大损害时发生;)

我建议您先阅读上半部分,然后再阅读下半部分,最后再阅读上半部分。比较两个鞋面,如果相等则没有问题。如果它们不同(第一个应该比最后一个小一个),您必须查看较低的位置以查看它应该与哪个较高的位置配对:如果设置了其最高位,则应与第一个位置配对,否则与最后一个位置配对。

When you need a 64-bit value on a 32-bit architecture (not sure how it works on 64-bit) and you read the TB register you can run into the problem of the lower half going from 0xffffffff to 0 - granted this doesn't happen often but you can be sure it will happen when it will do the most damage ;)

I recommend you read the upper half first, then the lower and finally the upper again. Compare the two uppers and if they are equal, no problemo. If they differ (the first should be one less than the last) you have to look at the lower to see which upper it should be paired with: if its highest bit is set it should be paired with the first, otherwise with the last.

说不完的你爱 2024-11-11 17:15:35

Apple 有三个版本的 mach_absolute_time( ) 适用于不同类型的代码:

  • 32 位
  • 64 位内核、32 位应用程序
  • 64 位内核、64 位应用程序

Apple has three versions of mach_absolute_time() for the different types of code:

  • 32-bit
  • 64-bit kernel, 32-bit app
  • 64-bit kernel, 64-bit app
何其悲哀 2024-11-11 17:15:35

受到 Peter Cordes 的评论和 clang 的 __builtin_readcyclecounter

mfspr 3, 268
blr

对于 gcc,您可以执行以下操作:

unsigned long long rdtsc(){
        unsigned long long rval;
        __asm__ __volatile__("mfspr %%r3, 268": "=r" (rval));
        return rval;
}

或者对于 clang:

unsigned long long readTSC() {
    // _mm_lfence();  // optionally wait for earlier insns to retire before reading the clock
    return __builtin_readcyclecounter();
}

Inspired by a comment from Peter Cordes and the disassembly of clang's __builtin_readcyclecounter:

mfspr 3, 268
blr

For gcc you can do the following:

unsigned long long rdtsc(){
        unsigned long long rval;
        __asm__ __volatile__("mfspr %%r3, 268": "=r" (rval));
        return rval;
}

Or For clang:

unsigned long long readTSC() {
    // _mm_lfence();  // optionally wait for earlier insns to retire before reading the clock
    return __builtin_readcyclecounter();
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文