I revisited some old code and noticed there was a BSR using piece of
assembler there that used bsr as a cheap 2log for some buffer dimensioning.
When I tried to replace it with the intrinsic bsrdword, hoping making it
both inlinable and more portablw I noted that the intrinsic was exactly the
same as my code but returned 255 instead of -1 for "0".
Since this is a higher number than other values, it required another test to
avoid outrageous large buffers, resulting in asm code (-O4):
# Var $result located in register eax
#  if result=255 then result:=-1;
and then leal 2(%eax),%ebx to add two. Pretty hideous.
If the dword version returned $FFFFFFFF it could be at least typecasted to
So the questions are:
1. why do the primitives deliver a signed result ?
2. why do they not all deliver -1 for their with ($FFFF for 2-byte etc).
3. (for Michael: :-) why doesn't the documentation doesn't mention the
behaviour for no bits set?).
Since (3) the behaviour is not documented, we can still fix this ? :-)
The current choices (0..31 and 255) seem pointless.
fpc-devel maillist - email@example.com