Replies: 6 comments 3 replies
-
|
Please feel free to add comments, suggestions, complains and corrections as new comments below. Don't forget to click the ((Vote)) button after selecting your choice above. |
Beta Was this translation helpful? Give feedback.
-
|
The proposal to include int128_t type in C: https://open-std.org/jtc1/sc22/wg14/www/docs/n2888.htm I don't know if it was accepted or not. |
Beta Was this translation helpful? Give feedback.
-
|
We have hard from calc users who have hardware accelerators that use calc' as custom functions and higher level builtin functions. So far all are in favor of the proposed version 3 change. Some have been asking for near-terabyte ZVALUE capabilities for a few years. They are not GitHub users but wanted us to indicate their support anyway. We heard from a vintage computer hardware fan who runs a version of calc in both an 8086 and a z80. Via email they said they have a c99 compiler that can pass the |
Beta Was this translation helpful? Give feedback.
-
|
I didn't understand why you can't support BASEB which could be 16/32/64 in one version. Why is it 16/32 or 32/64.
Typo: four instead of for.
I think that 16-bit machines should use the old version. |
Beta Was this translation helpful? Give feedback.
-
|
Just on the C99 issue: it has now been 24 years since C99, and even many historic systems (like Vaxes) have versions of gcc etc. that support C99. I think it's totally fine to say "if you have an old system, find a C99 compiler." C99 has a lot of nice features and it's been a very long time since I've personally made any attempt to be compatible with older versions of C than that. On the 16 bit thing: does anyone actually have a functioning 16 bit computer that can run calc? I'd be shocked. If they do, they can always run an older version, and I doubt they're using such a machine as their daily driver. |
Beta Was this translation helpful? Give feedback.
-
|
We received via messages, 4 more YES votes. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
TL;DR question
Should calc change to version 3, support values those "digit" lengths are limited by 64-bit signed value (this change the
ZVALUEmemory layout), drop support for 16-bit processors and 32-bit processors that do not have at least a c99 compiler with<stdint.h>include file?Even so, please read the rest of this discussion ...
Background - calc v2 limits
Historically calc version 2 has limited integers to 268435455 "digits" where a "digit" is 32-bit (or 16-bits in some cases of very small processors). For 32-bit "digits" integers are limited to a maximum of about 8589934588 bytes. Non-integer real numbers are implemented as fractions consisting of 2 integers, "
a/b", where an and b are both subjected to the same limits. Complex values consist of 4 integers, "a/b + sqrt(-1)*c/d", where a, b, c, and d are also subjected to the same limits.There are other limits, such as the exponent must fit into a 32-bit (or fir small processors 16-bit) digit (called a
HALFinside calc).For 32-bit "digits" or
HALFs the largest exponent was 4294967295. So, for 32-bitHALF, calc can attempt to compute2147483648^2147483647if the machine had enough memory.BTW: Converting
2147483648^2147483647will take a LONG TIME, however you can push close to the maximum value edge with:is fast, assuming a system had enough memory, and you don't try to allocate too many such values. :-)
This also assumes your processor can support addresses larger than 32-bits in size, otherwise you are even more limited. A true 32-bit processor would run out of memory with values probably about 1G byte in size (due to memory needed for stack, instructions, etc.)
Fortunately, most hardware running today can support addresses larger than 32-bits in size.
Backward in calc compatibility is important
Calc has been around since 1984. Part of its stay power is that calc code written long ago still works. Calc runs in a very wide variety of processors, custom hardware, and devices: both big and small. Backward compatibility has been an import part of calc history. The calc tool has gone to significant efforts to maintain backward compatibly, especially for those hardware implementations that use custom functions. For example, the layout of the above integers, the
ZVALUEtype, has been the same for nearly 4 decades.The
ZVALUEcontains a length element that is the number ofHALFs in aZVALUE. For calc v2, this length is currently a 32-bit signed value. Lengths are signed values and not unsigned values for various internal and algorithmic reasons. Even if we changed to a 32-bit unsigned length, that effort would only "kick the can" down the road only twice as far.Supporting values larger than calc v2 limit
To support even larger integers, the ZVALUE would need to change its memory layout. In particular, the
ZVALUEHALFlength element became a 64-bit signed value.The largest exponent allowed would need to be raised from a 32-bit exponent to a 64-bit exponent.
A change to using a 64-bit signed
ZVALUElength element would change the fundamental internal memory layout of calc.The philosophy of version numbers outlined in:
states that when the internal memory layout changes, the top-level version number MUST CHANGE. Thus, to do this
calcwould need to advance to version 3.CALC2_COMPAT and calc version 3
Since commit 3c18e6e, calc supports the define of
CALC2_COMPAT. Any calc version 2 today definesCALC2_COMPATby default.In the proposed calc version 3,
CALC2_COMPATwould be ** UNDEFINED by default**.In the proposed calc version 3, if one were to force
CALC2_COMPATto be defined, then ZVALUEHALFlength to be limited to is current 32-bit signed value. Such binaries would use a memory layout that was **compatible with current calc v2 memory layouts**. Acalcorlibcalcorlibcustcalcwith version that was compiled withCALC2_COMPATdefined would be **INCOMPATIBLE** with default calc v3 code whereCALC2_COMPATwas undefined. Nevertheless, if one wanted to have a calc version 3 memory layout that was compatible with the current calc v2 memory layouts, one could compile withCALC2_COMPATdefined. One would just not be able to link with calc code whereCALC2_COMPAT` was undefined in that case.Dropping support for 16-bit CPUs without c99 fixed-width integer types
Calc v2 supports a 16-bit
HALFas well as a 32-bitHALF. Modern processors can use integer machine values such that in calc version 2, they default to a 32-bitHALFsize.It will be awkward to support 16-bit
HALFcode in calc version 3. Nevertheless after 39 years, perhaps it is time for calc in the proposed version 3 to drop support of 16-bit CPUs? :-)Such 16-bit CPUs can always download the latest calc version 2 source and use that code. Or one could use a c99 or later compiler to compile fixed-width integer types for such a 16-bit CPU. Such a C compiler implementation, under the covers, would compile the appropriate instructions to simulate computing with a 32-bit
HALFsize.Limiting support for 32-bit CPUs without c99 fixed-width integer types
In several cases, 32-bit processors were limited to 16-bit
HALFs as well. Such 32-bit processors used alongas aFULLwhen it needed to multiple two 16-bitHALFs and get a 32-bit result.Calc version 3 will be able to support 32-bit CPUs that either support a 64-bit integer data type in C. In several 32-bit CPUs, a
longis sometimes 64-bits, so such systems would be OK under calc version 3. However, if a 32-bit CPU lacked C support for 64-bit integers, it would not work under calc version 3.Again, such 32-bit CPUs could use a c99 or later compiler to compile fixed-width integer types for such a 32-bit CPU. Such a C compiler implementation, under the covers, would compile the appropriate instructions to simulate computing with a 64-bit
FULLsize.c99 (or later) compilers and fixed-width integer types
Starting with calc version 2.15, calc will require support of
<stdint.h>and the fixed-width integer types. Calc will replace data types such asUSB32,SB32,USB64andSB64with standard C types such asint32_t,uint32_t,int64_tanduint64_t.Calc will keep the
HALFandFULLdata types. It would simply typedef then to the appropriate fixed-width integer type.The c99 standard requires that implementations support such types. A 16-bit CPU, or a 32-bit CPU that supports a c99 or later C compiler would still work. Such a C compiler implementation, under the covers, would compile the appropriate instructions to simulate computing with 32-bit
HALFs and 64-bitFULLsizes.Calc would require a c99 or later C compiler and implementation with full <stdint.h> support.
128-bit future
With fixed-width integer types AND some newer C compilers, the possibility of calc using 128-bit data types is there. In such a case calc would support a 64-bit
HALFs and 128-bitFULLvalues.This would allow for the implementation of issue #48 as well.
Calc would test for the
__int128andunsigned __int128data types and if found, allow those types to be used. If the compiler implements them, then calc would typedefHALFto a 64-bit data type andFULLto a 128-bit data type.The default, without
__int128andunsigned __int128data type support, would beBASEB == 32. However with__int128andunsigned __int128data type support,BASEB == 64would be used.This would be similar to how
BASEBof either 16 or 32 works now: we would simply shift the level up by a factor of 2.And if/when
int128_tanduint128_tbecame standard, calc would switch to supporting that via typedefs.Doing all the above would make implementing 128-bit operations and implementing
BASEB == 64practical for those C compiles with__int128andunsigned __int128data type support.2 votes ·
Beta Was this translation helpful? Give feedback.
All reactions