Re: Storing 64-bit result on ARM using inline assembly

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Leonitis wrote:
> [working with ARM XScale processor and GCC cross-compiler]
> 
> I am trying to write an inline function that does a 32-bit by 32-bit
> multiply (32x32->64).
> I want to save the result into a long long type. I also want to use the
> SMULL instruction followed by a STRD instruction.
> 
> SMULL: Returns 64-bit product of 32x32 multiplication in two registers
> STRD: Stores contents of two consecutive registers into two consecutive
> memory slots
> 
> So far I have:
> static inline void MULT32_32_64(volatile long long* result, int a, int b)
> {
> 	asm volatile("SMULL r2, r3, %[a], %[b]\n\t"
> 			 "STRD r2, %[result]\n\t"
> 			   : [res] "=m" (*result)
> 		           : [a] "r" (a), [b] "r" (b)
> 			   : "r2", "r3", "memory" );
> 	return;
> }
> 
> Here's what's strange: it works correctly for all optimization levels except
> -O2 (so it works for -O3). With -O2, the 64-bit output gets some very
> strange value (146406845186048), regardless of input.

Please send a test case that displays the problem.
The test you just sent doesn't even compile for me.

This does:

#include <stdio.h>

static inline void MULT32_32_64(volatile long long* result, int a, int b)
{
  asm volatile("SMULL r2, r3, %[a], %[b]\n\t"
	       "STRD r2, %[res]\n\t"
	       : [res] "=m" (*result)
	       : [a] "r" (a), [b] "r" (b)
	       : "r2", "r3", "memory" );
  return;
}

long long test (int a, int b)
{
  long long result;

  MULT32_32_64(&result, a, b);

  return result;
}

void main()
{
  printf ("%llx\n", test (0x7fffffff, 0x7fffffff));
  printf ("%llx\n", (0x7fffffffLL * 0x7fffffffLL));
}

Andrew.


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux