MCPcopy Create free account
hub / github.com/davisking/dlib / shift_left

Method shift_left

dlib/bigint/bigint_kernel_1.cpp:1463–1504  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1461// ----------------------------------------------------------------------------------------
1462
1463 void bigint_kernel_1::
1464 shift_left (
1465 const data_record* data,
1466 data_record* result,
1467 uint32 shift_amount
1468 ) const
1469 {
1470 uint32 offset = shift_amount/16;
1471 shift_amount &= 0xf; // same as shift_amount %= 16;
1472
1473 uint16* r = result->number + data->digits_used + offset; // result
1474 uint16* end = data->number;
1475 uint16* s = end + data->digits_used; // source
1476 const uint32 temp = 16 - shift_amount;
1477
1478 *r = (*(--s) >> temp);
1479 // set the number of digits used in the result
1480 // if the upper bits from *s were zero then don't count this first word
1481 if (*r == 0)
1482 {
1483 result->digits_used = data->digits_used + offset;
1484 }
1485 else
1486 {
1487 result->digits_used = data->digits_used + offset + 1;
1488 }
1489 --r;
1490
1491 while (s != end)
1492 {
1493 *r = ((*s << shift_amount) | ( *(s-1) >> temp));
1494 --r;
1495 --s;
1496 }
1497 *r = *s << shift_amount;
1498
1499 // now zero the rest of the result
1500 end = result->number;
1501 while (r != end)
1502 *(--r) = 0;
1503
1504 }
1505
1506// ----------------------------------------------------------------------------------------
1507

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected