Permalink
Browse files

uint16 arithmetic is faster

  • Loading branch information...
Reperator committed Jan 29, 2019
1 parent 44d4ccb commit 47b8136cc8abd0106d37d13e780d6d0216cd6c59
Showing with 11 additions and 8 deletions.
  1. +7 −5 lib/rXD.ml
  2. +4 −3 lib/tXD.ml
@@ -17,7 +17,8 @@ type t = Cstruct.t
hdr_info : uint16;
ip_id : uint16;
csum : uint16;
status_error : uint32;
status : uint16; (* Cstruct.uint16 is unboxed and therefore faster *)
error : uint16;
length : uint16;
vlan : uint16
} [@@little_endian]
@@ -28,10 +29,11 @@ let () = assert (sizeof_adv_rxd_wb = sizeof_adv_rxd_read)
let sizeof = sizeof_adv_rxd_wb

let dd t =
let status = get_adv_rxd_wb_status_error t in
match Int32.logand status 0b11l with (* check stat_dd and stat_eop *)
| 0b11l -> true
| 0b01l -> error "jumbo frames are not supported"
let status = get_adv_rxd_wb_status t in
let stat_dd, stat_eop = 0b01, 0b10 in
match status land (stat_dd lor stat_eop) with
| 0b11 -> true
| 0b01 -> error "jumbo frames are not supported"
| _ -> false

let size t = get_adv_rxd_wb_length t
@@ -16,7 +16,8 @@ type t = Cstruct.t
type adv_tx_wb = {
rsvd : uint64;
nxtseq_seed : uint32;
status : uint32
status : uint16; (* Cstruct.uint16 is unboxed and therefore faster *)
more_rsvd : uint16
} [@@little_endian]
]

@@ -25,8 +26,8 @@ let () = assert (sizeof_adv_tx_wb = sizeof_adv_tx_read)
let sizeof = sizeof_adv_tx_wb

let dd t =
let stat_dd = 0b1l in
Int32.logand (get_adv_tx_wb_status t) stat_dd <> 0l
let stat_dd = 0b1 in
(get_adv_tx_wb_status t) land stat_dd <> 0

let split num cs =
let len = Cstruct.len cs in

0 comments on commit 47b8136

Please sign in to comment.