Bit-shifting

new topic     » topic index » view thread      » older message » newer message

Will bit-shifting operators be available in the next version of
Euphoria?  I would much rather use a built-in machine code instead of a
multiply or divide.  Does Euphoria optimize multiplication into a shift
when one of the numbers is an integer power of two?  Does it convert a
value to floating-point when dividing?

I would much rather be able to
        integer SHR 1   -- shift right
        integer SAR 1   -- shift arithmetic right  (keeps the sign)
instead of using
        floor(integer / 2)

If bit-shifting becomes available I would like a function that does bit
slicing.  It would work with integers the same way as sequences, without
having to convert the integer into a sequence of integers and back
again.  I think it could be coded like this:
  -- returns source[lower_bit..upper_bit]
  function bit_slice(source, lower_bit, upper_bit)
    integer mask
    mask = #FFFFFFFF shr (32 - upper_bit + lower_bit)
    source = source shr lower_bit
    return and_bits(source, mask)
  end function

  -- returns dest with [lower_bit..upper_bit] overwritten by source
  function bit_splice(source, dest, lower_bit, upper_bit)
    integer mask
    mask = (#FFFFFFFF shr (32 - upper_bit + lower_bit)) shl lower_bit
    source = source shl lower_bit
    return or_bits(and_bits(dest, not_bits(mask)), and_bits(source,
mask))
  end function

I could see a lot of code optimizations using these functions.  Speed is
one thing I like about Euphoria, and I would like to see it pushed to
the absolute max.

Also would it be possible to have a 32-bit peek and poke for integers?

Thanks

--
                   _____         _____         _____
    ________      /\    \       /\    \       /\    \
   /   \    \    /  \____\     /  \____\     /  \____\
  /  _  \____\  /   / ___/_   /   /____/    /   / ___/_
 /  / \  |____|/   / /\____\ /    \    \   /   / /\____\
 \  \_/ /    / \   \/ / ___/_\     \    \  \   \/ / ___/_
  \    /____/   \    / /\    \\/\   \    \  \    / /\    \
   \   \    \    \   \/  \____\  \   \    \  \   \/  \____\
    \   \    \    \      /    /   \   \____\  \      /    /
     \   \____\    \    /    /     \  /    /   \    /    /
      \  /    /     \  /    /       \/____/     \  /    /
       \/____/       \/____/                     \/____/

new topic     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu