Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neoppod
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Levin Zimmermann
neoppod
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
Hide 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 {
func
ntoh16
(
v
be16
)
uint16
{
b
:=
(
*
[
2
]
byte
)(
unsafe
.
Pointer
(
&
v
))
return
binary
.
BigEndian
.
Uint16
(
b
[
:
])
//return uint16(v._1) | uint16(v._0)<<8 XXX gives bad code
}
// bad
func
ntoh16_1
(
v
be16
)
uint16
{
//return uint16(v._1) | uint16(v._0)<<8
return
uint16
(
v
.
_
0
)
<<
8
|
uint16
(
v
.
_1
)
// bad
(unnecessary MOVBLZX AL, AX + shifts not combined into ROLW $8)
// XXX why?
func
_ntoh16_1
(
v
be16
)
uint16
{
return
uint16
(
v
.
_
1
)
|
uint16
(
v
.
_0
)
<<
8
}
// good
...
...
@@ -69,14 +68,31 @@ func hton16(v uint16) be16 {
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
func
ntoh32
(
v
be32
)
uint32
{
b
:=
(
*
[
4
]
byte
)(
unsafe
.
Pointer
(
&
v
))
return
binary
.
BigEndian
.
Uint32
(
b
[
:
])
}
// baaaadd
func
ntoh32_1
(
v
be32
)
uint32
{
// baaaadd (unnecessary MOVBLZX AL, AX + shifts not combined into BSWAPL)
// XXX why?
func
_ntoh32_1
(
v
be32
)
uint32
{
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 {
return
be32
{
byte
(
v
>>
24
),
byte
(
v
>>
16
),
byte
(
v
>>
8
),
byte
(
v
)}
}
// good
func
hton32_1
(
v
uint32
)
(
r
be32
)
{
func
_
hton32_1
(
v
uint32
)
(
r
be32
)
{
r
.
_0
=
byte
(
v
>>
24
)
r
.
_1
=
byte
(
v
>>
16
)
r
.
_2
=
byte
(
v
>>
8
)
...
...
@@ -101,6 +118,8 @@ func hton32_2(v uint32) (r be32) {
return
r
}
// ----------------------------------------
// good
func
ntoh64
(
v
be64
)
uint64
{
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