All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Petr Cervenka" <grugh@domain.hid>
To: gilles.chanteperdrix@xenomai.org
Cc: xenomai@xenomai.org
Subject: Re: [Xenomai-help] Slow sin function
Date: Thu, 14 Feb 2008 17:05:15 +0100	[thread overview]
Message-ID: <200802141705.17258@domain.hid> (raw)
In-Reply-To: <200802141648.10545@domain.hid>

_
>On Thu, Feb 14, 2008 at 10:58 AM, Petr Cervenka <grugh@domain.hid> wrote:
>> Hello again.
>>  I have another problem and I'm not sure if it is connected with Xenomai ,
>>  but perhaps you already met similar problem.
>>  Occasionally  the math sin function takes an enormous amount of time
>>  (400-450 us on Athlon A64 X2 4800+). When I detect this and make the sin function
>>  call with the same parameter again, it takes the same (long) time. I
>>  suspect that this function is for some values is unreasonably slow. I'll
>>  try to capture some such values and post them here.
>>  I don't remember such behavior before the transition to newer 64bit linux
>>  distribution (Kubuntu 7.10 amd64 and kernel 2.6.24).
>>  Petr Cervenka
>
>I would expect the sin function to be built-in, at least, I think it
>is built-in on x86_32.
>
>Now, looking at glibc code, there seem to be a loop in the
>implementation of these functions.
>
>-- 
> Gilles Chanteperdrix
>
I managed to capture two such numbers:
0.93340582292648832662962377071381	(0x00b06be375deed3f)
3.9225160069792437411706487182528 	(0x5019801250610f40)

Tried on similar 32bit machine (2.6.19.7), everything is OK there.
Any idea how to solve it or who to inform about this problem?

Short program for trying this problem:
usage: hextodbl 00 b0 6b e3 75 de ed 3f
or          hextodbl 0.93340582292648832662962377071381

#include <stdlib.h>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <math.h>
#include <sys/time.h>

using namespace std;

int main(int argc, char** argv) {
    
    unsigned char hexdbl_hex[sizeof(double)];
    volatile double &hexdbl_dbl = *((double*)hexdbl_hex);
    
    if (argc == sizeof(double)+1) {
        for (int i=0; i < sizeof(double); i++) {
            istringstream s(argv[i+1]);
            int tmp;
            s >> hex >> tmp;
            hexdbl_hex[i] = tmp;
        }
    } else if (argc == 2) {
        istringstream s(argv[1]);
        double tmp;
        s >> tmp;
        hexdbl_dbl = tmp;
    } else {
        cout << "usage: hextodbl 11 02 f3 e4 d5 c6 b7 a8\n"
		"       hextodbl 0.123456789\n";
        return (EXIT_FAILURE);
    }
    
    cout.precision(32);
    cout << hexdbl_dbl << endl;

    struct timeval time1, time2;
    struct timeval diftime;
    cout << "start\n";
    gettimeofday(&time1, NULL);
    for (int i=0; i < 10000; i++) {
        volatile double out = sin(hexdbl_dbl);
        out = 0;
    }
    gettimeofday(&time2, NULL);
    diftime.tv_usec = time2.tv_usec - time1.tv_usec;
    diftime.tv_sec = time2.tv_sec - time1.tv_sec;
    
    while (diftime.tv_usec < 0) {
        diftime.tv_usec += 1000000;
        diftime.tv_sec--;
    }
    while (diftime.tv_usec >= 1000000) {
        diftime.tv_usec -= 1000000;
        diftime.tv_sec++;
    }
    cout << "end: " << diftime.tv_sec << '.' << setw(6) << setfill('0') << diftime.tv_usec << endl;
    
    return (EXIT_SUCCESS);
}



  parent reply	other threads:[~2008-02-14 16:05 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <200802141029.19685@domain.hid>
     [not found] ` <200802141055.1177@domain.hid>
2008-02-14  9:58   ` [Xenomai-help] Slow sin function Petr Cervenka
2008-02-14 13:32     ` Gilles Chanteperdrix
     [not found]       ` <200802141648.10545@domain.hid>
2008-02-14 16:05         ` Petr Cervenka [this message]
2008-02-14 17:27           ` Gilles Chanteperdrix

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200802141705.17258@domain.hid \
    --to=grugh@domain.hid \
    --cc=gilles.chanteperdrix@xenomai.org \
    --cc=xenomai@xenomai.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.