Rules | Recent posts | topic RSS | Search | Register  | Log in

How to write a C code in 64-bit fixed point?

 
Post new topic  Reply to topic    EDAboard.com Forum Index -> PC Programming and Interfacing
Author Message
boeysue



Joined: 23 Dec 2004
Posts: 190
Helped: 3


Post02 Jan 2005 16:49   How to write a C code in 64-bit fixed point?

How to write a 64-bit fixed point C code in unix ?Because in unix ,the operation of 64-bit fixed point is not right...So can anyone tell me how to write a 64-bit fixed point operation in C code!thanks for help!
Back to top
echo47



Joined: 07 Apr 2002
Posts: 4206
Helped: 565


Post03 Jan 2005 6:09   How to write a C code in 64-bit fixed point?

64-bit integer syntax tends to be non-portable on 32-bit compilers. Which compiler are you using, and what problem are you seeing? Post a small program that demonstrates the problem.

This works in MinGW GCC 3.4.2, but the long long, LL, and %I64d may be different on your compiler:
Code:
#include <stdio.h>
int main(void)
{
  long long a=1122334455667788LL, b=1000;
  printf("product=%I64d\n", a*b);
  return 0;
}

product=1122334455667788000
Back to top
boeysue



Joined: 23 Dec 2004
Posts: 190
Helped: 3


Post03 Jan 2005 6:13   Re: How to write a C code in 64-bit fixed point?

64-bit long long
the operation with shift and + seems to be wrong.
Because I use the server to change the 32-bit directly to 64-bit,It seems to be saturated on 2^16.
So I just think the ansi didn't support the operation of 64-bit operation.
By the way,What is the answer to help me of the shift/add operation on 64-bit!
Thanks a lot.
Back to top
echo47



Joined: 07 Apr 2002
Posts: 4206
Helped: 565


Post03 Jan 2005 6:28   How to write a C code in 64-bit fixed point?

Tell us your compiler version and show us your non-working code so we can help you.

What do you mean, use server to change 32-bit to 64-bit??

ANSI doesn't specify the number of bits. That's compiler dependent.
Back to top
boeysue



Joined: 23 Dec 2004
Posts: 190
Helped: 3


Post03 Jan 2005 6:53   Re: How to write a C code in 64-bit fixed point?

Actually I just do a cic decimation filter just as my decimation is 128 and my stage is 5th order,then I see the output of the bitstream stick to 2^16.
By the way,How to use the cicdecim command on matlab?The IWL/OWL setting seems strange ,maybe I get the wrong idea about it.
plz help me..
Back to top
echo47



Joined: 07 Apr 2002
Posts: 4206
Helped: 565


Post03 Jan 2005 7:36   How to write a C code in 64-bit fixed point?

I've never used that MATLAB filter. Type this command to see lots of info and examples:
doc mfilt.cicdecim
Back to top
boeysue



Joined: 23 Dec 2004
Posts: 190
Helped: 3


Post03 Jan 2005 7:38   Re: How to write a C code in 64-bit fixed point?

Actually I use +1/-1 as input ,and setting IWL = 1,there is many warning message.
But if I use IWL = 2,the output bitstream seams error..
So I make confused of the introduction of mathworks.
Back to top
muko



Joined: 03 Mar 2004
Posts: 37
Helped: 1


Post04 Jan 2005 13:54   How to write a C code in 64-bit fixed point?

union {
unsigned long x;
unsigned long y;
};

this is a 64-bit integer is it right?
Back to top
bilgekaan



Joined: 18 Nov 2004
Posts: 118
Helped: 14
Location: Turkiye


Post04 Jan 2005 14:18   Re: How to write a C code in 64-bit fixed point?

union {
unsigned long x;
unsigned long y;
};

this is a 64-bit integer is it right?

no unsigned long x and y resides in the same place . size of struct is equal to

sizeof longest data type .

sizeof(union { unsigned long x; unsigned long y; }) = sizeof( unsigned long );



you can define like this

typedef struct
{
unsigned long upperPart;
unsigned long lowerPart;
} int_64_Bits;

but you cannot use this structure directly in arihtmetic operations. you mast define custom operators or functions
Back to top
boeysue



Joined: 23 Dec 2004
Posts: 190
Helped: 3


Post05 Jan 2005 11:26   Re: How to write a C code in 64-bit fixed point?

mmm..
Do you mean it need to take apart to two 32-bit part?
But how to do the operation of add and multiply?
Especially multiply....
Thanks for answering.
Back to top
boeysue



Joined: 23 Dec 2004
Posts: 190
Helped: 3


Post06 Jan 2005 7:13   Re: How to write a C code in 64-bit fixed point?

How to use two part in unix without assembly?
Because the carry-out bit after the operation of addition,It is the problem I couldn't understand.
Plz help.
Back to top
arturt134



Joined: 01 Jan 1970
Posts: 140
Helped: 1
Location: Poland


Post06 Jan 2005 8:15   Re: How to write a C code in 64-bit fixed point?

Look at the: http://www.edaboard.com/ftopic102863.html
There is definition of <inttypes.h> header file.
Back to top
boeysue



Joined: 23 Dec 2004
Posts: 190
Helped: 3


Post06 Jan 2005 8:45   Re: How to write a C code in 64-bit fixed point?

Can you express more clearly?
Which parameter or variables did it use for that?
Because I print the __WORDSIZE ,it is 32.I dont use it for extending for 64-bit operation.Thanks for that.

Added after 7 minutes:

this seems problem...
long long x=0x01<<33;
printf("%x\n",x);

But I don't know why the following is correct:
long long x=0x01;

printf("%x\n",x<<33);

Thanks for help lorh..
It seems to bother me so long long time.

By the way,the compiler I used is gcc 2.96.

Added after 12 minutes:

mmm..
the machine is i686.//uname -m
compiler is gcc-2.96.//man gcc
and how to get more information in command?

thanks for help ...
Back to top
echo47



Joined: 07 Apr 2002
Posts: 4206
Helped: 565


Post06 Jan 2005 8:55   How to write a C code in 64-bit fixed point?

Boeysue, at last you are giving us some information! But it's still not enough.

If you compile that with the -Wall option (full warnings), gcc should warn you that your printf has inconsistent int format and argument type. Your %x tells printf to assume an int argument (apparently 32-bits in your compiler). Try %llx or %I64x instead. I can't guess the exact syntax, because it depends on your operating system and precise compiler version (type gcc --version).

... addition ...

Ok, i686 means it's a Pentium box. 32-bit integers as you determined. I haven't used that exact compiler, but %llx is a good candidate. Try it!

I don't understand "how to get more information in command?". Maybe you are asking about -Wall. I run the compiler like this:
gcc -Wall myprogram.c
Back to top
boeysue



Joined: 23 Dec 2004
Posts: 190
Helped: 3


Post06 Jan 2005 9:06   Re: How to write a C code in 64-bit fixed point?

this seems problem...
long long x=0x01<<33;
printf("%x\n",x);

But I don't know why the following is correct:
long long x=0x01;

printf("%x\n",x<<33);



Actually,In long long x=0x01<<33;//<---- this happens to be wrong...
the warning message is left shift is more than width of the type.
But when i print sizeof long long it is 8. So I am confused of this.
Back to top
echo47



Joined: 07 Apr 2002
Posts: 4206
Helped: 565


Post06 Jan 2005 9:22   How to write a C code in 64-bit fixed point?

long long x=0x01<<33;
No, 0x01 is a 32-bit int on your compiler, so shifting it by 33 bits gives you trouble. You will have better luck with this:
long long x=0x01LL<<33;

What did this output on your compiler?
long long x=0x01;
printf("%x\n",x<<33);

I would expect "0" or maybe "2" but not the desired result "200000000"

I'm guessing that this will produce the expected result "200000000":
long long x=0x01;
printf("%llx\n",x<<33);
Back to top
boeysue



Joined: 23 Dec 2004
Posts: 190
Helped: 3


Post06 Jan 2005 9:28   Re: How to write a C code in 64-bit fixed point?

mmm...
That's right...It helps me not to doing many nonuseless thing for work.Because I see many document not to recommand to write more than 32 bit code.So the above discussion helps me much more ,thanks.
Back to top
echo47



Joined: 07 Apr 2002
Posts: 4206
Helped: 565


Post06 Jan 2005 9:47   How to write a C code in 64-bit fixed point?

Ahh! See how much easier it is for us to help you when you show us your source code? Wink

These pages may be helpful too:

GCC manual section 4.10 (describes "LL" and "long long"):
http://gcc.gnu.org/onlinedocs/gcc-2.95.3/gcc_4.html#SEC71

GLIBC printf() integer precision specifiers (describes "ll"):
http://www.gnu.org/software/libc/manual/html_node/Integer-Conversions.html#Integer%20Conversions

GCC is an excellent compiler. If it does something that I didn't expect, it's usually my fault!
Back to top
boeysue



Joined: 23 Dec 2004
Posts: 190
Helped: 3


Post06 Jan 2005 17:58   Re: How to write a C code in 64-bit fixed point?

Does there exit any detailed document about gcc's tools?thanks for help :sm9:
Back to top
echo47



Joined: 07 Apr 2002
Posts: 4206
Helped: 565


Post07 Jan 2005 15:18   How to write a C code in 64-bit fixed point?

GNU Manuals Online, including gcc, glibc, etc:
http://www.gnu.org/manual/

Also look in your gcc install directory.
Back to top
boeysue



Joined: 23 Dec 2004
Posts: 190
Helped: 3


Post07 Jan 2005 19:39   Re: How to write a C code in 64-bit fixed point?

Is there any PC gnu development tool ?Not in the server?
By the way,the editer with joe not vim.Thanks.
Back to top
echo47



Joined: 07 Apr 2002
Posts: 4206
Helped: 565


Post08 Jan 2005 11:17   How to write a C code in 64-bit fixed point?

Sure! Search this forum for comments from other folks.

Lots of people use Cygwin, but I prefer MinGW for Windows apps:
http://www.mingw.org/
http://cygwin.com/

If you need to run under DOS:
http://www.delorie.com/djgpp/

There are others.
Back to top
Post new topic  Reply to topic    EDAboard.com Forum Index -> PC Programming and Interfacing
Page 1 of 1 All times are GMT + 1 Hour


Abuse
Administrator
Moderators
topic RSS 
sitemap