On 19/05/2024 1:41 am, Hans Bezemer wrote:
Well, this one is the longest I've published - and it took me some time to get there.
You can find it at: https://www.youtube.com/watch?v=gfE8arB3uWk
This could be one that gives rise to some discussion ;-)
At least I hope you're entertained!
Hans Bezemer
This SQRT from Wil Baden is claimed to be fast.
Modified here to return root and remainder.
: SQRT ( u -- rem root )
0 0 [ 4 CELLS ] LITERAL 0 DO
>R D2* D2* R> 2*
2DUP 2* U> IF
DUP >R 2* - 1- R> 1+
THEN
LOOP
ROT DROP ;
I would have found it earlier had I needed one. Never saw the value of translating algorithms myself esp. if someone had already done it. I'll
give it a look-over to see whether it needs a clean-up :)
On 19/05/2024 1:41 am, Hans Bezemer wrote:
Well, this one is the longest I've published - and it took me sometime to get there.
You can find it at: https://www.youtube.com/watch?v=gfE8arB3uWk
This could be one that gives rise to some discussion ;-)
At least I hope you're entertained!
Hans Bezemer
This SQRT from Wil Baden is claimed to be fast.
Modified here to return root and remainder.
: SQRT ( u -- rem root )
0 0 [ 4 CELLS ] LITERAL 0 DO
>R D2* D2* R> 2*
2DUP 2* U> IF
DUP >R 2* - 1- R> 1+
THEN
LOOP
ROT DROP ;
I would have found it earlier had I needed one. Never saw the value of >translating algorithms myself esp. if someone had already done it. I'll
give it a look-over to see whether it needs a clean-up :)
If you think it's about the promotion of Forth, you're dead wrong. If anything, it's about the idea and the enigma of Forth. Whether you care
to share that fascination is entirely up to the viewer.
And then 'u' . When was the last time you calculate a root between 8FFF,FFFF,FFFF,FFFF and FFFF,FFFF,FFFF,FFFF ?
On 23/05/2024 12:14, albert@spenarnc.xs4all.nl wrote:
And then 'u' . When was the last time you calculate a root between
8FFF,FFFF,FFFF,FFFF and FFFF,FFFF,FFFF,FFFF ?
You mean that you are happy that USQRT fails for half the integers
available to you. Anyway not everybody uses 64 bits.
--
Gerry
In article <v3a3dq$1np8e$1@dont-email.me>,
Gerry Jackson <do-not-use@swldwa.uk> wrote:
On 23/05/2024 12:14, albert@spenarnc.xs4all.nl wrote:
And then 'u' . When was the last time you calculate a root between
8FFF,FFFF,FFFF,FFFF and FFFF,FFFF,FFFF,FFFF ?
You mean that you are happy that USQRT fails for half the integers
available to you. Anyway not everybody uses 64 bits.
If you claim that it works for unsigned numbers, then you have to
test for that. What happens to 0x8000 , a number where ABS doesn't
work >
I'm happier ignoring those case, than writing tests for them.
Groetjes Albert
If you only use stacks in Forth, you have nothing to offer them
but limitations and confusion.
Actually that's what programming in Forth is about; about
using stack for passing (and processing) values -- isn't it?
If you only use stacks in Forth, you have nothing to offer them
but limitations and confusion.
Actually that's what programming in Forth is about; about
using stack for passing (and processing) values -- isn't it?
This SQRT from Wil Baden is claimed to be fast.
Modified here to return root and remainder.
On 4/06/2024 8:30 am, mhx wrote:
Sorry, that should've been (AMD 5800X):
\ roottest : 109 ticks/root.
\ roottest2 : 184 ticks/root.
Individual circumstances can be a factor e.g. second routine is
unsigned. For my use (16-bit DTC) I found Gerry's routine to be
shorter and faster than Baden's.
dxf wrote:
On 4/06/2024 8:30 am, mhx wrote:
Sorry, that should've been (AMD 5800X):
\ roottest : 109 ticks/root.
\ roottest2 : 184 ticks/root.
Individual circumstances can be a factor e.g. second routine is
unsigned. For my use (16-bit DTC) I found Gerry's routine to be
shorter and faster than Baden's.
The first one uses Newton-Raphson (quadratical convergence)
but pays for that with the '/' instruction. The algorithm of
the second routine is unclear but uses (in principle) only
very fast shift instructions. My guess would be that Baden's
original simply uses many more steps.
I think AMD improved integer division some time ago.
-marcel
This time, we delve into a forgotten way to handle fixed point
arithmetic. Which IMHO deserves to be dusted off now we entered the
64-bit era!
https://www.youtube.com/watch?v=VwPForQL10Y
Hans Bezemer
This time, we delve into a forgotten way to handle fixed point
arithmetic. Which IMHO deserves to be dusted off now we entered the
64-bit era!
https://www.youtube.com/watch?v=VwPForQL10Y
Hans Bezemer--
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 475 |
Nodes: | 16 (2 / 14) |
Uptime: | 19:33:26 |
Calls: | 9,487 |
Calls today: | 6 |
Files: | 13,617 |
Messages: | 6,121,093 |