FPGA 算法实战手册(续)
从第 13 章查找表开方处继续// 用高位做地址查表 always @(posedge clk) begin sqrt_out = sqrt_table[din[IN_W-1 -: LUT_AW]]; end endmodule // 资源:1 BRAM(256×8) // 延迟:1 拍 // 精度:取决于 LUT 大小,256 点 → ~8 bit 精度13.1.3 Newton-Raphson 开方(高精度)// Newton-Raphson 迭代:x_{n+1} = 0.5 × (x_n + S/x_n) // 收敛速度:每次迭代精度翻倍(二次收敛) module sqrt_newton #( parameter W = 32 // Q16.16 格式 ) ( input wire clk, input wire rst_n, input wire start, input wire [W-1:0] din, // Q16.16 无符号 output reg [W/2-1:0] sqrt_out, // Q8.8 output reg done ); // 状态机 localparam IDLE = 0, INIT = 1, ITER = 2, DONE_S = 3; reg [1:0]