From: bc@freeuk.com   
      
   On 24/11/2025 09:29, David Brown wrote:   
   > On 23/11/2025 16:06, Michael S wrote:   
   >> On Sun, 23 Nov 2025 13:59:59 +0000   
   >> bart wrote:   
      
   >>> So what is the result type of multiplying values of those two types?   
   >>>   
   >>   
   >> I think, traditional C rules for integer types apply here as well: type   
   >> of result is the same as type of wider operand. It is arithmetically   
   >> unsatisfactory, but consistent with the rest of language.   
   >   
   > There is one key difference between the _BitInt() types and other   
   > integer types - with _BitInt(), there are no automatic promotions to   
   > other integer types. Thus if you are using _BitInt() operands in an   
   > arithmetic expression, these are not promoted to "int" or "unsigned int"   
   > even if they are smaller (lower rank). If you mix _BitInt()'s of   
   > different sizes, then the smaller one is first converted to the larger   
   > type.   
      
   >> I think, the Standard is written in such way that implementing _BitInt   
   >> as an arbitrary precision numbers, i.e. with number of bits held as part   
   >> of the data, is not allowed.   
      
   > Correct. _BitInt(N) is a signed integer type with precisely N value   
   > bits. It can have padding bits if necessary (according to the target   
   > ABI), but it can't have any other information.   
   >   
   >> Of course, Language Support Library can be   
   >> (and hopefully is, at least for gcc; clang is messy a.t.m.) based on   
   >> arbitrary precision core routines, but the API used by compiler should   
   >> be similar to GMP's mpn_xxx family of functions rather than GMP's   
   >> mpz_xxx family, i.e. # of bits as separate parameters from data arrays   
   >> rather than combined.   
   >>   
   >   
   > Yes, exactly. At the call site, the size of the _BitInt type is always   
   > a known compile-time constant, so it can easily be passed on. Thus :   
   >   
   > _BitInt(N) x;   
   > _BitInt(M) y;   
   > _BitInt(NM) z = x * y;   
      
   So what is NM here; is it N*M (the potential maximum size of the   
   result), or max(N, M)?   
      
   It sounds like the max precision you get will be the latter.   
      
      
   > can be implemented as something like :   
   >   
   > __bit_int_signed_mult(NM, (unsigned char *) &z,   
   > N, (const unsigned char *) &x,   
   > M, (const unsigned char *) &y);   
   >   
   >   
      
      
   How would you write a generic user function that operates on any size   
   BitInt? For example:   
      
    _BitInt(?) bi_square(_BitInt(?));   
      
   Even if you passed the size as a parameter, there would be a problem   
   with the BitInt type.   
      
   This assumes BitInts are passed and returned by value, but even using   
   BitInt* wouldn't help.   
      
   This sets it apart from arrays, where you also define very large, fixed   
   size arrays, but can use a T(*)[] type to write generic functions, that   
   take an additional length parameter.   
      
   This will be for a particular T, but for BitInt, T is also fixed; it   
   happens to be an implicit bit type.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|