#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <inttypes.h>
uint32_t multiply (uint16_t a, uint16_t b)
{
//uint16_t mask = 0b0000000000000001;
register uint32_t result = 0;
result += (a & ( (int16_t)( ( b & (1 << 0) ) << 15 ) ) / ( 1 << 15) ) << 0;
result += (a & ( (int16_t)( ( b & (1 << 1) ) << 14 ) ) / ( 1 << 15) ) << 1;
result += (a & ( (int16_t)( ( b & (1 << 2) ) << 13 ) ) / ( 1 << 15) ) << 2;
result += (a & ( (int16_t)( ( b & (1 << 3) ) << 12 ) ) / ( 1 << 15) ) << 3;
result += (a & ( (int16_t)( ( b & (1 << 4) ) << 11 ) ) / ( 1 << 15) ) << 4;
result += (a & ( (int16_t)( ( b & (1 << 5) ) << 10 ) ) / ( 1 << 15) ) << 5;
result += (a & ( (int16_t)( ( b & (1 << 6) ) << 9 ) ) / ( 1 << 15) ) << 6;
result += (a & ( (int16_t)( ( b & (1 << 7) ) << 8 ) ) / ( 1 << 15) ) << 7;
result += (a & ( (int16_t)( ( b & (1 << 8) ) << 7 ) ) / ( 1 << 15) ) << 8;
result += (a & ( (int16_t)( ( b & (1 << 9) ) << 6 ) ) / ( 1 << 15) ) << 9;
result += (a & ( (int16_t)( ( b & (1 <<10) ) << 5 ) ) / ( 1 << 15) ) << 10;
result += (a & ( (int16_t)( ( b & (1 <<11) ) << 4 ) ) / ( 1 << 15) ) << 11;
result += (a & ( (int16_t)( ( b & (1 <<12) ) << 3 ) ) / ( 1 << 15) ) << 12;
result += (a & ( (int16_t)( ( b & (1 <<13) ) << 2 ) ) / ( 1 << 15) ) << 13;
result += (a & ( (int16_t)( ( b & (1 <<14) ) << 1 ) ) / ( 1 << 15) ) << 14;
result += (a & ( (int16_t)( ( b & (1 <<15) ) << 0 ) ) / ( 1 << 15) ) << 15;
return result;
}
int main(void)
{
uint16_t a, b;
a = 0;
b = 0;
do
{
if (multiply(a, b) != a * b)
"ERROR:\n"
"my: %u\n"
"norm: %u\n"
"%hu * %hu\n"
"\n",
multiply(a, b), (a * b),a, b
);
if (UINT16_MAX == a)
{
b++;
}
a++;
//fprintf(stderr, "%hu * %hu\n", a, b);
} while ( ( a != 0 ) || (b != 0) );
fprintf(stderr
, "%"PRIu16
"* ""%"PRIu16
"\n", a
, b
);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <inttypes.h>
uint32_t multiply (uint16_t a, uint16_t b)
{
//uint16_t mask = 0b0000000000000001;
register uint32_t result = 0;
result += (a & ( (int16_t)( ( b & (1 << 0) ) << 15 ) ) / ( 1 << 15) ) << 0;
result += (a & ( (int16_t)( ( b & (1 << 1) ) << 14 ) ) / ( 1 << 15) ) << 1;
result += (a & ( (int16_t)( ( b & (1 << 2) ) << 13 ) ) / ( 1 << 15) ) << 2;
result += (a & ( (int16_t)( ( b & (1 << 3) ) << 12 ) ) / ( 1 << 15) ) << 3;
result += (a & ( (int16_t)( ( b & (1 << 4) ) << 11 ) ) / ( 1 << 15) ) << 4;
result += (a & ( (int16_t)( ( b & (1 << 5) ) << 10 ) ) / ( 1 << 15) ) << 5;
result += (a & ( (int16_t)( ( b & (1 << 6) ) << 9 ) ) / ( 1 << 15) ) << 6;
result += (a & ( (int16_t)( ( b & (1 << 7) ) << 8 ) ) / ( 1 << 15) ) << 7;
result += (a & ( (int16_t)( ( b & (1 << 8) ) << 7 ) ) / ( 1 << 15) ) << 8;
result += (a & ( (int16_t)( ( b & (1 << 9) ) << 6 ) ) / ( 1 << 15) ) << 9;
result += (a & ( (int16_t)( ( b & (1 <<10) ) << 5 ) ) / ( 1 << 15) ) << 10;
result += (a & ( (int16_t)( ( b & (1 <<11) ) << 4 ) ) / ( 1 << 15) ) << 11;
result += (a & ( (int16_t)( ( b & (1 <<12) ) << 3 ) ) / ( 1 << 15) ) << 12;
result += (a & ( (int16_t)( ( b & (1 <<13) ) << 2 ) ) / ( 1 << 15) ) << 13;
result += (a & ( (int16_t)( ( b & (1 <<14) ) << 1 ) ) / ( 1 << 15) ) << 14;
result += (a & ( (int16_t)( ( b & (1 <<15) ) << 0 ) ) / ( 1 << 15) ) << 15;
return result;
}
int main(void)
{
uint16_t a, b;
a = 0;
b = 0;
do
{
if (multiply(a, b) != a * b)
"ERROR:\n"
"my: %u\n"
"norm: %u\n"
"%hu * %hu\n"
"\n",
multiply(a, b), (a * b),a, b
);
if (UINT16_MAX == a)
{
b++;
}
a++;
//fprintf(stderr, "%hu * %hu\n", a, b);
} while ( ( a != 0 ) || (b != 0) );
fprintf(stderr
, "%"PRIu16
"* ""%"PRIu16
"\n", a
, b
);
return 0;
}