Re: What exactly is our CRC algorithm?

From: Andres Freund <andres(at)2ndquadrant(dot)com>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: Abhijit Menon-Sen <ams(at)2ndQuadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org, Heikki Linnakangas <hlinnakangas(at)vmware(dot)com>, Robert Haas <robertmhaas(at)gmail(dot)com>
Subject: Re: What exactly is our CRC algorithm?
Date: 2014-12-26 17:12:20
Message-ID: 6E182344-D12E-4E8B-A03A-C69338EAD6DF@2ndquadrant.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On December 26, 2014 6:05:34 PM CET, Bruce Momjian <bruce(at)momjian(dot)us> wrote:
>On Fri, Dec 26, 2014 at 04:52:58PM +0100, Andres Freund wrote:
>> On December 26, 2014 4:50:33 PM CET, Bruce Momjian <bruce(at)momjian(dot)us>
>wrote:
>> >On Thu, Dec 25, 2014 at 11:57:29AM +0530, Abhijit Menon-Sen wrote:
>> >> Hi.
>> >>
>> >> Here's a proposed patch to use CPUID at startup to determine if
>the
>> >> SSE4.2 CRC instructions are available, to use them instead of the
>> >> slice-by-8 implementation (posted earlier).
>> >>
>> >> A few notes:
>> >>
>> >> 1. GCC has included cpuid.h since 4.3.0, so I figured it was safe
>to
>> >> use. It can be replaced with some inline assembly otherwise.
>> >>
>> >> 2. I've also used the crc32b/crc32q instructions directly rather
>than
>> >> using ".bytes" to encode the instructions; bintuils versions
>since
>> >> 2007 or so have supported them.
>> >>
>> >> 3. I've included the MSVC implementation mostly as an example of
>how
>> >to
>> >> extend this to different compilers/platforms. It's written
>> >according
>> >> to the documentation for MSVC intrinsics, but I have not tested
>> >it.
>> >> Suggestions/improvements are welcome.
>> >
>> >Uh, what happens if the system is compiled on a different CPU that
>it
>> >is
>> >run on? Seems we would need a run-time CPU test.
>>
>> That's the cpuid thing mentioned above.
>
>Oh, so cpuid is not a macro exported by the compiler but a C API.
>Good

Neither, really. It's a instruction returning CPU capabilities.

--
Please excuse brevity and formatting - I am writing this on my mobile phone.

Andres Freund http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Kevin Grittner 2014-12-26 17:16:15 Re: BUG #12330: ACID is broken for unique constraints
Previous Message Alvaro Herrera 2014-12-26 17:10:51 Re: Some other odd buildfarm failures