Rocksolid Light

Welcome to Rocksolid Light

mail  files  register  newsreader  groups  login

Message-ID:  

"A dirty mind is a joy forever." -- Randy Kunkee


devel / comp.lang.forth / 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
DLSHIFT and DRSHIFT

<utvgki$2ciso$1@dont-email.me>

  copy mid

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

  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: DLSHIFT and DRSHIFT
Date: Tue, 26 Mar 2024 17:01:53 -0500
Organization: A noiseless patient Spider
Lines: 63
Message-ID: <utvgki$2ciso$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 26 Mar 2024 22:01:54 +0100 (CET)
Injection-Info: dont-email.me; posting-host="acec8ef818285f59458e07fda27aca86";
logging-data="2509720"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18se9pzkV6t347vkju9HR2f"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:acFuWq1wOGr6rqLi9EtxtqFqzFE=
Content-Language: en-US
 by: Krishna Myneni - Tue, 26 Mar 2024 22:01 UTC

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.

--
Krishna Myneni

=== Start Code ===

1 cells 3 lshift constant BITS_PER_CELL
BITS_PER_CELL 2* constant BITS_PER_DOUBLE

\ Return the u least significant bits of cell value u1
\ as the most significant bits of u2
: lsbits ( u1 u -- u2 )
BITS_PER_CELL min
BITS_PER_CELL - negate
lshift ;

\ Return the u most significant bits of cell value u1
\ as the least significant bits of u2
: msbits ( u1 u -- u2 )
BITS_PER_CELL min
BITS_PER_CELL - negate
rshift ;

0 value ubits

\ u is the number of bits to shift

: DLSHIFT ( ud u -- ud2 )
dup 0= IF drop EXIT THEN
BITS_PER_DOUBLE min dup to ubits
BITS_PER_CELL > IF
drop \ high double has been left shifted out
ubits BITS_PER_CELL - lshift
0 swap \ new low double
ELSE
ubits lshift swap
dup >r
ubits msbits or
r> ubits lshift
swap
THEN ;

: DRSHIFT ( ud u -- ud2 )
dup 0= IF drop EXIT THEN
BITS_PER_DOUBLE min dup to ubits
BITS_PER_CELL > IF
nip \ low double has been right shifted out
ubits BITS_PER_CELL - rshift
0 \ new high double
ELSE
swap ubits rshift
swap dup >r
ubits lsbits or
r> ubits rshift
THEN ;

=== End Code ===

Re: DLSHIFT and DRSHIFT

<utvque$2elom$1@dont-email.me>

  copy mid

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

  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: Tue, 26 Mar 2024 19:57:49 -0500
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <utvque$2elom$1@dont-email.me>
References: <utvgki$2ciso$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 27 Mar 2024 00:57:50 +0100 (CET)
Injection-Info: dont-email.me; posting-host="f67980be10a8cd411c5e7271afe37e40";
logging-data="2578198"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18F3ewIWntM7ZIhxew9eXay"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:YqZnYW4obfGpPGjt+ohG7CsQU8M=
Content-Language: en-US
In-Reply-To: <utvgki$2ciso$1@dont-email.me>
 by: Krishna Myneni - Wed, 27 Mar 2024 00:57 UTC

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.

--
Krishna

Re: DLSHIFT and DRSHIFT

<uu02tt$2k3jf$1@dont-email.me>

  copy mid

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

  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: Tue, 26 Mar 2024 22:14:04 -0500
Organization: A noiseless patient Spider
Lines: 117
Message-ID: <uu02tt$2k3jf$1@dont-email.me>
References: <utvgki$2ciso$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 27 Mar 2024 03:14:06 +0100 (CET)
Injection-Info: dont-email.me; posting-host="f67980be10a8cd411c5e7271afe37e40";
logging-data="2756207"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX197+xHHfh0zB91PanuR60d4"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Z8gMZ36+WsFAE4G5xwmUAzMin4k=
Content-Language: en-US
In-Reply-To: <utvgki$2ciso$1@dont-email.me>
 by: Krishna Myneni - Wed, 27 Mar 2024 03:14 UTC

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.
> ...

This version fixes the issue with the ambiguity of LSHIFT and RSHIFT,
and gives the behavior of DLSHIFT and DRSHIFT which I want. Tests
included below for 32-bit and 64-bit systems.

--
KM

=== dshift.4th ===
\ dshift.4th
\ \ Source code definitions of DLSHIFT and DRSHIFT

1 cells 3 lshift constant BITS_PER_CELL
BITS_PER_CELL 2* constant BITS_PER_DOUBLE

\ Return the u least significant bits of cell value u1
\ as the most significant bits of u2
: lsbits ( u1 u -- u2 )
BITS_PER_CELL min
BITS_PER_CELL - negate
lshift ;

\ Return the u most significant bits of cell value u1
\ as the least significant bits of u2
: msbits ( u1 u -- u2 )
BITS_PER_CELL min
BITS_PER_CELL - negate
rshift ;

0 value ubits

\ u is the number of bits to shift

