Arrays are arrays regardless of what they're arrays of. So it would be
strange for arrays of certain things to have properties that other
arrays don't have and bitwise ops don't make sense for arrays of, say,
strings.

Also some processors support these sizes natively but wouldn't support
a [4096]byte natively. On processors that don't support all or some of
these sizes it would need to fake it by doing m operations† but that's
bounded and if, for example, the target processor supports 256 bit but
not 512 bit values it can use two 256 ORs instead of four 64 bit ORs.
Maybe that could be made to work in general and if so that would be
great but it's not the only benefit of these types.

† except for shifts, those would have to deal with carries. That may
be a problem, but I think even then it should be fast enough to not be
an issue the way faking div or something very expensive like that
would be.

On Mon, May 13, 2024 at 8:41 PM Kevin Chowski <ke...@chowski.com> wrote:
>
> Sorry, sent too early.
>
> Obviously that doesn't support the bitwise type conversion you mentioned; I 
> don't really have an opinion on that one, I don't really convert from float 
> to bits very often.
>
> It seems like the compiler optimizations you mention could happen with or 
> without these extra types, if such optimizations just worked on byte arrays 
> in general.
>
> On Monday, May 13, 2024 at 9:38:36 PM UTC-6 Kevin Chowski wrote:
>>
>> How about just allowing bitwise operations on byte arrays (of the same 
>> length)?
>>
>> On Monday, May 13, 2024 at 2:51:19 PM UTC-6 jimmy frasche wrote:
>>>
>>> I'm not 100% sure if this is a good idea but it's been knocking around
>>> in my head all week so I thought I'd share in case it has any merit:
>>>
>>> Introduce bitsN types for N=8, 16, 32, 64, 128, 256, and 512.
>>>
>>> These are similar to uintN but they are unordered and have no
>>> arithmetic operations defined.
>>>
>>> They only have literals, comparison, and bitwise operations.
>>> (fmt.Print and friends should render them in hex by default.)
>>>
>>> Conversions between the numeric types and the bitN are allowed, which,
>>> for example, let's us rewrite math.Float64bits as simply
>>>
>>> func Float64bits(f float64) uint64 {
>>> return uint64(bits64(f))
>>> }
>>>
>>> Since there are no arithmetic operations, the 128+ sizes should be
>>> fairly efficient to fake on architectures without special
>>> instructions/registers.
>>>
>>> Potential uses:
>>>
>>> UUIDs could be stored as a bits128 instead of a [2]uint64 or [16]byte.
>>>
>>> SIMD vectors could be created and stored easily, even if they need
>>> assembly to operate on them efficiently.
>>>
>>> Same for int128/uint128 values or even for more exotic numeric types
>>> like the various float16 definitions or "floating slash" rationals.
>>>
>>> It would also be handy to have larger bitsets that are easy to work with.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/golang-nuts/1f0329c1-8b82-4683-999e-62b9a046c0a8n%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CANG3jXLdcRs9AMS_xE15EEgqKmYFRgexgGBfpSxVA-%3D60A69sQ%40mail.gmail.com.

Reply via email to