login
Header Space

 
 

Re: OT: Does Linux have any "Perfect Code"

Score:
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: Russell Leighton <russ@...>
Cc: LKML <linux-kernel@...>
Date: Thursday, November 15, 2007 - 2:29 am

Russell Leighton a écrit :

I dont know, (what a strange idea is it anyway ?) but reading two Solaris 
functions just gave me the example of non true software perfection.

http://cvs.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/uts/common/os/timers.c#1...

I would say this code was OK 10 years ago.

Now that a processor (say an Opteron in 64 bits mode, used on SUN hardware), 
can perform a multiply in few cycles, ts2hrt() could use a normal multiply and 
an addition.

Processors are improving, compilers are improving, memory sizes are 
increasing, source code (and algorithms) should be changed accordingly.

(gcc for example already knows the reciprocal division trick and so can 
compile this :

hrt2ts_div(hrtime_t hrt, timestruc_t *tsp)
{
     tsp->tv_nsec = do_div(hrt, NANOSEC);
     tsp->tv_sec = hrt;
}

to :

         movq    %rdi, %rdx
         movabsq $19342813113834067, %rax
         shrq    $9, %rdx
         mulq    %rdx
         shrq    $11, %rdx
         imulq   $1000000000, %rdx, %rax
         movq    %rdx, (%rsi)
         subq    %rax, %rdi
         movl    %edi, 8(%rsi)

while

hrtime_t
ts2hrt(const timestruc_t *tsp)
{
return tsp->tv_sec * NANOSEC + tsp->tv_nsec;
}

can be inlined as it is trivial (and much faster than Solaris version)

         movq    (%rdi), %rdx
         mov     8(%rdi), %eax
         imulq   $1000000000, %rdx, %rdx
         addq    %rdx, %rax

-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
OT: Does Linux have any "Perfect Code", Russell Leighton, (Wed Nov 14, 9:21 pm)
Re: OT: Does Linux have any "Perfect Code", Philippe Elie, (Thu Nov 15, 4:27 am)
Re: OT: Does Linux have any "Perfect Code", Michael Gerdau, (Thu Nov 15, 9:16 am)
Re: OT: Does Linux have any "Perfect Code", Chris Friesen, (Thu Nov 15, 1:05 pm)
Re: OT: Does Linux have any "Perfect Code", Daniel Barkalow, (Thu Nov 15, 11:10 am)
Re: OT: Does Linux have any "Perfect Code", Geert Uytterhoeven, (Sat Nov 17, 4:44 am)
Re: OT: Does Linux have any "Perfect Code", Eric Dumazet, (Thu Nov 15, 2:29 am)
Re: OT: Does Linux have any "Perfect Code", Andi Kleen, (Thu Nov 15, 3:43 am)
Re: OT: Does Linux have any "Perfect Code", David Miller, (Thu Nov 15, 3:11 am)
Re: OT: Does Linux have any "Perfect Code", David Miller, (Wed Nov 14, 9:33 pm)
speck-geostationary