: DLSHIFT ( ud u -- ud2 )
dup 0= IF drop EXIT THEN
BITS_PER_DOUBLE min dup to ubits
BITS_PER_CELL >= IF
drop \ high double has been left shifted out
ubits BITS_PER_CELL -
dup BITS_PER_CELL = IF
2drop 0 0
ELSE
lshift 0 swap
THEN
ELSE
ubits lshift swap
dup >r
ubits msbits or
r> ubits lshift
swap
THEN ;

: DRSHIFT ( ud u -- ud2 )
dup 0= IF drop EXIT THEN
BITS_PER_DOUBLE min dup to ubits
BITS_PER_CELL >= IF
nip \ low double has been right shifted out
ubits BITS_PER_CELL -
dup BITS_PER_CELL = IF
2drop 0 0
ELSE
rshift 0
THEN
ELSE
swap ubits rshift
swap dup >r
ubits lsbits or
r> ubits rshift
THEN ;

=== End of dshift.4th ===

Test Code

=== dshift-test.4th ===
\ dshift-test.4th
\ include ans-words \ <-- only for kForth
include ttester
include dshift

HEX

TESTING DLSHIFT DRSHIFT

t{ 03 01 BITS_PER_CELL dlshift -> 00 03 }t
t{ FF 00 BITS_PER_CELL dlshift -> 00 FF }t
t{ 00 01 BITS_PER_CELL drshift -> 01 00 }t
t{ 00 FF BITS_PER_CELL drshift -> FF 00 }t
t{ -1 -1 BITS_PER_DOUBLE dlshift -> 00 00 }t
t{ -1 -1 BITS_PER_DOUBLE drshift -> 00 00 }t

BITS_PER_CELL 20 = [IF]
t{ 03 01 BITS_PER_CELL 1- dlshift -> 80000000 80000001 }t
t{ 80000000 02 1 dlshift -> 00 05 }t
t{ 07 03 1 drshift -> 80000003 01 }t
[THEN]

BITS_PER_CELL 40 = [IF]
t{ 03 01 BITS_PER_CELL 1- dlshift -> 8000000000000000 8000000000000001 }t
t{ 8000000000000000 02 1 dlshift -> 00 05 }t
t{ 07 03 1 drshift -> 8000000000000003 01 }t
[THEN]

DECIMAL

=== end of dshift-test.4th ===

Re: DLSHIFT and DRSHIFT

<2024Mar27.085332@mips.complang.tuwien.ac.at>

  copy mid

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

  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: Wed, 27 Mar 2024 07:53:32 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 64
Message-ID: <2024Mar27.085332@mips.complang.tuwien.ac.at>
References: <utvgki$2ciso$1@dont-email.me> <utvque$2elom$1@dont-email.me>
Injection-Date: Wed, 27 Mar 2024 08:28:14 +0100 (CET)
Injection-Info: dont-email.me; posting-host="dd96cb78367ba2d846b5f6040a81f592";
logging-data="2881218"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19UvhFFHssobWm871w9GgvI"
Cancel-Lock: sha1:ovr+E23MsZSp3ZZnjvXtTYmd6yg=
X-newsreader: xrn 10.11
 by: Anton Ertl - Wed, 27 Mar 2024 07:53 UTC

Krishna Myneni <krishna.myneni@ccreweb.org> writes:
>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!

On one hand, programmers expect the result of ( n m ) LSHIFT and ( n m
) RSHIFT to be 0 when m>=CELL_BITS. As you write:

>u 64 LSHIFT should be zero on all systems with cell sizes up to 64 bits.

OTOH, it's relatively rare to need this, so most computer architects
have decided not to pay the relatively small hardware cost to produce
this result, and instead only consider the lower 5 or 6 bits of the
shift amount. The cost in language implementations is a little higher
than at the hardware level, and various programming languages,
including Forth have decided to leave this unspecified (there are also
architectures where one bit more is used, and IIRC also hardware (IIRC
Power) where a result of 0 is guaranteed).

One interesting case is Java, which specifies the language pretty
completely in order to make Java write-once-run-everywhere. Java's
designers chose to go along with the common practice in computer
architecture
<https://docs.oracle.com/javase/specs/jls/se21/html/jls-15.html#jls-15.19>:

|If the promoted type of the left-hand operand is int, then only the
|five lowest-order bits of the right-hand operand are used as the shift
|distance.

|If the promoted type of the left-hand operand is long, then only the
|six lowest-order bits of the right-hand operand are used as the shift
|distance.

See also
<https://forth-standard.org/standard/core/LSHIFT#contribution-335>.

- 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$6b4a48e2$541725e4@05aa1f7f36145ce8>

  copy mid

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

  copy link   Newsgroups: comp.lang.forth
Newsgroups: comp.lang.forth
Subject: Re: DLSHIFT and DRSHIFT
References: <utvgki$2ciso$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$6b4a48e2$541725e4@05aa1f7f36145ce8>
Organization: KPN B.V.
Date: Wed, 27 Mar 2024 09:34:25 +0100
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!feed.abavia.com!abe006.abavia.com!abp002.abavia.com!news.kpn.nl!not-for-mail
Lines: 77
Injection-Date: Wed, 27 Mar 2024 09:34:25 +0100
Injection-Info: news.kpn.nl; mail-complaints-to="abuse@kpn.com"
 by: albert@spenarnc.xs4all.nl - Wed, 27 Mar 2024 08:34 UTC

