# Re: Efficient output for integer types

From: David Fetter Andrew Gierth Kyotaro Horiguchi , pgsql-hackers(at)postgresql(dot)org Re: Efficient output for integer types 2019-09-21 06:08:35 20190921060835.GH31596@fetter.org Raw Message | Whole Thread | Download mbox | Resend email 2019-09-15 07:18:49 from David Fetter 📎  2019-09-15 09:06:29 from Andrey Borodin   2019-09-15 16:12:03 from David Fetter  2019-09-17 06:55:05 from David Fetter 📎   2019-09-17 07:01:57 from David Fetter 📎    2019-09-18 03:42:01 from David Fetter 📎     2019-09-18 05:51:42 from David Fetter 📎      2019-09-18 06:26:35 from David Fetter 📎     2019-09-18 07:27:46 from Kyotaro Horiguchi      2019-09-20 19:14:51 from David Fetter 📎       2019-09-20 21:09:16 from David Fetter 📎        2019-09-20 21:18:13 from David Fetter 📎         2019-09-21 02:36:21 from Andrew Gierth          2019-09-21 06:08:35 from David Fetter 📎           2019-09-21 06:29:25 from Andrew Gierth            2019-09-22 21:58:04 from David Fetter 📎             2019-09-23 08:28:09 from Tels              2019-09-23 20:25:54 from David Fetter             2019-09-23 12:16:36 from Andrew Gierth              2019-09-23 21:35:07 from David Fetter 📎               2019-09-24 04:30:18 from David Fetter 📎                2019-09-24 05:26:21 from David Fetter 📎                 2020-01-11 13:31:59 from Tomas Vondra pgsql-hackers

On Sat, Sep 21, 2019 at 03:36:21AM +0100, Andrew Gierth wrote:
> >>>>> "David" == David Fetter <david(at)fetter(dot)org> writes:
>
> David> + /* Compute the result string. */
> David> + if (value >= 100000000)
> David> + {
> David> + const uint32 value2 = value % 100000000;
> David> +
> David> + const uint32 c = value2 % 10000;
> David> + const uint32 d = value2 / 10000;
> David> + const uint32 c0 = (c % 100) << 1;
> David> + const uint32 c1 = (c / 100) << 1;
> David> + const uint32 d0 = (d % 100) << 1;
> David> + const uint32 d1 = (d / 100) << 1;
> David> +
> David> + char *pos = a + olength - i;
> David> +
> David> + value /= 100000000;
> David> +
> David> + memcpy(pos - 2, DIGIT_TABLE + c0, 2);
> David> + memcpy(pos - 4, DIGIT_TABLE + c1, 2);
> David> + memcpy(pos - 6, DIGIT_TABLE + d0, 2);
> David> + memcpy(pos - 8, DIGIT_TABLE + d1, 2);
> David> + i += 8;
> David> + }
>
> For the 32-bit case, there's no point in doing an 8-digit divide
> specially, it doesn't save any time. It's sufficient to just change
>
> David> + if (value >= 10000)
>
> to while(value >= 10000)

Done.

> in order to process 4 digits at a time.
>
> David> + for(int i = 0; i < minwidth - len; i++)
> David> + {
> David> + memcpy(str + i, DIGIT_TABLE, 1);
> David> + }
>
> Should be:
> memset(str, '0', minwidth-len);

Done.

Best,
David.
--
David Fetter <david(at)fetter(dot)org> http://fetter.org/
Phone: +1 415 235 3778

Remember to vote!