GCC problems.
GCC problems.
Hi,
Here I have a problem I can't fix.:
In file included in stdio.c:20:
../include/string.h 26: warning: conflicting types for built-in function 'memset'
Here is my string line 26:
extern inline void *memset(void *s,char c,int count);
I also tried:
inline void *memset(void *s,char c,int count);
And the memset function in string.h:
inline void *memset(void *s,char c,int count)
{
int d0, d1;
__asm__ __volatile__(
"cld\n\t"
"rep\n\t"
"stosb"
: "=&c" (d0), "=&D" (d1)
:"a" (c),"1" (s),"0" (count)
:"memory");
return s;
Here I have a problem I can't fix.:
In file included in stdio.c:20:
../include/string.h 26: warning: conflicting types for built-in function 'memset'
Here is my string line 26:
extern inline void *memset(void *s,char c,int count);
I also tried:
inline void *memset(void *s,char c,int count);
And the memset function in string.h:
inline void *memset(void *s,char c,int count)
{
int d0, d1;
__asm__ __volatile__(
"cld\n\t"
"rep\n\t"
"stosb"
: "=&c" (d0), "=&D" (d1)
:"a" (c),"1" (s),"0" (count)
:"memory");
return s;
-
- Member
- Posts: 1600
- Joined: Wed Oct 18, 2006 11:59 am
- Location: Vienna/Austria
- Contact:
Re:GCC problems.
this problem I ve experienced too. I don't know if my solution is the right one, but I compiled the files with
-fno-builtin (or similar check man gcc for this) and it compiled without complaining anymore. This is because there exists a standard memset routine in c which the c compiler refers to usually - its already buldt in.
Pls correct me, if I am in err.
stay safe
-fno-builtin (or similar check man gcc for this) and it compiled without complaining anymore. This is because there exists a standard memset routine in c which the c compiler refers to usually - its already buldt in.
Pls correct me, if I am in err.
stay safe
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
BlueillusionOS iso image
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:GCC problems.
what i hardly understand is why you have ecx and edi declared as outputs ...
i personally use
Where the last asm command do nothing, but tell the compiler
not to rely on the content of edi and ecx anymore. I guess you're doing something similar, but won't the compiler have to reserve
space for d0 and d1 and issue mov instructions ?
Maybe not if the optimizer is smart enough ... though i would be pleased if you could tell me if you checked the generated code
i personally use
Code: Select all
/* sets N bytes of DEST to character C */
__inline__ void memset(void* dest,int c,int n)
{
asm volatile("cld;rep;stosb":
:"D"(dest),"c"(n),"a"(c));
asm("": : :"%edi","%ecx");
}
not to rely on the content of edi and ecx anymore. I guess you're doing something similar, but won't the compiler have to reserve
space for d0 and d1 and issue mov instructions ?
Maybe not if the optimizer is smart enough ... though i would be pleased if you could tell me if you checked the generated code
-
- Member
- Posts: 1600
- Joined: Wed Oct 18, 2006 11:59 am
- Location: Vienna/Austria
- Contact:
Re:GCC problems.
I wonder why this function is made in asm instead of c?
in case of memset it is really easier to understand when there stands:
The syntax of this inline assembly of gcc is also something very obscure to me .
what are the benefits of using inline assembly?
in case of memset it is really easier to understand when there stands:
Code: Select all
void memset(void *target,unsigned char character,int length){
while(length--) *target++=character;
}
what are the benefits of using inline assembly?
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
BlueillusionOS iso image
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:GCC problems.
because the processor can make things faster when a "rep stosb" is used (afaik).
Note that in order to be *really* faster, it would be wise to use a dword-aligned rep stosd ...
Note that in order to be *really* faster, it would be wise to use a dword-aligned rep stosd ...
-
- Member
- Posts: 1600
- Joined: Wed Oct 18, 2006 11:59 am
- Location: Vienna/Austria
- Contact:
Re:GCC problems.
well... would this then look like the following?
extern void memset(void *target, unsigned char zeichen,int length);
in nasm:
Would this code do what one expects from memset?
extern void memset(void *target, unsigned char zeichen,int length);
in nasm:
Code: Select all
[global memset]
memset:
push ebp
mov ebp,esp
mov [ebp+8],edi ;*target
mov [ebp+12],al ; zeichen
mov [ebp+13],ecx ; length
cld
rep stosb
pop ebp
ret
Code: Select all
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
BlueillusionOS iso image
Re:GCC problems.
Not quite. There are a few mistakes there: you had the MOV operands the wrong way round, and everything on the stack is dword-aligned.
Code: Select all
[global memset]
memset:
push ebp
mov ebp,esp
mov edi, [ebp+8] ;*target
mov al, [ebp+12] ; zeichen
mov ecx, [ebp+16] ; length
cld
rep stosb
pop ebp
ret
Re:GCC problems.
Well pype,
Maybe i forget to check generated code ::)
The true is i recently learned the asm at&t sintaxi. My natural sintaxis is intel. But i want to prove, but my frankeinstein don't works well.
Thanks for all.
Maybe i forget to check generated code ::)
The true is i recently learned the asm at&t sintaxi. My natural sintaxis is intel. But i want to prove, but my frankeinstein don't works well.
Thanks for all.
-
- Member
- Posts: 1600
- Joined: Wed Oct 18, 2006 11:59 am
- Location: Vienna/Austria
- Contact:
Re:GCC problems.
tim, thanks for correction ... this comes from trying to type code when one is too tired to think.
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
BlueillusionOS iso image
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:GCC problems.
BTW, GCC (and most other C compiler) will expect registers like EDI and ECX not to be destroyed by the function, so you should push them before and pop them after.Tim Robinson wrote:Code: Select all
[global memset] memset: push ebp mov ebp,esp mov edi, [ebp+8] ;*target mov al, [ebp+12] ; zeichen mov ecx, [ebp+16] ; length cld rep stosb pop ebp ret
And that's why inlined code can be quicker than pure asm function.