In article <utvgki$2ciso$1@dont-email.me>,
Krishna Myneni <krishna.myneni@ccreweb.org> 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.
>
>--
>Krishna Myneni
>
>
>=== Start Code ===
>
>1 cells 3 lshift constant BITS_PER_CELL
>BITS_PER_CELL 2* constant BITS_PER_DOUBLE
>
>\ Return the u least significant bits of cell value u1
>\ as the most significant bits of u2
>: lsbits ( u1 u -- u2 )
> BITS_PER_CELL min
> BITS_PER_CELL - negate
> lshift ;
>
>\ Return the u most significant bits of cell value u1
>\ as the least significant bits of u2
>: msbits ( u1 u -- u2 )
> BITS_PER_CELL min
> BITS_PER_CELL - negate
> rshift ;
>
>0 value ubits
>
>\ u is the number of bits to shift
>
>: DLSHIFT ( ud u -- ud2 )
> dup 0= IF drop EXIT THEN
> BITS_PER_DOUBLE min dup to ubits
> BITS_PER_CELL > IF
> drop \ high double has been left shifted out
> ubits BITS_PER_CELL - lshift
> 0 swap \ new low double
> ELSE
> ubits lshift swap
> dup >r
> ubits msbits or
> r> ubits lshift
> swap
> THEN ;
>
>: DRSHIFT ( ud u -- ud2 )
> dup 0= IF drop EXIT THEN
> BITS_PER_DOUBLE min dup to ubits
> BITS_PER_CELL > IF
> nip \ low double has been right shifted out
> ubits BITS_PER_CELL - rshift
> 0 \ new high double
> ELSE
> swap ubits rshift
> swap dup >r
> ubits lsbits or
> r> ubits rshift
> THEN ;
>
>=== End Code ===

These words should be in assembler anyway.
So a rigorous testset is more valuable than a supposedly
standard implementation.

Groetjes Albert
--
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

<uu0vpa$2qdel$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.forth
Path: i2pn2.org!i2pn.org!news.hispagatos.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: ruvim.pinka@gmail.com (Ruvim)
Newsgroups: comp.lang.forth
Subject: Re: DLSHIFT and DRSHIFT
Date: Wed, 27 Mar 2024 15:26:29 +0400
Organization: A noiseless patient Spider
Lines: 60
Message-ID: <uu0vpa$2qdel$1@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: Wed, 27 Mar 2024 11:26:35 +0100 (CET)
Injection-Info: dont-email.me; posting-host="35a9ecf0327e02d476c25333b219b16a";
logging-data="2962901"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/uo3+NPFZgN18BJhfqRXx9"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:wLE3ocOor7YwAAOKTyDnG/NEiJc=
Content-Language: en-US
In-Reply-To: <utvque$2elom$1@dont-email.me>
 by: Ruvim - Wed, 27 Mar 2024 11:26 UTC

On 2024-03-27 04: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.
>
[...]
> 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.

And I agree, this is rarely needed. So if a program requires this
behavior, it can test the behavior of "shift" operations in this regard
and redefine them in its own word list as:

: lshift ( x u -- x )
dup bits_per_cell u< if lshift exit then
2drop 0
;

[1] An ambiguous condition in LSHIFT (2024-02-05)
<https://forth-standard.org/standard/core/LSHIFT#contribution-335>

--
Ruvim

Re: DLSHIFT and DRSHIFT

<uu13cn$2r980$1@dont-email.me>

  copy mid

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

  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: Wed, 27 Mar 2024 07:28:05 -0500
Organization: A noiseless patient Spider
Lines: 89
Message-ID: <uu13cn$2r980$1@dont-email.me>
References: <utvgki$2ciso$1@dont-email.me> <utvque$2elom$1@dont-email.me>
<uu0vpa$2qdel$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 27 Mar 2024 12:28:07 +0100 (CET)
Injection-Info: dont-email.me; posting-host="f67980be10a8cd411c5e7271afe37e40";
logging-data="2991360"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18NDALFJJUdYZtoVYRVOl1F"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:GI0tOroPcIkBOap7q4W8mKX7FFI=
In-Reply-To: <uu0vpa$2qdel$1@dont-email.me>
Content-Language: en-US
 by: Krishna Myneni - Wed, 27 Mar 2024 12:28 UTC

On 3/27/24 06:26, Ruvim wrote:
> On 2024-03-27 04: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.
>>
> [...]
>> 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.
>

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. 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.

One would also expect the following two expressions to be consistent

1 64 LSHIFT .

and

: TEST2* 1 64 0 DO 2* LOOP . ;
TEST2*

Currently, on some systems (kForth and Gforth), we get,

1 64 LSHIFT . \ gives 1
TEST2* \ gives 0

For system implementers to ensure LSHIFT uses 6 bits of the shift count
would be trivial and should not break past code provided that code did
not use specific behavior which was called out as undefined behavior in
the standard.

If we get enough common practice in systems to have LSHIFT and RSHIFT
behave in a consistent and expected manner, then it can be standardized.
The important thing is to avoid nonsense in the language spec because of
low-level hardware choices.

--
Krishna

Re: DLSHIFT and DRSHIFT

