据我了解,在 SPARC 中,32 位整数存储在单个寄存器中,64 位整数存储在相邻的寄存器对中,偶数寄存器包含高 32 位,奇数寄存器包含低 32 位。
我需要编写一些专门的 SPARC 内联汇编宏(内联汇编函数也可以)来处理 64 位整数双字对,我不知道如何泛指(使用 GCC 扩展内联汇编)我的内联汇编中的两半。虽然我的汇编宏比下面显示的 MULTIPLY() 宏稍微复杂一点,但乘法示例(如果有效)将演示如何处理 64 位双字对的两半。谁能告诉我如何修复我的 MULTIPLY() 宏?
以防万一,我在...
bash-2.03$ uname -a
SunOS [...] 5.8 Generic_117350-39 sun4u sparc SUNW,Ultra-80
这是我的简单示例程序(在 C 中):
#include <stdio.h>
//#include <stdint.h>
#define uint32 unsigned long int
#define uint64 unsigned long long int
#define MULTIPLY(r, a, b) /* (r = a * b) */ \
asm("umul %1, %2, %0;" /* unsigned mul */ \
: /* regs out */ "=h"(r) \
: /* regs in */ "r"(a), "r"(b));
#if 0
: /* clobbers */ "%y" );
#endif
int main(int argc, char** argv)
{
uint64 r;
uint32 a=0xdeadbeef, b=0xc0deba5e;
// loses the top 32 bits of the multiplication because the result is
// truncated at 32 bits which then gets assigned to the 64-bit 'r'...
r = a * b;
printf("u64=u32*u32 ----> r=a*b "
"----> 0x%016llx = 0x%x * 0x%x\n",
r, a, b);
// force promotion of 'a' to uint64 to get 64-bit multiplication
// (could cast either a or b as uint64, which one doesn't matter,
// as one explicit cast causes the other to be promoted as well)...
r = ((uint64)a) * b;
printf("u64=u64*u32 ----> r=((u64)a)*b "
"----> 0x%016llx = 0x%x * 0x%x\n",
r, a, b);
MULTIPLY(r, a, b);
printf("u64=u64*u32 ----> MULTIPLY(r,a,b) "
"----> 0x%016llx = 0x%x * 0x%x\n",
r, a, b);
return 0;
}
其中,当使用 编译时gcc-3.2-sun4u/bin/gcc -o mult -mcpu=ultrasparc mult.c
,会产生以下输出:
u64=u32*u32 ----> r=a*b ----> 0x00000000d3c7c1c2 = 0xdeadbeef * 0xc0deba5e
u64=u64*u32 ----> r=((u64)a)*b ----> 0xa7c40bfad3c7c1c2 = 0xdeadbeef * 0xc0deba5e
u64=u64*u32 ----> MULTIPLY(r,a,b) ----> 0xd3c7c1c2deadbeef = 0xdeadbeef * 0xc0deba5e
我查看了-S -fverbose-asm
gcc 的输出,它正在对结果寄存器(偶数)进行一些奇怪的移位并写入相邻的奇数寄存器。我的问题是我不知道如何在扩展 asm 语法中泛指相邻的奇数寄存器。我想也许 'h' asm 约束"=h"(r)
可能与它有关,但我找不到任何如何使用它的例子。