module __hfloat16__from_float32( input wire [31:0] f32, output wire [15:0] out ); function automatic dynamic_bit_slice_w1_24b_32b (input reg [23:0] operand, input reg [31:0] start); reg [24:0] extended_operand; begin extended_operand = {1'h0, operand}; dynamic_bit_slice_w1_24b_32b = start >= 5'h18 ? 1'h0 : extended_operand[start +: 1]; end endfunction function automatic [9:0] dynamic_bit_slice_w10_11b_32b (input reg [10:0] operand, input reg [31:0] start); reg [20:0] extended_operand; begin extended_operand = {10'h000, operand}; dynamic_bit_slice_w10_11b_32b = start >= 4'hb ? 10'h000 : extended_operand[start +: 10]; end endfunction function automatic [4:0] priority_sel_5b_2way (input reg [1:0] sel, input reg [4:0] case0, input reg [4:0] case1, input reg [4:0] default_value); begin casez (sel) 2'b?1: begin priority_sel_5b_2way = case0; end 2'b10: begin priority_sel_5b_2way = case1; end 2'b00: begin priority_sel_5b_2way = default_value; end default: begin // Propagate X priority_sel_5b_2way = 5'dx; end endcase end endfunction function automatic priority_sel_1b_2way (input reg [1:0] sel, input reg case0, input reg case1, input reg default_value); begin casez (sel) 2'b?1: begin priority_sel_1b_2way = case0; end 2'b10: begin priority_sel_1b_2way = case1; end 2'b00: begin priority_sel_1b_2way = default_value; end default: begin // Propagate X priority_sel_1b_2way = 1'dx; end endcase end endfunction wire [7:0] f32_bexp__1; wire [3:0] add_2072; wire [7:0] neg_2075; wire [8:0] sign_ext_2076; wire [22:0] f32_fraction__1; wire [8:0] add_2079; wire literal_2082; wire [31:0] f32irst_lost_bit_idx__2; wire [7:0] add_2086; wire literal_2088; wire [8:0] concat_2091; wire [23:0] concat_2092; wire [8:0] literal_2095; wire round_bit__1; wire sticky__1; wire [9:0] truncated_frac; wire [8:0] add_2103; wire [10:0] f32ull_frac__2; wire [31:0] right_shift_cnt; wire [8:0] literal_2110; wire round_up__1; wire round_bit; wire sticky; wire [9:0] unrounded_subnormal_frac; wire [7:0] literal_2119; wire [9:0] subnormal_frac; wire round_up; wire eq_2125; wire eq_2126; wire renormalize; wire ugt_2129; wire rounds_to_normal; wire [7:0] f32_cast_bexp__2; wire [7:0] literal_2134; wire [7:0] EXPR_MASK; wire [7:0] uexp; wire [7:0] TO_BIAS; wire eq_2141; wire eq_2146; wire sgt_2147; wire [4:0] BIAS; wire eq_2153; wire eq_2154; wire sle_2155; wire [9:0] f32_cast_fraction__1; wire [4:0] add_2159; wire [4:0] literal_2169; wire nor_2171; wire [9:0] and_2172; wire nor_2173; wire [4:0] literal_2175; wire [4:0] x_bexp__1; wire f32_sign__2; wire [7:0] uexp__1; wire [7:0] literal_2185; wire [9:0] concat_2196; wire and_2190; wire x_sign; assign f32_bexp__1 = f32[30:23]; assign add_2072 = f32_bexp__1[7:4] + 4'h9; assign neg_2075 = -{add_2072, f32_bexp__1[3:0]}; assign sign_ext_2076 = {{1{neg_2075[7]}}, neg_2075}; assign f32_fraction__1 = f32[22:0]; assign add_2079 = sign_ext_2076 + 9'h00d; assign literal_2082 = 1'h0; assign f32irst_lost_bit_idx__2 = {{23{add_2079[8]}}, add_2079}; assign add_2086 = sign_ext_2076[8:1] + 8'h07; assign literal_2088 = 1'h1; assign concat_2091 = {add_2086, neg_2075[0]}; assign concat_2092 = {literal_2088, f32_fraction__1}; assign literal_2095 = 9'h018; assign round_bit__1 = dynamic_bit_slice_w1_24b_32b(concat_2092, f32irst_lost_bit_idx__2); assign sticky__1 = ~({literal_2082, ~f32_fraction__1} | (f32irst_lost_bit_idx__2 >= 32'h0000_0018 ? 24'h00_0000 : 24'hff_ffff << f32irst_lost_bit_idx__2)) != 24'h00_0000; assign truncated_frac = f32_fraction__1[22:13]; assign add_2103 = sign_ext_2076 + 9'h001; assign f32ull_frac__2 = {literal_2088, truncated_frac}; assign right_shift_cnt = {{23{add_2103[8]}}, add_2103}; assign literal_2110 = 9'h000; assign round_up__1 = round_bit__1 & sticky__1 | round_bit__1 & concat_2091 < literal_2095 & dynamic_bit_slice_w1_24b_32b(concat_2092, {{23{concat_2091[8]}}, concat_2091}); assign round_bit = f32_fraction__1[12]; assign sticky = f32_fraction__1[11:0] != 12'h000; assign unrounded_subnormal_frac = dynamic_bit_slice_w10_11b_32b(f32ull_frac__2, right_shift_cnt); assign literal_2119 = 8'h00; assign subnormal_frac = unrounded_subnormal_frac + {literal_2110, round_up__1}; assign round_up = round_bit & sticky | round_bit & f32_fraction__1[13]; assign eq_2125 = neg_2075 == literal_2119; assign eq_2126 = subnormal_frac == 10'h000; assign renormalize = round_up & (&truncated_frac); assign ugt_2129 = add_2103 > 9'h00b; assign rounds_to_normal = eq_2125 & eq_2126; assign f32_cast_bexp__2 = f32_bexp__1 + {7'h00, renormalize}; assign literal_2134 = 8'h81; assign EXPR_MASK = 8'hff; assign uexp = f32_cast_bexp__2 + literal_2134; assign TO_BIAS = 8'h0f; assign eq_2141 = f32_bexp__1 == literal_2119; assign eq_2146 = f32_cast_bexp__2 == EXPR_MASK; assign sgt_2147 = $signed(uexp) > $signed(TO_BIAS); assign BIAS = 5'h0f; assign eq_2153 = f32_fraction__1 == 23'h00_0000; assign eq_2154 = f32_bexp__1 == EXPR_MASK; assign sle_2155 = $signed(uexp) <= $signed(8'hf1); assign f32_cast_fraction__1 = truncated_frac + {literal_2110, round_up}; assign add_2159 = uexp[4:0] + BIAS; assign literal_2169 = 5'h1f; assign nor_2171 = ~(~eq_2154 | eq_2153); assign and_2172 = (sle_2155 ? subnormal_frac & {10{~(ugt_2129 | rounds_to_normal)}} : f32_cast_fraction__1) & {10{~(eq_2146 | sgt_2147)}}; assign nor_2173 = ~(eq_2154 | eq_2141); assign literal_2175 = 5'h00; assign x_bexp__1 = priority_sel_5b_2way({eq_2141, eq_2154}, literal_2169, literal_2175, eq_2146 | sgt_2147 ? literal_2169 : (sle_2155 ? {4'h0, ~(ugt_2129 | ~eq_2125 | ~eq_2126)} : add_2159)); assign f32_sign__2 = f32[31:31]; assign uexp__1 = f32_bexp__1 + literal_2134; assign literal_2185 = 8'hf2; assign concat_2196 = {priority_sel_1b_2way({~(~eq_2141 | eq_2153) | eq_2141 & eq_2153 | eq_2154 & eq_2153, nor_2171}, literal_2088, literal_2082, and_2172[9]), and_2172[8:0] & {9{nor_2173}}}; assign and_2190 = nor_2173 & ~eq_2146 & ~sgt_2147 & sle_2155; assign x_sign = ~(nor_2171 | ~f32_sign__2); assign out = {x_sign, x_bexp__1, concat_2196 & {10{x_bexp__1 != literal_2175}}}; endmodule