Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
ca4dac39
Commit
ca4dac39
authored
Dec 11, 2016
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
f88fb726
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
8 deletions
+27
-8
t/neo/packed.go
t/neo/packed.go
+27
-8
No files found.
t/neo/packed.go
View file @
ca4dac39
...
@@ -55,13 +55,12 @@ type be64 struct {
...
@@ -55,13 +55,12 @@ type be64 struct {
func
ntoh16
(
v
be16
)
uint16
{
func
ntoh16
(
v
be16
)
uint16
{
b
:=
(
*
[
2
]
byte
)(
unsafe
.
Pointer
(
&
v
))
b
:=
(
*
[
2
]
byte
)(
unsafe
.
Pointer
(
&
v
))
return
binary
.
BigEndian
.
Uint16
(
b
[
:
])
return
binary
.
BigEndian
.
Uint16
(
b
[
:
])
//return uint16(v._1) | uint16(v._0)<<8 XXX gives bad code
}
}
// bad
// bad
(unnecessary MOVBLZX AL, AX + shifts not combined into ROLW $8)
func
ntoh16_1
(
v
be16
)
uint16
{
// XXX why?
//return uint16(v._1) | uint16(v._0)<<8
func
_ntoh16_1
(
v
be16
)
uint16
{
return
uint16
(
v
.
_
0
)
<<
8
|
uint16
(
v
.
_1
)
return
uint16
(
v
.
_
1
)
|
uint16
(
v
.
_0
)
<<
8
}
}
// good
// good
...
@@ -69,14 +68,31 @@ func hton16(v uint16) be16 {
...
@@ -69,14 +68,31 @@ func hton16(v uint16) be16 {
return
be16
{
byte
(
v
>>
8
),
byte
(
v
)}
return
be16
{
byte
(
v
>>
8
),
byte
(
v
)}
}
}
// good
func
_hton16_1
(
v
uint16
)
(
r
be16
)
{
r
.
_0
=
byte
(
v
>>
8
)
r
.
_1
=
byte
(
v
)
return
r
}
// bad (partly (!?) preclears r)
func
_hton16_2
(
v
uint16
)
(
r
be16
)
{
b
:=
(
*
[
2
]
byte
)(
unsafe
.
Pointer
(
&
r
))
binary
.
BigEndian
.
PutUint16
(
b
[
:
],
v
)
return
r
}
// ----------------------------------------
// good
// good
func
ntoh32
(
v
be32
)
uint32
{
func
ntoh32
(
v
be32
)
uint32
{
b
:=
(
*
[
4
]
byte
)(
unsafe
.
Pointer
(
&
v
))
b
:=
(
*
[
4
]
byte
)(
unsafe
.
Pointer
(
&
v
))
return
binary
.
BigEndian
.
Uint32
(
b
[
:
])
return
binary
.
BigEndian
.
Uint32
(
b
[
:
])
}
}
// baaaadd
// baaaadd (unnecessary MOVBLZX AL, AX + shifts not combined into BSWAPL)
func
ntoh32_1
(
v
be32
)
uint32
{
// XXX why?
func
_ntoh32_1
(
v
be32
)
uint32
{
return
uint32
(
v
.
_3
)
|
uint32
(
v
.
_2
)
<<
8
|
uint32
(
v
.
_1
)
<<
16
|
uint32
(
v
.
_0
)
<<
24
return
uint32
(
v
.
_3
)
|
uint32
(
v
.
_2
)
<<
8
|
uint32
(
v
.
_1
)
<<
16
|
uint32
(
v
.
_0
)
<<
24
}
}
...
@@ -85,8 +101,9 @@ func hton32(v uint32) be32 {
...
@@ -85,8 +101,9 @@ func hton32(v uint32) be32 {
return
be32
{
byte
(
v
>>
24
),
byte
(
v
>>
16
),
byte
(
v
>>
8
),
byte
(
v
)}
return
be32
{
byte
(
v
>>
24
),
byte
(
v
>>
16
),
byte
(
v
>>
8
),
byte
(
v
)}
}
}
// good
// good
func
hton32_1
(
v
uint32
)
(
r
be32
)
{
func
_
hton32_1
(
v
uint32
)
(
r
be32
)
{
r
.
_0
=
byte
(
v
>>
24
)
r
.
_0
=
byte
(
v
>>
24
)
r
.
_1
=
byte
(
v
>>
16
)
r
.
_1
=
byte
(
v
>>
16
)
r
.
_2
=
byte
(
v
>>
8
)
r
.
_2
=
byte
(
v
>>
8
)
...
@@ -101,6 +118,8 @@ func hton32_2(v uint32) (r be32) {
...
@@ -101,6 +118,8 @@ func hton32_2(v uint32) (r be32) {
return
r
return
r
}
}
// ----------------------------------------
// good
// good
func
ntoh64
(
v
be64
)
uint64
{
func
ntoh64
(
v
be64
)
uint64
{
b
:=
(
*
[
8
]
byte
)(
unsafe
.
Pointer
(
&
v
))
b
:=
(
*
[
8
]
byte
)(
unsafe
.
Pointer
(
&
v
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment