// parallel square root // sm basic building block is a subtractor multiplexer // if u=0 then return x otherwise return x-y taking into account borrow define sm(y, u, x, b, bout, dout) circuits bout<=(~x&y&b) |(x&y&b)|(~x&y&~b)|(~x&~y&b) after 1ns; dout<=(((~x&y&~b)|(x&y&b)|(~x&~y&b)|(x&~y&~b))&u)|(x&~u) after 1ns; end circuits; end sm; // 8 bit input sqrt gives 4 bits out define sqrt8(p[8], u[4]) signal b3[1]; signal b2[3]; signal b1[4]; signal b0[5]; signal x3[8]; signal x2[8]; signal x1[7]; signal nc; // no connection, junk output, could use tailored sm signal ubar[4]; circuits u[0]<=~ubar[0] after 1ns; u[1]<=~ubar[1] after 1ns; u[2]<=~ubar[2] after 1ns; u[3]<=~ubar[3] after 1ns; b36 use sm(#b1, u[3], p[6], #b0, b3[0], x3[6]); b37 use sm(#b0, u[3], p[7], b3[0], ubar[3], x3[7]); b24 use sm(#b1, u[2], p[4], #b0, b2[0], x2[4]); b25 use sm(#b0, u[2], p[5], b2[0], b2[1], x2[5]); b26 use sm(u[3], u[2], x3[6], b2[1], b2[2], x2[6]); b27 use sm(#b0, #b0, x3[7], b2[2], ubar[2], x2[7]); b12 use sm(#b1, u[1], p[2], #b0, b1[0], x1[2]); b13 use sm(#b0, u[1], p[3], b1[0], b1[1], x1[3]); b14 use sm(u[2], u[1], x2[4], b1[1], b1[2], x1[4]); b15 use sm(u[3], u[1], x2[5], b1[2], b1[3], x1[5]); b16 use sm(#b0, #b0, x2[6], b1[3], ubar[1], x1[6]); b00 use sm(#b1, #b0, p[0], #b0, b0[0], nc); b01 use sm(#b0, #b0, p[1], b0[0], b0[1], nc); b02 use sm(u[1], #b0, x1[2], b0[1], b0[2], nc); b03 use sm(u[2], #b0, x1[3], b0[2], b0[3], nc); b04 use sm(u[3], #b0, x1[4], b0[3], b0[4], nc); b05 use sm(#b0, #b0, x1[5], b0[4], ubar[0], nc); end circuits; end sqrt8; signal p[8]<=#b00010000; signal u[4]; circuits s8 use sqrt8(p, u); end circuits;