DJGPP Inline Problem

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Mohanty
Member
Member
Posts: 28
Joined: Fri Jul 30, 2010 9:15 am
Location: India
Contact:

DJGPP Inline Problem

Post by Mohanty »

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;
}
tharkun
Member
Member
Posts: 51
Joined: Sat Mar 21, 2009 1:29 pm
Location: Ireland

Re: DJGPP Inline Problem

Post by tharkun »

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;
}
User avatar
Mohanty
Member
Member
Posts: 28
Joined: Fri Jul 30, 2010 9:15 am
Location: India
Contact:

Re: DJGPP Inline Problem

Post by Mohanty »

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.
User avatar
Combuster
Member
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

Post by Combuster »

SatyaNarayan wrote:Because Optimization Don't Support Inline Assembly.
That's utterly Bulls**t. It means you depend on GCC to manage resources in a specific way, which differs between O0 and O2.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Mohanty
Member
Member
Posts: 28
Joined: Fri Jul 30, 2010 9:15 am
Location: India
Contact:

Re: DJGPP Inline Problem

Post by Mohanty »

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.
Last edited by Mohanty on Thu Sep 09, 2010 11:01 pm, edited 1 time in total.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: DJGPP Inline Problem

Post by gerryg400 »

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 ?
User avatar
Owen
Member
Member
Posts: 1700
Joined: Fri Jun 13, 2008 3:21 pm
Location: Cambridge, United Kingdom
Contact:

Re: DJGPP Inline Problem

Post by Owen »

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 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)

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!)
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: DJGPP Inline Problem

Post by gerryg400 »

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.
Sorry SatyaNarayan, I mis-wrote. It was actually JoeDavis code that I tried not your code.
If a trainstation is where trains stop, what is a workstation ?
User avatar
Mohanty
Member
Member
Posts: 28
Joined: Fri Jul 30, 2010 9:15 am
Location: India
Contact:

Re: DJGPP Inline Problem

Post by Mohanty »

Hi Combuster,
I am Really Really Sorry, That I Misunderstood You.
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: DJGPP Inline Problem

Post by gerryg400 »

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)
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: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!)
The first part is correct but an upgrade to gcc won't help.

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 ?
Post Reply