RTXI 1.3
comedi/include/asm/div64.h
Go to the documentation of this file.
00001 /***************************************************************************
00002                                   asm/div64.h
00003                              -------------------
00004 
00005     copyright            : (C) 2002 by Frank Mori Hess
00006     email                : fmhess@users.sourceforge.net
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef _DIV64_COMPAT_H
00019 #define _DIV64_COMPAT_H
00020 
00021 #include <linux/version.h>
00022 
00023 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 4, 0)
00024 
00025 static inline u64 my_ull_div(u64 numerator, unsigned long denominator)
00026 {
00027         u32 value;
00028         u64 remainder, temp, answer = 0;
00029         unsigned int shift;
00030         static const u32 max_u32 = 0xffffffff;
00031 
00032         remainder = numerator;
00033 
00034         while (remainder >= denominator) {
00035                 shift = 0;
00036                 numerator = remainder;
00037                 // shift most significant bits into 32 bit variable
00038                 while (numerator > max_u32) {
00039                         numerator >>= 1;
00040                         shift++;
00041                 }
00042                 if (numerator < denominator) {
00043                         shift--;
00044                         value = 1;
00045                 } else {
00046                         value = numerator;
00047                         value /= denominator;
00048                 }
00049                 temp = ((u64) value) << shift;
00050                 answer += temp;
00051                 remainder -= temp * denominator;
00052         }
00053 
00054         return answer;
00055 }
00056 
00057 #define do_div(n, base) ((n) = my_ull_div(n, base))
00058 
00059 #else
00060 
00061 #include_next <asm/div64.h>
00062 
00063 #endif
00064 
00065 #endif // _DIV64_COMPAT_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines