Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

19 May, 2024: Line wrapping has been changed to be more consistent with Usenet standards.
 If you find that it is broken please let me know here rocksolid.nodes.help


devel / comp.lang.forth / Re: DLSHIFT and DRSHIFT

SubjectAuthor
* DLSHIFT and DRSHIFTKrishna Myneni
+* Re: DLSHIFT and DRSHIFTKrishna Myneni
|+* Re: DLSHIFT and DRSHIFTAnton Ertl
||`- Re: DLSHIFT and DRSHIFTKrishna Myneni
|+* Re: DLSHIFT and DRSHIFTRuvim
||+* Re: DLSHIFT and DRSHIFTKrishna Myneni
|||+* Re: DLSHIFT and DRSHIFTBernd Linsel
||||`* Re: DLSHIFT and DRSHIFTalbert
|||| `- Re: DLSHIFT and DRSHIFTAnton Ertl
|||`* Re: DLSHIFT and DRSHIFTAnton Ertl
||| `* Re: DLSHIFT and DRSHIFTKrishna Myneni
|||  +* Re: DLSHIFT and DRSHIFTminforth
|||  |`* Re: DLSHIFT and DRSHIFTKrishna Myneni
|||  | `- Re: DLSHIFT and DRSHIFTminforth
|||  `* Re: DLSHIFT and DRSHIFTAnton Ertl
|||   `* Re: DLSHIFT and DRSHIFTKrishna Myneni
|||    `* Re: DLSHIFT and DRSHIFTAnton Ertl
|||     `* Re: DLSHIFT and DRSHIFTKrishna Myneni
|||      `- Re: DLSHIFT and DRSHIFTAnton Ertl
||`* Re: DLSHIFT and DRSHIFTdxf
|| `* Re: DLSHIFT and DRSHIFTKrishna Myneni
||  `* Re: DLSHIFT and DRSHIFTdxf
||   `* Re: DLSHIFT and DRSHIFTKrishna Myneni
||    `- Re: DLSHIFT and DRSHIFTdxf
|+- Re: DLSHIFT and DRSHIFTHans Bezemer
|`- Re: DLSHIFT and DRSHIFTKrishna Myneni
+* Re: DLSHIFT and DRSHIFTKrishna Myneni
|`* Re: DLSHIFT and DRSHIFTRuvim
| `* Re: DLSHIFT and DRSHIFTKrishna Myneni
|  `* Re: DLSHIFT and DRSHIFTRuvim
|   +* Re: DLSHIFT and DRSHIFTKrishna Myneni
|   |`* Re: DLSHIFT and DRSHIFTHans Bezemer
|   | +- Re: DLSHIFT and DRSHIFTKrishna Myneni
|   | +- Re: DLSHIFT and DRSHIFTdxf
|   | `* Re: DLSHIFT and DRSHIFTdxf
|   |  +* Re: DLSHIFT and DRSHIFTminforth
|   |  |`* Re: DLSHIFT and DRSHIFTdxf
|   |  | `* Re: DLSHIFT and DRSHIFTKrishna Myneni
|   |  |  `* Re: DLSHIFT and DRSHIFTdxf
|   |  |   +* Re: DLSHIFT and DRSHIFTHans Bezemer
|   |  |   |`- Re: DLSHIFT and DRSHIFTdxf
|   |  |   `* Re: DLSHIFT and DRSHIFTAnton Ertl
|   |  |    +- Re: DLSHIFT and DRSHIFTHans Bezemer
|   |  |    `- Re: DLSHIFT and DRSHIFTdxf
|   |  +* Re: DLSHIFT and DRSHIFTHans Bezemer
|   |  |`* Re: DLSHIFT and DRSHIFTKrishna Myneni
|   |  | `* Re: DLSHIFT and DRSHIFTHans Bezemer
|   |  |  `* Re: DLSHIFT and DRSHIFTKrishna Myneni
|   |  |   `- Re: DLSHIFT and DRSHIFTHans Bezemer
|   |  +* Re: DLSHIFT and DRSHIFTHans Bezemer
|   |  |`- Re: DLSHIFT and DRSHIFTHans Bezemer
|   |  `* Re: DLSHIFT and DRSHIFTHans Bezemer
|   |   `* Re: DLSHIFT and DRSHIFTdxf
|   |    `* Re: DLSHIFT and DRSHIFTdxf
|   |     `* Re: DLSHIFT and DRSHIFTdxf
|   |      `* Re: DLSHIFT and DRSHIFTalbert
|   |       `* Re: DLSHIFT and DRSHIFTdxf
|   |        +* Re: DLSHIFT and DRSHIFTmhx
|   |        |+- Re: DLSHIFT and DRSHIFTKrishna Myneni
|   |        |`- Re: DLSHIFT and DRSHIFTdxf
|   |        `* Re: DLSHIFT and DRSHIFTalbert
|   |         `- Re: DLSHIFT and DRSHIFTHans Bezemer
|   `- Re: DLSHIFT and DRSHIFTdxf
`* Re: DLSHIFT and DRSHIFTalbert
 +- Re: DLSHIFT and DRSHIFTKrishna Myneni
 `- Re: DLSHIFT and DRSHIFTBernd Linsel

Pages:123
Re: DLSHIFT and DRSHIFT

<66060a06$1@news.ausics.net>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=26561&group=comp.lang.forth#26561

  copy link   Newsgroups: comp.lang.forth
Date: Fri, 29 Mar 2024 11:23:34 +1100
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: DLSHIFT and DRSHIFT
Newsgroups: comp.lang.forth
References: <utvgki$2ciso$1@dont-email.me> <utvque$2elom$1@dont-email.me>
<uu0vpa$2qdel$1@dont-email.me> <660425d7$1@news.ausics.net>
<uu1esa$2tueu$2@dont-email.me> <66055488$1@news.ausics.net>
<uu3rrv$3jq9f$1@dont-email.me>
Content-Language: en-GB
From: dxforth@gmail.com (dxf)
In-Reply-To: <uu3rrv$3jq9f$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
NNTP-Posting-Host: news.ausics.net
Message-ID: <66060a06$1@news.ausics.net>
Organization: Ausics - https://newsgroups.ausics.net
Lines: 36
X-Complaints: abuse@ausics.net
Path: i2pn2.org!i2pn.org!news.bbs.nz!news.ausics.net!not-for-mail
 by: dxf - Fri, 29 Mar 2024 00:23 UTC

On 29/03/2024 12:38 am, Krishna Myneni wrote:
> On 3/28/24 06:29, dxf wrote:
>> On 28/03/2024 2:44 am, Krishna Myneni wrote:
>>> On 3/27/24 08:57, dxf wrote:
>>>> On 27/03/2024 10:26 pm, Ruvim wrote:
>>>>> On 2024-03-27 04:57, Krishna Myneni wrote:
>>>>> [...]
>>>>>> We shouldn't have an ambiguous condition here because of some idiosyncratic behavior of the SHL instruction!
>>>>>>
>>>>>> u 64 LSHIFT should be zero on all systems with cell sizes up to 64 bits.
>>>>>
>>>>> Ideally — yes.
>>>>>
>>>>> My rationale (see [1]) is that for any `x` and `u`, the result of a single shift of `x` by `u` bits should always be equivalent to `u` sequential shifts by 1 bit.
>>>>>
>>>>> But neither the standard nor implementations follow this idea.
>>>>
>>>> The same occurred with 2/ and 2 / .  Those who saw Forth as a language wanted
>>>> consistent results; whereas those who saw Forth as a toolkit said give us what
>>>> the hardware provides.
>>>>
>>>
>>> If one needs the machine shift instructions, they should be using the Forth assembler to write the word in which it is needed. The language specification has no justification (that I can see) for undefined behavior for the LSHIFT and RSHIFT instructions.
>>
>> Some 40 years ago Intel told their customers there's no justification for shifting
>> a full cell of bits.  ANS told the same thing to forthers.
>>
>>
>
> This really isn't an issue with the processor design -- they're under more severe constraints in what they can put in the hardware. The desired behavior can be achieved in software.

If it's an issue of algorithm design - how many shifts does it take before a programmer
realizes the result must be 0 - and should the language indulge him? If a forth programmer
is determined that any shift count should work then he won't mind the performance loss of
putting 2* or U2/ in a loop. Leave LSHIFT and RSHIFT to programmers whose goal is efficiency.

Re: DLSHIFT and DRSHIFT

<nnd$6f1e3321$1a7547b1@188caa05314af2d8>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=26562&group=comp.lang.forth#26562

  copy link   Newsgroups: comp.lang.forth
Date: Fri, 29 Mar 2024 14:03:55 +0100
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: DLSHIFT and DRSHIFT
References: <utvgki$2ciso$1@dont-email.me> <utvque$2elom$1@dont-email.me>
Content-Language: en-US
From: the.beez.speaks@gmail.com (Hans Bezemer)
Newsgroups: comp.lang.forth
In-Reply-To: <utvque$2elom$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Message-ID: <nnd$6f1e3321$1a7547b1@188caa05314af2d8>
Organization: KPN B.V.
Path: i2pn2.org!i2pn.org!news.swapon.de!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!feed.abavia.com!abe005.abavia.com!abp002.abavia.com!news.kpn.nl!not-for-mail
Lines: 31
Injection-Date: Fri, 29 Mar 2024 14:03:55 +0100
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
 by: Hans Bezemer - Fri, 29 Mar 2024 13:03 UTC

On 27-03-2024 01:57, Krishna Myneni wrote:
> On 3/26/24 17:01, Krishna Myneni wrote:
>> Standard source definitions of DLSHIFT and DRSHIFT (double number left
>> shift and right shift), over full shift range, per discussion in prior
>> thread.
>>
>> Tests needed.
>
> Just tested DLSHIFT and found weird things going on. Traced the problem
> to LSHIFT.

Yep. That's why I had to create this horrible code in order to force the
compiler to give me the behavior I want:

CODE (SHIFT) DSIZE (2); a = DPOP;
b = (sizeof (cell) * CHAR_BIT);
if ((a < b) && (a > -b))
{ /* within cell size? */
if (a < 0L)
{ /* force logical right shift */
DS (1) = (DS (1) >> 1L) & CELL_MAX;
a = -1L - a; DS (1) >>= a;
} /* shift one bit, clear it */
else DS (1) <<= a;
} /* we're in zero territory now */
else DS (1) = 0L;
NEXT;

Hans Bezemer

Re: DLSHIFT and DRSHIFT

<uu6eo4$a8hm$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=26563&group=comp.lang.forth#26563

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: krishna.myneni@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: DLSHIFT and DRSHIFT
Date: Fri, 29 Mar 2024 08:12:36 -0500
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <uu6eo4$a8hm$1@dont-email.me>
References: <utvgki$2ciso$1@dont-email.me> <utvque$2elom$1@dont-email.me>
<uu0vpa$2qdel$1@dont-email.me> <uu13cn$2r980$1@dont-email.me>
<2024Mar27.194610@mips.complang.tuwien.ac.at> <uu1ths$31jjc$2@dont-email.me>
<2024Mar28.094943@mips.complang.tuwien.ac.at>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 29 Mar 2024 13:12:37 +0100 (CET)
Injection-Info: dont-email.me; posting-host="2c9365f1d570a9448132d713760afcc5";
logging-data="336438"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/fSCGAvI0BA8Z+LNsmGTKB"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:nVuYzlskNbToYg+S16t3EKkSvYk=
Content-Language: en-US
In-Reply-To: <2024Mar28.094943@mips.complang.tuwien.ac.at>
 by: Krishna Myneni - Fri, 29 Mar 2024 13:12 UTC

On 3/28/24 03:49, Anton Ertl wrote:
> Krishna Myneni <krishna.myneni@ccreweb.org> writes:
>> On 3/27/24 13:46, Anton Ertl wrote:
>>> You could point out that the extra cost of the check is only incurred
>>> for shifts with non-constant shift amounts, and if you could provide
>>> data on the frequency of constant and non-constant shift amounts, this
>>> might help convince system implementors.
>
> Here's some data about the occurences in the Gforth image:
>
> Non-constant shift amount:
> 2 lshift
> 1 rshift
> 0 arshift
>
> Constant shift amount:
> 18 lit lshift
> 41 lit rshift
> 0 lit arshift
>
....

Checking the Forth code base which I use, I find ~ 100:1 ratio between
uses of constant shift amount to non-constant shifts. The existing
instances of non-constant shifts are comparable to yours: two in number
theory programs e.g., finding an exact fraction for a floating point
number, and one use in the assembler.

I don't know what to conclude from this other than the kind of
application development I have been doing favors one over the other. The
large number of constant shifts have to do with defining constants,
largely for data acquisition interfaces.

--
Krishna

Re: DLSHIFT and DRSHIFT

<nnd$51ea08c7$4ebacde5@98ba4a1ad989127a>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=26564&group=comp.lang.forth#26564

  copy link   Newsgroups: comp.lang.forth
Date: Fri, 29 Mar 2024 15:32:05 +0100
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: DLSHIFT and DRSHIFT
Newsgroups: comp.lang.forth
References: <utvgki$2ciso$1@dont-email.me> <uu02tt$2k3jf$1@dont-email.me> <uu1c3r$2tdj0$1@dont-email.me> <uu1e7t$2tueu$1@dont-email.me> <uu1huv$2uqc2$1@dont-email.me> <uu1t7e$31jjc$1@dont-email.me>
Content-Language: en-US
From: the.beez.speaks@gmail.com (Hans Bezemer)
In-Reply-To: <uu1t7e$31jjc$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Message-ID: <nnd$51ea08c7$4ebacde5@98ba4a1ad989127a>
Organization: KPN B.V.
Path: i2pn2.org!i2pn.org!news.furie.org.uk!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!tr3.iad1.usenetexpress.com!feeder.usenetexpress.com!tr1.eu1.usenetexpress.com!2001:67c:174:101:1:67:202:5.MISMATCH!feed.abavia.com!abe005.abavia.com!abp001.abavia.com!news.kpn.nl!not-for-mail
Lines: 60
Injection-Date: Fri, 29 Mar 2024 15:32:05 +0100
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
 by: Hans Bezemer - Fri, 29 Mar 2024 14:32 UTC

On 27-03-2024 20:49, Krishna Myneni wrote:
> On 3/27/24 11:36, Ruvim wrote:
>
>>>> === "double-shift.fth"
>>>>
>>>> :NONAME 0 -1 BEGIN DUP WHILE SWAP 1+ SWAP 1 RSHIFT REPEAT DROP ;
>>>> EXECUTE
>>>> CONSTANT BITS-PER-CELL
>>>>
>>>> BITS-PER-CELL 1-      CONSTANT MAX-FOR-SHIFT1
>>>> BITS-PER-CELL 2* 1-   CONSTANT MAX-FOR-SHIFT2
>>>>
>>>> : (DLSHIFT) ( xd1 u -- xd2 )
>>>>    ( x.lo x.hi  u )
>>>>    TUCK LSHIFT >R
>>>>    2DUP NEGATE BITS-PER-CELL + RSHIFT >R
>>>>    LSHIFT 2R> OR
>>>> ;
>>>> : DLSHIFT ( xd1 u -- xd2 )
>>>>    DUP 0= IF  DROP EXIT THEN
>>>>    DUP MAX-FOR-SHIFT2 U> IF  DROP 2DROP 0. EXIT THEN
>>>>    DUP MAX-FOR-SHIFT1 U> IF  NIP BITS-PER-CELL - LSHIFT 0 SWAP EXIT
>>>> THEN
>>>>    (DLSHIFT)
>>>> ;
>>>> : (DRSHIFT) ( xd1 u -- xd2 )
>>>>    ( x.lo x.hi  u )
>>>>    2DUP RSHIFT >R
>>>>    TUCK NEGATE BITS-PER-CELL + LSHIFT >R
>>>>    RSHIFT R> OR R>
>>>> ;
>>>> : DRSHIFT ( xd1 u -- xd2 )
>>>>    DUP 0= IF  DROP EXIT THEN
>>>>    DUP MAX-FOR-SHIFT2 U> IF  DROP 2DROP 0. EXIT THEN
>>>>    DUP MAX-FOR-SHIFT1 U> IF  >R NIP R> BITS-PER-CELL - RSHIFT 0 EXIT
>>>> THEN
>>>>    (DRSHIFT)
>>>> ;
>>>>
>>>> === End of "double-shift.fth"

Can't make it any shorter than this. And no idea what happens with less
robust LSHIFT or RSHIFT implementations. CELL-BITS should be most
obvious, : SPIN SWAP ROT ; should fix most porting issues, replace ;THEN
with EXIT THEN. It passes all tests.

: dlshift
dup 0> 0= if drop ;then
>r over 0 invert cell-bits r@ - dup >r lshift and r> rshift swap
r@ lshift or swap r> lshift swap
;

: drshift
dup 0> 0= if drop ;then
>r dup 0 invert cell-bits r@ - dup >r rshift and r> lshift swap
r@ rshift spin r> rshift or swap
;

Hans Bezemer

Re: DLSHIFT and DRSHIFT

<uu6jig$bdpk$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=26565&group=comp.lang.forth#26565

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: krishna.myneni@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: DLSHIFT and DRSHIFT
Date: Fri, 29 Mar 2024 09:34:55 -0500
Organization: A noiseless patient Spider
Lines: 68
Message-ID: <uu6jig$bdpk$1@dont-email.me>
References: <utvgki$2ciso$1@dont-email.me> <uu02tt$2k3jf$1@dont-email.me>
<uu1c3r$2tdj0$1@dont-email.me> <uu1e7t$2tueu$1@dont-email.me>
<uu1huv$2uqc2$1@dont-email.me> <uu1t7e$31jjc$1@dont-email.me>
<nnd$51ea08c7$4ebacde5@98ba4a1ad989127a>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 29 Mar 2024 14:34:56 +0100 (CET)
Injection-Info: dont-email.me; posting-host="2c9365f1d570a9448132d713760afcc5";
logging-data="374580"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+PPq7tFhgTUi1UAG05lYSp"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:oWNyvq6IQiZS8BoKXSb9QPsxcaU=
In-Reply-To: <nnd$51ea08c7$4ebacde5@98ba4a1ad989127a>
Content-Language: en-US
 by: Krishna Myneni - Fri, 29 Mar 2024 14:34 UTC

On 3/29/24 09:32, Hans Bezemer wrote:
> On 27-03-2024 20:49, Krishna Myneni wrote:
>> On 3/27/24 11:36, Ruvim wrote:
>>
>>>>> === "double-shift.fth"
>>>>>
>>>>> :NONAME 0 -1 BEGIN DUP WHILE SWAP 1+ SWAP 1 RSHIFT REPEAT DROP ;
>>>>> EXECUTE
>>>>> CONSTANT BITS-PER-CELL
>>>>>
>>>>> BITS-PER-CELL 1-      CONSTANT MAX-FOR-SHIFT1
>>>>> BITS-PER-CELL 2* 1-   CONSTANT MAX-FOR-SHIFT2
>>>>>
>>>>> : (DLSHIFT) ( xd1 u -- xd2 )
>>>>>    ( x.lo x.hi  u )
>>>>>    TUCK LSHIFT >R
>>>>>    2DUP NEGATE BITS-PER-CELL + RSHIFT >R
>>>>>    LSHIFT 2R> OR
>>>>> ;
>>>>> : DLSHIFT ( xd1 u -- xd2 )
>>>>>    DUP 0= IF  DROP EXIT THEN
>>>>>    DUP MAX-FOR-SHIFT2 U> IF  DROP 2DROP 0. EXIT THEN
>>>>>    DUP MAX-FOR-SHIFT1 U> IF  NIP BITS-PER-CELL - LSHIFT 0 SWAP EXIT
>>>>> THEN
>>>>>    (DLSHIFT)
>>>>> ;
>>>>> : (DRSHIFT) ( xd1 u -- xd2 )
>>>>>    ( x.lo x.hi  u )
>>>>>    2DUP RSHIFT >R
>>>>>    TUCK NEGATE BITS-PER-CELL + LSHIFT >R
>>>>>    RSHIFT R> OR R>
>>>>> ;
>>>>> : DRSHIFT ( xd1 u -- xd2 )
>>>>>    DUP 0= IF  DROP EXIT THEN
>>>>>    DUP MAX-FOR-SHIFT2 U> IF  DROP 2DROP 0. EXIT THEN
>>>>>    DUP MAX-FOR-SHIFT1 U> IF  >R NIP R> BITS-PER-CELL - RSHIFT 0
>>>>> EXIT THEN
>>>>>    (DRSHIFT)
>>>>> ;
>>>>>
>>>>> === End of "double-shift.fth"
>
> Can't make it any shorter than this. And no idea what happens with less
> robust LSHIFT or RSHIFT implementations. CELL-BITS should be most
> obvious, : SPIN SWAP ROT ; should fix most porting issues, replace ;THEN
> with EXIT THEN. It passes all tests.
>
> : dlshift
>   dup 0> 0= if drop ;then
>   >r over 0 invert cell-bits r@ - dup >r lshift and r> rshift swap
>   r@ lshift or swap r> lshift swap
> ;
>
> : drshift
>   dup 0> 0= if drop ;then
>   >r dup 0 invert cell-bits r@ - dup >r rshift and r> lshift swap
>   r@ rshift spin r> rshift or swap
> ;
>

Thanks! I have updated LSHIFT and RSHIFT in kForth-32 and kForth-64 to
handle shift count >= BITS_PER_CELL to give the expected answer (0).

--
Krishna

Re: DLSHIFT and DRSHIFT

<uu6ju4$bdpk$2@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=26566&group=comp.lang.forth#26566

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: krishna.myneni@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: DLSHIFT and DRSHIFT
Date: Fri, 29 Mar 2024 09:41:08 -0500
Organization: A noiseless patient Spider
Lines: 151
Message-ID: <uu6ju4$bdpk$2@dont-email.me>
References: <utvgki$2ciso$1@dont-email.me> <utvque$2elom$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 29 Mar 2024 14:41:09 +0100 (CET)
Injection-Info: dont-email.me; posting-host="2c9365f1d570a9448132d713760afcc5";
logging-data="374580"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX188epA6uoKrnD5kjz8bP6aT"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:wPaZGKq0VheyB9yKnS6ZF4o04c4=
In-Reply-To: <utvque$2elom$1@dont-email.me>
Content-Language: en-US
 by: Krishna Myneni - Fri, 29 Mar 2024 14:41 UTC

On 3/26/24 19:57, Krishna Myneni wrote:
> On 3/26/24 17:01, Krishna Myneni wrote:
>> Standard source definitions of DLSHIFT and DRSHIFT (double number left
>> shift and right shift), over full shift range, per discussion in prior
>> thread.
>>
>> Tests needed.
>
> Just tested DLSHIFT and found weird things going on. Traced the problem
> to LSHIFT.
>
>
> kforth64
>
> 1 64 LSHIFT .  \ expected to get zero
> 1              \ instead, got 1
>
> Then, I looked at the spec. for LSHIFT and, indeed, there is an
> ambiguous condition for u >= BITS_PER_CELL .
>
>
> 6.1.1805
> LSHIFT “l-shift”
> CORE
> ( x1 u – – x2 )
> Perform a logical left shift of u bit-places on x1, giving x2. Put
> zeroes into the least significant bits vacated by the shift. An
> ambiguous condition exists if u is greater than or equal to the number
> of bits in a cell.
>
> Gforth does the same thing
>
> 1 64 LSHIFT .  1
> 1 65 LSHIFT .  2
> etc.
>
>
> We shouldn't have an ambiguous condition here because of some
> idiosyncratic behavior of the SHL instruction!
>
> u 64 LSHIFT should be zero on all systems with cell sizes up to 64 bits.
>

I have revised LSHIFT and RSHIFT in kForth-32 and kForth-64 to give
expected results for shift count >= BITS_PER_CELL (still have to update
kForth-Win32). Some test code to check that these words behave as expected:

1 CELLS 8 * constant BITS_PER_CELL

: test-lshift ( -- )
BITS_PER_CELL 6 + 0 DO
I 2 .R 2 SPACES
1 I LSHIFT
BINARY BITS_PER_CELL U.R CR DECIMAL
LOOP ;

: test-rshift ( -- )
1 BITS_PER_CELL 1- LSHIFT
BITS_PER_CELL 6 + 0 DO
I 2 .R 2 SPACES
DUP I RSHIFT
BINARY BITS_PER_CELL U.R CR DECIMAL
LOOP DROP ;

TEST-LSHIFT ( on 32-bit system )
0 1
1 10
2 100
3 1000
4 10000
5 100000
6 1000000
7 10000000
8 100000000
9 1000000000
10 10000000000
11 100000000000
12 1000000000000
13 10000000000000
14 100000000000000
15 1000000000000000
16 10000000000000000
17 100000000000000000
18 1000000000000000000
19 10000000000000000000
20 100000000000000000000
21 1000000000000000000000
22 10000000000000000000000
23 100000000000000000000000
24 1000000000000000000000000
25 10000000000000000000000000
26 100000000000000000000000000
27 1000000000000000000000000000
28 10000000000000000000000000000
29 100000000000000000000000000000
30 1000000000000000000000000000000
31 10000000000000000000000000000000
32 0
33 0
34 0
35 0
36 0
37 0
ok
TEST-RSHIFT ( on 32-bit system )
0 10000000000000000000000000000000
1 1000000000000000000000000000000
2 100000000000000000000000000000
3 10000000000000000000000000000
4 1000000000000000000000000000
5 100000000000000000000000000
6 10000000000000000000000000
7 1000000000000000000000000
8 100000000000000000000000
9 10000000000000000000000
10 1000000000000000000000
11 100000000000000000000
12 10000000000000000000
13 1000000000000000000
14 100000000000000000
15 10000000000000000
16 1000000000000000
17 100000000000000
18 10000000000000
19 1000000000000
20 100000000000
21 10000000000
22 1000000000
23 100000000
24 10000000
25 1000000
26 100000
27 10000
28 1000
29 100
30 10
31 1
32 0
33 0
34 0
35 0
36 0
37 0
ok

Similar displays for 64-bit systems.

--
KM

Re: DLSHIFT and DRSHIFT

<2024Mar29.175532@mips.complang.tuwien.ac.at>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=26567&group=comp.lang.forth#26567

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: Re: DLSHIFT and DRSHIFT
Date: Fri, 29 Mar 2024 16:55:32 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 37
Message-ID: <2024Mar29.175532@mips.complang.tuwien.ac.at>
References: <utvgki$2ciso$1@dont-email.me> <utvque$2elom$1@dont-email.me> <uu0vpa$2qdel$1@dont-email.me> <uu13cn$2r980$1@dont-email.me> <2024Mar27.194610@mips.complang.tuwien.ac.at> <uu1ths$31jjc$2@dont-email.me> <2024Mar28.094943@mips.complang.tuwien.ac.at> <uu6eo4$a8hm$1@dont-email.me>
Injection-Date: Fri, 29 Mar 2024 17:09:32 +0100 (CET)
Injection-Info: dont-email.me; posting-host="9141c1be92b2959fef0d1c0935a58120";
logging-data="446659"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX181qJHxN94qIIDK4MjXp1T7"
Cancel-Lock: sha1:Tn0yLAywJVaRYxKQdD5Rw64cpls=
X-newsreader: xrn 10.11
 by: Anton Ertl - Fri, 29 Mar 2024 16:55 UTC

Krishna Myneni <krishna.myneni@ccreweb.org> writes:
>On 3/28/24 03:49, Anton Ertl wrote:
>> Here's some data about the occurences in the Gforth image:
>>
>> Non-constant shift amount:
>> 2 lshift
>> 1 rshift
>> 0 arshift
>>
>> Constant shift amount:
>> 18 lit lshift
>> 41 lit rshift
>> 0 lit arshift
>>
>...
>
>Checking the Forth code base which I use, I find ~ 100:1 ratio between
>uses of constant shift amount to non-constant shifts. The existing
>instances of non-constant shifts are comparable to yours: two in number
>theory programs e.g., finding an exact fraction for a floating point
>number, and one use in the assembler.
>
>I don't know what to conclude from this other than the kind of
>application development I have been doing favors one over the other.

It shows that Forth systems that support special code generation for
operations with constants (probably all native-code systems, as well
as Gforth) would be able to generate the same code in the vast
majority of cases even with the change you propose. Only in the few
non-constant cases a few extra instructions would be needed.

- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: https://forth-standard.org/
EuroForth 2023: https://euro.theforth.net/2023

Re: DLSHIFT and DRSHIFT

<66076504$1@news.ausics.net>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=26569&group=comp.lang.forth#26569

  copy link   Newsgroups: comp.lang.forth
Date: Sat, 30 Mar 2024 12:04:05 +1100
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: DLSHIFT and DRSHIFT
Newsgroups: comp.lang.forth
References: <utvgki$2ciso$1@dont-email.me> <uu02tt$2k3jf$1@dont-email.me>
<uu1c3r$2tdj0$1@dont-email.me> <uu1e7t$2tueu$1@dont-email.me>
<uu1huv$2uqc2$1@dont-email.me>
Content-Language: en-GB
From: dxforth@gmail.com (dxf)
In-Reply-To: <uu1huv$2uqc2$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
NNTP-Posting-Host: news.ausics.net
Message-ID: <66076504$1@news.ausics.net>
Organization: Ausics - https://newsgroups.ausics.net
Lines: 13
X-Complaints: abuse@ausics.net
Path: i2pn2.org!i2pn.org!news.bbs.nz!news.ausics.net!not-for-mail
 by: dxf - Sat, 30 Mar 2024 01:04 UTC

On 28/03/2024 3:36 am, Ruvim wrote:
> On 2024-03-27 19:33, Krishna Myneni wrote:
>> ...
>> Does it succeed on all of the tests I gave?
>
> Of course, I checked — it succeed your tests.

VFX's implementations are simpler still and pass the tests with the
exception of 5 and 6 (same ambiguous conditions as ANS).

Re: DLSHIFT and DRSHIFT

<uu929q$10h7i$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=26570&group=comp.lang.forth#26570

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: krishna.myneni@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: DLSHIFT and DRSHIFT
Date: Sat, 30 Mar 2024 07:58:34 -0500
Organization: A noiseless patient Spider
Lines: 68
Message-ID: <uu929q$10h7i$1@dont-email.me>
References: <utvgki$2ciso$1@dont-email.me> <utvque$2elom$1@dont-email.me>
<uu0vpa$2qdel$1@dont-email.me> <uu13cn$2r980$1@dont-email.me>
<2024Mar27.194610@mips.complang.tuwien.ac.at> <uu1ths$31jjc$2@dont-email.me>
<2024Mar28.094943@mips.complang.tuwien.ac.at> <uu6eo4$a8hm$1@dont-email.me>
<2024Mar29.175532@mips.complang.tuwien.ac.at>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 30 Mar 2024 12:58:35 +0100 (CET)
Injection-Info: dont-email.me; posting-host="f3855d741fd08540848e896873e462f8";
logging-data="1066226"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19B4lvzuqyMOaxGuS1BJgNn"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:2CIRPdgwRkOBbb2F/6v9ruEY7dI=
In-Reply-To: <2024Mar29.175532@mips.complang.tuwien.ac.at>
Content-Language: en-US
 by: Krishna Myneni - Sat, 30 Mar 2024 12:58 UTC

On 3/29/24 11:55, Anton Ertl wrote:
> Krishna Myneni <krishna.myneni@ccreweb.org> writes:
>> On 3/28/24 03:49, Anton Ertl wrote:
>>> Here's some data about the occurences in the Gforth image:
>>>
>>> Non-constant shift amount:
>>> 2 lshift
>>> 1 rshift
>>> 0 arshift
>>>
>>> Constant shift amount:
>>> 18 lit lshift
>>> 41 lit rshift
>>> 0 lit arshift
>>>
>> ...
>>
>> Checking the Forth code base which I use, I find ~ 100:1 ratio between
>> uses of constant shift amount to non-constant shifts. The existing
>> instances of non-constant shifts are comparable to yours: two in number
>> theory programs e.g., finding an exact fraction for a floating point
>> number, and one use in the assembler.
>>
>> I don't know what to conclude from this other than the kind of
>> application development I have been doing favors one over the other.
>
> It shows that Forth systems that support special code generation for
> operations with constants (probably all native-code systems, as well
> as Gforth) would be able to generate the same code in the vast
> majority of cases even with the change you propose. Only in the few
> non-constant cases a few extra instructions would be needed.
>

Ah, so optimizing Forth compilers can do a compile-time check for
literal shifts and not have to insert instructions for compare and
branch e.g., my new implementation of LSHIFT in kforth64

(from vm64-common.s)

..equ MAX_SHIFT_COUNT, WSIZE*8-1

L_lshift:
LDSP
DROP
mov (%rbx), %rcx
cmp $MAX_SHIFT_COUNT, %rcx
jbe lshift1
movq $0, WSIZE(%rbx)
NEXT
lshift1:
shlq %cl, WSIZE(%rbx)
NEXT

The older version was:

L_lshift:
LDSP
DROP
mov (%rbx), %rcx
shlq %cl, WSIZE(%rbx)
NEXT

Similarly for RSHIFT.

--
KM

Re: DLSHIFT and DRSHIFT

<2024Mar30.182904@mips.complang.tuwien.ac.at>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=26572&group=comp.lang.forth#26572

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: Re: DLSHIFT and DRSHIFT
Date: Sat, 30 Mar 2024 17:29:04 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 13
Message-ID: <2024Mar30.182904@mips.complang.tuwien.ac.at>
References: <utvgki$2ciso$1@dont-email.me> <utvque$2elom$1@dont-email.me> <uu0vpa$2qdel$1@dont-email.me> <uu13cn$2r980$1@dont-email.me> <2024Mar27.194610@mips.complang.tuwien.ac.at> <uu1ths$31jjc$2@dont-email.me> <2024Mar28.094943@mips.complang.tuwien.ac.at> <uu6eo4$a8hm$1@dont-email.me> <2024Mar29.175532@mips.complang.tuwien.ac.at> <uu929q$10h7i$1@dont-email.me>
Injection-Date: Sat, 30 Mar 2024 17:30:15 +0100 (CET)
Injection-Info: dont-email.me; posting-host="332d6d2bfc16aa8c3ab76c214da8f0cf";
logging-data="1195411"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+FtZ5soR7vVacYhnAj1Nrl"
Cancel-Lock: sha1:1BgUylsyQJedecJ0f9SQ7U/LYXQ=
X-newsreader: xrn 10.11
 by: Anton Ertl - Sat, 30 Mar 2024 17:29 UTC

Krishna Myneni <krishna.myneni@ccreweb.org> writes:
>Ah, so optimizing Forth compilers can do a compile-time check for
>literal shifts and not have to insert instructions for compare and
>branch

Yes.

- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: https://forth-standard.org/
EuroForth 2023: https://euro.theforth.net/2023

Re: DLSHIFT and DRSHIFT

<6608bb35$1@news.ausics.net>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=26573&group=comp.lang.forth#26573

  copy link   Newsgroups: comp.lang.forth
Date: Sun, 31 Mar 2024 12:24:05 +1100
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: DLSHIFT and DRSHIFT
Newsgroups: comp.lang.forth
References: <utvgki$2ciso$1@dont-email.me> <uu02tt$2k3jf$1@dont-email.me>
<uu1c3r$2tdj0$1@dont-email.me> <uu1e7t$2tueu$1@dont-email.me>
<uu1huv$2uqc2$1@dont-email.me> <uu1t7e$31jjc$1@dont-email.me>
<nnd$51ea08c7$4ebacde5@98ba4a1ad989127a>
Content-Language: en-GB
From: dxforth@gmail.com (dxf)
In-Reply-To: <nnd$51ea08c7$4ebacde5@98ba4a1ad989127a>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: news.ausics.net
Message-ID: <6608bb35$1@news.ausics.net>
Organization: Ausics - https://newsgroups.ausics.net
Lines: 12
X-Complaints: abuse@ausics.net
Path: i2pn2.org!i2pn.org!news.bbs.nz!news.ausics.net!not-for-mail
 by: dxf - Sun, 31 Mar 2024 01:24 UTC

On 30/03/2024 1:32 am, Hans Bezemer wrote:
> ...
> And no idea what happens with less robust LSHIFT or RSHIFT implementations.

Simply define:

: lshift dup cell-bits u< 0= abort" **shift-arg**" lshift ;
: rshift dup cell-bits u< 0= abort" **shift-arg**" rshift ;

It will reveal all the out-of-bounds cases in one's code that's been masked
by having LSHIFT and RSHIFT return zero.

Re: DLSHIFT and DRSHIFT

<660a0c49$1@news.ausics.net>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=26582&group=comp.lang.forth#26582

  copy link   Newsgroups: comp.lang.forth
Date: Mon, 1 Apr 2024 12:22:18 +1100
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: DLSHIFT and DRSHIFT
Newsgroups: comp.lang.forth
References: <utvgki$2ciso$1@dont-email.me> <uu02tt$2k3jf$1@dont-email.me>
<uu1c3r$2tdj0$1@dont-email.me> <uu1e7t$2tueu$1@dont-email.me>
<uu1huv$2uqc2$1@dont-email.me> <uu1t7e$31jjc$1@dont-email.me>
<nnd$51ea08c7$4ebacde5@98ba4a1ad989127a>
Content-Language: en-GB
From: dxforth@gmail.com (dxf)
In-Reply-To: <nnd$51ea08c7$4ebacde5@98ba4a1ad989127a>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
NNTP-Posting-Host: news.ausics.net
Message-ID: <660a0c49$1@news.ausics.net>
Organization: Ausics - https://newsgroups.ausics.net
Lines: 49
X-Complaints: abuse@ausics.net
Path: i2pn2.org!i2pn.org!news.bbs.nz!news.ausics.net!not-for-mail
 by: dxf - Mon, 1 Apr 2024 01:22 UTC

On 30/03/2024 1:32 am, Hans Bezemer wrote:
> ...
> Can't make it any shorter than this. And no idea what happens with less robust LSHIFT or RSHIFT implementations. CELL-BITS should be most obvious, : SPIN SWAP ROT ; should fix most porting issues, replace ;THEN
> with EXIT THEN. It passes all tests.
>
> : dlshift
>   dup 0> 0= if drop ;then
>   >r over 0 invert cell-bits r@ - dup >r lshift and r> rshift swap
>   r@ lshift or swap r> lshift swap
> ;
>
> : drshift
>   dup 0> 0= if drop ;then
>   >r dup 0 invert cell-bits r@ - dup >r rshift and r> lshift swap
>   r@ rshift spin r> rshift or swap
> ;

The table below shows the arguments (number and shift) presented to each
RSHIFT/LSHIFT in your double-shift algorithm using the 9 tests Krishna provided.

I've used a 32-bit forth in which RSHIFT/LSHIFT have been modified such that
shifts greater than 31 bits will return 0 per the 'no ambiguous conditions'
recommendation.

-1 0 3 0 1 20 3 20 00 03

-1 0 FF 0 0 20 FF 20 00 FF

-1 0 1 0 1 20 0 20 01 00

-1 0 FF 0 FF 20 0 20 FF 00

-1 -20 0 -20 -1 40 -1 40 00 00

-1 -20 0 -20 -1 40 -1 40 00 00

-1 1 2 1 1 1F 3 1F

-1 1F -80000000 1F 2 1 -80000000 1

-1 1F 1 1F 3 1 7 1

While your double-shift algorithm produces the correct results (not shown here),
the intermediate values presented to each RSHIFT/LSHIFT can be quite out-of-bounds
e.g. a shift of 40 and -20 (actually FFFFFFE0) would concern me. That an 'unambiguous'
RSHIFT/LSHIFT will mask questionable parameters fed to it and return a result of 0,
I for one find problematic. IMO it were better that RSHIFT/LSHIFT should fail than
do this.

Re: DLSHIFT and DRSHIFT

<c4647d14d5348badce538c50b74a1a62@www.novabbs.com>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=26583&group=comp.lang.forth#26583

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!.POSTED!not-for-mail
From: minforth@gmx.net (minforth)
Newsgroups: comp.lang.forth
Subject: Re: DLSHIFT and DRSHIFT
Date: Mon, 1 Apr 2024 08:03:56 +0000
Organization: novaBBS
Message-ID: <c4647d14d5348badce538c50b74a1a62@www.novabbs.com>
References: <utvgki$2ciso$1@dont-email.me> <uu02tt$2k3jf$1@dont-email.me> <uu1c3r$2tdj0$1@dont-email.me> <uu1e7t$2tueu$1@dont-email.me> <uu1huv$2uqc2$1@dont-email.me> <uu1t7e$31jjc$1@dont-email.me> <nnd$51ea08c7$4ebacde5@98ba4a1ad989127a> <660a0c49$1@news.ausics.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="3904348"; mail-complaints-to="usenet@i2pn2.org";
posting-account="t+lO0yBNO1zGxasPvGSZV1BRu71QKx+JE37DnW+83jQ";
User-Agent: Rocksolid Light
X-Rslight-Site: $2y$10$mlWwDJKSzA5l0FD31xf2tehrye7IHOmg.Fw1gnqMMZKKmxcC8dUPK
X-Spam-Checker-Version: SpamAssassin 4.0.0
X-Rslight-Posting-User: d2a19558f194e2f1f8393b8d9be9ef51734a4da3
 by: minforth - Mon, 1 Apr 2024 08:03 UTC

dxf wrote:

> While your double-shift algorithm produces the correct results (not shown here),
> the intermediate values presented to each RSHIFT/LSHIFT can be quite out-of-bounds
> e.g. a shift of 40 and -20 (actually FFFFFFE0) would concern me. That an 'unambiguous'
> RSHIFT/LSHIFT will mask questionable parameters fed to it and return a result of 0,
> I for one find problematic. IMO it were better that RSHIFT/LSHIFT should fail than
> do this.

Doesn't make sense during fp number addition/subtraction.

Re: DLSHIFT and DRSHIFT

<660a7c93$1@news.ausics.net>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=26584&group=comp.lang.forth#26584

  copy link   Newsgroups: comp.lang.forth
Date: Mon, 1 Apr 2024 20:21:23 +1100
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: DLSHIFT and DRSHIFT
Newsgroups: comp.lang.forth
References: <utvgki$2ciso$1@dont-email.me> <uu02tt$2k3jf$1@dont-email.me>
<uu1c3r$2tdj0$1@dont-email.me> <uu1e7t$2tueu$1@dont-email.me>
<uu1huv$2uqc2$1@dont-email.me> <uu1t7e$31jjc$1@dont-email.me>
<nnd$51ea08c7$4ebacde5@98ba4a1ad989127a> <660a0c49$1@news.ausics.net>
<c4647d14d5348badce538c50b74a1a62@www.novabbs.com>
Content-Language: en-GB
From: dxforth@gmail.com (dxf)
In-Reply-To: <c4647d14d5348badce538c50b74a1a62@www.novabbs.com>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
NNTP-Posting-Host: news.ausics.net
Message-ID: <660a7c93$1@news.ausics.net>
Organization: Ausics - https://newsgroups.ausics.net
Lines: 14
X-Complaints: abuse@ausics.net
Path: i2pn2.org!i2pn.org!news.bbs.nz!news.ausics.net!not-for-mail
 by: dxf - Mon, 1 Apr 2024 09:21 UTC

On 1/04/2024 7:03 pm, minforth wrote:
> dxf wrote:
>
>> While your double-shift algorithm produces the correct results (not shown here),
>> the intermediate values presented to each RSHIFT/LSHIFT can be quite out-of-bounds
>> e.g. a shift of 40 and -20 (actually FFFFFFE0) would concern me.  That an 'unambiguous'
>> RSHIFT/LSHIFT will mask questionable parameters fed to it and return a result of 0,
>> I for one find problematic.  IMO it were better that RSHIFT/LSHIFT should fail than
>> do this.
>
> Doesn't make sense during fp number addition/subtraction.

Example?

Re: DLSHIFT and DRSHIFT

<nnd$15d1791a$5079757b@7d2d1b8d6acdcd7c>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=26585&group=comp.lang.forth#26585

  copy link   Newsgroups: comp.lang.forth
Newsgroups: comp.lang.forth
Subject: Re: DLSHIFT and DRSHIFT
References: <utvgki$2ciso$1@dont-email.me> <uu0vpa$2qdel$1@dont-email.me> <uu13cn$2r980$1@dont-email.me> <uu1pmo$305br$1@dont-email.me>
From: albert@spenarnc.xs4all.nl
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: albert@cherry.(none) (albert)
Message-ID: <nnd$15d1791a$5079757b@7d2d1b8d6acdcd7c>
Organization: KPN B.V.
Date: Mon, 01 Apr 2024 11:35:05 +0200
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!newsfeed.endofthelinebbs.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!feed.abavia.com!abe006.abavia.com!abp003.abavia.com!news.kpn.nl!not-for-mail
Lines: 64
Injection-Date: Mon, 01 Apr 2024 11:35:05 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
 by: albert@spenarnc.xs4all.nl - Mon, 1 Apr 2024 09:35 UTC

In article <uu1pmo$305br$1@dont-email.me>,
Bernd Linsel <bl1-thispartdoesnotbelonghere@gmx.com> wrote:
>On 27.03.2024 13:28, Krishna Myneni wrote:
>>
>> I really think it is a bad idea to have UB in the spec of LSHIFT and
>> RSHIFT due to the arbitrariness of low level shift operations at the
> > hardware level.
>
>It's not UB, it is IB and thus it should be required that an implementer
>documents the respective behaviour of their system.
>
> > Here we have a chance to remove that UB and guarantee that>
>> 1 BITS_PER_CELL LSHIFT  returns zero
>> and
>> 1 BITS_PER_CELL RSHIFT  returns zero
>>
>> so that the expected result for a shift operation on the cell operand
>> does not have UB.
>>
>> Efficiency because of extra instructions needed to implement this
>> guarantee are not even worth bothering about -- we are not C.
>
>Forth does care about efficiency. Otherwise you could eliminate over the
>half of the ambiguous conditions in the Forth standard that only arise
>from the fact that hardware platforms differ in their behaviour.
>
>[snip]
>
>For the rare situation that a variable shift count is needed, and is not
>per se restricted to 0..ADDRESS-UNIT-BITS - 1, you can always write either
>
>0 MAX S" ADDRESS-UNIT-BITS" 1- MIN LSHIFT ( or RSHIFT)
>
>or
>
>DUP 0< INVERT IF DUP S" ADDRESS-UNIT-BITS" < IF LSHIFT ( or RSHIFT)
>ELSE ( whatever to do if shift-amount < 0)
>ELSE ( whatever to do if shift-amount >= cell width)
>THEN THEN
>
>or simply
>
>DUP 0< ABORT" shift amount less than 0"
>DUP S" ADDRESS-UNIT-BITS" 1- > ABORT" shift amount greater/equal cell width)
>LSHIFT ( or RSHIFT)

I hate ABORT in this context. Are you sure that you want to shut down
the nuclear power plant in this situation?

>
>NB: The behaviour of most processors to only regard the 5 or 6 LSBs is
>useful for expressions like -1 64 <n> - LSHIFT to produce bit masks,
>these can simply be expressed as <n> NEGATE LSHIFT (with an
>environmental dependency on processors that behave this way).
>
>
>--
>Bernd Linsel
--
Don't praise the day before the evening. One swallow doesn't make spring.
You must not say "hey" before you have crossed the bridge. Don't sell the
hide of the bear until you shot it. Better one bird in the hand than ten in
the air. First gain is a cat purring. - the Wise from Antrim -

Re: DLSHIFT and DRSHIFT

<2024Apr1.115659@mips.complang.tuwien.ac.at>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=26586&group=comp.lang.forth#26586

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton@mips.complang.tuwien.ac.at (Anton Ertl)
Newsgroups: comp.lang.forth
Subject: Re: DLSHIFT and DRSHIFT
Date: Mon, 01 Apr 2024 09:56:59 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 53
Message-ID: <2024Apr1.115659@mips.complang.tuwien.ac.at>
References: <utvgki$2ciso$1@dont-email.me> <uu0vpa$2qdel$1@dont-email.me> <uu13cn$2r980$1@dont-email.me> <uu1pmo$305br$1@dont-email.me> <nnd$15d1791a$5079757b@7d2d1b8d6acdcd7c>
Injection-Date: Mon, 01 Apr 2024 10:28:53 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="a1fa2e7cbcc6ad9fb2ba996cb1358ea1";
logging-data="2568290"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+nBGGB+pv3VMIpmFavrw6T"
Cancel-Lock: sha1:d0akGMvzCcCp34W7/DCKYjMCMB8=
X-newsreader: xrn 10.11
 by: Anton Ertl - Mon, 1 Apr 2024 09:56 UTC

albert@spenarnc.xs4all.nl writes:
>In article <uu1pmo$305br$1@dont-email.me>,
>Bernd Linsel <bl1-thispartdoesnotbelonghere@gmx.com> wrote:
>>NB: The behaviour of most processors to only regard the 5 or 6 LSBs is
>>useful for expressions like -1 64 <n> - LSHIFT to produce bit masks,
>>these can simply be expressed as <n> NEGATE LSHIFT (with an
>>environmental dependency on processors that behave this way).

Let's see:

-1 64 2 - lshift hex. $C000000000000000 ok
-1 64 1 - lshift hex. $8000000000000000 ok
-1 64 0 - lshift hex. $FFFFFFFFFFFFFFFF ok

I have my doubts that somebody performing such a computation intends
to produce the last result. A result of 0 is more likely to be
intended. Of course, there is some chance that providing a zero <n>
for that computation is not intended, which may be a justification for
everybody involved to produce arbitrary results in that case.

Anyway, given 64-bt cells, the standard LSHIFT and twos-complement
arithmetic (which is assumed by the "-1" above already), one can
express the intention as follows:

: gen-mask1 ( n -- x )
\ produce -1 if <n>=0
negate 63 and -1 swap lshift ;

: gen-mask2 ( n -- x )
\ produce 0 if <n>=0
64 swap - dup 64 u< if
-1 swap lshift
else
drop 0
then ;

: gen-mask3 ( n -- x )
\ throw if <n>=0
64 swap - dup 64 u< 0= -24 and throw -1 swap lshift ;

And similarly for machine code. So, if GEN-MASK1 is intended, even an
LSHIFT that produces 0 for larger shift counts is only one instruction
away. So it is unlikely that the computer architects decided to look
at only the LSB bits for that purpose.

BTW, I ignore base64-encoded postings.

- anton
--
M. Anton Ertl http://www.complang.tuwien.ac.at/anton/home.html
comp.lang.forth FAQs: http://www.complang.tuwien.ac.at/forth/faq/toc.html
New standard: https://forth-standard.org/
EuroForth 2023: https://euro.theforth.net/2023

Re: DLSHIFT and DRSHIFT

<nnd$3f79d89a$1719b54b@d25a550e35ff0832>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=26589&group=comp.lang.forth#26589

  copy link   Newsgroups: comp.lang.forth
Date: Mon, 1 Apr 2024 17:18:16 +0200
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: DLSHIFT and DRSHIFT
Newsgroups: comp.lang.forth
References: <utvgki$2ciso$1@dont-email.me> <uu02tt$2k3jf$1@dont-email.me>
<uu1c3r$2tdj0$1@dont-email.me> <uu1e7t$2tueu$1@dont-email.me>
<uu1huv$2uqc2$1@dont-email.me> <uu1t7e$31jjc$1@dont-email.me>
<nnd$51ea08c7$4ebacde5@98ba4a1ad989127a> <660a0c49$1@news.ausics.net>
Content-Language: en-US
From: the.beez.speaks@gmail.com (Hans Bezemer)
In-Reply-To: <660a0c49$1@news.ausics.net>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Message-ID: <nnd$3f79d89a$1719b54b@d25a550e35ff0832>
Organization: KPN B.V.
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!newsfeed.hasname.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!feed.abavia.com!abe004.abavia.com!abp001.abavia.com!news.kpn.nl!not-for-mail
Lines: 79
Injection-Date: Mon, 01 Apr 2024 17:18:16 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
 by: Hans Bezemer - Mon, 1 Apr 2024 15:18 UTC

On 01-04-2024 03:22, dxf wrote:
> On 30/03/2024 1:32 am, Hans Bezemer wrote:
>> ...
>> Can't make it any shorter than this. And no idea what happens with less robust LSHIFT or RSHIFT implementations. CELL-BITS should be most obvious, : SPIN SWAP ROT ; should fix most porting issues, replace ;THEN
>> with EXIT THEN. It passes all tests.
>>
>> : dlshift
>>   dup 0> 0= if drop ;then
>>   >r over 0 invert cell-bits r@ - dup >r lshift and r> rshift swap
>>   r@ lshift or swap r> lshift swap
>> ;
>>
>> : drshift
>>   dup 0> 0= if drop ;then
>>   >r dup 0 invert cell-bits r@ - dup >r rshift and r> lshift swap
>>   r@ rshift spin r> rshift or swap
>> ;
>
> The table below shows the arguments (number and shift) presented to each
> RSHIFT/LSHIFT in your double-shift algorithm using the 9 tests Krishna provided.
>
> I've used a 32-bit forth in which RSHIFT/LSHIFT have been modified such that
> shifts greater than 31 bits will return 0 per the 'no ambiguous conditions'
> recommendation.
>
> -1 0 3 0 1 20 3 20 00 03
>
> -1 0 FF 0 0 20 FF 20 00 FF
>
> -1 0 1 0 1 20 0 20 01 00
>
> -1 0 FF 0 FF 20 0 20 FF 00
>
> -1 -20 0 -20 -1 40 -1 40 00 00
>
> -1 -20 0 -20 -1 40 -1 40 00 00
>
> -1 1 2 1 1 1F 3 1F
>
> -1 1F -80000000 1F 2 1 -80000000 1
>
> -1 1F 1 1F 3 1 7 1
>
> While your double-shift algorithm produces the correct results (not shown here),
> the intermediate values presented to each RSHIFT/LSHIFT can be quite out-of-bounds
> e.g. a shift of 40 and -20 (actually FFFFFFE0) would concern me. That an 'unambiguous'
> RSHIFT/LSHIFT will mask questionable parameters fed to it and return a result of 0,
> I for one find problematic. IMO it were better that RSHIFT/LSHIFT should fail than
> do this.
I see where you're going with this. I have two things to say about this:
1. If you're confronted with a LSHIFT/RSHIFT that's not reliable when
you exceed a CELL-BITS shift, the entire discussion is moot anyway;
2. 4tH's implementation does not have a separate LSHIFT/RSHIFT. It's the
same thing, so a negative shift works as expected.

That may seem a bit harsh, but it's the consequence of "An ambiguous
condition exists if u is greater than or equal to the number of bits in
a cell" and a separate LSHIFT and RSHIFT. I mean a MAX-U shift is
meaningless in every universe (spoiler alert: it's "ambiguous"), why not
make it "+/-n"?

The only viable alternative is:

: DLSHIFT ( xd1 n -- xd2) 0 ?do d2* loop ;
: DRSHIFT ( xd1 n -- xd2) 0 ?do d2/ loop ;

Which is okay in my book, but may be not fast enough for some.

One could save the routine by adding:
dup cell-bits - dup 0< 0= if abs >r >r swap dup xor r> r> swap then drop

Sure, it wont be any faster, but it'd avoid "ambiguous" LSHIFT/RSHIFT
issues.

Hans Bezemer

Re: DLSHIFT and DRSHIFT

<nnd$3d3082fa$1e59be89@15cfbe7ce4fc662a>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=26590&group=comp.lang.forth#26590

  copy link   Newsgroups: comp.lang.forth
Date: Mon, 1 Apr 2024 17:53:59 +0200
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: DLSHIFT and DRSHIFT
Newsgroups: comp.lang.forth
References: <utvgki$2ciso$1@dont-email.me> <uu02tt$2k3jf$1@dont-email.me>
<uu1c3r$2tdj0$1@dont-email.me> <uu1e7t$2tueu$1@dont-email.me>
<uu1huv$2uqc2$1@dont-email.me> <uu1t7e$31jjc$1@dont-email.me>
<nnd$51ea08c7$4ebacde5@98ba4a1ad989127a> <660a0c49$1@news.ausics.net>
Content-Language: en-US
From: the.beez.speaks@gmail.com (Hans Bezemer)
In-Reply-To: <660a0c49$1@news.ausics.net>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Message-ID: <nnd$3d3082fa$1e59be89@15cfbe7ce4fc662a>
Organization: KPN B.V.
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!feed.abavia.com!abe005.abavia.com!abp003.abavia.com!news.kpn.nl!not-for-mail
Lines: 60
Injection-Date: Mon, 01 Apr 2024 17:53:59 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
 by: Hans Bezemer - Mon, 1 Apr 2024 15:53 UTC

On 01-04-2024 03:22, dxf wrote:
> On 30/03/2024 1:32 am, Hans Bezemer wrote:
>> ...
>> Can't make it any shorter than this. And no idea what happens with less robust LSHIFT or RSHIFT implementations. CELL-BITS should be most obvious, : SPIN SWAP ROT ; should fix most porting issues, replace ;THEN
>> with EXIT THEN. It passes all tests.
>>
>> : dlshift
>>   dup 0> 0= if drop ;then
>>   >r over 0 invert cell-bits r@ - dup >r lshift and r> rshift swap
>>   r@ lshift or swap r> lshift swap
>> ;
>>
>> : drshift
>>   dup 0> 0= if drop ;then
>>   >r dup 0 invert cell-bits r@ - dup >r rshift and r> lshift swap
>>   r@ rshift spin r> rshift or swap
>> ;
>
> The table below shows the arguments (number and shift) presented to each
> RSHIFT/LSHIFT in your double-shift algorithm using the 9 tests Krishna provided.
>
> I've used a 32-bit forth in which RSHIFT/LSHIFT have been modified such that
> shifts greater than 31 bits will return 0 per the 'no ambiguous conditions'
> recommendation.
>
> -1 0 3 0 1 20 3 20 00 03
>
> -1 0 FF 0 0 20 FF 20 00 FF
>
> -1 0 1 0 1 20 0 20 01 00
>
> -1 0 FF 0 FF 20 0 20 FF 00
>
> -1 -20 0 -20 -1 40 -1 40 00 00
>
> -1 -20 0 -20 -1 40 -1 40 00 00
>
> -1 1 2 1 1 1F 3 1F
>
> -1 1F -80000000 1F 2 1 -80000000 1
>
> -1 1F 1 1F 3 1 7 1
>
> While your double-shift algorithm produces the correct results (not shown here),
> the intermediate values presented to each RSHIFT/LSHIFT can be quite out-of-bounds
> e.g. a shift of 40 and -20 (actually FFFFFFE0) would concern me. That an 'unambiguous'
> RSHIFT/LSHIFT will mask questionable parameters fed to it and return a result of 0,
> I for one find problematic. IMO it were better that RSHIFT/LSHIFT should fail than
> do this.

This should fix it with minimal overhead:

RSHIFT: dup cell-bits - dup 0< 0= if >r drop nip r> rshift 0 swap ;then drop
LSHIFT: dup cell-bits - dup 0< 0= if >r drop drop r> lshift 0 ;then drop

Moderately tested.

Hans Bezemer

Re: DLSHIFT and DRSHIFT

<nnd$6fc03763$38a91c50@99bfff59f1b8c3dd>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=26591&group=comp.lang.forth#26591

  copy link   Newsgroups: comp.lang.forth
Date: Mon, 1 Apr 2024 18:03:03 +0200
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: DLSHIFT and DRSHIFT
Newsgroups: comp.lang.forth
References: <utvgki$2ciso$1@dont-email.me> <uu02tt$2k3jf$1@dont-email.me>
<uu1c3r$2tdj0$1@dont-email.me> <uu1e7t$2tueu$1@dont-email.me>
<uu1huv$2uqc2$1@dont-email.me> <uu1t7e$31jjc$1@dont-email.me>
<nnd$51ea08c7$4ebacde5@98ba4a1ad989127a> <660a0c49$1@news.ausics.net>
<nnd$3d3082fa$1e59be89@15cfbe7ce4fc662a>
Content-Language: en-US
From: the.beez.speaks@gmail.com (Hans Bezemer)
In-Reply-To: <nnd$3d3082fa$1e59be89@15cfbe7ce4fc662a>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Message-ID: <nnd$6fc03763$38a91c50@99bfff59f1b8c3dd>
Organization: KPN B.V.
Path: i2pn2.org!i2pn.org!news.chmurka.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!feed.abavia.com!abe004.abavia.com!abp001.abavia.com!news.kpn.nl!not-for-mail
Lines: 82
Injection-Date: Mon, 01 Apr 2024 18:03:03 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
 by: Hans Bezemer - Mon, 1 Apr 2024 16:03 UTC

On 01-04-2024 17:53, Hans Bezemer wrote:
> On 01-04-2024 03:22, dxf wrote:
>> On 30/03/2024 1:32 am, Hans Bezemer wrote:
>>> ...
>>> Can't make it any shorter than this. And no idea what happens with
>>> less robust LSHIFT or RSHIFT implementations. CELL-BITS should be
>>> most obvious, : SPIN SWAP ROT ; should fix most porting issues,
>>> replace ;THEN
>>> with EXIT THEN. It passes all tests.
>>>
>>> : dlshift
>>>    dup 0> 0= if drop ;then
>>>    >r over 0 invert cell-bits r@ - dup >r lshift and r> rshift swap
>>>    r@ lshift or swap r> lshift swap
>>> ;
>>>
>>> : drshift
>>>    dup 0> 0= if drop ;then
>>>    >r dup 0 invert cell-bits r@ - dup >r rshift and r> lshift swap
>>>    r@ rshift spin r> rshift or swap
>>> ;
>>
>> The table below shows the arguments (number and shift) presented to each
>> RSHIFT/LSHIFT in your double-shift algorithm using the 9 tests Krishna
>> provided.
>>
>> I've used a 32-bit forth in which RSHIFT/LSHIFT have been modified
>> such that
>> shifts greater than 31 bits will return 0 per the 'no ambiguous
>> conditions'
>> recommendation.
>>
>> -1 0   3 0   1 20   3 20   00 03
>>
>> -1 0   FF 0   0  20   FF 20   00 FF
>>
>> -1 0   1  0   1  20   0  20   01 00
>>
>> -1 0   FF 0   FF 20   0  20   FF 00
>>
>> -1 -20   0 -20   -1 40   -1 40   00 00
>>
>> -1 -20   0 -20   -1 40   -1 40   00 00
>>
>> -1 1   2 1   1 1F   3 1F
>>
>> -1 1F   -80000000 1F   2 1   -80000000 1
>>
>> -1 1F   1 1F   3 1   7 1
>>
>> While your double-shift algorithm produces the correct results (not
>> shown here),
>> the intermediate values presented to each RSHIFT/LSHIFT can be quite
>> out-of-bounds
>> e.g. a shift of 40 and -20 (actually FFFFFFE0) would concern me.  That
>> an 'unambiguous'
>> RSHIFT/LSHIFT will mask questionable parameters fed to it and return a
>> result of 0,
>> I for one find problematic.  IMO it were better that RSHIFT/LSHIFT
>> should fail than
>> do this.
>
> This should fix it with minimal overhead:
>
> RSHIFT: dup cell-bits - dup 0< 0= if >r drop nip r> rshift 0 swap ;then
> drop
> LSHIFT: dup cell-bits - dup 0< 0= if >r drop drop r> lshift 0 ;then drop
>
> Moderately tested.
>
> Hans Bezemer
>

Darn, scrap that:

RSHIFT: dup cell-bits - dup 0< 0= if >r drop nip r> rshift 0 ;then drop
LSHIFT: dup cell-bits - dup 0< 0= if >r drop drop r> lshift 0 swap ;then
drop

Hans Bezemer

Re: DLSHIFT and DRSHIFT

<uufl4k$2q7l6$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=26592&group=comp.lang.forth#26592

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: krishna.myneni@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: DLSHIFT and DRSHIFT
Date: Mon, 1 Apr 2024 19:56:52 -0500
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <uufl4k$2q7l6$1@dont-email.me>
References: <utvgki$2ciso$1@dont-email.me> <uu02tt$2k3jf$1@dont-email.me>
<uu1c3r$2tdj0$1@dont-email.me> <uu1e7t$2tueu$1@dont-email.me>
<uu1huv$2uqc2$1@dont-email.me> <uu1t7e$31jjc$1@dont-email.me>
<nnd$51ea08c7$4ebacde5@98ba4a1ad989127a> <660a0c49$1@news.ausics.net>
<nnd$3f79d89a$1719b54b@d25a550e35ff0832>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 02 Apr 2024 00:56:52 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="946861b41e51efe3d1583a9f6b240c72";
logging-data="2956966"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+XgzsuVhpwp5Hh8Soe6wfs"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:687LJgPN+u9Zqbw99Zl2QPRTJlc=
Content-Language: en-US
In-Reply-To: <nnd$3f79d89a$1719b54b@d25a550e35ff0832>
 by: Krishna Myneni - Tue, 2 Apr 2024 00:56 UTC

On 4/1/24 10:18, Hans Bezemer wrote:
....
> The only viable alternative is:
>
> : DLSHIFT  ( xd1 n -- xd2)     0 ?do d2* loop ;
> : DRSHIFT  ( xd1 n -- xd2)     0 ?do d2/ loop ;
>

DRSHIFT cannot be coded with D2/ which is an arithmetic right shift,
i.e. it preserves the sign bit. DRSHIFT has to pad from the left with
zero bits.

--
Krishna

Re: DLSHIFT and DRSHIFT

<uufnci$2qom1$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=26593&group=comp.lang.forth#26593

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: krishna.myneni@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: DLSHIFT and DRSHIFT
Date: Mon, 1 Apr 2024 20:35:12 -0500
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <uufnci$2qom1$1@dont-email.me>
References: <utvgki$2ciso$1@dont-email.me> <uu02tt$2k3jf$1@dont-email.me>
<uu1c3r$2tdj0$1@dont-email.me> <uu1e7t$2tueu$1@dont-email.me>
<uu1huv$2uqc2$1@dont-email.me> <uu1t7e$31jjc$1@dont-email.me>
<nnd$51ea08c7$4ebacde5@98ba4a1ad989127a> <660a0c49$1@news.ausics.net>
<c4647d14d5348badce538c50b74a1a62@www.novabbs.com>
<660a7c93$1@news.ausics.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 02 Apr 2024 01:35:15 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="946861b41e51efe3d1583a9f6b240c72";
logging-data="2974401"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19KGRvdQefWofZ6opRMRJyK"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:xFiF5kE4Y+j3o8Jhk48VqR5Yq/A=
In-Reply-To: <660a7c93$1@news.ausics.net>
Content-Language: en-US
 by: Krishna Myneni - Tue, 2 Apr 2024 01:35 UTC

On 4/1/24 04:21, dxf wrote:
> On 1/04/2024 7:03 pm, minforth wrote:
>> dxf wrote:
>>
>>> While your double-shift algorithm produces the correct results (not shown here),
>>> the intermediate values presented to each RSHIFT/LSHIFT can be quite out-of-bounds
>>> e.g. a shift of 40 and -20 (actually FFFFFFE0) would concern me.  That an 'unambiguous'
>>> RSHIFT/LSHIFT will mask questionable parameters fed to it and return a result of 0,
>>> I for one find problematic.  IMO it were better that RSHIFT/LSHIFT should fail than
>>> do this.
>>
>> Doesn't make sense during fp number addition/subtraction.
>
> Example?
>

First, there is no negative shift count argument for LSHIFT RSHIFT
DLSHIFT or DRSHIFT . The arguments are unsigned.

For an ieee 754 double precision number, there is an effective distance
of 53 bits between the most significant bit and the least significant
bit. On a 32-bit system, consider adding 1.0e0 to the number 1.0e10.

The ieee-754 unbiased base 2 exponents for the two floating point
arguments are 0 (for 1.0e0) and 33 (for 1.0e10). This means that adding
the two 53-bit significands using two double numbers (two 64-bit numbers
on a 32 bit system) requires a relative right shift of 33 bits for the
argument 1.0e0.

Here are the bit patterns for the two significands, along with their
base 2 exponents:

21098765432109876543210987654321098765432109876543210
10010101000000101111100100000000000000000000000000000 33
10000000000000000000000000000000000000000000000000000 00

There are 53 bits in each significand, and the 53rd bit is always an
implied 1. To add these, we can use 33 DRSHIFT on the one argument to
align the significands and add the two double length numbers to obtain
the new significand.

For ieee 754 quad precision, there are 113 bits in the significand, so
relative shifts can be as large as 112 bits for addition and subtraction.

--
Krishna

Re: DLSHIFT and DRSHIFT

<nnd$1b10217d$2bc99deb@9c6202ecd2ab696f>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=26594&group=comp.lang.forth#26594

  copy link   Newsgroups: comp.lang.forth
Date: Tue, 2 Apr 2024 10:56:26 +0200
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: DLSHIFT and DRSHIFT
Newsgroups: comp.lang.forth
References: <utvgki$2ciso$1@dont-email.me> <uu02tt$2k3jf$1@dont-email.me>
<uu1c3r$2tdj0$1@dont-email.me> <uu1e7t$2tueu$1@dont-email.me>
<uu1huv$2uqc2$1@dont-email.me> <uu1t7e$31jjc$1@dont-email.me>
<nnd$51ea08c7$4ebacde5@98ba4a1ad989127a> <660a0c49$1@news.ausics.net>
<nnd$3f79d89a$1719b54b@d25a550e35ff0832> <uufl4k$2q7l6$1@dont-email.me>
Content-Language: en-US
From: the.beez.speaks@gmail.com (Hans Bezemer)
In-Reply-To: <uufl4k$2q7l6$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Message-ID: <nnd$1b10217d$2bc99deb@9c6202ecd2ab696f>
Organization: KPN B.V.
Path: i2pn2.org!rocksolid2!news.neodome.net!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!feed.abavia.com!abe005.abavia.com!abp002.abavia.com!news.kpn.nl!not-for-mail
Lines: 25
Injection-Date: Tue, 02 Apr 2024 10:56:26 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
 by: Hans Bezemer - Tue, 2 Apr 2024 08:56 UTC

On 02-04-2024 02:56, Krishna Myneni wrote:
> On 4/1/24 10:18, Hans Bezemer wrote:
> ...
>> The only viable alternative is:
>>
>> : DLSHIFT  ( xd1 n -- xd2)     0 ?do d2* loop ;
>> : DRSHIFT  ( xd1 n -- xd2)     0 ?do d2/ loop ;
>>
>
> DRSHIFT cannot be coded with D2/ which is an arithmetic right shift,
> i.e. it preserves the sign bit. DRSHIFT has to pad from the left with
> zero bits.

True, but if you know my coding style - this is not it. And it is
acknowledged as such in the source:

\ DXForth MISC.SCR, Copyright Ed, 2011-03-25
\ Albert van der Horst, Thursday 09 April 2015 19:57:13, c.l.f

So it's not uncommon to define it like this. Apart from that - "D2/" is
not a standardized word - so it can mean anything. Although I do agree
with you that your definition is the most likely one.

Hans Bezemer

Re: DLSHIFT and DRSHIFT

<uugqeq$3643o$1@dont-email.me>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=26595&group=comp.lang.forth#26595

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!rocksolid2!news.neodome.net!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: krishna.myneni@ccreweb.org (Krishna Myneni)
Newsgroups: comp.lang.forth
Subject: Re: DLSHIFT and DRSHIFT
Date: Tue, 2 Apr 2024 06:33:46 -0500
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <uugqeq$3643o$1@dont-email.me>
References: <utvgki$2ciso$1@dont-email.me> <uu02tt$2k3jf$1@dont-email.me>
<uu1c3r$2tdj0$1@dont-email.me> <uu1e7t$2tueu$1@dont-email.me>
<uu1huv$2uqc2$1@dont-email.me> <uu1t7e$31jjc$1@dont-email.me>
<nnd$51ea08c7$4ebacde5@98ba4a1ad989127a> <660a0c49$1@news.ausics.net>
<nnd$3f79d89a$1719b54b@d25a550e35ff0832> <uufl4k$2q7l6$1@dont-email.me>
<nnd$1b10217d$2bc99deb@9c6202ecd2ab696f>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 02 Apr 2024 11:33:46 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="946861b41e51efe3d1583a9f6b240c72";
logging-data="3346552"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19wnbtCmEBPKayiw2q5JBzr"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:S2n4RIaJ/9kU/Thtak+F5nwn1JM=
Content-Language: en-US
In-Reply-To: <nnd$1b10217d$2bc99deb@9c6202ecd2ab696f>
 by: Krishna Myneni - Tue, 2 Apr 2024 11:33 UTC

On 4/2/24 03:56, Hans Bezemer wrote:
> On 02-04-2024 02:56, Krishna Myneni wrote:
>> On 4/1/24 10:18, Hans Bezemer wrote:
>> ...
>>> The only viable alternative is:
>>>
>>> : DLSHIFT  ( xd1 n -- xd2)     0 ?do d2* loop ;
>>> : DRSHIFT  ( xd1 n -- xd2)     0 ?do d2/ loop ;
>>>
>>
>> DRSHIFT cannot be coded with D2/ which is an arithmetic right shift,
>> i.e. it preserves the sign bit. DRSHIFT has to pad from the left with
>> zero bits.
>
> True, but if you know my coding style - this is not it. And it is
> acknowledged as such in the source:
>
> \ DXForth MISC.SCR, Copyright Ed, 2011-03-25
> \ Albert van der Horst, Thursday 09 April 2015 19:57:13, c.l.f
>
> So it's not uncommon to define it like this. Apart from that - "D2/" is
> not a standardized word - so it can mean anything. Although I do agree
> with you that your definition is the most likely one.
>
> Hans Bezemer

D2/ is a standardized word, since ANS Forth:

8.6.1.1100
D2/
“d-two-slash”
DOUBLE
( xd1 – – xd2 )
xd2 is the result of shifting xd1 one bit toward the least-significant
bit, leaving the most-significant bit unchanged.

--
KM

Re: DLSHIFT and DRSHIFT

<nnd$4171964c$512dfce9@8f5d46ee39b3b8e2>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=26596&group=comp.lang.forth#26596

  copy link   Newsgroups: comp.lang.forth
Date: Tue, 2 Apr 2024 16:10:04 +0200
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: DLSHIFT and DRSHIFT
Newsgroups: comp.lang.forth
References: <utvgki$2ciso$1@dont-email.me> <uu02tt$2k3jf$1@dont-email.me> <uu1c3r$2tdj0$1@dont-email.me> <uu1e7t$2tueu$1@dont-email.me> <uu1huv$2uqc2$1@dont-email.me> <uu1t7e$31jjc$1@dont-email.me> <nnd$51ea08c7$4ebacde5@98ba4a1ad989127a> <660a0c49$1@news.ausics.net> <nnd$3f79d89a$1719b54b@d25a550e35ff0832> <uufl4k$2q7l6$1@dont-email.me> <nnd$1b10217d$2bc99deb@9c6202ecd2ab696f> <uugqeq$3643o$1@dont-email.me>
Content-Language: en-US
From: the.beez.speaks@gmail.com (Hans Bezemer)
In-Reply-To: <uugqeq$3643o$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Message-ID: <nnd$4171964c$512dfce9@8f5d46ee39b3b8e2>
Organization: KPN B.V.
Path: i2pn2.org!i2pn.org!news.furie.org.uk!newsfeed.endofthelinebbs.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!tr2.iad1.usenetexpress.com!feeder.usenetexpress.com!tr1.eu1.usenetexpress.com!2001:67c:174:101:2:67:202:4.MISMATCH!feed.abavia.com!abe004.abavia.com!abp001.abavia.com!news.kpn.nl!not-for-mail
Lines: 42
Injection-Date: Tue, 02 Apr 2024 16:10:04 +0200
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
 by: Hans Bezemer - Tue, 2 Apr 2024 14:10 UTC

On 02-04-2024 13:33, Krishna Myneni wrote:
> On 4/2/24 03:56, Hans Bezemer wrote:
>> On 02-04-2024 02:56, Krishna Myneni wrote:
>>> On 4/1/24 10:18, Hans Bezemer wrote:
>>> ...
>>>> The only viable alternative is:
>>>>
>>>> : DLSHIFT  ( xd1 n -- xd2)     0 ?do d2* loop ;
>>>> : DRSHIFT  ( xd1 n -- xd2)     0 ?do d2/ loop ;
>>>>
>>>
>>> DRSHIFT cannot be coded with D2/ which is an arithmetic right shift,
>>> i.e. it preserves the sign bit. DRSHIFT has to pad from the left with
>>> zero bits.
>>
>> True, but if you know my coding style - this is not it. And it is
>> acknowledged as such in the source:
>>
>> \ DXForth MISC.SCR, Copyright Ed, 2011-03-25
>> \ Albert van der Horst, Thursday 09 April 2015 19:57:13, c.l.f
>>
>> So it's not uncommon to define it like this. Apart from that - "D2/"
>> is not a standardized word - so it can mean anything. Although I do
>> agree with you that your definition is the most likely one.
>>
>> Hans Bezemer
>
> D2/ is a standardized word, since ANS Forth:
>
> 8.6.1.1100
> D2/
> “d-two-slash”
> DOUBLE
> ( xd1 – – xd2 )
> xd2 is the result of shifting xd1 one bit toward the least-significant
> bit, leaving the most-significant bit unchanged.

I stand corrected, sir. ;-)

Hans Bezemer

Re: DLSHIFT and DRSHIFT

<660e59cd$1@news.ausics.net>

  copy mid

https://news.novabbs.org/devel/article-flat.php?id=26605&group=comp.lang.forth#26605

  copy link   Newsgroups: comp.lang.forth
Date: Thu, 4 Apr 2024 18:42:07 +1100
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: DLSHIFT and DRSHIFT
Newsgroups: comp.lang.forth
References: <utvgki$2ciso$1@dont-email.me> <uu02tt$2k3jf$1@dont-email.me>
<uu1c3r$2tdj0$1@dont-email.me> <uu1e7t$2tueu$1@dont-email.me>
<uu1huv$2uqc2$1@dont-email.me> <uu1t7e$31jjc$1@dont-email.me>
<nnd$51ea08c7$4ebacde5@98ba4a1ad989127a> <660a0c49$1@news.ausics.net>
<c4647d14d5348badce538c50b74a1a62@www.novabbs.com>
<660a7c93$1@news.ausics.net> <uufnci$2qom1$1@dont-email.me>
<660b7557$1@news.ausics.net>
Content-Language: en-GB
From: dxforth@gmail.com (dxf)
In-Reply-To: <660b7557$1@news.ausics.net>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: news.ausics.net
Message-ID: <660e59cd$1@news.ausics.net>
Organization: Ausics - https://newsgroups.ausics.net
Lines: 22
X-Complaints: abuse@ausics.net
Path: i2pn2.org!i2pn.org!news.bbs.nz!news.ausics.net!not-for-mail
 by: dxf - Thu, 4 Apr 2024 07:42 UTC

On 2/04/2024 2:02 pm, dxf wrote:
> ...
> LSHIFT/RSHIFT was intended to support the corresponding machine-code primitives available on
> modern architectures.

Not a bad guess as it turns out.

Digging further I found this from ANS 'BASIS17' June 1991:

8.1.2205 SHIFT

( x1 n -- x2 )

Perform a logical shift of n bit-places on x1, giving x2. If n is
positive, shift the bits n places toward the most significant bit. If n is
negative, shift them toward the least significant bits. Put zero into
the places "uncovered" by the shift.

That led to this Jan 1992 message:

https://groups.google.com/g/comp.lang.forth/c/DqrKMIiyLWc/m/1XUyYBaHyfYJ


devel / comp.lang.forth / Re: DLSHIFT and DRSHIFT

Pages:123
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor