| From: | David Fetter <david(at)fetter(dot)org> | 
|---|---|
| To: | Andrew Gierth <andrew(at)tao11(dot)riddles(dot)org(dot)uk> | 
| Cc: | Kyotaro Horiguchi <horikyota(dot)ntt(at)gmail(dot)com>, pgsql-hackers(at)postgresql(dot)org | 
| Subject: | Re: Efficient output for integer types | 
| Date: | 2019-09-21 06:08:35 | 
| Message-ID: | 20190921060835.GH31596@fetter.org | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | 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!
Consider donating to Postgres: http://www.postgresql.org/about/donate
| Attachment | Content-Type | Size | 
|---|---|---|
| v10-0001-Make-int4-and-int8-operations-more-efficent.patch | text/x-diff | 13.9 KB | 
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Dilip Kumar | 2019-09-21 06:28:17 | Re: A problem about partitionwise join | 
| Previous Message | Soumyadeep Chakraborty | 2019-09-21 05:19:46 | Re: Don't codegen deform code for virtual tuples in expr eval for scan fetch |