1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859(*
* Copyright (c) 2010-2011 Anil Madhavapeddy <anil@recoil.org>
* Copyright (c) 2012 Citrix Systems, Inc
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*)openRingmoduleRing=structmoduleLayout=struct(* memory layout from the frontend's point of view *)(*
type ring = {
output: uint8_t [@len 1024];
input: uint8_t [@len 1024];
(* (* unsafe to use these as they produce multi byte load/stores *)
output_cons: uint32_t;
output_prod: uint32_t;
input_cons: uint32_t;
input_prod: uint32_t;
*)
} [@@little_endian]
*)letget_ring_outputc=Cstruct.subc01024letget_ring_inputc=Cstruct.subc10241024let_output_cons=2048let_output_prod=_output_cons+4let_input_cons=_output_prod+4let_input_prod=_input_cons+4letget_ring_output_consc=Int32.of_int(unsafe_load_uint32c_output_cons)letget_ring_output_prodc=Int32.of_int(unsafe_load_uint32c_output_prod)letget_ring_input_consc=Int32.of_int(unsafe_load_uint32c_input_cons)letget_ring_input_prodc=Int32.of_int(unsafe_load_uint32c_input_prod)letset_ring_output_conscx=unsafe_save_uint32c_output_cons(Int32.to_intx)letset_ring_output_prodcx=unsafe_save_uint32c_output_prod(Int32.to_intx)letset_ring_input_conscx=unsafe_save_uint32c_input_cons(Int32.to_intx)letset_ring_input_prodcx=unsafe_save_uint32c_input_prod(Int32.to_intx)endletinit=zeroletto_debug_mapt=["input-cons",Int32.to_string(Layout.get_ring_input_const);"input-prod",Int32.to_string(Layout.get_ring_input_prodt);"output-cons",Int32.to_string(Layout.get_ring_output_const);"output-prod",Int32.to_string(Layout.get_ring_output_prodt);]moduleFront=Pipe(Layout)moduleBack=Pipe(Reverse(Layout))end