Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdcff1d5

Browse files
committed
Why not
1 parentee91e18 commitdcff1d5

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

‎src/bitblockarray.jl‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,26 @@ function transpose_8x8bit(a::UInt64)
6262
return x
6363
end
6464

65+
66+
# https://discourse.julialang.org/t/covert-bitarray-to-int64/9193/6
67+
# This was stated to be better than the LLVM intrinsic!
68+
functionrevbits(z::UInt64)
69+
z= (((z&0xaaaaaaaaaaaaaaaa)>>1)| ((z&0x5555555555555555)<<1))
70+
z= (((z&0xcccccccccccccccc)>>2)| ((z&0x3333333333333333)<<2))
71+
z= (((z&0xf0f0f0f0f0f0f0f0)>>4)| ((z&0x0f0f0f0f0f0f0f0f)<<4))
72+
z= (((z&0xff00ff00ff00ff00)>>8)| ((z&0x00ff00ff00ff00ff)<<8))
73+
z= (((z&0xffff0000ffff0000)>>16)| ((z&0x0000ffff0000ffff)<<16))
74+
z= (((z&0xffffffff00000000)>>32)| ((z&0x00000000ffffffff)<<32))
75+
return z
76+
end
77+
78+
6579
function Base.permutedims(A::BitBlockArray{2, UInt64, Tuple{3,3}})
6680
BitBlockArray{2, UInt64, Tuple{3,3}}(transpose_8x8bit(A.x))
6781
end
82+
83+
84+
function Base.rot180(A::BitBlockArray{2, UInt64, Tuple{3,3}})
85+
#TODO would work for other sizes, too
86+
BitBlockArray{2, UInt64, Tuple{3,3}}(revbits(A.x))
87+
end

‎test/runtests.jl‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,12 @@ end
3333
@testcollect(at)==collect(a)'
3434
end
3535
end
36+
37+
@testset"8-by-8 rot180"begin
38+
for i=0:64
39+
x=UInt64(0x1)<< i
40+
a=BitBlockArray(x,8,8)
41+
42+
@testcollect(rot180(a))==rot180(collect(a))
43+
end
44+
end

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp