Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

"inline-assembly/C++ template" issue

131 views
Skip to first unread message

Pallav singh

unread,
Mar 14, 2015, 2:20:25 PM3/14/15
to
Hi All,


We can have textual substitution inside ASM, but i am getting error only for first substitution. Please do let me know how to solve it.

template.cc:109:27: error: expected string-literal before 'right_string'
asm volatile ( right_string<T>::instr_str
^

////////////////////////////////////////////////////////////////////////////////////
template < >
struct right_string<signed char> {
static constexpr const char * instr_str = "mov %2, %%bh \n\tinc %%bh \n\tmov %%bh, %0 \n\tpushf \n\tpop %1\n\t;";
static constexpr const char * clobber_str = "%bh";
}


asm volatile ( right_string<T>::instr_str
: "=r"(result), "=r"(post_eflags)
: "r"(counter)
: right_string<T>::clobber_str);


////////////////////////////////////////////////////////////////////////////////////

Thanks
Pallav Singh

Victor Bazarov

unread,
Mar 14, 2015, 6:36:32 PM3/14/15
to
On 3/14/2015 2:20 PM, Pallav singh wrote:
> We can have textual substitution inside ASM, but i am getting error only for first substitution. Please do let me know how to solve it.
>
> template.cc:109:27: error: expected string-literal before 'right_string'
> asm volatile ( right_string<T>::instr_str
> ^

'asm' is implementation- and platform-specific. First, youi have never
mentioned what your platform or implementation was. Second, it is
better to post to the newsgroup that actually deals with your platform
or your compiler.

Also, see FAQ 5.8.

>
> ////////////////////////////////////////////////////////////////////////////////////
> template < >
> struct right_string<signed char> {
> static constexpr const char * instr_str = "mov %2, %%bh \n\tinc %%bh \n\tmov %%bh, %0 \n\tpushf \n\tpop %1\n\t;";
> static constexpr const char * clobber_str = "%bh";
> }
>
>
> asm volatile ( right_string<T>::instr_str
> : "=r"(result), "=r"(post_eflags)
> : "r"(counter)
> : right_string<T>::clobber_str);
>
>
> ////////////////////////////////////////////////////////////////////////////////////
>
> Thanks
> Pallav Singh
>

V
--
I do not respond to top-posted replies, please don't ask

Pallav singh

unread,
Mar 15, 2015, 2:11:04 AM3/15/15
to
Hi Victor,

i am using g++ as compiler and its X86 platform. its looks wizard as asm is not allowing textual substitution . please do let me know is i am missing something.

Thanks
Pallav singh

Bo Persson

unread,
Mar 15, 2015, 7:39:36 AM3/15/15
to
I think you have got the cause.

The message "error: expected string-literal" seems to indicate that the
asm keyword doesn't support constexpr members of struct templates.

I very much doubt that this limitation is explicitly documented.


Bo Persson

fefe

unread,
Mar 15, 2015, 9:40:00 PM3/15/15
to
This is documented in the C++ specification. The grammar for asm-definition is:

asm-definition:
asm ( string-literal ) ;

Which means only string literal can appear inside asm().
0 new messages