Re: Integer Division on 32 Bit Machines

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Andreas,

On Thu, Sep 9, 2010 at 1:28 AM, Andreas Leppert <wudmx@xxxxxx> 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 ecartis@xxxxxxxxxxxx
Please read the FAQ at http://kernelnewbies.org/FAQ



[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux