#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;
char n = 0;
/*
for (n = 0; b >= (1 << n); n++)
{
if ( b & (1 << n) )
result += a << n;
}*/
if ( b & (1 << n) )
result += a << n;
n++;
if ( b & (1 << n) )
result += a << n;
n++;
if ( b & (1 << n) )
result += a << n;
n++;
if ( b & (1 << n) )
result += a << n;
n++;
if ( b & (1 << n) )
result += a << n;
n++;
if ( b & (1 << n) )
result += a << n;
n++;
if ( b & (1 << n) )
result += a << n;
n++;
if ( b & (1 << n) )
result += a << n;
n++;
if ( b & (1 << n) )
result += a << n;
n++;
if ( b & (1 << n) )
result += a << n;
n++;
if ( b & (1 << n) )
result += a << n;
n++;
if ( b & (1 << n) )
result += a << n;
n++;
if ( b & (1 << n) )
result += a << n;
n++;
if ( b & (1 << n) )
result += a << n;
n++;
if ( b & (1 << n) )
result += a << n;
n++;
if ( b & (1 << n) )
result += a << n;
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;
}
I2luY2x1ZGUgPHN0ZGlvLmg+CiNpbmNsdWRlIDxzdGRsaWIuaD4KI2luY2x1ZGUgPGxpbWl0cy5oPgojaW5jbHVkZSA8aW50dHlwZXMuaD4KIAp1aW50MzJfdCBtdWx0aXBseSAodWludDE2X3QgYSwgdWludDE2X3QgYikKewogIC8vdWludDE2X3QgbWFzayA9IDBiMDAwMDAwMDAwMDAwMDAwMTsKICAKICByZWdpc3RlciB1aW50MzJfdCByZXN1bHQgPSAwOwogIGNoYXIgbiA9IDA7CiAgLyoKICBmb3IgKG4gPSAwOyBiID49ICgxIDw8IG4pOyBuKyspCiAgewogICAgaWYgKCBiICYgKDEgPDwgbikgKQogICAgICByZXN1bHQgKz0gYSA8PCBuOwogIH0qLwogIGlmICggYiAmICgxIDw8IG4pICkKICAgIHJlc3VsdCArPSBhIDw8IG47ICAKICBuKys7CiAgaWYgKCBiICYgKDEgPDwgbikgKQogICAgcmVzdWx0ICs9IGEgPDwgbjsgIAogIG4rKzsKICBpZiAoIGIgJiAoMSA8PCBuKSApCiAgICByZXN1bHQgKz0gYSA8PCBuOyAgCiAgbisrOwogIGlmICggYiAmICgxIDw8IG4pICkKICAgIHJlc3VsdCArPSBhIDw8IG47ICAKICBuKys7CiAgaWYgKCBiICYgKDEgPDwgbikgKQogICAgcmVzdWx0ICs9IGEgPDwgbjsgIAogIG4rKzsKICBpZiAoIGIgJiAoMSA8PCBuKSApCiAgICByZXN1bHQgKz0gYSA8PCBuOyAgCiAgbisrOwogIGlmICggYiAmICgxIDw8IG4pICkKICAgIHJlc3VsdCArPSBhIDw8IG47ICAKICBuKys7CiAgaWYgKCBiICYgKDEgPDwgbikgKQogICAgcmVzdWx0ICs9IGEgPDwgbjsgIAogIG4rKzsKICBpZiAoIGIgJiAoMSA8PCBuKSApCiAgICByZXN1bHQgKz0gYSA8PCBuOyAgCiAgbisrOwogIGlmICggYiAmICgxIDw8IG4pICkKICAgIHJlc3VsdCArPSBhIDw8IG47ICAKICBuKys7CiAgaWYgKCBiICYgKDEgPDwgbikgKQogICAgcmVzdWx0ICs9IGEgPDwgbjsgIAogIG4rKzsKICBpZiAoIGIgJiAoMSA8PCBuKSApCiAgICByZXN1bHQgKz0gYSA8PCBuOyAgCiAgbisrOwogIGlmICggYiAmICgxIDw8IG4pICkKICAgIHJlc3VsdCArPSBhIDw8IG47ICAKICBuKys7CiAgaWYgKCBiICYgKDEgPDwgbikgKQogICAgcmVzdWx0ICs9IGEgPDwgbjsgIAogIG4rKzsKICBpZiAoIGIgJiAoMSA8PCBuKSApCiAgICByZXN1bHQgKz0gYSA8PCBuOyAgCiAgbisrOwogIGlmICggYiAmICgxIDw8IG4pICkKICAgIHJlc3VsdCArPSBhIDw8IG47ICAKICByZXR1cm4gcmVzdWx0Owp9CiAKaW50IG1haW4odm9pZCkKewogCiAgdWludDE2X3QgYSwgYjsKICBhID0gMDsKICBiID0gMDsKICAKICBkbwogIHsKICAgIGlmIChtdWx0aXBseShhLCBiKSAhPSBhICogYikKICAgIAogICAgCiAgICAgIGZwcmludGYoc3RkZXJyLAogICAgICAgICAgICAgICAiRVJST1I6XG4iCiAgICAgICAgICAgICAgICJteTogJXVcbiIKICAgICAgICAgICAgICAgIm5vcm06ICV1XG4iCiAgICAgICAgICAgICAgICIlaHUgKiAlaHVcbiIKICAgICAgICAgICAgICAgIlxuIiwKICAgICAgICAgICAgICAgbXVsdGlwbHkoYSwgYiksIChhICogYiksYSwgYgogICAgICAgICAgICAgKTsKCiAgICBpZiAoVUlOVDE2X01BWCA9PSBhKQogICAgewogICAgICBiKys7CiAgICB9CiAgICBhKys7CiAgLy9mcHJpbnRmKHN0ZGVyciwgIiVodSAqICVodVxuIiwgYSwgYik7CiAgfSB3aGlsZSAoICggYSAhPSAwICkgfHwgKGIgIT0gMCkgKTsKICAKICBmcHJpbnRmKHN0ZGVyciwgIiUiUFJJdTE2IiogIiIlIlBSSXUxNiJcbiIsIGEsIGIpOwogIHByaW50ZigiRG9uZSFcbiIpOwogCiAgcmV0dXJuIDA7Cn0K