1. Bit Shift Left and Bit Shift Right

In the early days of Euphoria I was complaining about Bit shifting as
much as you are now.  Euphoria now optimizes some math computations
into bit shifting...

integer i
i = rand(324)-- just some random number
i *= 2 -- Shift Left
i *= 4 -- Shift left twice.
i = floor(i/2) -- Shift right
i = floor(i/4) -- Shift right twice?

PS: if that doesn't actually become a Shift right it is still
computationally equivalent.  Don't sweat it.  Euphoria is pretty fast
for an interpreted language.

        Lucius L. Hilley III
        lhilley at cdc.net
+----------+--------------+--------------+
| Hollow   | ICQ: 9638898 | AIM: LLHIII  |
|  Horse   +--------------+--------------+
| Software | http://www.cdc.net/~lhilley |
+----------+-----------------------------+

new topic     » topic index » view message » categorize

2. Re: Bit Shift Left and Bit Shift Right

--=====================_520899497==_.ALT


I coded some shift functions that are little more formal:

-- Euphoric Shift Registers
--
-- t is the value to be shifted
-- b is the range (number of bits) of the shift
-- this can replace a C entry of : x=(a>>10)
--with
-- x=shift_right(a,10)
--

function shift_left(atom t,atom b)
        atom sl
        sl=t*power(2,b)
        return sl
end function

function shift_right(atom t,atom b)
        atom sr
        sr=t/power(2,b)
        return sr
end function

It also turns out I was incorrect in stating the need for *32* logical
operators --- it seems that 64 bit logical operators are required.

At 12:12 AM 02/18/2000 -0500, you wrote:
>    In the early days of Euphoria I was complaining about Bit shifting as
>much as you are now.  Euphoria now optimizes some math computations
>into bit shifting...
>
>integer i
>i = rand(324)-- just some random number
>i *= 2 -- Shift Left
>i *= 4 -- Shift left twice.
>i = floor(i/2) -- Shift right
>i = floor(i/4) -- Shift right twice?
>
>PS: if that doesn't actually become a Shift right it is still
>computationally equivalent.  Don't sweat it.  Euphoria is pretty fast
>for an interpreted language.
>
>        Lucius L. Hilley III
>        lhilley at cdc.net
>+----------+--------------+--------------+
>| Hollow   | ICQ: 9638898 | AIM: LLHIII  |
>|  Horse   +--------------+--------------+
>| Software | http://www.cdc.net/~lhilley |
>+----------+-----------------------------+

Joel H. Crook

Manager, Information Services
Certified Novell Administrator
Microsoft Certified Professional, OS Specialist

Kellogg & Andelson Accountancy Corp.
14724 Ventura Blvd. 2nd Floor
Sherman Oaks, CA 91403
(818) 971-5100

--=====================_520899497==_.ALT

<html><div>I coded some shift functions that are little more
formal:</div>
<br>
<div>-- Euphoric Shift Registers</div>
<div>--</div>
<div>-- t is the value to be shifted</div>
<div>-- b is the range (number of bits) of the shift</div>
<div>-- this can replace a C entry of : x=(a&gt;&gt;10) </div>
<div>--with </div>
<div>-- x=shift_right(a,10)</div>
<div>-- </div>
<br>
<div>function shift_left(atom t,atom b)</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; atom sl</div>
sl</div>
<div>end function</div>
<br>
<div>function shift_right(atom t,atom b)</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; atom sr</div>
sr</div>
<div>end function</div>
<br>
<div>It also turns out I was incorrect in stating the need for *32*
logical operators --- it seems that 64 bit logical operators are
required.</div>
<br>
<div>At 12:12 AM 02/18/2000 -0500, you wrote:</div>
<div>&gt;&nbsp;&nbsp;&nbsp; In the early days of Euphoria I was
complaining about Bit shifting as</div>
<div>&gt;much as you are now.&nbsp; Euphoria now optimizes some math
computations</div>
<div>&gt;into bit shifting...</div>
<div>&gt;</div>
<div>&gt;integer i</div>
<div>&gt;i = rand(324)-- just some random number</div>
<div>&gt;i *= 2 -- Shift Left</div>
<div>&gt;i *= 4 -- Shift left twice.</div>
<div>&gt;i = floor(i/2) -- Shift right</div>
<div>&gt;i = floor(i/4) -- Shift right twice?</div>
<div>&gt;</div>
<div>&gt;PS: if that doesn't actually become a Shift right it is
still</div>
<div>&gt;computationally equivalent.&nbsp; Don't sweat it.&nbsp; Euphoria
is pretty fast</div>
<div>&gt;for an interpreted language.</div>
<div>&gt;</div>
<div>&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Lucius L. Hilley
III</div>
lhilley at cdc.net</div>
<div>&gt;| Hollow&nbsp;&nbsp; | ICQ: 9638898 | AIM: LLHIII&nbsp;
|</div>
<div>&gt;|&nbsp; Horse&nbsp;&nbsp;
+--------------+--------------+</div>
<div>&gt;| Software |
<a href="http://www.cdc.net/~lhilley"
EUDORA=AUTOURL>http://www.cdc.net/~lhilley</a>
|</div>
<br>

Joel H. Crook<br>
<br>
Manager, Information Services<br>
<font size=1>Certified Novell Administrator<br>
Microsoft Certified Professional, OS Specialist<br>
<br>
</font><b>Kellogg &amp; Andelson Accountancy Corp.<br>
</b><font size=1>14724 Ventura Blvd. 2nd Floor<br>
Sherman Oaks, CA 91403<br>
(818) 971-5100<br>
</font></html>

--=====================_520899497==_.ALT--

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu