Re: Integer Division on 32 Bit Machines
On Fri, Sep 10, 2010 at 10:08 AM, arshad hussain arshad.su...@gmail.comwrote: I agree with Silesh 100% here. Thanks. Rather than agreeing with Silesh show some real suggestion to original posters question. I have a habit of understanding what other people ask and try to understand what they have problem.
Re: Integer Division on 32 Bit Machines
On 9/10/2010 12:22 PM, Bond wrote: On Fri, Sep 10, 2010 at 10:08 AM, arshad hussain arshad.su...@gmail.com mailto:arshad.su...@gmail.com wrote: I agree with Silesh 100% here. Thanks. Rather than agreeing with Silesh show some real suggestion to original posters question. Do not tell me what to do... Not going to take suggestions form someone who does not understand plain instruction that hijacking mail is a no-no. I have a habit of understanding what other people ask and try to understand what they have problem. No body cares. The only point is there is a _process_ and that's need to be adhered. -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: Integer Division on 32 Bit Machines
Hi Dave, On Thu, Sep 09, 2010 at 06:16:07PM -0700, Dave Hylands wrote: I've understood so far your explanations. But one thing I am missing: I claim that I do not do an 64-bit division, but an 32-bit division. Why? I have run make tags to create an architecture dependent tags file. When I go to s64 and jump to the definition I land in include/asm-generic/int-l64.h . There is the typedef: typedef signed long s64; I think you're looking in the wrong file. include/linux/types.h includes asm/types.h arch/x86/include/asm/types.h includes asm-generic/types.h include/asm-generic/types.h includes asm-generic/int-ll64.h include/asm-generic/int-ll64.h has the following typedef for s64: typedef signed long long s64; which is in fact a 64-bit type. You're right. I've misused ctags within vim - it was configured to jump to the first entry if there are several files found (for vim users: now I use g] instead of CTRL-] so that I get a list of all hits). So for example I get for g] on s64 the following list (showing only the first two hits): # pri verw. tag Datei 1 F ts64 include/asm-generic/int-l64.h typedef signed long s64; 2 F ts64 include/asm-generic/int-ll64.h typedef signed long long s64; ... Is there any way to know which one is the correct one, i.e. the one which is really used in my context? Am I correct that arch/x86/include/asm/types.h is for all 32-bit machines and arch/ia64/include/asm/types.h is for all 64-bit machines with an intel compatible architecture? Thanks again! Andreas -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: Integer Division on 32 Bit Machines
Hi Andreas, Replying to the list this time... On Tue, Sep 7, 2010 at 3:02 AM, Andreas Leppert wu...@web.de wrote: Hello, I have encountered a problem on my 32 bit machine. Here some code snippets: ...snip... optimizer/built-in.o: In function `sys_optStopMeasure': /source/trunk/linux-2.6.34/optimizer/sys_optStopMeasure.c:144: undefined reference to `__divdi3' Another person which has tried the code had no problems - he compiled the code for a 64 bit machine. Can you explain to me the problem? Why does the code work on 64 but not on 32 bit? I've looked for some workarounds and found do_div(). Is this the way to go? Or are there better ways? 32-bit kernels do not support 64-bit divides in the kernel. Using do_div is the correct way to do things. The reason it works in a 64-bit kernel is because a 64-bit CPU can do 64-bit divides. A 32-but CPU can only do 32-bit divides. You also have to consider that the linux kernel runs on more platforms that just x86. It also runs on ARM, MIPS, PowerPC, etc. The general rule is: there is no floating point support in kernel space (as a general rule: it may happen to work on some CPUs). Another general rule, is that on 32-bit CPUs you can only do 32-bit arithmetic, with 64-bit addition, subtraction, and multiplications. 64-bit divides must be done using do_div or do_div64. -- Dave Hylands Shuswap, BC, Canada http://www.DaveHylands.com/ -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: Integer Division on 32 Bit Machines
Hi Dave, On Wed, Sep 08, 2010 at 11:14:30PM -0700, Dave Hylands wrote: Replying to the list this time... finally an answer to *my* problem, thanks :-D Another general rule, is that on 32-bit CPUs you can only do 32-bit arithmetic, with 64-bit addition, subtraction, and multiplications. 64-bit divides must be done using do_div or do_div64. I've understood so far your explanations. But one thing I am missing: I claim that I do not do an 64-bit division, but an 32-bit division. Why? I have run make tags to create an architecture dependent tags file. When I go to s64 and jump to the definition I land in include/asm-generic/int-l64.h . There is the typedef: typedef signed long s64; On my system, the size of long int is the same as int (I've wrote a simple C program to get this information). I.e. there should be no difference between an 'signed int division' and an 'signed long division'. What am I missing? Another question: I've encountered several #ifdef __ASSEMBLY__ and __KERNEL__ in the header files. What do these two preprocessor definitions stand for? Thanks in advance for your help! Andreas -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: Integer Division on 32 Bit Machines
On Wed, Sep 8, 2010 at 10:51 PM, Bond jamesbond.2...@gmail.com wrote: On Thu, Sep 9, 2010 at 8:11 AM, ptchinster ptchins...@archlinux.us wrote: What do you think? Apply what you have learned so far and come up with the pros and cons of being able to use negative numbers. I read that book of Robert Love LKD. I am not very impressed by the book. The book does discuss some things which are not easy to find else where. What I am looking for is some material where I can jump with some working examples. This book, LDD(Linux Device Drivers) has some code examples and is free. http://www.xml.com/ldd/chapter/book/ it is a classic, but showing its age. It is still worth reading. I personally have read it over 10 times and learn something new every read. -- John -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: Integer Division on 32 Bit Machines
Hi Andreas, On Thu, Sep 9, 2010 at 1:28 AM, Andreas Leppert wu...@web.de wrote: Hi Dave, On Wed, Sep 08, 2010 at 11:14:30PM -0700, Dave Hylands wrote: Replying to the list this time... finally an answer to *my* problem, thanks :-D Another general rule, is that on 32-bit CPUs you can only do 32-bit arithmetic, with 64-bit addition, subtraction, and multiplications. 64-bit divides must be done using do_div or do_div64. I've understood so far your explanations. But one thing I am missing: I claim that I do not do an 64-bit division, but an 32-bit division. Why? I have run make tags to create an architecture dependent tags file. When I go to s64 and jump to the definition I land in include/asm-generic/int-l64.h . There is the typedef: typedef signed long s64; I think you're looking in the wrong file. include/linux/types.h includes asm/types.h arch/x86/include/asm/types.h includes asm-generic/types.h include/asm-generic/types.h includes asm-generic/int-ll64.h include/asm-generic/int-ll64.h has the following typedef for s64: typedef signed long long s64; which is in fact a 64-bit type. On my system, the size of long int is the same as int (I've wrote a simple C program to get this information). I.e. there should be no difference between an 'signed int division' and an 'signed long division'. What am I missing? Another question: I've encountered several #ifdef __ASSEMBLY__ and __KERNEL__ in the header files. What do these two preprocessor definitions stand for? I normally use __KERNEL__ in my header/source files to tell if the code is being compiled as part of the kernel, versus say being compiled as part of a boot-loader or part of a user-mode application. __ASSEMBLY__ is defined when assembling source files that include .h files. Since the preprocessor is used on .S files, the #defines are good, but the assembler doesn't understand typedefs structs, function prototypes, etc. -- Dave Hylands Shuswap, BC, Canada http://www.DaveHylands.com/ -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: Integer Division on 32 Bit Machines
It would be better if you do not hijack other e-mail threads to post your own question. I agree with Silesh 100% here. Thanks. -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: Integer Division on 32 Bit Machines
On Tue, Sep 7, 2010 at 11:29 PM, hiren panchasara hiren.panchas...@gmail.com wrote: Bond, This should help: http://en.wikipedia.org/wiki/Typedef Thanks I read that. but in the question which original poster asked he mentioned signed long s64. I am not clear with that.
Re: Integer Division on 32 Bit Machines
On Tue, Sep 7, 2010 at 11:22 PM, Bond jamesbond.2...@gmail.com wrote: On Tue, Sep 7, 2010 at 11:29 PM, hiren panchasara hiren.panchas...@gmail.com wrote: Bond, This should help: http://en.wikipedia.org/wiki/Typedef Thanks I read that. but in the question which original poster asked he mentioned signed long s64. I am not clear with that. What exactly is your question? Please elaborate. Thanks, Hiren
Re: Integer Division on 32 Bit Machines
On Tue, Sep 7, 2010 at 11:14 PM, Bond jamesbond.2...@gmail.com wrote: On Tue, Sep 7, 2010 at 3:32 PM, Andreas Leppert wu...@web.de wrote: Hello, I have encountered a problem on my 32 bit machine. Here some code snippets: typedef signed long s64; Ok here is an article which cleared my doubts http://www.linuxfordevices.com/c/a/Linux-For-Devices-Articles/ELJonlineBRWriting-Portable-Device-Drivers/ but I am not clear with meaning of signed and unsigned.
Re: Integer Division on 32 Bit Machines
On Wed, Sep 8, 2010 at 12:22 PM, hiren panchasara hiren.panchas...@gmail.com wrote: What exactly is your question? Please elaborate. In the code signed and unsigned word are used what is that and why is that used?
Re: Integer Division on 32 Bit Machines
On Tue, Sep 7, 2010 at 11:53 PM, Bond jamesbond.2...@gmail.com wrote: On Wed, Sep 8, 2010 at 12:22 PM, hiren panchasara hiren.panchas...@gmail.com wrote: What exactly is your question? Please elaborate. In the code signed and unsigned word are used what is that and why is that used? First search in google gave me this: http://www.rwc.uc.edu/koehler/comath/13.html I think you should read up more on C. http://www.amazon.com/Programming-Language-2nd-Brian-Kernighan/dp/0131103628 Thanks, Hiren
Re: Integer Division on 32 Bit Machines
On Wed, Sep 8, 2010 at 12:27 PM, hiren panchasara hiren.panchas...@gmail.com wrote: First search in google gave me this: but what did you searched that is my problem?
Re: Integer Division on 32 Bit Machines
On Wed, Sep 8, 2010 at 8:40 AM, DG dang...@gmail.com wrote: On Wed, Sep 8, 2010 at 12:51 AM, Bond jamesbond.2...@gmail.com wrote: On Tue, Sep 7, 2010 at 11:14 PM, Bond jamesbond.2...@gmail.com wrote: On Tue, Sep 7, 2010 at 3:32 PM, Andreas Leppert wu...@web.de wrote: Hello, I have encountered a problem on my 32 bit machine. Here some code snippets: typedef signed long s64; Ok here is an article which cleared my doubts http://www.linuxfordevices.com/c/a/Linux-For-Devices-Articles/ELJonlineBRWriting-Portable-Device-Drivers/ but I am not clear with meaning of signed and unsigned. Quick explanation/example: With 8 bits you can represent (2 ** 8) -1 possible numbers. Unsigned numbers mean that the number cannot be negative so the numbers go from 0 - 255 (0b - 0b ) Signed numbers _can_ be negative so they represent the numbers in the range -128 - 127 (0b1000 - 0b0111 ) The same thing applies to 32 bit integers. Both signed and unsigned use the same number of bits, but they represent different ranges of numbers. If your number is never expected to be negative, unsigned numbers give you a higher positive range. To understand the negative numbering: http://en.wikipedia.org/wiki/Twos_complement Whoops, I meant to say: with 8 bits you can represent 2 ** 8 (256) different numbers. Unsigned numbers go from 0 - (2 ** 8) -1
Re: Integer Division on 32 Bit Machines
On Wed, Sep 8, 2010 at 12:51 AM, Bond jamesbond.2...@gmail.com wrote: On Tue, Sep 7, 2010 at 11:14 PM, Bond jamesbond.2...@gmail.com wrote: On Tue, Sep 7, 2010 at 3:32 PM, Andreas Leppert wu...@web.de wrote: Hello, I have encountered a problem on my 32 bit machine. Here some code snippets: typedef signed long s64; Ok here is an article which cleared my doubts http://www.linuxfordevices.com/c/a/Linux-For-Devices-Articles/ELJonlineBRWriting-Portable-Device-Drivers/ but I am not clear with meaning of signed and unsigned. Quick explanation/example: With 8 bits you can represent (2 ** 8) -1 possible numbers. Unsigned numbers mean that the number cannot be negative so the numbers go from 0 - 255 (0b - 0b ) Signed numbers _can_ be negative so they represent the numbers in the range -128 - 127 (0b1000 - 0b0111 ) The same thing applies to 32 bit integers. Both signed and unsigned use the same number of bits, but they represent different ranges of numbers. If your number is never expected to be negative, unsigned numbers give you a higher positive range. To understand the negative numbering: http://en.wikipedia.org/wiki/Twos_complement
Re: Integer Division on 32 Bit Machines
On Wed, Sep 8, 2010 at 8:10 PM, DG dang...@gmail.com wrote: If your number is never expected to be negative, unsigned numbers give you a higher positive range. To understand the negative numbering: http://en.wikipedia.org/wiki/Twos_complement Hi, I am not clear with what does a -ve number has to do with a CPU instruction.Meaning does Linux Kernel uses -ve number?
Re: Integer Division on 32 Bit Machines
DG and Mark thanks I understood the concept.
Re: Integer Division on 32 Bit Machines
On Wed, Sep 8, 2010 at 9:41 PM, Bond jamesbond.2...@gmail.com wrote: does Linux Kernel uses -ve number? I forgot to say except the error things like ENOENT type other than that how are -ve number helpful.
Re: Integer Division on 32 Bit Machines
On Wed, Sep 8, 2010 at 12:12 PM, Bond jamesbond.2...@gmail.com wrote: On Wed, Sep 8, 2010 at 9:41 PM, Bond jamesbond.2...@gmail.com wrote: does Linux Kernel uses -ve number? I forgot to say except the error things like ENOENT type other than that how are -ve number helpful. Are you asking if negative numbers are useful for anything but error codes? Seriously, you're asking that? Greg -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: Integer Division on 32 Bit Machines
On Thu, Sep 9, 2010 at 1:32 AM, Greg Freemyer greg.freem...@gmail.comwrote: Are you asking if negative numbers are useful for anything but error codes? Seriously, you're asking that? Greg Yes I am asking this.
Re: Integer Division on 32 Bit Machines
Sorry guys for interrupting your thread. I have trouble mailing to the group. So just testing on this thread whether I can mail to group. kernelnewbies On Wed, Sep 8, 2010 at 8:57 PM, Bond jamesbond.2...@gmail.com wrote: On Thu, Sep 9, 2010 at 1:32 AM, Greg Freemyer greg.freem...@gmail.comwrote: Are you asking if negative numbers are useful for anything but error codes? Seriously, you're asking that? Greg Yes I am asking this.
Re: Integer Division on 32 Bit Machines
On Thu, Sep 9, 2010 at 8:11 AM, ptchinster ptchins...@archlinux.us wrote: What do you think? Apply what you have learned so far and come up with the pros and cons of being able to use negative numbers. I read that book of Robert Love LKD. I am not very impressed by the book. The book does discuss some things which are not easy to find else where. What I am looking for is some material where I can jump with some working examples. For example I wrote my Kernel Module.I also wrote a small driver for my experiment. Both of them were working. I also read the Essential Linux Device Driver Development (4 chapters of starting and last 2 where they discuss about debugging Kernel) These books discuss the kernel things services which might be needed by the driver code. See in my case I do not work in a company or organization that has any thing to do with Linux. What I am looking at is some small exercise which I can do on my own and after I try it I get back here. What next do I try I am not clear with that part?
Re: Integer Division on 32 Bit Machines
On Thu, Sep 9, 2010 at 8:21 AM, Bond jamesbond.2...@gmail.com wrote: On Thu, Sep 9, 2010 at 8:11 AM, ptchinster ptchins...@archlinux.us wrote: What do you think? Apply what you have learned so far and come up with the pros and cons of being able to use negative numbers. I read that book of Robert Love LKD. I am not very impressed by the book. The book does discuss some things which are not easy to find else where. What I am looking for is some material where I can jump with some working examples. For example I wrote my Kernel Module.I also wrote a small driver for my experiment. Both of them were working. I also read the Essential Linux Device Driver Development (4 chapters of starting and last 2 where they discuss about debugging Kernel) These books discuss the kernel things services which might be needed by the driver code. See in my case I do not work in a company or organization that has any thing to do with Linux. What I am looking at is some small exercise which I can do on my own and after I try it I get back here. What next do I try I am not clear with that part? It would be better if you do not hijack other e-mail threads to post your own question. Please start a new e-mail thread to post your queries. This will help folks who go through this mailing list archive to find out answer to a specific problem. In this case, the original question was Integer Division on 32 Bit Machines. So it would be easy to find the answer to this if one e-mail thread handled only this or may be some closely related stuff. Thanks, Silesh -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: Integer Division on 32 Bit Machines
On Thu, Sep 9, 2010 at 8:42 AM, Silesh C V sailes...@gmail.com wrote: It would be better if you do not hijack other e-mail threads to post your own question. I wanted to know what his code is doing.So I asked. Please start a new e-mail thread to post your queries. This will help folks who go through this mailing list archive to find out answer to a specific problem. In this case, the original question was Integer Division on 32 Bit Machines. So it would be easy to find the answer Please answer this.
Integer Division on 32 Bit Machines
Hello, I have encountered a problem on my 32 bit machine. Here some code snippets: typedef signed long s64; asmlinkage long sys_optStopMeasure(int __user workamount) { s64 currentPerformance, currentTimePerWork; ... currentTimePerWork = currentPerformance / workamount; ... } When I run a make, I get this error at the end: LD vmlinux.o MODPOST vmlinux.o GEN .version CHK include/generated/compile.h UPD include/generated/compile.h CC init/version.o LD init/built-in.o LD .tmp_vmlinux1 optimizer/built-in.o: In function `sys_optStopMeasure': /source/trunk/linux-2.6.34/optimizer/sys_optStopMeasure.c:144: undefined reference to `__divdi3' Another person which has tried the code had no problems - he compiled the code for a 64 bit machine. Can you explain to me the problem? Why does the code work on 64 but not on 32 bit? I've looked for some workarounds and found do_div(). Is this the way to go? Or are there better ways? Thanks for your help! Andreas -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: Integer Division on 32 Bit Machines
use do_div On Tue, Sep 7, 2010 at 1:02 PM, Andreas Leppert wu...@web.de wrote: Hello, I have encountered a problem on my 32 bit machine. Here some code snippets: typedef signed long s64; asmlinkage long sys_optStopMeasure(int __user workamount) { s64 currentPerformance, currentTimePerWork; ... currentTimePerWork = currentPerformance / workamount; ... } When I run a make, I get this error at the end: LD vmlinux.o MODPOST vmlinux.o GEN .version CHK include/generated/compile.h UPD include/generated/compile.h CC init/version.o LD init/built-in.o LD .tmp_vmlinux1 optimizer/built-in.o: In function `sys_optStopMeasure': /source/trunk/linux-2.6.34/optimizer/sys_optStopMeasure.c:144: undefined reference to `__divdi3' Another person which has tried the code had no problems - he compiled the code for a 64 bit machine. Can you explain to me the problem? Why does the code work on 64 but not on 32 bit? I've looked for some workarounds and found do_div(). Is this the way to go? Or are there better ways? Thanks for your help! Andreas -- To unsubscribe from this list: send an email with unsubscribe kernelnewbies to ecar...@nl.linux.org Please read the FAQ at http://kernelnewbies.org/FAQ
Re: Integer Division on 32 Bit Machines
On Tue, Sep 7, 2010 at 3:32 PM, Andreas Leppert wu...@web.de wrote: Hello, I have encountered a problem on my 32 bit machine. Here some code snippets: typedef signed long s64; Hi sorry my reply wont help you. Since I was reading this thread wanted to know what is the meaning of typedef signed long s64 I searched at Google but could not find it. -- Everything is okay in the end, if it's not ok, then it's not the end.
Re: Integer Division on 32 Bit Machines
Bond, On Tue, Sep 7, 2010 at 10:44 AM, Bond jamesbond.2...@gmail.com wrote: On Tue, Sep 7, 2010 at 3:32 PM, Andreas Leppert wu...@web.de wrote: Hello, I have encountered a problem on my 32 bit machine. Here some code snippets: typedef signed long s64; Hi sorry my reply wont help you. Since I was reading this thread wanted to know what is the meaning of typedef signed long s64 I searched at Google but could not find it. This should help: http://en.wikipedia.org/wiki/Typedef Thanks, Hiren -- Everything is okay in the end, if it's not ok, then it's not the end.