<uu16hb$2s10o$1@dont-email.me>

  copy mid

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

  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: Wed, 27 Mar 2024 08:21:47 -0500
Organization: A noiseless patient Spider
Lines: 50
Message-ID: <uu16hb$2s10o$1@dont-email.me>
References: <utvgki$2ciso$1@dont-email.me> <utvque$2elom$1@dont-email.me>
<2024Mar27.085332@mips.complang.tuwien.ac.at>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 27 Mar 2024 13:21:48 +0100 (CET)
Injection-Info: dont-email.me; posting-host="f67980be10a8cd411c5e7271afe37e40";
logging-data="3015704"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX197AaHC9K3PIX/ICqw39est"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Vv0AIpdNcA4Ry32SAyHlxPZmL/w=
In-Reply-To: <2024Mar27.085332@mips.complang.tuwien.ac.at>
Content-Language: en-US
 by: Krishna Myneni - Wed, 27 Mar 2024 13:21 UTC

On 3/27/24 02:53, Anton Ertl wrote:
> Krishna Myneni <krishna.myneni@ccreweb.org> writes:
>> 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.
>>
....
>
> One interesting case is Java, which specifies the language pretty
> completely in order to make Java write-once-run-everywhere. Java's
> designers chose to go along with the common practice in computer
> architecture
> <https://docs.oracle.com/javase/specs/jls/se21/html/jls-15.html#jls-15.19>:
>
> |If the promoted type of the left-hand operand is int, then only the
> |five lowest-order bits of the right-hand operand are used as the shift
> |distance.
>
> |If the promoted type of the left-hand operand is long, then only the
> |six lowest-order bits of the right-hand operand are used as the shift
> |distance.
>

For Forth, it would seem reasonable and natural to guarantee that the
number of bits in the shift count which are honored are enough to
represent the data stack width in bits. This would ensure that

1 u LSHIFT

and

-1 u RSHIFT

would be zero for u >= BITS_PER_CELL.

--
Krishna

Re: DLSHIFT and DRSHIFT

<uu16n8$2s10o$2@dont-email.me>

  copy mid

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

  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: Wed, 27 Mar 2024 08:24:56 -0500
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <uu16n8$2s10o$2@dont-email.me>
References: <utvgki$2ciso$1@dont-email.me>
<nnd$6b4a48e2$541725e4@05aa1f7f36145ce8>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 27 Mar 2024 13:24:57 +0100 (CET)
Injection-Info: dont-email.me; posting-host="f67980be10a8cd411c5e7271afe37e40";
logging-data="3015704"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19CGJ6g394xY52tWA2dfJwC"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Pv4RPCHQtyiYkYWaep2vtm9UDEg=
Content-Language: en-US
In-Reply-To: <nnd$6b4a48e2$541725e4@05aa1f7f36145ce8>
 by: Krishna Myneni - Wed, 27 Mar 2024 13:24 UTC

On 3/27/24 03:34, albert@spenarnc.xs4all.nl wrote:
> In article <utvgki$2ciso$1@dont-email.me>,
> Krishna Myneni <krishna.myneni@ccreweb.org> 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.
>>
....
>
> These words should be in assembler anyway.
> So a rigorous testset is more valuable than a supposedly
> standard implementation.

There is no standard implementation -- DLSHIFT and DRSHIFT are not
standard words. What I meant by "standard source definitions" is that
the Forth level definitions only use Forth standard words.

Tests for my latest revision are provided.

--
KM

Re: DLSHIFT and DRSHIFT

<660425d7$1@news.ausics.net>

  copy mid

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

  copy link   Newsgroups: comp.lang.forth
Date: Thu, 28 Mar 2024 00:57:43 +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>
Content-Language: en-GB
From: dxforth@gmail.com (dxf)
In-Reply-To: <uu0vpa$2qdel$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
NNTP-Posting-Host: news.ausics.net
Message-ID: <660425d7$1@news.ausics.net>
Organization: Ausics - https://newsgroups.ausics.net
Lines: 17
X-Complaints: abuse@ausics.net
Path: i2pn2.org!i2pn.org!news.bbs.nz!news.ausics.net!not-for-mail
 by: dxf - Wed, 27 Mar 2024 13:57 UTC

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.

Re: DLSHIFT and DRSHIFT

<uu1c3r$2tdj0$1@dont-email.me>

  copy mid

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

  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: ruvim.pinka@gmail.com (Ruvim)
Newsgroups: comp.lang.forth
Subject: Re: DLSHIFT and DRSHIFT
Date: Wed, 27 Mar 2024 18:56:54 +0400
Organization: A noiseless patient Spider
Lines: 129
Message-ID: <uu1c3r$2tdj0$1@dont-email.me>
References: <utvgki$2ciso$1@dont-email.me> <uu02tt$2k3jf$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 27 Mar 2024 14:57:00 +0100 (CET)
Injection-Info: dont-email.me; posting-host="35a9ecf0327e02d476c25333b219b16a";
logging-data="3061344"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19/ewgiUktGnLwMKJO6Uajb"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:ilRtrjUAJY6NlL0hkBB+O9mICwI=
Content-Language: en-US
In-Reply-To: <uu02tt$2k3jf$1@dont-email.me>
 by: Ruvim - Wed, 27 Mar 2024 14:56 UTC

