text stringlengths 12 786k |
|---|
let immediate i = i |> Targetint_32_64 . of_string |> Targetint_31_63 . Imm . of_targetint |> Targetint_31_63 . int |
let float f = f |> Numeric_types . Float_by_bit_pattern . create |
let rec value_kind_with_subkind ( k : Fexpr . kind_with_subkind ) : Flambda_kind . With_subkind . t = let module KWS = Flambda_kind . With_subkind in match k with | Any_value -> KWS . any_value | Block { tag ; fields } -> KWS . block tag ( List . map value_kind_with_subkind fields ) ... |
let value_kind : Fexpr . kind -> Flambda_kind . t = function | Value -> Flambda_kind . value | Naked_number naked_number_kind -> begin match naked_number_kind with | Naked_immediate -> Flambda_kind . naked_immediate | Naked_float -> Flambda_kind . naked_float | Naked_int32 -> Flambda_kind . nak... |
let value_kind_with_subkind_opt : Fexpr . kind_with_subkind option -> Flambda_kind . With_subkind . t = function | Some kind -> value_kind_with_subkind kind | None -> Flambda_kind . With_subkind . any_value |
let arity a = Flambda_arity . With_subkinds . create ( List . map value_kind_with_subkind a ) |
let const ( c : Fexpr . const ) : Reg_width_const . t = match c with | Tagged_immediate i -> Reg_width_const . tagged_immediate ( i |> immediate ) | Naked_immediate i -> Reg_width_const . naked_immediate ( i |> immediate ) | Naked_float f -> Reg_width_const . naked_float ( f |> float... |
let rec rec_info env ( ri : Fexpr . rec_info ) : Rec_info_expr . t = let module US = Rec_info_expr . Unrolling_state in match ri with | Depth d -> Rec_info_expr . const ~ depth ( : Finite d ) ~ unrolling : US . not_unrolling | Infinity -> Rec_info_expr . const ~ depth : Infinity ~ unr... |
let coercion env ( co : Fexpr . coercion ) : Coercion . t = match co with | Id -> Coercion . id | Change_depth { from ; to_ } -> Coercion . change_depth ~ from ( : rec_info env from ) ~ to_ ( : rec_info env to_ ) |
let rec simple env ( s : Fexpr . simple ) : Simple . t = match s with | Var { txt = v ; loc } -> begin match VM . find_opt v env . variables with | None -> Misc . fatal_errorf " Unbound variable % s : % a " v print_scoped_location loc | Some var -> Simple . var var end | Const c ... |
let name env ( s : Fexpr . name ) : Name . t = match s with | Var { txt = v ; loc } -> begin match VM . find_opt v env . variables with | None -> Misc . fatal_errorf " Unbound variable % s : % a " v print_scoped_location loc | Some var -> Name . var var end | Symbol sym -> Name ... |
let field_of_block env ( v : Fexpr . field_of_block ) : Field_of_static_block . t = match v with | Symbol s -> Symbol ( get_symbol env s ) | Tagged_immediate i -> let i = Targetint_32_64 . of_string i in Tagged_immediate ( Targetint_31_63 . int ( Targetint_31_63 . Imm . of_targetint i ) ... |
let or_variable f env ( ov : _ Fexpr . or_variable ) : _ Or_variable . t = match ov with | Const c -> Const ( f c ) | Var v -> Var ( find_var env v , Debuginfo . none ) |
let unop env ( unop : Fexpr . unop ) : Flambda_primitive . unary_primitive = match unop with | Array_length -> Array_length | Box_number bk -> Box_number ( bk , Heap ) | Unbox_number bk -> Unbox_number bk | Tag_immediate -> Tag_immediate | Untag_immediate -> Untag_immediate | Get_tag -> Get... |
let infix_binop ( binop : Fexpr . infix_binop ) : Flambda_primitive . binary_primitive = match binop with | Int_arith o -> Int_arith ( Tagged_immediate , o ) | Int_comp c -> Int_comp ( Tagged_immediate , Signed , c ) | Int_shift s -> Int_shift ( Tagged_immediate , s ) | Float_arith... |
let binop ( binop : Fexpr . binop ) : Flambda_primitive . binary_primitive = match binop with | Array_load ( ak , mut ) -> Array_load ( ak , mut ) | Block_load ( access_kind , mutability ) -> let size s : _ Or_unknown . t = match s with | None -> Unknown | Some s -> Known ( s... |
let ternop ( ternop : Fexpr . ternop ) : Flambda_primitive . ternary_primitive = match ternop with Array_set ( ak , ia ) -> Array_set ( ak , ia ) |
let convert_block_shape ~ num_fields = List . init num_fields ( fun _field : Flambda_primitive . Block_of_values_field . t -> Any_value ) |
let varop ( varop : Fexpr . varop ) n : Flambda_primitive . variadic_primitive = match varop with | Make_block ( tag , mutability ) -> let shape = convert_block_shape ~ num_fields : n in let kind : Flambda_primitive . Block_kind . t = Values ( Tag . Scannable . create_exn tag , shape... |
let prim env ( p : Fexpr . prim ) : Flambda_primitive . t = match p with | Unary ( op , arg ) -> Unary ( unop env op , simple env arg ) | Binary ( op , a1 , a2 ) -> Binary ( binop op , simple env a1 , simple env a2 ) | Ternary ( op , a1 , a2 , a3 ) -> Ternary ( t... |
let convert_recursive_flag ( flag : Fexpr . is_recursive ) : Recursive . t = match flag with Recursive -> Recursive | Nonrecursive -> Non_recursive |
let defining_expr env ( named : Fexpr . named ) : Flambda . Named . t = match named with | Simple s -> Flambda . Named . create_simple ( simple env s ) | Prim p -> let p = prim env p in Flambda . Named . create_prim p Debuginfo . none | Rec_info ri -> let ri = rec_info env ri in Flamb... |
let set_of_closures env fun_decls value_slots = let fun_decls : Function_declarations . t = let translate_fun_decl ( fun_decl : Fexpr . fun_decl ) : Function_slot . t * Code_id . t = let code_id = find_code_id env fun_decl . code_id in let function_slot = fun_decl . function_slot |> Option . ... |
let apply_cont env ( { cont ; args ; trap_action } : Fexpr . apply_cont ) = let trap_action : Trap_action . t option = trap_action |> Option . map ( fun ( ta : Fexpr . trap_action ) : Trap_action . t -> match ta with | Push { exn_handler } -> let exn_handler , _ = find_cont... |
let continuation_sort ( sort : Fexpr . continuation_sort ) : Continuation . Sort . t = match sort with | Normal -> Normal_or_exn | Exn -> Normal_or_exn | Define_root_symbol -> Define_root_symbol |
let rec expr env ( e : Fexpr . expr ) : Flambda . Expr . t = match e with | Let { bindings = [ ] ; _ } -> assert false | Let { bindings = { defining_expr = Closure _ ; _ } :: _ as bindings ; value_slots ; body } -> let binding_to_var_and_closure_binding : Fexpr . let_... |
let bind_all_code_ids env ( unit : Fexpr . flambda_unit ) = let rec go env ( e : Fexpr . expr ) = match e with | Let_symbol { bindings ; body ; _ } -> let env = List . fold_left ( fun env ( binding : Fexpr . symbol_binding ) -> match binding with | Code { id ; _ } | Dele... |
let conv ~ symbol_for_global ~ module_ident ( fexpr : Fexpr . flambda_unit ) : Flambda_unit . t = let module_symbol = symbol_for_global ? comp_unit : None ( Ident . create_persistent ( Ident . name module_ident ) ) in let env = init_env ( ) in let { done_continuation = return_continu... |
let tpi = 2 . 0 . * pi |
let fft px py np = let i = ref 2 in let m = ref 1 in while ( ! i < np ) do i := ! i + ! i ; m := ! m + 1 done ; let n = ! i in if n <> np then begin for i = np + 1 to n do px . ( i ) <- 0 . 0 ; py . ( i ) <- 0 . 0 done ; print_string " Use " ; print_int n ; ... |
let test np = print_int np ; print_string " . . . " ; flush stdout ; let enp = float np in let npm = np / 2 - 1 in let pxr = Array . create ( np + 2 ) 0 . 0 and pxi = Array . create ( np + 2 ) 0 . 0 in let t = pi . / enp in pxr . ( 1 ) <- ( enp . - 1 . ... |
let _ = let np = ref 16 in for i = 1 to 16 do test ! np ; np := ! np * 2 done |
let tpi = 2 . 0 . * pi |
let fft ( px : ( float , float64_elt , c_layout ) Array1 . t ) ( py : ( float , float64_elt , c_layout ) Array1 . t ) np = let i = ref 2 in let m = ref 1 in while ( ! i < np ) do i := ! i + ! i ; m := ! m + 1 done ; let n = ! i in if n <> np then begin for i = np... |
let test np = print_int np ; print_string " . . . " ; flush stdout ; let enp = float np in let npm = np / 2 - 1 in let pxr = Array1 . create float64 c_layout ( np + 2 ) and pxi = Array1 . create float64 c_layout ( np + 2 ) in let t = pi . / enp in pxr . { 1 } <- ( ... |
let _ = let np = ref 16 in for i = 1 to 13 do test ! np ; np := ! np * 2 done |
let rec fib m = if m = 0 then 1 else if m = 1 then 1 else fib ( m - 1 ) + fib ( m - 2 ) |
let rec fib_cps ( m , cnt ) = if m = 0 then cnt 1 else if m = 1 then cnt 1 else fib_cps ( m - 1 , fun a -> fib_cps ( m - 2 , fun b -> cnt ( a + b ) ) ) |
let rec fib_cps_v2 ( m , cnt ) = if m = 0 then cnt 1 else if m = 1 then cnt 1 else let cnt2 a b = cnt ( a + b ) in let cnt1 a = fib_cps_v2 ( m - 2 , cnt2 a ) in fib_cps_v2 ( m - 1 , cnt1 ) |
let id ( x : int ) = x |
let fib_1 m = fib_cps_v2 ( m , id ) |
type cnt = | ID | CNT1 of int * cnt | CNT2 of int * cnt |
let rec apply_cnt = function | ( ID , a ) -> a | ( CNT1 ( m , cnt ) , a ) -> fib_cps_dfc ( m - 2 , CNT2 ( a , cnt ) ) | ( CNT2 ( a , cnt ) , b ) -> apply_cnt ( cnt , a + b ) if m = 0 then apply_cnt ( cnt , 1 ) else if m = 1 then apply_cnt ( cnt , ... |
let fib_2 m = fib_cps_dfc ( m , ID ) |
type tag = | SUB2 of int | PLUS of int |
type tag_list_cnt = tag list |
let rec apply_tag_list_cnt = function | ( [ ] , a ) -> a | ( ( SUB2 m ) :: cnt , a ) -> fib_cps_dfc_tags ( m - 2 , ( PLUS a ) :: cnt ) | ( ( PLUS a ) :: cnt , b ) -> apply_tag_list_cnt ( cnt , a + b ) if m = 0 then apply_tag_list_cnt ( cnt , 1 ) else i... |
let fib_3 m = fib_cps_dfc_tags ( m , [ ] ) |
type state_type = | SUB1 | APPL |
type state = ( state_type * int * tag_list_cnt ) -> int |
let rec eval = function | ( SUB1 , 0 , cnt ) -> eval ( APPL , 1 , cnt ) | ( SUB1 , 1 , cnt ) -> eval ( APPL , 1 , cnt ) | ( SUB1 , m , cnt ) -> eval ( SUB1 , ( m - 1 ) , ( SUB2 m ) :: cnt ) | ( APPL , a , ( SUB2 m ) :: cnt ) -> eval ( ... |
let fib_4 m = eval ( SUB1 , m , [ ] ) |
let step = function | ( SUB1 , 0 , cnt ) -> ( APPL , 1 , cnt ) | ( SUB1 , 1 , cnt ) -> ( APPL , 1 , cnt ) | ( SUB1 , m , cnt ) -> ( SUB1 , ( m - 1 ) , ( SUB2 m ) :: cnt ) | ( APPL , a , ( SUB2 m ) :: cnt ) -> ( SUB1 , ( m - 2 )... |
let string_of_state_type = function | SUB1 -> " SUB1 " | APPL -> " APPL " |
let string_of_tag = function | SUB2 m -> " SUB2 " ^ ( string_of_int m ) | PLUS m -> " PLUS " ^ ( string_of_int m ) |
let rec string_of_tag_list_aux = function | [ ] -> " " | [ t ] -> ( string_of_tag t ) | t :: rest -> ( string_of_tag t ) ^ " , " ^ ( string_of_tag_list_aux rest ) |
let string_of_tag_list l = " [ " ^ ( string_of_tag_list_aux l ) ^ " ] " |
let print_state n ( t , m , cnt ) = print_string ( ( string_of_int n ) ^ " " |
let verbose = ref true |
let rec eval_steps n state = let _ = if ! verbose then print_state n state else ( ) in match state with | ( APPL , a , [ ] ) -> a | _ -> eval_steps ( n + 1 ) ( step state ) |
let fib_5 m = eval_steps 1 ( SUB1 , m , [ ] ) |
let fibs m = [ fib m ; fib_1 m ; fib_2 m ; fib_3 m ; fib_4 m ; fib_5 m ] |
type t = | Varint of Int64 . t | Fixed_64_bit of Int64 . t | Length_delimited of { offset : int ; length : int ; data : string ; } | Fixed_32_bit of Int32 . t |
let varint v = Varint v |
let fixed_32_bit v = Fixed_32_bit v |
let fixed_64_bit v = Fixed_64_bit v |
let length_delimited ( ? offset = 0 ) ? length data = let length = Option . value ~ default ( : String . length data - offset ) length in Length_delimited { offset ; length ; data } |
let pp : Format . formatter -> t -> unit = fun fmt -> function | Varint a0 -> ( Format . fprintf fmt " ( [ @< 2 > Field . Varint @ " ; ( Format . fprintf fmt " % LdL " ) a0 ; Format . fprintf fmt " ] ) " ) @ | Fixed_64_bit a0 -> ( Format . fprintf fmt " ( ... |
let show : t -> string = Format . asprintf " % a " pp |
type t = | Symbol of Symbol . t | Tagged_immediate of Targetint_31_63 . t | Dynamically_computed of Variable . t * Debuginfo . t type nonrec t = t let compare t1 t2 = match t1 , t2 with | Symbol s1 , Symbol s2 -> Symbol . compare s1 s2 | Tagged_immediate t1 , Tagged_immediate t2 -> Targetint_... |
let apply_renaming t renaming = match t with | Tagged_immediate _ -> t | Symbol symbol -> let symbol ' = Renaming . apply_symbol renaming symbol in if symbol == symbol ' then t else Symbol symbol ' | Dynamically_computed ( var , dbg ) -> let var ' = Renaming . apply_variable renaming var in... |
let free_names t = match t with | Dynamically_computed ( var , _dbg ) -> Name_occurrences . singleton_variable var Name_mode . normal | Symbol sym -> Name_occurrences . singleton_symbol sym Name_mode . normal | Tagged_immediate _ -> Name_occurrences . empty |
let all_ids_for_export t = match t with | Dynamically_computed ( var , _dbg ) -> Ids_for_export . add_variable Ids_for_export . empty var | Symbol sym -> Ids_for_export . add_symbol Ids_for_export . empty sym | Tagged_immediate _ -> Ids_for_export . empty |
let ram_wbr_safe capacity ~ write_port ~ read_port ~ ram_attributes = let open Signal in let collision = reg ( Reg_spec . create ~ clock : write_port . write_clock ( ) ) ~ enable : read_port . read_enable ( write_port . write_enable &: read_port . read_enable &: ( write_port . write_a... |
let capacity_and_used_bits showahead ram_capacity = let actual_capacity = if showahead then ram_capacity + 1 else ram_capacity in let used_bits = num_bits_to_represent actual_capacity in actual_capacity , used_bits ; ; |
let create ( ? showahead = false ) ( ? nearly_empty = 1 ) ? nearly_full ( ? overflow_check = true ) ( ? reset = Signal . empty ) ( ? underflow_check = true ) ( ? ram_attributes = [ Rtl_attribute . Vivado . Ram_style . block ] ) ? scope ( ) ~ capacity : ram_capaci... |
let create_classic_with_extra_reg ? nearly_empty ? nearly_full ? overflow_check ? reset ? underflow_check ? ram_attributes ? scope ( ) ~ capacity ~ clock ~ clear ~ wr ~ d ~ rd = let spec = Reg_spec . create ~ clock ~ clear ( ) in let fifo_valid = wire 1 in let middle_valid = wire 1 in let... |
let showahead_fifo_of_classic_fifo ( create_fifo : capacity : int -> write_clock : Signal . t -> read_clock : Signal . t -> clear : Signal . t -> wr : Signal . t -> d : Signal . t -> rd : Signal . t -> ( Signal . t , [ ` Classic ] ) Kinded_fifo . t ) = Staged . stage ( ... |
let create_showahead_from_classic ? nearly_empty ? nearly_full ? overflow_check ? reset ? underflow_check ? ram_attributes ? scope ( ) = let create_fifo ~ capacity ~ write_clock ~ read_clock ~ clear ~ wr ~ d ~ rd = assert ( Signal . equal write_clock read_clock ) ; create ~ showahead : fal... |
let create_showahead_with_extra_reg ? nearly_empty ? nearly_full ? overflow_check ? reset ? underflow_check ? ram_attributes ? scope ( ) ~ capacity ~ clock ~ clear ~ wr ~ d ~ rd = let spec = Reg_spec . create ~ clock ~ clear ( ) in let fifo_rd_en = wire 1 in let fifo = create ~ showahead ... |
module type Config = Fifo_intf . Config |
module With_interface ( Config : Config ) = struct let _actual_capacity , used_bits = capacity_and_used_bits Config . showahead Config . capacity ; ; module I = struct type ' a t = { clock : ' a ; clear : ' a ; wr : ' a ; d : ' a [ @ bits Config . data_width ] ; rd : ... |
module type Config = sig val data_width : int val capacity : int val showahead : bool end |
module T = struct type ' a t = { q : ' a ; full : ' a ; empty : ' a ; nearly_full : ' a ; nearly_empty : ' a ; used : ' a } [ @@ deriving sexp_of , hardcaml ] type ' a create_params = ? nearly_empty : int -> ? nearly_full : int -> ? overflow_check : bool -> ? rese... |
module Kinded_fifo = struct type ( ' a , ' b ) t = | Classic : ' a T . t -> ( ' a , [ ` Classic ] ) t | Showahead : ' a T . t -> ( ' a , [ ` Showahead ] ) t type ' a packed = T : ( ' a , ' b ) t -> ' a packed type create_classic = capacity : int ... |
module type S = sig include module type of T with type ' a t = ' a T . t module Kinded_fifo = Kinded_fifo val create : ? showahead : bool -> T . create_fifo val showahead_fifo_of_classic_fifo : Kinded_fifo . create_classic -> Kinded_fifo . create_showahead Staged . t val create_classic_with_extra... |
type result = | Same | Different | Unexpected_output | Error of string * int |
type ignore = { bytes : int ; lines : int } |
type tool = | External of { tool_name : string ; tool_flags : string ; result_of_exitcode : string -> int -> result } | Internal of ignore |
let cmp_result_of_exitcode commandline = function | 0 -> Same | 1 -> Different | exit_code -> ( Error ( commandline , exit_code ) ) |
let make_cmp_tool ~ ignore = Internal ignore |
let make_comparison_tool ( ? result_of_exitcode = cmp_result_of_exitcode ) name flags = External { tool_name = name ; tool_flags = flags ; result_of_exitcode } |
let default_comparison_tool = make_cmp_tool ~ ignore { : bytes = 0 ; lines = 0 } |
type filetype = Binary | Text |
type files = { filetype : filetype ; reference_filename : string ; output_filename : string ; } |
let last_is_cr s = let l = String . length s in l > 0 && s . [ l - 1 ] = ' \ r ' |
let last_char ic = seek_in ic ( in_channel_length ic - 1 ) ; input_char ic |
let line_seq_of_in_channel ~ normalise ic = let normalise = if normalise then fun s -> if last_is_cr s then String . sub s 0 ( String . length s - 1 ) else raise Exit else Fun . id in let rec read_line last ( ) = match input_line ic with | line -> Seq . Cons ( normalise last ^ " \ n " ... |
let compare_text_files ignored_lines file1 file2 = Sys . with_input_file ~ bin : true file2 @@ fun ic2 -> let ( crlf_endings2 , line2 , reached_end_file2 ) = let rec loop crlf_endings2 k = match input_line ic2 with | line -> let crlf_endings2 = crlf_endings2 && last_is_cr line in if k = 0 then ( ... |
let really_input_up_to ic = let block_size = 8192 in let buf = Bytes . create block_size in let rec read pos = let bytes_read = input ic buf pos ( block_size - pos ) in let new_pos = pos + bytes_read in if bytes_read = 0 || new_pos = block_size then new_pos else read new_pos in let bytes_read = read... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.