DJGPP Inline Problem
DJGPP Inline Problem
why it is showing an error "can't find a register in class AREG while reloading asm" ?
extern inline int strlen(const char * s)
{
register int __res __asm__("cx");
__asm__("cld\n\t"
"repne\n\t"
"scasb\n\t"
"notl %0\n\t"
"decl %0"
:"=c" (__res):"D" (s),"a" (0),"0" (0xffffffff):"di");
return __res;
}
extern inline int strlen(const char * s)
{
register int __res __asm__("cx");
__asm__("cld\n\t"
"repne\n\t"
"scasb\n\t"
"notl %0\n\t"
"decl %0"
:"=c" (__res):"D" (s),"a" (0),"0" (0xffffffff):"di");
return __res;
}
Re: DJGPP Inline Problem
Try getting rid of __asm__("cx") so your code should look like this (oh and try to use code tags when posting)
Code: Select all
extern inline
int strlen (const char * s)
{
register int __res;
__asm__ ("cld\n\t"
"repne\n\t"
"scasb\n\t"
"notl %0\n\t"
"decl %0"
: "=c" (__res) : "D" (s), "a" (0), "0" (0xffffffff) : "di");
return __res;
}
Re: DJGPP Inline Problem
Thank You JoeDavis, But is is Showing The Same Problem, But Now I have Found The Solution.
Solution:
When -O2 (Optimization) is Enabled Then It is Showing The Problem. Because Optimization Don't Support Inline Assembly.
Eg: gcc -g -W -Wall -O2 -oxyz.o xyz.c
After Removing "-O2" it is working Cool.
Solution:
When -O2 (Optimization) is Enabled Then It is Showing The Problem. Because Optimization Don't Support Inline Assembly.
Eg: gcc -g -W -Wall -O2 -oxyz.o xyz.c
After Removing "-O2" it is working Cool.
- Combuster
- Member
- Posts: 9301
- Joined: Wed Oct 18, 2006 3:45 am
- Libera.chat IRC: [com]buster
- Location: On the balcony, where I can actually keep 1½m distance
- Contact:
Re: DJGPP Inline Problem
That's utterly Bulls**t. It means you depend on GCC to manage resources in a specific way, which differs between O0 and O2.SatyaNarayan wrote:Because Optimization Don't Support Inline Assembly.
Re: DJGPP Inline Problem
Hi Combuster,
Please Compile The Above Code in GCC, with -O2 Option. I am Sure it will show Error Message. Remove That Option It will work, then what is That means.......? may be it don't supports Optimization.
Please Compile The Above Code in GCC, with -O2 Option. I am Sure it will show Error Message. Remove That Option It will work, then what is That means.......? may be it don't supports Optimization.
Last edited by Mohanty on Thu Sep 09, 2010 11:01 pm, edited 1 time in total.
Re: DJGPP Inline Problem
If you have a reg in the input list, it should not also be in the clobber list. So remove the "di". Actually I think it should be "%di", but it must be removed anyway.
BTW, I tried your code with "di" removed at various levels of -O and it made no difference. In all cases it compiled, ran and gave the correct length of the strings I tried.
Also, Combuster is correct I think. You just didn't understand the meaning of his comment. I didn't either until just now. Certainly, gcc inline assembler does support optimisation.
BTW, I tried your code with "di" removed at various levels of -O and it made no difference. In all cases it compiled, ran and gave the correct length of the strings I tried.
Also, Combuster is correct I think. You just didn't understand the meaning of his comment. I didn't either until just now. Certainly, gcc inline assembler does support optimisation.
If a trainstation is where trains stop, what is a workstation ?
- Owen
- Member
- Posts: 1700
- Joined: Fri Jun 13, 2008 3:21 pm
- Location: Cambridge, United Kingdom
- Contact:
Re: DJGPP Inline Problem
If its modified, it must be listed as clobbered; however, you are generally best specifying it as an output (GCC behaves badly when an input register is clobbered - this may be a bug fixed in latter versions)gerryg400 wrote:If you have a reg in the input list, it should not also be in the clobber list. So remove the "di". Actually I think it should be "%di", but it must be removed anyway.
BTW, I tried your code with "di" removed at various levels of -O and it made no difference. In all cases it compiled, ran and gave the correct length of the strings I tried.
Also, Combuster is correct I think. You just didn't understand the meaning of his comment. I didn't either until just now. Certainly, gcc inline assembler does support optimisation.
As for why the OP's code is failing: You have overly constrained the optimizer and it has ran out of registers. Sounds like you need to upgrade also. I have done significantly more complex things with GCC inline assembly (Including one expression where, of all 15 GPRs, 13 were clobbered and two were inout!)
Re: DJGPP Inline Problem
Sorry SatyaNarayan, I mis-wrote. It was actually JoeDavis code that I tried not your code.gerryg400 wrote:If you have a reg in the input list, it should not also be in the clobber list. So remove the "di". Actually I think it should be "%di", but it must be removed anyway.
BTW, I tried your code with "di" removed at various levels of -O and it made no difference. In all cases it compiled, ran and gave the correct length of the strings I tried.
Also, Combuster is correct I think. You just didn't understand the meaning of his comment. I didn't either until just now. Certainly, gcc inline assembler does support optimisation.
If a trainstation is where trains stop, what is a workstation ?
Re: DJGPP Inline Problem
Hi Combuster,
I am Really Really Sorry, That I Misunderstood You.
I am Really Really Sorry, That I Misunderstood You.
Re: DJGPP Inline Problem
In later gcc versions (2.8 and later) gcc doesn't like you to use a clobbered reg as input or output. It seems that the best thing to do is, if an input reg is clobbered list it as a fake output. Older versions of gcc weren't so fussy but 4.51 definitely doesn't always allow input regs in the clobber list. It will complain about running out of regs. And as the OP found this might depend on the optimisation level.Owen wrote:If its modified, it must be listed as clobbered; however, you are generally best specifying it as an output (GCC behaves badly when an input register is clobbered - this may be a bug fixed in latter versions)
The first part is correct but an upgrade to gcc won't help.Owen wrote:As for why the OP's code is failing: You have overly constrained the optimizer and it has ran out of registers. Sounds like you need to upgrade also. I have done significantly more complex things with GCC inline assembly (Including one expression where, of all 15 GPRs, 13 were clobbered and two were inout!)
I feel this whole thing is a clear change in the way inline assy works.
The gcc manual wrote:You may not write a clobber description in a way that overlaps with an input or output operand. For example, you may not have an operand describing a register class with one member if you mention that register in the clobber list. Variables declared to live in specific registers (see Section 5.40 [Explicit Reg Vars], page 345), and used as asm input or output operands must have no part mentioned in the clobber description. There is no way for you to specify that an input operand is modified without also specifying it as an output operand. Note that if all the output operands you specify are for this purpose (and hence unused), you will then also need to specify volatile for the asm construct, as described below, to prevent GCC from deleting the asm statement as unused
If a trainstation is where trains stop, what is a workstation ?