On 2024-03-27 07:14, 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.
>> ...
>
> This version fixes the issue with the ambiguity of LSHIFT and RSHIFT,
> and gives the behavior of DLSHIFT and DRSHIFT which I want. Tests
> included below for 32-bit and 64-bit systems.
>
> --
> KM
>
> === dshift.4th ===
> \ dshift.4th
> \
> \ Source code definitions of DLSHIFT and DRSHIFT
>
> 1 cells 3 lshift constant BITS_PER_CELL
> BITS_PER_CELL 2* constant BITS_PER_DOUBLE
>
> \ Return the u least significant bits of cell value u1
> \ as the most significant bits of u2
> : lsbits ( u1 u -- u2 )
>      BITS_PER_CELL min
>      BITS_PER_CELL - negate
>      lshift ;
>
> \ Return the u most significant bits of cell value u1
> \ as the least significant bits of u2
> : msbits ( u1 u -- u2 )
>      BITS_PER_CELL min
>      BITS_PER_CELL - negate
>      rshift ;
>
> 0 value ubits
>
> \ u is the number of bits to shift
>
> : DLSHIFT ( ud u -- ud2 )
>     dup 0= IF drop EXIT THEN
>     BITS_PER_DOUBLE min dup to ubits
>     BITS_PER_CELL >= IF
>       drop      \ high double has been left shifted out
>       ubits BITS_PER_CELL -
>       dup BITS_PER_CELL = IF
>         2drop 0 0
>       ELSE
>         lshift 0 swap
>       THEN
>     ELSE
>       ubits lshift swap
>       dup >r
>       ubits msbits or
>       r> ubits lshift
>       swap
>     THEN ;
>
> : DRSHIFT ( ud u -- ud2 )
>     dup 0= IF drop EXIT THEN
>     BITS_PER_DOUBLE min dup to ubits
>     BITS_PER_CELL >= IF
>       nip    \ low double has been right shifted out
>       ubits BITS_PER_CELL -
>       dup BITS_PER_CELL = IF
>         2drop 0 0
>       ELSE
>         rshift 0
>       THEN
>     ELSE
>       swap ubits rshift
>       swap dup >r
>       ubits lsbits or
>       r> ubits rshift
>     THEN ;
>
> === End of dshift.4th ===

I wrote a simpler implementation a long time ago. The file
"double-shift.fth" below is a translation from [2] using different names
for constants.

=== "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"

[2] Low-level definition for doubling cell size (in ForthML)
<https://github.com/rufig/spf4-utf8/blob/master/devel/~pinka/model/forthproc/doubling-cell.f.xml>

--
Ruvim

Re: DLSHIFT and DRSHIFT

<uu1e7t$2tueu$1@dont-email.me>

  copy mid

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

  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: Wed, 27 Mar 2024 10:33:17 -0500
Organization: A noiseless patient Spider
Lines: 56
Message-ID: <uu1e7t$2tueu$1@dont-email.me>
References: <utvgki$2ciso$1@dont-email.me> <uu02tt$2k3jf$1@dont-email.me>
<uu1c3r$2tdj0$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 27 Mar 2024 15:33:18 +0100 (CET)
Injection-Info: dont-email.me; posting-host="f67980be10a8cd411c5e7271afe37e40";
logging-data="3078622"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18AE1nhEfptvxBFYGYSDzmL"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:0Np0tunZ++jXuxBQH7CNl1PWB0c=
Content-Language: en-US
In-Reply-To: <uu1c3r$2tdj0$1@dont-email.me>
 by: Krishna Myneni - Wed, 27 Mar 2024 15:33 UTC

On 3/27/24 09:56, Ruvim wrote:
> On 2024-03-27 07:14, 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.
>>> ...
....
>
> I wrote a simpler implementation a long time ago. The file
> "double-shift.fth" below is a translation from [2] using different names
> for constants.
>
>
> === "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"
>

Does it succeed on all of the tests I gave?

--
Krishna

Re: DLSHIFT and DRSHIFT

<uu1esa$2tueu$2@dont-email.me>

  copy mid

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

  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: Wed, 27 Mar 2024 10:44:10 -0500
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <uu1esa$2tueu$2@dont-email.me>
References: <utvgki$2ciso$1@dont-email.me> <utvque$2elom$1@dont-email.me>
<uu0vpa$2qdel$1@dont-email.me> <660425d7$1@news.ausics.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 27 Mar 2024 15:44:11 +0100 (CET)
Injection-Info: dont-email.me; posting-host="f67980be10a8cd411c5e7271afe37e40";
logging-data="3078622"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18aQR5sj89uCO6clWAMUq3T"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:tWRidRbXjeKyYlCQuI7abih6YIk=
Content-Language: en-US
In-Reply-To: <660425d7$1@news.ausics.net>
 by: Krishna Myneni - Wed, 27 Mar 2024 15:44 UTC

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.

--
Krishna

Re: DLSHIFT and DRSHIFT

<uu1huv$2uqc2$1@dont-email.me>

  copy mid

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

  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: ruvim.pinka@gmail.com (Ruvim)
