Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bit-wise operation and strict aliasing

Bit-wise operation and strict alising

I am trying to write some high-performance functions for bit-based operations that taking the advantage of latest features of hardware, the problem I am facing is:

I want to include a bit-wise count operation, in which case I used Intel SSE4.2's popcnt that only accecpt integer type values.

Whilst, if I need to conduct other bitwise logical operations, then AVX support 256-bit wide bit-wise logical operations like VORPD (instead of SSE2's 128 bit wide bit-wise logical operations), but only on floating data.

Coupling with the fact for bit-wise setting/resetting operations, char is fastest, so I may need at least three types of pointers pointed to the same memory locations: a char type, a long long (64-bit integer for optimal bit-wise counting), and a floating type pointers, however the co-existence of Integer and floating type of pointers break the strict-aliasing rules.

Any suggestion to working around with this? thanks.

like image 544
user0002128 Avatar asked Nov 30 '25 14:11

user0002128


1 Answers

Are you using gcc or clang or something that behaves similarly? They have __attribute__((__may_alias__)) to work around these problems.

like image 122
Carl Norum Avatar answered Dec 03 '25 03:12

Carl Norum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!