eGospodarka.pl
eGospodarka.pl poleca

eGospodarka.plGrupypl.comp.programmingSzybkie szukanie ustawionego bitu › Re: Szybkie szukanie ustawionego bitu
  • Path: news-archive.icm.edu.pl!agh.edu.pl!news.agh.edu.pl!news.cyf-kr.edu.pl!news.nask
    .pl!news.nask.org.pl!news.unit0.net!cyclone01.ams2.highwinds-media.com!voer-me.
    highwinds-media.com!peer01.am1!peering.am1!peer02.fr7!news.highwinds-media.com!
    newsfeed.neostrada.pl!unt-exc-01.news.neostrada.pl!unt-spo-b-01.news.neostrada.
    pl!news.neostrada.pl.POSTED!not-for-mail
    From: szemrany <s...@o...off>
    Subject: Re: Szybkie szukanie ustawionego bitu
    Newsgroups: pl.comp.programming
    User-Agent: 40tude_Dialog/2.0.15.84
    MIME-Version: 1.0
    Content-Type: text/plain; charset="utf-8"
    Content-Transfer-Encoding: 8bit
    Sender: n...@p...no
    References: <1...@4...net>
    <wc4ru3v45dm0$.1mtwq7sfflbyu.dlg@40tude.net>
    Date: Tue, 1 Sep 2015 22:20:03 +0200
    Message-ID: <1...@4...net>
    Lines: 131
    Organization: Telekomunikacja Polska
    NNTP-Posting-Host: 89-71-60-55.dynamic.chello.pl
    X-Trace: 1441138804 unt-rea-a-02.news.neostrada.pl 27509 89.71.60.55:12964
    X-Complaints-To: a...@n...neostrada.pl
    X-Received-Body-CRC: 3952062383
    X-Received-Bytes: 3472
    Xref: news-archive.icm.edu.pl pl.comp.programming:208119
    [ ukryj nagłówki ]

    On Tue, 1 Sep 2015 14:40:34 +0200, szemrany wrote:

    > Czas: 813 ms
    > Czas: 67 ms
    > Czas: 51 ms
    > Czas: 28 ms

    Specjalnie dla AK źrodła funkcji:

    function SzukajBita_1(u64 : UInt64) : Integer;
    var
    I: Integer;
    u32: UInt32;
    begin
    I := 0;
    while u64 and 1 <> 1 do
    begin
    u64 := u64 shr 1;
    Inc(i);
    end;
    Result := I;
    end;

    function SzukajBita_2(u64 : UInt64) : Integer;
    var
    I: Integer;
    begin
    I := 0;
    if (u64 and $00000000FFFFFFFF) = 0 then
    begin
    I := I + 32;
    u64 := u64 shr 32;
    end;
    if (u64 and $000000000000FFFF) = 0 then
    begin
    I := I + 16;
    u64 := u64 shr 16;
    end;
    if (u64 and $00000000000000FF) = 0 then
    begin
    I := I + 8;
    u64 := u64 shr 8;
    end;
    if (u64 and $000000000000000F) = 0 then
    begin
    I := I + 4;
    u64 := u64 shr 4;
    end;
    if (u64 and $0000000000000003) = 0 then
    begin
    I := I + 2;
    u64 := u64 shr 2;
    end;
    if (u64 and $0000000000000001) = 0 then
    begin
    I := I + 1;
    end;
    Result := I;
    end;

    function SzukajBita_3(u64 : UInt64) : Integer;
    var
    I: Integer;
    u32: UInt32;
    begin
    I := 0;
    u64 := u64 and -u64;
    u32 := u64 and $ffffffff;
    if u32 = 0 then
    begin
    u32 := u64 shr 32;
    I := 32;
    end;
    case u32 of
    2: Inc(I, 1);
    4: Inc(I, 2);
    8: Inc(I, 3);
    16: Inc(I, 4);
    32: Inc(I, 5);
    64: Inc(I, 6);
    128: Inc(I, 7);
    256: Inc(I, 8);
    512: Inc(I, 9);
    1024: Inc(I, 10);
    2048: Inc(I, 11);
    4096: Inc(I, 12);
    8192: Inc(I, 13);
    16384: Inc(I, 14);
    32768: Inc(I, 15);
    65536: Inc(I, 16);
    131072: Inc(I, 17);
    262144: Inc(I, 18);
    524288: Inc(I, 19);
    1048576: Inc(I, 20);
    2097152: Inc(I, 21);
    4194304: Inc(I, 22);
    8388608: Inc(I, 23);
    16777216: Inc(I, 24);
    33554432: Inc(I, 25);
    67108864: Inc(I, 26);
    134217728: Inc(I, 27);
    268435456: Inc(I, 28);
    536870912: Inc(I, 29);
    1073741824: Inc(I, 30);
    2147483648: Inc(I, 31);
    4294967296: Inc(I, 32);
    end;
    Result := I;
    end;

    function SzukajBita_4(u64 : UInt64) : Integer;
    begin
    asm
    MOV EAX, -1
    BSF EAX, DWORD PTR [&u64]
    JNZ @@Exit
    BSF EAX, DWORD PTR [&u64 + 4]
    JZ @@Exit
    ADD EAX, 32
    @@Exit:
    MOV &Result, EAX
    end;
    end;



    --
    howgh
    szemrany
    "Trzeba z żywymi naprzód iść, po życie sięgać nowe,
    a nie w uwiędłych laurów liść z uporem stroić głowę"

Podziel się

Poleć ten post znajomemu poleć

Wydrukuj ten post drukuj


Następne wpisy z tego wątku

Najnowsze wątki z tej grupy


Najnowsze wątki

Szukaj w grupach

Eksperci egospodarka.pl

1 1 1

Wpisz nazwę miasta, dla którego chcesz znaleźć jednostkę ZUS.

Wzory dokumentów

Bezpłatne wzory dokumentów i formularzy.
Wyszukaj i pobierz za darmo: