Error: matching constraint not valid in output operand
I'm having trouble getting GCC inline assembler to accept some inline assembly for Power9.
The regular assembly I am trying to get GCC to accept is darn 3, 1
, where 3
is r3
and 1
is parameter called L
in the docs. It disassembles to this on big-endian:
0: e6 05 61 7c darn r3,1
And on little-endian:
0: 7c 61 05 e6 darn r3,1
Due to various reasons and problems, including old compilers and compilers that pretend to be other compilers, I want to issue byte codes for the instruction. My test program:
gcc112:~$ cat test.c
#include <stdint.h>
void random()
{
volatile uint64_t x = __builtin_darn();
__asm__ __volatile__ ("darn 3, 1");
uint64_t y;
__asm__ __volatile__ (".byte 0x7c, 0x61, 0x05, 0xe6 n" : "=r3" (y));
}
Compiling it results in:
$ /opt/cfarm/gcc-latest/bin/gcc -mcpu=power9 -c test.c
test.c: In function 'random':
test.c:10:3: error: matching constraint not valid in output operand
__asm__ __volatile__ (".byte 0x7c, 0x61, 0x05, 0xe6 n" : "=r3" (y));
^~~~~~~
test.c:10:3: error: matching constraint not valid in output operand
test.c:10:3: error: invalid lvalue in asm output 0
Here's the section of the GCC inline assembly manual that should cover it, but I don't see it expalined: 6.45.2.3 Output Operands. I also checked simple and machine constraints but did not see it.
How do I tell GCC to execute the instruction, and then move r3
into y
?
We do the same thing on x86 with rdrand
. It works without problems on all version of GCC going back to 2.9:
uint64_t temp;
__asm__ __volatile__
(
// radrand rax with retry
"1:n"
".byte 0x48, 0x0f, 0xc7, 0xf0;n"
"jnc 1b;n"
: "=a" (temp)
: : "cc"
);
gcc inline-assembly powerpc altivec
add a comment |
I'm having trouble getting GCC inline assembler to accept some inline assembly for Power9.
The regular assembly I am trying to get GCC to accept is darn 3, 1
, where 3
is r3
and 1
is parameter called L
in the docs. It disassembles to this on big-endian:
0: e6 05 61 7c darn r3,1
And on little-endian:
0: 7c 61 05 e6 darn r3,1
Due to various reasons and problems, including old compilers and compilers that pretend to be other compilers, I want to issue byte codes for the instruction. My test program:
gcc112:~$ cat test.c
#include <stdint.h>
void random()
{
volatile uint64_t x = __builtin_darn();
__asm__ __volatile__ ("darn 3, 1");
uint64_t y;
__asm__ __volatile__ (".byte 0x7c, 0x61, 0x05, 0xe6 n" : "=r3" (y));
}
Compiling it results in:
$ /opt/cfarm/gcc-latest/bin/gcc -mcpu=power9 -c test.c
test.c: In function 'random':
test.c:10:3: error: matching constraint not valid in output operand
__asm__ __volatile__ (".byte 0x7c, 0x61, 0x05, 0xe6 n" : "=r3" (y));
^~~~~~~
test.c:10:3: error: matching constraint not valid in output operand
test.c:10:3: error: invalid lvalue in asm output 0
Here's the section of the GCC inline assembly manual that should cover it, but I don't see it expalined: 6.45.2.3 Output Operands. I also checked simple and machine constraints but did not see it.
How do I tell GCC to execute the instruction, and then move r3
into y
?
We do the same thing on x86 with rdrand
. It works without problems on all version of GCC going back to 2.9:
uint64_t temp;
__asm__ __volatile__
(
// radrand rax with retry
"1:n"
".byte 0x48, 0x0f, 0xc7, 0xf0;n"
"jnc 1b;n"
: "=a" (temp)
: : "cc"
);
gcc inline-assembly powerpc altivec
3
I'm not familiar withr3
as an output constraint. I'm guessing this is intended to indicated that the output will be in the 'r3' register, but I don't think you can do it this way (although I'm no expert on powerpc's machine constraints). Perhaps you could tryregister uint64_t y asm("r3");
(ie a local register variable) and then just use=r
as the constraint?
– David Wohlferd
Nov 27 '18 at 3:01
Possible duplicate of How to have GCC combine "move r10, r3; store r10" into a "store r3"?, where I posted basically the same register-asm local variable answer as @David.
– Peter Cordes
Nov 30 '18 at 4:24
add a comment |
I'm having trouble getting GCC inline assembler to accept some inline assembly for Power9.
The regular assembly I am trying to get GCC to accept is darn 3, 1
, where 3
is r3
and 1
is parameter called L
in the docs. It disassembles to this on big-endian:
0: e6 05 61 7c darn r3,1
And on little-endian:
0: 7c 61 05 e6 darn r3,1
Due to various reasons and problems, including old compilers and compilers that pretend to be other compilers, I want to issue byte codes for the instruction. My test program:
gcc112:~$ cat test.c
#include <stdint.h>
void random()
{
volatile uint64_t x = __builtin_darn();
__asm__ __volatile__ ("darn 3, 1");
uint64_t y;
__asm__ __volatile__ (".byte 0x7c, 0x61, 0x05, 0xe6 n" : "=r3" (y));
}
Compiling it results in:
$ /opt/cfarm/gcc-latest/bin/gcc -mcpu=power9 -c test.c
test.c: In function 'random':
test.c:10:3: error: matching constraint not valid in output operand
__asm__ __volatile__ (".byte 0x7c, 0x61, 0x05, 0xe6 n" : "=r3" (y));
^~~~~~~
test.c:10:3: error: matching constraint not valid in output operand
test.c:10:3: error: invalid lvalue in asm output 0
Here's the section of the GCC inline assembly manual that should cover it, but I don't see it expalined: 6.45.2.3 Output Operands. I also checked simple and machine constraints but did not see it.
How do I tell GCC to execute the instruction, and then move r3
into y
?
We do the same thing on x86 with rdrand
. It works without problems on all version of GCC going back to 2.9:
uint64_t temp;
__asm__ __volatile__
(
// radrand rax with retry
"1:n"
".byte 0x48, 0x0f, 0xc7, 0xf0;n"
"jnc 1b;n"
: "=a" (temp)
: : "cc"
);
gcc inline-assembly powerpc altivec
I'm having trouble getting GCC inline assembler to accept some inline assembly for Power9.
The regular assembly I am trying to get GCC to accept is darn 3, 1
, where 3
is r3
and 1
is parameter called L
in the docs. It disassembles to this on big-endian:
0: e6 05 61 7c darn r3,1
And on little-endian:
0: 7c 61 05 e6 darn r3,1
Due to various reasons and problems, including old compilers and compilers that pretend to be other compilers, I want to issue byte codes for the instruction. My test program:
gcc112:~$ cat test.c
#include <stdint.h>
void random()
{
volatile uint64_t x = __builtin_darn();
__asm__ __volatile__ ("darn 3, 1");
uint64_t y;
__asm__ __volatile__ (".byte 0x7c, 0x61, 0x05, 0xe6 n" : "=r3" (y));
}
Compiling it results in:
$ /opt/cfarm/gcc-latest/bin/gcc -mcpu=power9 -c test.c
test.c: In function 'random':
test.c:10:3: error: matching constraint not valid in output operand
__asm__ __volatile__ (".byte 0x7c, 0x61, 0x05, 0xe6 n" : "=r3" (y));
^~~~~~~
test.c:10:3: error: matching constraint not valid in output operand
test.c:10:3: error: invalid lvalue in asm output 0
Here's the section of the GCC inline assembly manual that should cover it, but I don't see it expalined: 6.45.2.3 Output Operands. I also checked simple and machine constraints but did not see it.
How do I tell GCC to execute the instruction, and then move r3
into y
?
We do the same thing on x86 with rdrand
. It works without problems on all version of GCC going back to 2.9:
uint64_t temp;
__asm__ __volatile__
(
// radrand rax with retry
"1:n"
".byte 0x48, 0x0f, 0xc7, 0xf0;n"
"jnc 1b;n"
: "=a" (temp)
: : "cc"
);
gcc inline-assembly powerpc altivec
gcc inline-assembly powerpc altivec
edited Nov 26 '18 at 11:22
jww
asked Nov 26 '18 at 11:04
jwwjww
54.1k41234513
54.1k41234513
3
I'm not familiar withr3
as an output constraint. I'm guessing this is intended to indicated that the output will be in the 'r3' register, but I don't think you can do it this way (although I'm no expert on powerpc's machine constraints). Perhaps you could tryregister uint64_t y asm("r3");
(ie a local register variable) and then just use=r
as the constraint?
– David Wohlferd
Nov 27 '18 at 3:01
Possible duplicate of How to have GCC combine "move r10, r3; store r10" into a "store r3"?, where I posted basically the same register-asm local variable answer as @David.
– Peter Cordes
Nov 30 '18 at 4:24
add a comment |
3
I'm not familiar withr3
as an output constraint. I'm guessing this is intended to indicated that the output will be in the 'r3' register, but I don't think you can do it this way (although I'm no expert on powerpc's machine constraints). Perhaps you could tryregister uint64_t y asm("r3");
(ie a local register variable) and then just use=r
as the constraint?
– David Wohlferd
Nov 27 '18 at 3:01
Possible duplicate of How to have GCC combine "move r10, r3; store r10" into a "store r3"?, where I posted basically the same register-asm local variable answer as @David.
– Peter Cordes
Nov 30 '18 at 4:24
3
3
I'm not familiar with
r3
as an output constraint. I'm guessing this is intended to indicated that the output will be in the 'r3' register, but I don't think you can do it this way (although I'm no expert on powerpc's machine constraints). Perhaps you could try register uint64_t y asm("r3");
(ie a local register variable) and then just use =r
as the constraint?– David Wohlferd
Nov 27 '18 at 3:01
I'm not familiar with
r3
as an output constraint. I'm guessing this is intended to indicated that the output will be in the 'r3' register, but I don't think you can do it this way (although I'm no expert on powerpc's machine constraints). Perhaps you could try register uint64_t y asm("r3");
(ie a local register variable) and then just use =r
as the constraint?– David Wohlferd
Nov 27 '18 at 3:01
Possible duplicate of How to have GCC combine "move r10, r3; store r10" into a "store r3"?, where I posted basically the same register-asm local variable answer as @David.
– Peter Cordes
Nov 30 '18 at 4:24
Possible duplicate of How to have GCC combine "move r10, r3; store r10" into a "store r3"?, where I posted basically the same register-asm local variable answer as @David.
– Peter Cordes
Nov 30 '18 at 4:24
add a comment |
1 Answer
1
active
oldest
votes
Moving my (untested) comment to an answer to attempt to close this out
I'm not familiar with r3
as an output constraint. I'm guessing this is intended to indicate that the output will be in the 'r3' register, but I don't think you can do it this way (although I'm no expert on powerpc's machine constraints). Instead, perhaps you could try:
register uint64_t y asm("r3");
(ie make y
a local register variable) and then just use "=r" as the constraint?
Thanks David. I tried both the register local and pointer to register local but neither worked. Both resulted in a wild write that segfault'd the program. The disassembly showed two stores occurring. That's why I want to get=r3
working as expected (which I don't think is possible).
– jww
Nov 30 '18 at 9:35
1
Looking at the output from godbolt, I'm seeing the same results for __builtin_darn that I see for using a local register. If there's a wild pointer, I'm not convinced it's coming from this code. Did you remove the 'extra'__asm__ __volatile__ ("darn 3, 1");
? That code is invalid as it overwrites r3 without informing the compiler.
– David Wohlferd
Nov 30 '18 at 18:36
add a comment |
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53479766%2ferror-matching-constraint-not-valid-in-output-operand%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Moving my (untested) comment to an answer to attempt to close this out
I'm not familiar with r3
as an output constraint. I'm guessing this is intended to indicate that the output will be in the 'r3' register, but I don't think you can do it this way (although I'm no expert on powerpc's machine constraints). Instead, perhaps you could try:
register uint64_t y asm("r3");
(ie make y
a local register variable) and then just use "=r" as the constraint?
Thanks David. I tried both the register local and pointer to register local but neither worked. Both resulted in a wild write that segfault'd the program. The disassembly showed two stores occurring. That's why I want to get=r3
working as expected (which I don't think is possible).
– jww
Nov 30 '18 at 9:35
1
Looking at the output from godbolt, I'm seeing the same results for __builtin_darn that I see for using a local register. If there's a wild pointer, I'm not convinced it's coming from this code. Did you remove the 'extra'__asm__ __volatile__ ("darn 3, 1");
? That code is invalid as it overwrites r3 without informing the compiler.
– David Wohlferd
Nov 30 '18 at 18:36
add a comment |
Moving my (untested) comment to an answer to attempt to close this out
I'm not familiar with r3
as an output constraint. I'm guessing this is intended to indicate that the output will be in the 'r3' register, but I don't think you can do it this way (although I'm no expert on powerpc's machine constraints). Instead, perhaps you could try:
register uint64_t y asm("r3");
(ie make y
a local register variable) and then just use "=r" as the constraint?
Thanks David. I tried both the register local and pointer to register local but neither worked. Both resulted in a wild write that segfault'd the program. The disassembly showed two stores occurring. That's why I want to get=r3
working as expected (which I don't think is possible).
– jww
Nov 30 '18 at 9:35
1
Looking at the output from godbolt, I'm seeing the same results for __builtin_darn that I see for using a local register. If there's a wild pointer, I'm not convinced it's coming from this code. Did you remove the 'extra'__asm__ __volatile__ ("darn 3, 1");
? That code is invalid as it overwrites r3 without informing the compiler.
– David Wohlferd
Nov 30 '18 at 18:36
add a comment |
Moving my (untested) comment to an answer to attempt to close this out
I'm not familiar with r3
as an output constraint. I'm guessing this is intended to indicate that the output will be in the 'r3' register, but I don't think you can do it this way (although I'm no expert on powerpc's machine constraints). Instead, perhaps you could try:
register uint64_t y asm("r3");
(ie make y
a local register variable) and then just use "=r" as the constraint?
Moving my (untested) comment to an answer to attempt to close this out
I'm not familiar with r3
as an output constraint. I'm guessing this is intended to indicate that the output will be in the 'r3' register, but I don't think you can do it this way (although I'm no expert on powerpc's machine constraints). Instead, perhaps you could try:
register uint64_t y asm("r3");
(ie make y
a local register variable) and then just use "=r" as the constraint?
answered Nov 30 '18 at 4:20
David WohlferdDavid Wohlferd
4,68311434
4,68311434
Thanks David. I tried both the register local and pointer to register local but neither worked. Both resulted in a wild write that segfault'd the program. The disassembly showed two stores occurring. That's why I want to get=r3
working as expected (which I don't think is possible).
– jww
Nov 30 '18 at 9:35
1
Looking at the output from godbolt, I'm seeing the same results for __builtin_darn that I see for using a local register. If there's a wild pointer, I'm not convinced it's coming from this code. Did you remove the 'extra'__asm__ __volatile__ ("darn 3, 1");
? That code is invalid as it overwrites r3 without informing the compiler.
– David Wohlferd
Nov 30 '18 at 18:36
add a comment |
Thanks David. I tried both the register local and pointer to register local but neither worked. Both resulted in a wild write that segfault'd the program. The disassembly showed two stores occurring. That's why I want to get=r3
working as expected (which I don't think is possible).
– jww
Nov 30 '18 at 9:35
1
Looking at the output from godbolt, I'm seeing the same results for __builtin_darn that I see for using a local register. If there's a wild pointer, I'm not convinced it's coming from this code. Did you remove the 'extra'__asm__ __volatile__ ("darn 3, 1");
? That code is invalid as it overwrites r3 without informing the compiler.
– David Wohlferd
Nov 30 '18 at 18:36
Thanks David. I tried both the register local and pointer to register local but neither worked. Both resulted in a wild write that segfault'd the program. The disassembly showed two stores occurring. That's why I want to get
=r3
working as expected (which I don't think is possible).– jww
Nov 30 '18 at 9:35
Thanks David. I tried both the register local and pointer to register local but neither worked. Both resulted in a wild write that segfault'd the program. The disassembly showed two stores occurring. That's why I want to get
=r3
working as expected (which I don't think is possible).– jww
Nov 30 '18 at 9:35
1
1
Looking at the output from godbolt, I'm seeing the same results for __builtin_darn that I see for using a local register. If there's a wild pointer, I'm not convinced it's coming from this code. Did you remove the 'extra'
__asm__ __volatile__ ("darn 3, 1");
? That code is invalid as it overwrites r3 without informing the compiler.– David Wohlferd
Nov 30 '18 at 18:36
Looking at the output from godbolt, I'm seeing the same results for __builtin_darn that I see for using a local register. If there's a wild pointer, I'm not convinced it's coming from this code. Did you remove the 'extra'
__asm__ __volatile__ ("darn 3, 1");
? That code is invalid as it overwrites r3 without informing the compiler.– David Wohlferd
Nov 30 '18 at 18:36
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53479766%2ferror-matching-constraint-not-valid-in-output-operand%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
3
I'm not familiar with
r3
as an output constraint. I'm guessing this is intended to indicated that the output will be in the 'r3' register, but I don't think you can do it this way (although I'm no expert on powerpc's machine constraints). Perhaps you could tryregister uint64_t y asm("r3");
(ie a local register variable) and then just use=r
as the constraint?– David Wohlferd
Nov 27 '18 at 3:01
Possible duplicate of How to have GCC combine "move r10, r3; store r10" into a "store r3"?, where I posted basically the same register-asm local variable answer as @David.
– Peter Cordes
Nov 30 '18 at 4:24