Newsgroups: comp.lang.forth
Subject: Re: DLSHIFT and DRSHIFT
Date: Wed, 27 Mar 2024 20:36:43 +0400
Organization: A noiseless patient Spider
Lines: 59
Message-ID: <uu1huv$2uqc2$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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 27 Mar 2024 16:36:47 +0100 (CET)
Injection-Info: dont-email.me; posting-host="35a9ecf0327e02d476c25333b219b16a";
logging-data="3107202"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX196gGUpXNRAXMf31kL/5RpM"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:2wXcS3N1cKNFPmhLqD+aq01zN4g=
In-Reply-To: <uu1e7t$2tueu$1@dont-email.me>
Content-Language: en-US
 by: Ruvim - Wed, 27 Mar 2024 16:36 UTC

On 2024-03-27 19:33, Krishna Myneni wrote:
> On 3/27/24 09:56, Ruvim wrote:
>> On 2024-03-27 07:14, 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.
>>>> ...
> ...
>>
>> I wrote a simpler implementation a long time ago. The file
>> "double-shift.fth" below is a translation from [2] using different
>> names for constants.
>>
>>
>> === "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"
>>
>
> Does it succeed on all of the tests I gave?

Of course, I checked — it succeed your tests.

--
Ruvim

Re: DLSHIFT and DRSHIFT

<uu1pmo$305br$1@dont-email.me>

  copy mid

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

  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: bl1-thispartdoesnotbelonghere@gmx.com (Bernd Linsel)
Newsgroups: comp.lang.forth
Subject: Re: DLSHIFT and DRSHIFT
Date: Wed, 27 Mar 2024 19:48:56 +0100
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <uu1pmo$305br$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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: base64
Injection-Date: Wed, 27 Mar 2024 18:48:56 +0100 (CET)
Injection-Info: dont-email.me; posting-host="594478762326c9a169a2452563a4c1d6";
logging-data="3151227"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/NvRdNwVk7b20N8/stbtRI"
User-Agent: Betterbird (Windows)
Cancel-Lock: sha1:OBsXphvp2wC0x0Sb0mveXrXYcvk=
In-Reply-To: <uu13cn$2r980$1@dont-email.me>
Content-Language: en-US
 by: Bernd Linsel - Wed, 27 Mar 2024 18:48 UTC

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)

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

Re: DLSHIFT and DRSHIFT

<uu1pq6$305bs$1@dont-email.me>

  copy mid

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

  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: bl1-thispartdoesnotbelonghere@gmx.com (Bernd Linsel)
Newsgroups: comp.lang.forth
Subject: Re: DLSHIFT and DRSHIFT
Date: Wed, 27 Mar 2024 19:50:46 +0100
Organization: A noiseless patient Spider
Lines: 7
Message-ID: <uu1pq6$305bs$1@dont-email.me>
References: <utvgki$2ciso$1@dont-email.me>
<nnd$6b4a48e2$541725e4@05aa1f7f36145ce8>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 27 Mar 2024 18:50:46 +0100 (CET)
Injection-Info: dont-email.me; posting-host="594478762326c9a169a2452563a4c1d6";
logging-data="3151228"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18YpDkvBSvdlJMQBH/A/JF1"
User-Agent: Betterbird (Windows)
Cancel-Lock: sha1:Z7HDrjpGqLBVkGZr7bi0d6vXm9k=
In-Reply-To: <nnd$6b4a48e2$541725e4@05aa1f7f36145ce8>
Content-Language: en-US
 by: Bernd Linsel - Wed, 27 Mar 2024 18:50 UTC

On 27.03.2024 09:34, albert@spenarnc.xs4all.nl wrote:
> These words should be in assembler anyway.

+1

--
Bernd Linsel

Re: DLSHIFT and DRSHIFT

<2024Mar27.194610@mips.complang.tuwien.ac.at>

  copy mid

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

  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: Wed, 27 Mar 2024 18:46:10 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 42
Message-ID: <2024Mar27.194610@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>
Injection-Date: Wed, 27 Mar 2024 18:58:35 +0100 (CET)
Injection-Info: dont-email.me; posting-host="dd96cb78367ba2d846b5f6040a81f592";
logging-data="3175317"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Yz+vjdE3N/N857+ND24zm"
Cancel-Lock: sha1:hZ0GgvV006V8rFztFk0Yonb6KUw=
X-newsreader: xrn 10.11
 by: Anton Ertl - Wed, 27 Mar 2024 18:46 UTC

Krishna Myneni <krishna.myneni@ccreweb.org> writes:
>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. 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.

I guess you mean the ambiguous condition in the specification of
LSHIFT and RSHIFT, which is more like implementation-defined behaviour
in some other languages (and the advocates of undefined behaviour make
a lot of wind about the difference between implementation-defined and
undefined).

Well, if you want to see this happen, you have to convince some Forth
system implementors, so common practice moves in the direction you
prefer, and once that is done, make a proposal.

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. Of course, for commercial
implementors, you may get the usual answer that their customers have
not complained to them, but if you don't try, you can't win.

>Efficiency because of extra instructions needed to implement this
>guarantee are not even worth bothering about -- we are not C.

