How to use the model from Matlab

% The source code needs to be downloaded first:
websave("mex_evoapprox.c","https://ehw.fit.vutbr.cz/evoapproxlib/mex_evoapprox.c");
websave("mul16u_9DU.c","https://raw.githubusercontent.com/ehw-fit/approxlib/v1.2022/multiplers/16x16_unsigned/pareto_pwr_mse/mul16u_9DU.c");
% Then, the MEX function mul16u_9DU can be compiled:
mex mex_evoapprox.c mul16u_9DU.c -DEXTFUN=mul16u_9DU -output mul16u_9DU;
% Optionally, path to GCC compiler can be specified:
%mex GCC='/usr/local/bin/gcc-6.3' mex_evoapprox.c mul16u_9DU.c -DEXTFUN=mul16u_9DU -output mul16u_9DU;

% Finally, the MEX function can be called in your Matlab code as follows:
mul16u_9DU(123,210) % 123 * 210
mul16u_9DU([1,2,3,4,5],[10,20,30,40,50]) % 1*10 2*20 3*30 4*40 5*50

%ESTIMATE ERROR metrics:
BW = 16 %bit-width
SAMPLES = 10000000
inputs = floor((2^BW-1).*rand(2,SAMPLES)); %randomly generated input vectors

req = inputs(1,:).*inputs(2,:); %exact multiplication
res = mul16u_9DU(inputs(1,:),inputs(2,:));

ED = req - res; %error with respect to the `req`
ep=sum(ED~=0)/length(ED) % error probability
wce=max(abs(ED)) % worst-case error
nwce=max(abs(ED))/(2^(BW+BW)) % normalized worst-case error (multipliers)
nwce=max(abs(ED))/(2^(BW+1)) % normalized worst-case error (adders)
mae=mean(abs(ED)) % mean error distance
mse=mean(ED.^2) % mean square error