mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: error using unsigned long long not working in 2.4.x
  2003-03-18  5:44 error using unsigned long long not working in 2.4.x dave
@ 2003-03-17  8:54 ` Matti Aarnio
  2003-03-17 19:06 ` Randy.Dunlap
  1 sibling, 0 replies; 3+ messages in thread
From: Matti Aarnio @ 2003-03-17  8:54 UTC (permalink / raw)
  To: dave; +Cc: linux-kernel

On Mon, Mar 17, 2003 at 09:44:16PM -0800, dave wrote:
> hi i am writing a kernel 2.4.x driver and need to do maths on 64 bit ints
> (unsigned long long)
> bcause you can not use the FPU
> but when i insmod i get the error unresolved symbol __udivdi3 i need!! 64
> bit ints
> 
> i have included the code
> thank you

The original reason for Linux kernel not being linked with  -lgcc
where that routine is defined, is that of wanting to catch careless
coding of 64-bit arithmetic in kernel.  It does cause massiveish
performance penalty in the system, if used unchecked in code
fast paths.

If you can do it with at most 31 bit divider, and can handle 
side-effectfull division, system has   do_div()   macro.

Use like:

	#include <asm/div64.h>


	long long n, vco;
	long divisor;
	long remainder;

	n = vco;
	divisor = some_expression;
	remainder = do_div(n, divisor);


You will, most likely, ignore the remainder.
BECAUSE there is side-effect of modifying the dividend (n), you must
use it like in this illustriation.

The  divisor  can not have value in excess of 2^31.

Also there are architectures which do not properly implement this
routine, and do merely  32/32 division, where 64/32 is really wanted.
(The i386 architecture does handle it.)

/Matti Aarnio

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: error using unsigned long long not working in 2.4.x
  2003-03-18  5:44 error using unsigned long long not working in 2.4.x dave
  2003-03-17  8:54 ` Matti Aarnio
@ 2003-03-17 19:06 ` Randy.Dunlap
  1 sibling, 0 replies; 3+ messages in thread
From: Randy.Dunlap @ 2003-03-17 19:06 UTC (permalink / raw)
  To: dave; +Cc: linux-kernel

On Mon, 17 Mar 2003 21:44:16 -0800 "dave" <davekern@ihug.co.nz> wrote:

| hi i am writing a kernel 2.4.x driver and need to do maths on 64 bit ints
| (unsigned long long)
| bcause you can not use the FPU
| but when i insmod i get the error unresolved symbol __udivdi3 i need!! 64
| bit ints

Other alternatives are search the lkml archive for a patch from
George Anzinger on 2003-mar-05,
subject: [PATCH] Functions to do easy scaled math.

or if all you need is 64-bit mul and div, and only during setup
(when speed isn't a huge factor), you could use the divrem64()
function in this sample /procfs module:
  http://www.xenotime.net/linux/procfs_ex/procdiv64.c

--
~Randy

^ permalink raw reply	[flat|nested] 3+ messages in thread

* error using unsigned long long not working in 2.4.x
@ 2003-03-18  5:44 dave
  2003-03-17  8:54 ` Matti Aarnio
  2003-03-17 19:06 ` Randy.Dunlap
  0 siblings, 2 replies; 3+ messages in thread
From: dave @ 2003-03-18  5:44 UTC (permalink / raw)
  To: linux-kernel

[-- Attachment #1: Type: text/plain, Size: 247 bytes --]

hi i am writing a kernel 2.4.x driver and need to do maths on 64 bit ints
(unsigned long long)
bcause you can not use the FPU
but when i insmod i get the error unresolved symbol __udivdi3 i need!! 64
bit ints

i have included the code

thank you


[-- Attachment #2: lnvrm_nv05Pramdac.c --]
[-- Type: application/octet-stream, Size: 2231 bytes --]

#include <lnvrm.h>
#include <lnvrm_exports.h>

unsigned long nv05_pramdacPllCalc(struct _lnvrm_objNv01Device  *hw , unsigned long long clock)
{
  unsigned long long refClock  = hw->refClock ;
  unsigned long long vcoMax = 350000000 ;
  unsigned long long vcoMin =         0 ;
  unsigned long long nMax   =       255 ;
  unsigned long long nMin   =         1 ;
  unsigned long long mMax   =        14 ;
  unsigned long long mMin   =         1 ;
  unsigned long long pMax   =         4 ;
  unsigned long long pMin   =         1 ;
  unsigned long long f        ;
  unsigned long long fDif     ;
  unsigned long long fDifBest = ~0x00 ;
  unsigned long long fBest    = 0 ;
  unsigned long long nBest    = nMin ;
  unsigned long long mBest    = mMax ;
  unsigned long long pBest    = pMax ;
  unsigned long long vco   ;
  unsigned long long n     ;
  unsigned long long m     ;
  unsigned long long p     ;
  
  if(clock > vcoMax) clock = vco ;
  
  for(p = pMin ; p <= pMax ; p++) 
    {
      vco = clock * (1 << p) ;
      for(m = mMin ; m <= mMax ; m++)
	{
	  n = vco / (refClock / m) ;
	  if((n >= nMin) & (n <= nMax))
	    {
	      f = refClock / m * n ;
	      if(vco > f)
		fDif = vco - f ;
	      else
		fDif = f   - vco ;
	      if(fDif < fDifBest) { fDifBest = fDif ; fBest = f ; nBest = n ; mBest = m ; pBest = p ; } 
	    }
	}
    }
  printk("nv05_pramdacPllCalc: M:N:P %2.2LX:%2.2LX:%2.2LX f = %Ld Hz out = %Ld Hz\n",
	 mBest,
	 nBest,
	 pBest,
	 clock,
	 fBest / (1 << pBest));

  return((pBest << 16) | (nBest << 8) | mBest) ;
}

void nv05_pramdacSetPllNv(struct _lnvrm_objNv01Device  *hw , unsigned long long clock)
{
  unsigned long value ;
  value = nv05_pramdacPllCalc(hw,clock) ;
  nvr_regw(NV04_PRAMDAC_NVPLL_COEFF , value) ;
}

void nv05_pramdacSetPllMem(struct _lnvrm_objNv01Device  *hw , unsigned long long clock)
{
  unsigned long value ;
  value = nv05_pramdacPllCalc(hw,clock) ;
  nvr_regw(NV04_PRAMDAC_MPLL_COEFF , value) ;
}

void nv05_pramdacSetPllPixel(struct _lnvrm_objNv01Device  *hw , unsigned long long clock)
{
  unsigned long value ;
  value = nv05_pramdacPllCalc(hw,clock) ;
  nvr_regw(NV04_PRAMDAC_VPLL_COEFF , value) ;
}

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2003-03-17 18:59 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-03-18  5:44 error using unsigned long long not working in 2.4.x dave
2003-03-17  8:54 ` Matti Aarnio
2003-03-17 19:06 ` Randy.Dunlap

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®