I am sure someone can produce some saying by Chuck Moore that
contradicts this attitude. Sure, Forth is not C, but it's just as
performance-conscious.

- 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

<uu1t7e$31jjc$1@dont-email.me>

  copy mid

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

  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: Wed, 27 Mar 2024 14:49:02 -0500
Organization: A noiseless patient Spider
Lines: 50
Message-ID: <uu1t7e$31jjc$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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 27 Mar 2024 19:49:02 +0100 (CET)
Injection-Info: dont-email.me; posting-host="f67980be10a8cd411c5e7271afe37e40";
logging-data="3198572"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/h/vIXUWWWi3HsQMq01sy+"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:ZtY1cyCJKu2F/mtewynng88/K3Q=
In-Reply-To: <uu1huv$2uqc2$1@dont-email.me>
Content-Language: en-US
 by: Krishna Myneni - Wed, 27 Mar 2024 19:49 UTC

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"
>>>
>>
>> Does it succeed on all of the tests I gave?
>
> Of course, I checked — it succeed your tests.
>
>

Thanks.

-- KM

Re: DLSHIFT and DRSHIFT

<uu1ths$31jjc$2@dont-email.me>

  copy mid

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

  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: Wed, 27 Mar 2024 14:54:36 -0500
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <uu1ths$31jjc$2@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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 27 Mar 2024 19:54:36 +0100 (CET)
Injection-Info: dont-email.me; posting-host="f67980be10a8cd411c5e7271afe37e40";
logging-data="3198572"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/ht+6YsbdMiHUUhxS0HlA3"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:CGdS8DzASNyTaQJL0JM6WF5JPg0=
In-Reply-To: <2024Mar27.194610@mips.complang.tuwien.ac.at>
Content-Language: en-US
 by: Krishna Myneni - Wed, 27 Mar 2024 19:54 UTC

On 3/27/24 13:46, Anton Ertl wrote:
> Krishna Myneni <krishna.myneni@ccreweb.org> writes:
>> 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. 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.
>
> I guess you mean the ambiguous condition in the specification of
> LSHIFT and RSHIFT, which is more like implementation-defined behaviour
> in some other languages (and the advocates of undefined behaviour make
> a lot of wind about the difference between implementation-defined and
> undefined).

I have to admit that the distinction between mapping "ambiguous
condition" to IB vs UB escapes me.

>
> Well, if you want to see this happen, you have to convince some Forth
> system implementors, so common practice moves in the direction you
> prefer, and once that is done, make a proposal.
>

Sure. I would start with modifying LSHIFT and RSHIFT in my own Forth
systems. The revisions would still be consistent with the standard.

> 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. Of course, for commercial
> implementors, you may get the usual answer that their customers have
> not complained to them, but if you don't try, you can't win.
>
>> Efficiency because of extra instructions needed to implement this
>> guarantee are not even worth bothering about -- we are not C.
>
> I am sure someone can produce some saying by Chuck Moore that
> contradicts this attitude. Sure, Forth is not C, but it's just as
> performance-conscious.
>

My meaning was that I expect the performance change to be negligible. Of
course, we have to implement and test to check this.

--
Krishna

Re: DLSHIFT and DRSHIFT

<a67619691b2194b0d7224a6022262038@www.novabbs.com>

  copy mid

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

  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: Thu, 28 Mar 2024 08:06:15 +0000
Organization: novaBBS
Message-ID: <a67619691b2194b0d7224a6022262038@www.novabbs.com>
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>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="3479367"; mail-complaints-to="usenet@i2pn2.org";
posting-account="t+lO0yBNO1zGxasPvGSZV1BRu71QKx+JE37DnW+83jQ";
User-Agent: Rocksolid Light
X-Rslight-Site: $2y$10$rE00F9BMeEQc8D73B82WxOUkR1iB2jy5T24X8V3lKjgt3my0trWna
X-Rslight-Posting-User: d2a19558f194e2f1f8393b8d9be9ef51734a4da3
X-Spam-Checker-Version: SpamAssassin 4.0.0
 by: minforth - Thu, 28 Mar 2024 08:06 UTC

May I ask for what you need these double cell shifts?

I know of some crypto routines, but these require even much wider cell sizes.

Another example: in my field pseudo random number generators are common technique.
However PRNGs are closely related to prime numbers and they often require
rotations of sub-cell chunks (linear feedback shift registers).

Re: DLSHIFT and DRSHIFT

<2024Mar28.094943@mips.complang.tuwien.ac.at>

  copy mid

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

  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: Thu, 28 Mar 2024 08:49:43 GMT
Organization: Institut fuer Computersprachen, Technische Universitaet Wien
Lines: 30
Message-ID: <2024Mar28.094943@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>
Injection-Date: Thu, 28 Mar 2024 09:42:19 +0100 (CET)
Injection-Info: dont-email.me; posting-host="2e7064de8921778423bd25343da1f92e";
logging-data="3681838"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Ihvu289MJwUoEF0zGu+OY"
Cancel-Lock: sha1:xRh5CKoi59vYfjLyJbHm1i2J3u4=
X-newsreader: xrn 10.11
 by: Anton Ertl - Thu, 28 Mar 2024 08:49 UTC

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

