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("mul8_074.c","https://raw.githubusercontent.com/ehw-fit/evoapprox8b/master/multipliers_8/source_c/mul8_074.c");
% Then, the MEX function mul8_074 can be compiled:
mex mex_evoapprox.c mul8_074.c -DEXTFUN=mul8_074 -DOPTYPE=uint8_t -DRESTYPE=uint16_t -output mul8_074;
% Optionally, path to GCC compiler can be specified:
%mex GCC='/usr/local/bin/gcc-6.3' mex_evoapprox.c mul8_074.c -DEXTFUN=mul8_074 -DOPTYPE=uint8_t -DRESTYPE=uint16_t -output mul8_074;

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

%DETERMINE ERROR metrics:
BW = 8 %bit-width
allcombs = [0:1:2^(BW+BW)-1]; 
inputs = [floor(allcombs/2^BW); mod(allcombs,2^BW)]; %all possible input vectors

req = inputs(1,:).*inputs(2,:); %exact multiplication
res = mul8_074(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