From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,703c4f68db81387d X-Google-Thread: 115aec,703c4f68db81387d X-Google-Attributes: gid103376,gid115aec,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!wn13feed!worldnet.att.net!bgtnsc05-news.ops.worldnet.att.net.POSTED!53ab2750!not-for-mail Newsgroups: comp.lang.ada,comp.realtime Subject: Re: 10 rules for benchmarking (was Re: Teaching new tricks to an old dog (C++ -->Ada)) From: Jim Rogers References: <4229bad9$0$1019$afc38c87@news.optusnet.com.au> <87r7iu85lf.fsf@insalien.org> <1110052142.832650@athnrd02> <1110284070.410136.205090@o13g2000cwo.googlegroups.com> <395uqaF5rhu2mU1@individual.net> <112rs0bdr2aftdf@corp.supernews.com> <1inxxr988rxgg$.1w9dedak41k89.dlg@40tude.net> <112s1r0rf0o8nca@corp.supernews.com> <112sonip5v4dca6@corp.supernews.com> <112t3de6fu04f38@corp.supernews.com> <1110396477.596174.285520@o13g2000cwo.googlegroups.com> <112vb2t8eonuhed@corp.supernews.com> <1110422108.925127.54110@o13g2000cwo.googlegroups.com> <11329cb96h2p19f@corp.supernews.com> <1134l90ja5sqm73@corp.supernews.com> <39fr2iF5uq3mvU1@individual.net> <39g6jbF62g4qjU1@individual.net> <39g92iF62e0j3U1@individual.net> User-Agent: Xnews/5.04.25 Message-ID: Date: Sat, 12 Mar 2005 14:37:40 GMT NNTP-Posting-Host: 12.73.183.100 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc05-news.ops.worldnet.att.net 1110638260 12.73.183.100 (Sat, 12 Mar 2005 14:37:40 GMT) NNTP-Posting-Date: Sat, 12 Mar 2005 14:37:40 GMT Organization: AT&T Worldnet Xref: g2news1.google.com comp.lang.ada:9234 comp.realtime:1366 Date: 2005-03-12T14:37:40+00:00 List-Id: Here is my Ada version using a lookup table. My system is an AMD 64 cpu at 2.0 Ghz with 512Mb memory. I ran the program using the cygwin time function. The compiler is GNAT 3.15p. All times are with range-checking suppressed. when compiled without optimization the time is 1.8 seconds when compiled with -O2 the time is 1.4 seconds The Ada code is: with Interfaces; use type Interfaces.Unsigned_32; package Bits_Utils is type Array_Index is mod 2**8; subtype Bits_Adjust is Integer range 0..7; type Adjust_Array is array(Array_Index) of Bits_Adjust; High_Bit_Small : constant Adjust_Array := (0,0,1,1,2,2,2,2,3,3,3,3,3,3,3,3,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4, 5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5, 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,6, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7, 7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7,7); function Find_Highest_Bits(N : Interfaces.Unsigned_32) return Bits_Adjust; end Bits_Utils; package body Bits_Utils is pragma Suppress(Range_Check); function Find_Highest_Bits(N : Interfaces.Unsigned_32) return Bits_Adjust is Bits : Natural := 0; V : Interfaces.Unsigned_32 := N; begin if Interfaces.Shift_Right(Value => V, Amount => 16) > 0 then V := Interfaces.Shift_Right(Value => V, Amount => 16); Bits := 16; end if; if Interfaces.Shift_Right(Value => V, Amount => 8) > 0 then V := Interfaces.Shift_Right(Value => V, Amount => 8); Bits := Bits + 8; end if; return Bits + High_Bit_Small(Array_Index(V)); end Find_Highest_Bits; pragma Inline (Find_Highest_Bits); end Bits_Utils; with Bits_Utils; with Interfaces; use Interfaces; with Ada.Command_Line; use Ada.Command_Line; procedure Highest_Bits3 is type Index is mod 32; type Val_Array is array(Index) of Unsigned_32; Val : Val_Array; S : Natural := 0; I : Index := 0; U : Unsigned_32 := 1; begin loop Val(I) := Shift_Left(Value => U, Amount => Natural(I)) - 1; if I < Index'Last - 2 then Val(I + 1) := Shift_Left(U, 32 - Natural(I)); I := I + 2; else exit; end if; end loop; for N in 0..3124999 loop for J in Index'range loop S := S + Bits_Utils.Find_Highest_Bits(Val(J)); end loop; end loop; Set_Exit_Status(Exit_Status(S)); end Highest_Bits3; Jim Rogers