Produced by inserting superinstructions for the constant shifts,
rebuilding Gforth, and then

gforth-fast --ss-states=0 --print-prims -e bye

- 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

<66055488$1@news.ausics.net>

  copy mid

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

  copy link   Newsgroups: comp.lang.forth
Date: Thu, 28 Mar 2024 22:29:12 +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>
Content-Language: en-GB
From: dxforth@gmail.com (dxf)
In-Reply-To: <uu1esa$2tueu$2@dont-email.me>
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
NNTP-Posting-Host: news.ausics.net
Message-ID: <66055488$1@news.ausics.net>
Organization: Ausics - https://newsgroups.ausics.net
Lines: 26
X-Complaints: abuse@ausics.net
Path: i2pn2.org!i2pn.org!news.bbs.nz!news.ausics.net!not-for-mail
 by: dxf - Thu, 28 Mar 2024 11:29 UTC

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.

Re: DLSHIFT and DRSHIFT

<uu3q8o$3jfa1$1@dont-email.me>

  copy mid

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

  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: Thu, 28 Mar 2024 08:10:46 -0500
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <uu3q8o$3jfa1$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>
<a67619691b2194b0d7224a6022262038@www.novabbs.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 28 Mar 2024 13:10:48 +0100 (CET)
Injection-Info: dont-email.me; posting-host="81b065285b92801ed7f783dd37b99f68";
logging-data="3784001"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19I5RbMAzWpFfyq5suZDRXR"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:9qhwIxRBE9pxtgp94DI/W5ENbS4=
Content-Language: en-US
In-Reply-To: <a67619691b2194b0d7224a6022262038@www.novabbs.com>
 by: Krishna Myneni - Thu, 28 Mar 2024 13:10 UTC

On 3/28/24 03:06, minforth wrote:
> May I ask for what you need these double cell shifts?
>

I'm interested in writing a portable IEEE 754 quad precision arithmetic
library in Forth. The significands are 113 bits long, with implied bit
included. To perform addition or subtraction between two quad precision
numbers, the two significands have to be aligned using the difference in
their base 2 exponents (15 bit exponents). This requires a relative
shift of the two significands across a 128-bit representation of the two
numbers being added/subtracted. On a 64-bit system, we can use double
cell shifts to accomplish this.

> I know of some crypto routines, but these require even much wider cell
> sizes.
>
> Another example: in my field pseudo random number generators are common
> technique.
> However PRNGs are closely related to prime numbers and they often require
> rotations of sub-cell chunks (linear feedback shift registers).

I'm sure there are a lot of other uses that I don't know about. Shifts
registers came up during our previous discussion on SHA512 implementations.

--
Krishna

Re: DLSHIFT and DRSHIFT

<uu3rrv$3jq9f$1@dont-email.me>

  copy mid

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

  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: Thu, 28 Mar 2024 08:38:07 -0500
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <uu3rrv$3jq9f$1@dont-email.me>
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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 28 Mar 2024 13:38:08 +0100 (CET)
Injection-Info: dont-email.me; posting-host="81b065285b92801ed7f783dd37b99f68";
logging-data="3795247"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+wDFKdgAd3YXJUTXkR3s4b"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:KwIPdUfXRakdAmlM7+O7WKVQdNI=
In-Reply-To: <66055488$1@news.ausics.net>
Content-Language: en-US
 by: Krishna Myneni - Thu, 28 Mar 2024 13:38 UTC

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.

When I first started programming in Forth, I appreciated the fact that
it was close to the hardware. As processor speed and memory size and the
complexity of my programs grew, and the need to share them as well, the
cleanliness and portability of the language became more important.

--
Krishna

Re: DLSHIFT and DRSHIFT

<9f59628fecedcb0450de330a8c333d3d@www.novabbs.com>

  copy mid

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

  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: Thu, 28 Mar 2024 14:25:45 +0000
Organization: novaBBS
Message-ID: <9f59628fecedcb0450de330a8c333d3d@www.novabbs.com>
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> <a67619691b2194b0d7224a6022262038@www.novabbs.com> <uu3q8o$3jfa1$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: i2pn2.org;
logging-data="3508586"; mail-complaints-to="usenet@i2pn2.org";
posting-account="t+lO0yBNO1zGxasPvGSZV1BRu71QKx+JE37DnW+83jQ";
User-Agent: Rocksolid Light
X-Rslight-Posting-User: d2a19558f194e2f1f8393b8d9be9ef51734a4da3
X-Spam-Checker-Version: SpamAssassin 4.0.0
X-Rslight-Site: $2y$10$1HNUeg.jkhP6pO0n7KyVp.Vk/l5vucS9u/T/IxfRIX3iSW6FT9sPC
 by: minforth - Thu, 28 Mar 2024 14:25 UTC

Krishna Myneni wrote:

> On 3/28/24 03:06, minforth wrote:
>> May I ask for what you need these double cell shifts?
>>

> I'm interested in writing a portable IEEE 754 quad precision arithmetic
> library in Forth.

Respect! Scaling is a basic fp operation indeed.

You can test against libquadmath. For inspiration, browsing its source code
might be of interest:
https://codebrowser.dev/glibc/glibc/sysdeps/ieee754/float128/

Pages:123
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor