Hi Ian, Thanks for your comments.
On Wed, Apr 13, 2011 at 5:02 PM, Ian Lance Taylor <i...@google.com> wrote: > Feng LI <nemoking...@gmail.com> writes: > >> I'm currently try to add intrinsic functions to extend the x86 instruction >> set. Encountered a problem when the intrinsic function's return value >> is void, where the asm will not generate in this case. >> >> the intrinsic function looks like: >> >> extern void >> __attribute__((__gnu_inline__, __always_inline__, __artificial__)) >> __TTest (unsigned int __C, unsigned int __V, unsigned int offset) >> { >> __builtin_ia32_ttest (__C, __V, offset); >> } >> >> and the corresponding md part is: >> >> (define_expand "dta_ttest" >> [(set (match_operand:SI 1 "register_operand" "") >> (unspec:SI >> [(match_operand:SI 2 "register_operand" "") >> (match_operand:SI 3 "register_operand" "")] >> UNSPEC_TSTORE))] >> "TARGET_DTA" >> "(void) operand0;") >> >> (define_insn "*dta_ttest" >> [(set (match_operand:SI 0 "register_operand" "=r") >> (unspec:SI >> [(match_operand:SI 1 "register_operand" "0") >> (match_operand:SI 2 "register_operand" "")] >> UNSPEC_TSTORE))] >> "TARGET_DTA" >> "ttest\t%0 %1 %2" >> [(set_attr "length" "3") >> (set_attr "mode" "SI")]) >> >> >> The asm will not generate "ttest\t %0 %1 %2" in this case, but if I >> change the return value from void to uint, it will generate the correct >> code. >> >> I'm wondering how could I generate asm code for the intrinsic functions >> with return value of void. > > If the intrinsic has no return value, then you need to use > unspec_volatile. Otherwise the compiler will see that you have an > instruction which doesn't do anything, and will remove it. > > But if the instrinsic returns void, I don't understand why you are > setting an operand in the insn. What does it get set to? I tried the version with return value to see if it works at the beginning and forgot to change it back... I use unspec_volatile for a function with void arguments and void return value for some initialization work. But it didn't generate code in this case. I think probably I need to add more restrictions some where but I don't know why and how. The code looks like: extern __inline void __attribute__((__gnu_inline__, __always_inline__, __artificial__)) __TEnd (void) { __builtin_ia32_tend (); } (define_expand "dta_tend" [(unspec_volatile [(const_int 0)] UNSPEC_TEND)] "" "") (define_insn "*dta_tend" [(unspec_volatile [(const_int 0)] UNSPEC_TEND)] "" "tend" [(set_attr "length" "3") (set_attr "mode" "none")]) Thanks, Feng > > Ian >