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
b4170a64
Commit
b4170a64
authored
Dec 11, 2016
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
X checkpoint on current state of ntoh & hton
parent
1d0e0f99
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
18 deletions
+15
-18
t/neo/packed.go
t/neo/packed.go
+15
-18
No files found.
t/neo/packed.go
View file @
b4170a64
...
...
@@ -35,9 +35,14 @@ type be64 struct { _0, _1, _2, _3, _4, _5, _6, _7 byte }
// XXX naming ntoh{s,l,q} ?
func
ntoh16
(
v
be16
)
uint16
{
return
_ntoh16_0
(
v
)
// XXX becomes bad - why?
}
func
ntoh16
(
v
be16
)
uint16
{
return
_ntoh16_0
(
v
)
}
// FIXME becomes bad - why??? !!!
func
hton16
(
v
uint16
)
be16
{
return
_hton16_0
(
v
)
}
// good
func
ntoh32
(
v
be32
)
uint32
{
return
_ntoh32_0
(
v
)
}
// FIXME becomes bad - why??? !!!
func
hton32
(
v
uint32
)
be32
{
return
_hton32_0
(
v
)
}
// good
func
ntoh64
(
v
be64
)
uint64
{
return
_ntoh64_0
(
v
)
}
// bad: on-stack temp
//func ntoh64(v be64) uint64 { return _ntoh64_1(v) } // bad: on-stack temp
//func hton64(v uint64) be64 { return _hton64_0(v) } // bad: on-stack temp
func
hton64
(
v
uint64
)
be64
{
return
_hton64_1
(
v
)
}
// bad: pre-clears r (here twice)
// ----------------------------------------
...
...
@@ -47,6 +52,7 @@ func _ntoh16_0(v be16) uint16 {
return
binary
.
BigEndian
.
Uint16
(
b
[
:
])
}
// bad (unnecessary MOVBLZX AL, AX + shifts not combined into ROLW $8)
// XXX why?
func
_ntoh16_1
(
v
be16
)
uint16
{
...
...
@@ -54,7 +60,7 @@ func _ntoh16_1(v be16) uint16 {
}
// good
func
hton16
(
v
uint16
)
be16
{
func
_hton16_0
(
v
uint16
)
be16
{
return
be16
{
byte
(
v
>>
8
),
byte
(
v
)}
}
...
...
@@ -75,7 +81,7 @@ func _hton16_2(v uint16) (r be16) {
// ----------------------------------------
// good
func
ntoh32
(
v
be32
)
uint32
{
func
_ntoh32_0
(
v
be32
)
uint32
{
b
:=
(
*
[
4
]
byte
)(
unsafe
.
Pointer
(
&
v
))
return
binary
.
BigEndian
.
Uint32
(
b
[
:
])
}
...
...
@@ -87,7 +93,7 @@ func _ntoh32_1(v be32) uint32 {
}
// good
func
hton32
(
v
uint32
)
be32
{
func
_hton32_0
(
v
uint32
)
be32
{
return
be32
{
byte
(
v
>>
24
),
byte
(
v
>>
16
),
byte
(
v
>>
8
),
byte
(
v
)}
}
...
...
@@ -111,7 +117,7 @@ func hton32_2(v uint32) (r be32) {
// ----------------------------------------
// good
func
ntoh64
(
v
be64
)
uint64
{
func
_ntoh64_0
(
v
be64
)
uint64
{
b
:=
(
*
[
8
]
byte
)(
unsafe
.
Pointer
(
&
v
))
return
binary
.
BigEndian
.
Uint64
(
b
[
:
])
}
...
...
@@ -123,13 +129,13 @@ func _ntoh64_1(v be64) uint64 {
}
// baad (+local temp; r = temp)
func
hton64
(
v
uint64
)
be64
{
func
_hton64_0
(
v
uint64
)
be64
{
return
be64
{
byte
(
v
>>
56
),
byte
(
v
>>
48
),
byte
(
v
>>
40
),
byte
(
v
>>
32
),
byte
(
v
>>
24
),
byte
(
v
>>
16
),
byte
(
v
>>
8
),
byte
(
v
)}
}
// bad (pre-clears r)
func
hton64_1
(
v
uint64
)
(
r
be64
)
{
func
_
hton64_1
(
v
uint64
)
(
r
be64
)
{
r
.
_0
=
byte
(
v
>>
56
)
r
.
_1
=
byte
(
v
>>
48
)
r
.
_2
=
byte
(
v
>>
40
)
...
...
@@ -154,12 +160,3 @@ func hton64_3(v uint64) (r be64) {
*
(
*
uint64
)(
unsafe
.
Pointer
(
&
r
))
=
binary
.
BigEndian
.
Uint64
(
b
[
:
])
return
}
type
A
struct
{
z
be16
}
func
zzz
(
a
*
A
,
v
uint16
)
{
a
.
z
=
hton16
(
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