This is the mail archive of the crossgcc@sources.redhat.com mailing list for the crossgcc project.

See the CrossGCC FAQ for lots more information.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Q for inline arm assembly: 'M' constraint?


Doug Evans wrote:

Experiment:
Try defining fixp_mul_32s_nX as a macro instead of an inline,
and don't put values intended to be constants in temps (e.g. `p').
[gcc's "statement expressions" come in handy here]

Ok, after figuring out what a #define macro might look like using a statement expression, implemented in inline assembly (which took a while, since I'm a bit of a C novice), I got the following:


#define fixp_mul_32s_nX( a, b, n ) ({ \
	int _a = (a), _b = (b), res, tmp; \
	__asm__ __volatile__ ( \
		"smull	%0, %1, %2, %3		\n\t" \
		"movs	%0, %0, lsr %4		\n\t" \
		"adc	%1, %0, %1, lsl %5	\n\t" \
		: "=&r" (tmp), "=&r" (res) \
		: "r" (_a), "r" (_b), "M" (n), "M" (32-n) \
	); \
	res; \
})

to build pretty optimally with -O1:

int_res[j] = fixp_mul_32s_nX( int_a, int_b, 16 );
e0c65293 	smull	r5, r6, r3, r2
e1b05825 	movs	r5, r5, lsr #16
e0a56806 	adc	r6, r5, r6, lsl #16
e78e6104 	str	r6, [lr, r4, lsl #2]

It gives expected results in my little random-number test program. Now the question is do I really want to use it? It's awfully ugly to look at! Are there any C-gotcha's that this code is vulnerable to (other than the GCC dependence)?

--
Bryce Schober
Design Engineer
Dynon Avionics, Inc.
www.dynonavionics.com

---
[This E-mail scanned for viruses by digiposs.com]


------ Want more information? See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/ Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]