私が理解していることから、SPARCでは、32ビット整数量は単一のレジスタに格納され、64ビット整数量は隣接するレジスタペアに格納され、偶数レジスタには上位32ビットが含まれ、奇数レジスタには下位32ビットが含まれます。
64 ビット整数のダブルワード ペアを処理する特殊な SPARC インライン アセンブリ マクロ (インライン アセンブリ関数でも問題ありません) をいくつか作成する必要があります。私のインラインアセンブリのペアの半分。私のアセンブリ マクロは、以下に示す MULTIPLY() マクロよりも少し複雑になりますが、乗算の例が機能する場合は、64 ビットのダブルワード ペアの 2 つの半分を処理する方法を示します。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
gccの出力を調べたところ-S -fverbose-asm
、結果レジスタ (偶数) の奇妙なシフトと、隣接する奇数レジスタへの書き込みが行われています。私の問題は、拡張 asm 構文で隣接する奇数レジスタを一般的に参照する方法がわからないことです。おそらく 'h' asm 制約が"=h"(r)
関係しているのではないかと思いましたが、使用方法の例が見つかりません。