更快左移圆(旋转) [英] faster shift left circular (rotate)
问题描述
任何人都对如何提高速度这个过程有任何想法吗?
这就是我所拥有的...
Dim j,q As Integer
Dim x(16),y(16)As Byte
[并非所有代码都显示...仅相关零件]
x.CopyTo(y,0)''左转24位
for j = 0 to 15
q =(j + 3)和15
x(j + 1)= y(q + 1)
下一页
''向左移循环1更多位
如果x(1)和& H80然后q =真Else q = False
对于j = 1到16
x(j)=(x(j)* 2)和& HFF
如果j< 16然后
如果x(j + 1)和& H80则x(j)+ = 1
否则
如果q则x (j)+ = 1
结束如果
下一页
我需要移位移位数组中的所有位[x ]左边25位
(循环)尽快。
我不拥有有一个数组。如果需要,我可以使用64位整数。
Anyone got any ideas as to how this process could be improved for speed?
this is what I have...
Dim j, q As Integer
Dim x(16), y(16) As Byte
[ not all code is shown ... only the relevant parts ]
x.CopyTo(y, 0) '' shift left circular 24 bits
For j = 0 To 15
q = (j + 3) And 15
x(j + 1) = y(q + 1)
Next
'' shift left circular 1 more bit
If x(1) And &H80 Then q = True Else q = False
For j = 1 To 16
x(j) = (x(j) * 2) And &HFF
If j < 16 Then
If x(j + 1) And &H80 Then x(j) += 1
Else
If q Then x(j) += 1
End If
Next
I need to shift shift all the bits in the array [x] 25 bits to the left
(circular) as quickly as possible.
I don''t "have" to have an array. I could use a 64 bit integer if needed.
推荐答案
2003年12月22日星期一12:43:07 -0600,Kenneth Lantrip
< vi *** @ mindspring.com>写道:
On Mon, 22 Dec 2003 12:43:07 -0600, Kenneth Lantrip
<vi***@mindspring.com> wrote:
任何人都对如何改进这个过程有任何想法?
这就是我的...
Dim j,q As Integer
Dim x(16),y(16)As Byte
[并非所有代码都显示...只有相关部分]
x.CopyTo(y,0)''左移圆形24位
对于j = 0到15
q =(j + 3)和15
x(j + 1)= y(q + 1)
然后再向左移动1位
如果x(1)和& H80则q = True Else q = False
x(j)=(x(j)* 2)和& HFF
如果j <1。 16然后
如果x(j + 1)和& H80那么x(j)+ = 1
否则
如果q那么x(j)+ = 1
结束If
我需要尽快将数组[x]中的所有位移位到左侧
(圆形)。
Anyone got any ideas as to how this process could be improved for speed?
this is what I have...
Dim j, q As Integer
Dim x(16), y(16) As Byte
[ not all code is shown ... only the relevant parts ]
x.CopyTo(y, 0) '' shift left circular 24 bits
For j = 0 To 15
q = (j + 3) And 15
x(j + 1) = y(q + 1)
Next
'' shift left circular 1 more bit
If x(1) And &H80 Then q = True Else q = False
For j = 1 To 16
x(j) = (x(j) * 2) And &HFF
If j < 16 Then
If x(j + 1) And &H80 Then x(j) += 1
Else
If q Then x(j) += 1
End If
Next
I need to shift shift all the bits in the array [x] 25 bits to the left
(circular) as quickly as possible.
I don''t "have" to have an array. I could use a 64 bit integer if needed.
好的只是回答我自己的问题...我已经展开了循环并且
优化了一点......
dim x(16),y(4)整数
''左移25位
y(1)= x(1)
y(2)= x(2)
y(3)= x(3)
y(4)= x(4)
x(1)=(x(4)* 2 - ((x(5)And& H80)<> 0 )和& HFF
x(2)=(x(5)* 2 - ((x(6)和& H80)<> 0))和& HFF
x(3)=(x(6)* 2 - ((x(7)和& H80)<> 0))和& HFF
x(4 )=(x(7)* 2 - ((x(8)和& H80)<> 0))和& HFF
x(5)=(x(8)* 2 - ((x(9)和& H80)<> 0))和& HFF
x(6)=(x(9)* 2 - ((x(10)并且& H80)<> 0))和& HFF
x(7)=(x(10)* 2 - ((x(11)和& H80)<> ; 0))和& HFF
x(8)=(x(11)* 2 - ((x(12)和& H80)<> 0))和& HFF
x (9)=(x(12)* 2 - ((x(13)和& H80)< 0))和& HFF
x(10)=(x(13)* 2 - ((x(14)和& H80)<> 0))和& HFF
x(11)=(x(14)* 2 - ((x(15)和& H80)<> 0))和& HFF
x( 12)=(x(15)* 2 - ((x(16)和& H80)<> 0))和& HFF
x(13)=(x(16) * 2 - ((y(1)和& H80)<> 0))和& HFF
x(14)=(y(1)* 2 - ((y(2并且& H80)<> 0))和& HFF
x(15)=(y(2)* 2 - ((y(3)和& H80)< > 0))和& HFF
x(16)=(y(3)* 2 - ((y(4)和& H80)<> 0))和& HFF
OK just to answer my own question... I have unrolled the loops and
optimized just a little...
dim x(16), y(4) in integer
'' shift left circular 25 bits
y(1) = x(1)
y(2) = x(2)
y(3) = x(3)
y(4) = x(4)
x(1) = (x(4) * 2 - ((x(5) And &H80) <> 0)) And &HFF
x(2) = (x(5) * 2 - ((x(6) And &H80) <> 0)) And &HFF
x(3) = (x(6) * 2 - ((x(7) And &H80) <> 0)) And &HFF
x(4) = (x(7) * 2 - ((x(8) And &H80) <> 0)) And &HFF
x(5) = (x(8) * 2 - ((x(9) And &H80) <> 0)) And &HFF
x(6) = (x(9) * 2 - ((x(10) And &H80) <> 0)) And &HFF
x(7) = (x(10) * 2 - ((x(11) And &H80) <> 0)) And &HFF
x(8) = (x(11) * 2 - ((x(12) And &H80) <> 0)) And &HFF
x(9) = (x(12) * 2 - ((x(13) And &H80) <> 0)) And &HFF
x(10) = (x(13) * 2 - ((x(14) And &H80) <> 0)) And &HFF
x(11) = (x(14) * 2 - ((x(15) And &H80) <> 0)) And &HFF
x(12) = (x(15) * 2 - ((x(16) And &H80) <> 0)) And &HFF
x(13) = (x(16) * 2 - ((y(1) And &H80) <> 0)) And &HFF
x(14) = (y(1) * 2 - ((y(2) And &H80) <> 0)) And &HFF
x(15) = (y(2) * 2 - ((y(3) And &H80) <> 0)) And &HFF
x(16) = (y(3) * 2 - ((y(4) And &H80) <> 0)) And &HFF
Kenneth,
除了展开循环外,我还会考虑使用位移
运算符VS.NET 2003.另外我会考虑使用最长的整数
可用(长而不是整数)。
但我会简介长整数以确保Long为
给我提升速度。
希望这有助于
Jay >
" Kenneth Lantrip" <博******** @ mindspring.com>在消息中写道
news:s0 ******************************** @ 4ax.com ...
Kenneth,
In addition to unrolling the loop, I would consider using the bit shift
operators in VS.NET 2003. Plus I would consider using the longest integer
available (Long instead of Integer).
However I would "profile" Long verses Integer to ensure that the Long is
giving me a speed boost.
Hope this helps
Jay
"Kenneth Lantrip" <bo********@mindspring.com> wrote in message
news:s0********************************@4ax.com...
2003年12月22日星期一12:43:07 -0600,Kenneth Lantrip
< vi *** @ mindspring.com>写道:
On Mon, 22 Dec 2003 12:43:07 -0600, Kenneth Lantrip
<vi***@mindspring.com> wrote:
任何人都对如何改进这个过程有任何想法?
这就是我的...
Dim j,q As Integer
Dim x(16),y(16)As Byte
[并非所有代码都显示...只有相关部分]
x.CopyTo(y,0)''左移圆形24位
对于j = 0到15
q =(j + 3)和15
x(j + 1)= y(q + 1)
然后再向左移动1位
如果x(1)和& H80则q = True Else q = False
x(j)=(x(j)* 2)和& HFF
如果j <1。 16然后
如果x(j + 1)和& H80那么x(j)+ = 1
否则
如果q那么x(j)+ = 1
结束If
我需要尽快将数组[x]中的所有位移位到左侧
(圆形)。
Anyone got any ideas as to how this process could be improved for speed?
this is what I have...
Dim j, q As Integer
Dim x(16), y(16) As Byte
[ not all code is shown ... only the relevant parts ]
x.CopyTo(y, 0) '' shift left circular 24 bits
For j = 0 To 15
q = (j + 3) And 15
x(j + 1) = y(q + 1)
Next
'' shift left circular 1 more bit
If x(1) And &H80 Then q = True Else q = False
For j = 1 To 16
x(j) = (x(j) * 2) And &HFF
If j < 16 Then
If x(j + 1) And &H80 Then x(j) += 1
Else
If q Then x(j) += 1
End If
Next
I need to shift shift all the bits in the array [x] 25 bits to the left
(circular) as quickly as possible.
I don''t "have" to have an array. I could use a 64 bit integer if needed.
好的只是回答我自己的问题...我已经展开循环并且优化了一点...
dim x(16),y(4)整数
''左移圆25位
y(1)= x(1)
y(2)= x(2)
y(3)= x(3)
y(4)= x(4)
x(1)=(x(4) * 2 - ((x(5)和& H80)<> 0))和& HFF
x(2)=(x(5)* 2 - ((x(6)And& amp; ; H80)<> 0))和& HFF
x(3)=(x(6)* 2 - ((x(7)和& H80)<> 0))和& HFF
x(4)=(x(7)* 2 - ((x(8)和& H80)<> 0))和& HFF
x(5) =(x(8)* 2 - ((x(9)和& H80)<> 0))和& HFF
x(6)=(x(9)* 2 - (( x(10)和& H80)<> 0))和& HFF
x(7)=(x(10)* 2 - ((x(11)和& H80)< ;> 0))和& HFF
x(8)=(x(11)* 2 - ((x(12)和& H80)<> 0))和& HFF
x(9)=(x(12)* 2 - ((x(13)和& H80)<> 0))和& HFF
x(10)=(x(13)* 2 - ((x(14)和& H80)<> 0))和& HFF
x(11)=(x(14)* 2 - ((x(15)And& H80)<> 0))和& HFF
x(12)=(x(15)* 2 - ((x(16)和& H80)<> 0))和& ; HFF
x(13)=(x(16)* 2 - ((y(1)和& H80)<> 0))和& HFF
x(14)= (y(1)* 2 - ((y(2)和& H80)<> 0))和& HFF
x(15)=(y(2)* 2 - ((y (3)和& H80)<> 0))和& HFF
x(16)=(y(3)* 2 - ((y(4)和& H80)<> ; 0))和& HFF
OK just to answer my own question... I have unrolled the loops and
optimized just a little...
dim x(16), y(4) in integer
'' shift left circular 25 bits
y(1) = x(1)
y(2) = x(2)
y(3) = x(3)
y(4) = x(4)
x(1) = (x(4) * 2 - ((x(5) And &H80) <> 0)) And &HFF
x(2) = (x(5) * 2 - ((x(6) And &H80) <> 0)) And &HFF
x(3) = (x(6) * 2 - ((x(7) And &H80) <> 0)) And &HFF
x(4) = (x(7) * 2 - ((x(8) And &H80) <> 0)) And &HFF
x(5) = (x(8) * 2 - ((x(9) And &H80) <> 0)) And &HFF
x(6) = (x(9) * 2 - ((x(10) And &H80) <> 0)) And &HFF
x(7) = (x(10) * 2 - ((x(11) And &H80) <> 0)) And &HFF
x(8) = (x(11) * 2 - ((x(12) And &H80) <> 0)) And &HFF
x(9) = (x(12) * 2 - ((x(13) And &H80) <> 0)) And &HFF
x(10) = (x(13) * 2 - ((x(14) And &H80) <> 0)) And &HFF
x(11) = (x(14) * 2 - ((x(15) And &H80) <> 0)) And &HFF
x(12) = (x(15) * 2 - ((x(16) And &H80) <> 0)) And &HFF
x(13) = (x(16) * 2 - ((y(1) And &H80) <> 0)) And &HFF
x(14) = (y(1) * 2 - ((y(2) And &H80) <> 0)) And &HFF
x(15) = (y(2) * 2 - ((y(3) And &H80) <> 0)) And &HFF
x(16) = (y(3) * 2 - ((y(4) And &H80) <> 0)) And &HFF
Kenneth,
我没有测试过这100%,我相信以下是你想要的东西
使用VS.NET 200 3:
Dim x(15)As Byte''16个字节
Dim y(3)As Integer''4个整数
System.Buffer.BlockCopy(x,0,y,0,16)
Dim y4 As Integer = y(3)
>
y(3)= y(3)<< 25或y(2)>> 32 - 25
y(2)= y(2)<< 25或y(1)>> 32 - 25
y(1)= y(1)<< 25或y(0)>> 32 - 25
y(0)= y(0)<< 25或y4>> 32 - 25
System.Buffer.BlockCopy(y,0,x,0,16)
而不是位移你应该是能够使用乘法&分为
VS.NET 2002,适当的功率为2,类似于:
Const leftshift As Integer =& H2000000
Const rightshift As Integer =& H80
Dim x(15)As Byte
Dim y(3)As Integer
System.Buffer.BlockCopy(x,0,y,0,16)
Dim y4 As Integer = y(3)
>
y(3)=(y(3)And& H3F)* leftshift或y(2)\ rightshift
y(2)=(y(2)And& H3F )* leftshift或y(1)\ rightshift
y(1)=(y(1)And& H3F)* leftshift or y(0)\ rightshift
y(0)=(y(0)And& H3F)* leftshift or y4 \ rightshift
System.Buffer.BlockCopy(y,0,x,0,16)
请记住,数组以元素0开头,因此我的数组为15& 3是
上限。
希望这有帮助
Jay
" ; Kenneth Lantrip <博******** @ mindspring.com>在消息中写道
news:s0 ******************************** @ 4ax.com ...
Kenneth,
I have not tested this 100%, I believe the following does what you want
using VS.NET 2003:
Dim x(15) As Byte '' 16 bytes
Dim y(3) As Integer '' 4 integers
System.Buffer.BlockCopy(x, 0, y, 0, 16)
Dim y4 As Integer = y(3)
y(3) = y(3) << 25 Or y(2) >> 32 - 25
y(2) = y(2) << 25 Or y(1) >> 32 - 25
y(1) = y(1) << 25 Or y(0) >> 32 - 25
y(0) = y(0) << 25 Or y4 >> 32 - 25
System.Buffer.BlockCopy(y, 0, x, 0, 16)
Instead of bit shifts you should be able to use multiplication & division in
VS.NET 2002 with the appropriate power of 2, something like:
Const leftshift As Integer = &H2000000
Const rightshift As Integer = &H80
Dim x(15) As Byte
Dim y(3) As Integer
System.Buffer.BlockCopy(x, 0, y, 0, 16)
Dim y4 As Integer = y(3)
y(3) = (y(3) And &H3F) * leftshift Or y(2) \ rightshift
y(2) = (y(2) And &H3F) * leftshift Or y(1) \ rightshift
y(1) = (y(1) And &H3F) * leftshift Or y(0) \ rightshift
y(0) = (y(0) And &H3F) * leftshift Or y4 \ rightshift
System.Buffer.BlockCopy(y, 0, x, 0, 16)
Remember that arrays start with element 0, hence my array of 15 & 3 are
upper bounds.
Hope this helps
Jay
"Kenneth Lantrip" <bo********@mindspring.com> wrote in message
news:s0********************************@4ax.com...
2003年12月22日星期一12:43:07 -0600,Kenneth Lantrip
< vi *** @ mindspring.com>写道:
On Mon, 22 Dec 2003 12:43:07 -0600, Kenneth Lantrip
<vi***@mindspring.com> wrote:
任何人都对如何改进这个过程有任何想法?
这就是我的...
Dim j,q As Integer
Dim x(16),y(16)As Byte
[并非所有代码都显示...只有相关部分]
x.CopyTo(y,0)''左移圆形24位
对于j = 0到15
q =(j + 3)和15
x(j + 1)= y(q + 1)
然后再向左移动1位
如果x(1)和& H80则q = True Else q = False
x(j)=(x(j)* 2)和& HFF
如果j <1。 16然后
如果x(j + 1)和& H80那么x(j)+ = 1
否则
如果q那么x(j)+ = 1
结束If
我需要尽快将数组[x]中的所有位移位到左侧
(圆形)。
Anyone got any ideas as to how this process could be improved for speed?
this is what I have...
Dim j, q As Integer
Dim x(16), y(16) As Byte
[ not all code is shown ... only the relevant parts ]
x.CopyTo(y, 0) '' shift left circular 24 bits
For j = 0 To 15
q = (j + 3) And 15
x(j + 1) = y(q + 1)
Next
'' shift left circular 1 more bit
If x(1) And &H80 Then q = True Else q = False
For j = 1 To 16
x(j) = (x(j) * 2) And &HFF
If j < 16 Then
If x(j + 1) And &H80 Then x(j) += 1
Else
If q Then x(j) += 1
End If
Next
I need to shift shift all the bits in the array [x] 25 bits to the left
(circular) as quickly as possible.
I don''t "have" to have an array. I could use a 64 bit integer if needed.
好的只是回答我自己的问题...我已经展开循环并且优化了一点...
dim x(16),y(4)整数
''左移圆25位
y(1)= x(1)
y(2)= x(2)
y(3)= x(3)
y(4)= x(4)
x(1)=(x(4) * 2 - ((x(5)和& H80)<> 0))和& HFF
x(2)=(x(5)* 2 - ((x(6)And& amp; ; H80)<> 0))和& HFF
x(3)=(x(6)* 2 - ((x(7)和& H80)<> 0))和& HFF
x(4)=(x(7)* 2 - ((x(8)和& H80)<> 0))和& HFF
x(5) =(x(8)* 2 - ((x(9)和& H80)<> 0))和& HFF
x(6)=(x(9)* 2 - (( x(10)和& H80)<> 0))和& HFF
x(7)=(x(10)* 2 - ((x(11)和& H80)< ;> 0))和& HFF
x(8)=(x(11)* 2 - ((x(12)和& H80)<> 0))和& HFF
x(9)=(x(12)* 2 - ((x(13)和& H80)<> 0))和& HFF
x(10)=(x(13)* 2 - ((x(14)和& H80)<> 0))和& HFF
x(11)=(x(14)* 2 - ((x(15)And& H80)<> 0))和& HFF
x(12)=(x(15)* 2 - ((x(16)和& H80)<> 0))和& ; HFF
x(13)=(x(16)* 2 - ((y(1)和& H80)<> 0))和& HFF
x(14)= (y(1)* 2 - ((y(2)和& H80)<> 0))和& HFF
x(15)=(y(2)* 2 - ((y (3)和& H80)<> 0))和& HFF
x(16)=(y(3)* 2 - ((y(4)和& H80)<> ; 0))和& HFF
OK just to answer my own question... I have unrolled the loops and
optimized just a little...
dim x(16), y(4) in integer
'' shift left circular 25 bits
y(1) = x(1)
y(2) = x(2)
y(3) = x(3)
y(4) = x(4)
x(1) = (x(4) * 2 - ((x(5) And &H80) <> 0)) And &HFF
x(2) = (x(5) * 2 - ((x(6) And &H80) <> 0)) And &HFF
x(3) = (x(6) * 2 - ((x(7) And &H80) <> 0)) And &HFF
x(4) = (x(7) * 2 - ((x(8) And &H80) <> 0)) And &HFF
x(5) = (x(8) * 2 - ((x(9) And &H80) <> 0)) And &HFF
x(6) = (x(9) * 2 - ((x(10) And &H80) <> 0)) And &HFF
x(7) = (x(10) * 2 - ((x(11) And &H80) <> 0)) And &HFF
x(8) = (x(11) * 2 - ((x(12) And &H80) <> 0)) And &HFF
x(9) = (x(12) * 2 - ((x(13) And &H80) <> 0)) And &HFF
x(10) = (x(13) * 2 - ((x(14) And &H80) <> 0)) And &HFF
x(11) = (x(14) * 2 - ((x(15) And &H80) <> 0)) And &HFF
x(12) = (x(15) * 2 - ((x(16) And &H80) <> 0)) And &HFF
x(13) = (x(16) * 2 - ((y(1) And &H80) <> 0)) And &HFF
x(14) = (y(1) * 2 - ((y(2) And &H80) <> 0)) And &HFF
x(15) = (y(2) * 2 - ((y(3) And &H80) <> 0)) And &HFF
x(16) = (y(3) * 2 - ((y(4) And &H80) <> 0)) And &HFF
这篇关于更快左移圆(旋转)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!