On Wednesday, July 16, 2014 3:01:50 AM UTC-4, Raimond Dragomir wrote:
> I will concentrate on cortex-m microcontrollers (m0, m3, m4) but even so I don't like the 64bit math, because I just don't need it. But a 32bit system is usefull for smaller microcontrollers also. Even that noone seems to agree this for an 8051 or avr (avr is quite decent though) I can think of elegant implementations for MSP430 or PIC24 which are 16bitters.
It seems rather that whatever you are viewing as elegant, most prefer their Forth to map more closely to their processor. And then, under that preference, the double is not as striking an issue, since they have not defined all of their single cells operations to work on double processor words, so their double operations are double processor word operations, not quadruple processor word operations.
> Anyway, forth has this single cell/double cell "compatibility" kind of view, which is nice, but not all the time.
> But C does recognize the need of specifying the size of objects directly. That's why it has int8_t, int16_t, int32_t, int64_t and the unsigned uint... etc, even that this is done with some defines or typedefs.
Yes, as Forth systems have normally done, though with the flexibility of Forth those have been more commonly target specific words than abstract sizes.
> The idea is: sometimes you need an "int", a forth "cell". You don't care what the size is because you really know it is enough (a small index, or other variable) and you want it to be the most easy thing the system can deal with.
> But many times you need specific sizes. For example, I have an application with large tables of 16bit values. I choose the 16bit value despite the cpu being 32bit, because it saved me lot of ram. That brings me the real need of having half cells in my 32bit forth, H@, H!.
Yes, that is the normal Forth approach to that situation. There is a complete Forth200x proposal reserving a whole bucket of word size and big endian / little endian names, along those lines.
> The point is: Using (only) the terms "single" and "double" "cell" for portability is not enough in itself without the direct size specifiers.
It depends on portability to what. Having the direct size specifiers are not sufficient for portability either, since there is still big v little endian, compacted versus aligned, and so on.
> Now I'm having H@ H! for my 32bit forth, but these are just not possible in a 16bit forth.
But if you define unsigned 16s as "W"s, and name them W@ W!, they are possible whether in 16, 18, 20, 32, or 64 bits. And if 16 bits of unsigned range is sufficient for that algorithm, it will work on any of those.
> Also, for "doubles", if I use doubles in a 16bit systems, those will compile as 64bit objects in a 32bit forth system.
Which is precisely what many people who would only use a 32bit Forth on a 32bit processor would wish to have happen.
> People using doubles in the 16bit forths are using them because they need 32bits. Why forcing them to use 64bits in a 32bit forth system?
But as we have seen in the discussion, this is only partly true. People use 64bits intermediate product in a 32bit */ for largely the same reason they use a 32bit intermediate product in a 16bit */ ... because that is the natural range of a 32 bit multiply. If you don't WANT the intermediate product to be 64 bits, you can always do * and / in succession in the process clip the range, and still have */ for any occasion where you do not want to risk clipping the range.
> People do not need "doubles". They need specific sizes that cover their needs, and use the double because this is what they have at hand. It is used with care anyway.
You seem to enjoy double word operations so much that you have written Forth systems for 16bit word processors in which every operand is a double word. That implies you feel you can do without the single word operations.
And if your stack cells are already intrinsically double words, it makes sense for efficiency's sake, to dispense with doubling it up again, so you'd only need double operations for paired-cell operations, like:
: PARSE-NAME ( -- ca u ) in$ ws-skip 2DUP ws-scan chop 2SWAP >in$ ;
> Well, long story for quite a short subject. CELL compatibility is needed, and a good to have. For forth is almost a must because of the stacks. But it must stop here. "Doubles" shouldn't exist.
You were aiming to arrive at this conclusion, and so along the way made assertions about what "people need" which seem more to be what you find you need after you have baked double word operations into every single cell operation.
> Along with CELL, it must exists byte/char/int8, in16, int32, int64 or any better names you can find for forth.
For accessing specific hardware and for writing specific externally-defined data formats, certainly. But there are certain intrinsic relationships that followed from integer arithmetic, including the fact that for a cell size of 2^n bits, the intrinsic range of unsigned multiplication is 2^[2n] bits. While there may be a manner of elegance in carrying around those extra n bits all the time in order to avoid the inelegance of mixed size operations, there is also a different manner of elegance in tuning the cell size to the word size of the processor and only availing of those extra n bits when required.
Virtually,
@BruceMcF