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=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!feeder.eternal-september.org!news.uzoreto.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Bill Findlay Newsgroups: comp.lang.ada Subject: Re: Creating several types from a base type and conversion Date: Mon, 20 Jan 2020 16:38:11 +0000 Organization: none Message-ID: <0001HW.23D60EF30285768170000F6DB2EF@news.individual.net> References: <4b0649b3-aed2-44fd-822f-d6665b9352dd@googlegroups.com> <0001HW.23D35416021671CF70000511B2EF@news.individual.net> <0001HW.23D383F80221AAB870000511B2EF@news.individual.net> Reply-To: findlaybill@blueyonder.co.uk Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Trace: individual.net aByiT02eNZZWuTphUhAz7wV3aOt+74f46uqGJ71guH/xOlzRJe X-Orig-Path: not-for-mail Cancel-Lock: sha1:eLaVswwLEicPcc5QY+c1VgLI8b0= User-Agent: Hogwasher/5.24 Xref: reader01.eternal-september.org comp.lang.ada:57908 Date: 2020-01-20T16:38:11+00:00 List-Id: On 18 Jan 2020, Simon Wright wrote (in article ): > "Jeffrey R. Carter" writes: > > > On 1/18/20 7:20 PM, Bill Findlay wrote: > > > > type word is mod 2**30; > > > > > > subtype word_shift_length is Natural range 0..30; > > > > > > function shift_word_left (W : word; amount : word_shift_length) > > > return KDF9.word; > > > I don't know what KDF9.Word is, but surely you have to implement > > these. Or are you saying GNAT magically implements them? > > It doesn't; 'with Import, convention => Intrinsic' requires the first > argument to have size 8, 16, 32, or 64, and the second argument must be > Natural (not a subtype of it, even if unconstrained). D'oh! (Looks around for lost marbles - they are here somewhere.) Here are extracts from theactual code for KDF9's 48-bit shift operations, showing how they are built up from the intrinsic 64-bit shifts. Converting this to 30-bit shifts using 32-bit intrinsics should be simple: -- -- The fundamental emulated storage unit is the 48-bit word. -- type word is mod 2**48; -- -- This is the emulation host's 64-bit unsigned integer type. -- type u_64 is mod 2**64 with Size => 64; word_mask : constant := 8#7777777777777777#; function as_word (u : u_64) return word is (word(u and word_mask)); -- This GNAT-specific pragma declares all the 64-bit shift operations. pragma Provide_Shift_Operators (u_64); -- -- These are the 48-bit primitive, fixed-direction, shift operations. -- subtype word_shift_length is Natural range 0..48; function shift_word_left (W : word; amount : word_shift_length) return word is (as_word(shift_left(u_64(W), amount))); function shift_word_right (W : word; amount : word_shift_length) return word is (word(shift_right(u_64(W), amount))); function rotate_word_left (W : word; amount : word_shift_length) return word is (shift_word_left(W, amount) or shift_word_right(W, 48-amount)); function rotate_word_right (W : word; amount : word_shift_length) return word is (shift_word_right(W, amount) or shift_word_left(W, 48-amount)); -- -- KDF9 shift operations actually had a signed shift amount; e.g.: -- function shift_logical (W : word; L : signed_Q_part) return word is ( if abs L > 47 then 0 elsif L < 0 then shift_word_right(W, Natural(-L)) else shift_word_left (W, Natural(+L)) ); ... etc ... Sorry for the temporary brain malfunction! -- Bill Findlay