On 64-bit CPU architectures, the default InnoDB data type ulint, which is an alias of size_t is 64 bits wide.
The function ut_fold_ull() is converting a 64-bit integer to ulint. It can be simplified on 32-bit systems, and we could avoid the extra instructions altogether on 64-bit systems and just use the 64-bit index or table identifiers as is.
The function ut_hash_ulint() seems to be an unnecessary obfuscation. Computing an exclusive OR with a constant before performing a modulus operation does not seem to affect the entropy at all.
{"report":{"fcp":820,"ttfb":196.30000019073486,"pageVisibility":"visible","entityId":131336,"key":"jira.project.issue.view-issue","isInitial":true,"threshold":1000,"elementTimings":{},"userDeviceMemory":8,"userDeviceProcessors":64,"apdex":1,"journeyId":"88cc4336-f5b7-4092-be3d-746532aec6e7","navigationType":0,"readyForUser":888.3000001907349,"redirectCount":0,"resourceLoadedEnd":873.8000001907349,"resourceLoadedStart":202,"resourceTiming":[{"duration":7.40000057220459,"initiatorType":"link","name":"https://jira.mariadb.org/s/2c21342762a6a02add1c328bed317ffd-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/css/_super/batch.css","startTime":202,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":202,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":209.4000005722046,"responseStart":0,"secureConnectionStart":0},{"duration":7.300000190734863,"initiatorType":"link","name":"https://jira.mariadb.org/s/7ebd35e77e471bc30ff0eba799ebc151-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/css/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":202.30000019073486,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":202.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":209.60000038146973,"responseStart":0,"secureConnectionStart":0},{"duration":89.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/0917945aaa57108d00c5076fea35e069-CDN/lu2cib/820016/12ta74/0a8bac35585be7fc6c9cc5a0464cd4cf/_/download/contextbatch/js/_super/batch.js?locale=en","startTime":202.5,"connectEnd":202.5,"connectStart":202.5,"domainLookupEnd":202.5,"domainLookupStart":202.5,"fetchStart":202.5,"redirectEnd":0,"redirectStart":0,"requestStart":202.5,"responseEnd":292.30000019073486,"responseStart":292.20000076293945,"secureConnectionStart":202.5},{"duration":177.79999923706055,"initiatorType":"script","name":"https://jira.mariadb.org/s/2d8175ec2fa4c816e8023260bd8c1786-CDN/lu2cib/820016/12ta74/494e4c556ecbb29f90a3d3b4f09cb99c/_/download/contextbatch/js/jira.browse.project,project.issue.navigator,jira.view.issue,jira.general,jira.global,atl.general,-_super/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":202.70000076293945,"connectEnd":202.70000076293945,"connectStart":202.70000076293945,"domainLookupEnd":202.70000076293945,"domainLookupStart":202.70000076293945,"fetchStart":202.70000076293945,"redirectEnd":0,"redirectStart":0,"requestStart":202.70000076293945,"responseEnd":380.5,"responseStart":380.5,"secureConnectionStart":202.70000076293945},{"duration":181.39999961853027,"initiatorType":"script","name":"https://jira.mariadb.org/s/a9324d6758d385eb45c462685ad88f1d-CDN/lu2cib/820016/12ta74/c92c0caa9a024ae85b0ebdbed7fb4bd7/_/download/contextbatch/js/atl.global,-_super/batch.js?locale=en","startTime":202.9000005722046,"connectEnd":202.9000005722046,"connectStart":202.9000005722046,"domainLookupEnd":202.9000005722046,"domainLookupStart":202.9000005722046,"fetchStart":202.9000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":202.9000005722046,"responseEnd":384.30000019073486,"responseStart":384.30000019073486,"secureConnectionStart":202.9000005722046},{"duration":181.80000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-en/jira.webresources:calendar-en.js","startTime":203.10000038146973,"connectEnd":203.10000038146973,"connectStart":203.10000038146973,"domainLookupEnd":203.10000038146973,"domainLookupStart":203.10000038146973,"fetchStart":203.10000038146973,"redirectEnd":0,"redirectStart":0,"requestStart":203.10000038146973,"responseEnd":384.9000005722046,"responseStart":384.9000005722046,"secureConnectionStart":203.10000038146973},{"duration":182.19999980926514,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:calendar-localisation-moment/jira.webresources:calendar-localisation-moment.js","startTime":203.20000076293945,"connectEnd":203.20000076293945,"connectStart":203.20000076293945,"domainLookupEnd":203.20000076293945,"domainLookupStart":203.20000076293945,"fetchStart":203.20000076293945,"redirectEnd":0,"redirectStart":0,"requestStart":203.20000076293945,"responseEnd":385.4000005722046,"responseStart":385.4000005722046,"secureConnectionStart":203.20000076293945},{"duration":231.30000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/b04b06a02d1959df322d9cded3aeecc1-CDN/lu2cib/820016/12ta74/a2ff6aa845ffc9a1d22fe23d9ee791fc/_/download/contextbatch/css/jira.global.look-and-feel,-_super/batch.css","startTime":203.4000005722046,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":203.4000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":434.70000076293945,"responseStart":0,"secureConnectionStart":0},{"duration":182.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/rest/api/1.0/shortcuts/820016/47140b6e0a9bc2e4913da06536125810/shortcuts.js?context=issuenavigation&context=issueaction","startTime":203.5,"connectEnd":203.5,"connectStart":203.5,"domainLookupEnd":203.5,"domainLookupStart":203.5,"fetchStart":203.5,"redirectEnd":0,"redirectStart":0,"requestStart":203.5,"responseEnd":385.80000019073486,"responseStart":385.80000019073486,"secureConnectionStart":203.5},{"duration":231.0999994277954,"initiatorType":"link","name":"https://jira.mariadb.org/s/3ac36323ba5e4eb0af2aa7ac7211b4bb-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/css/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.css?jira.create.linked.issue=true","startTime":203.70000076293945,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":203.70000076293945,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":434.80000019073486,"responseStart":0,"secureConnectionStart":0},{"duration":182.5,"initiatorType":"script","name":"https://jira.mariadb.org/s/5d5e8fe91fbc506585e83ea3b62ccc4b-CDN/lu2cib/820016/12ta74/d176f0986478cc64f24226b3d20c140d/_/download/contextbatch/js/com.atlassian.jira.projects.sidebar.init,-_super,-project.issue.navigator,-jira.view.issue/batch.js?jira.create.linked.issue=true&locale=en","startTime":203.9000005722046,"connectEnd":203.9000005722046,"connectStart":203.9000005722046,"domainLookupEnd":203.9000005722046,"domainLookupStart":203.9000005722046,"fetchStart":203.9000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":203.9000005722046,"responseEnd":386.4000005722046,"responseStart":386.4000005722046,"secureConnectionStart":203.9000005722046},{"duration":348.4000005722046,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-js/jira.webresources:bigpipe-js.js","startTime":204.80000019073486,"connectEnd":204.80000019073486,"connectStart":204.80000019073486,"domainLookupEnd":204.80000019073486,"domainLookupStart":204.80000019073486,"fetchStart":204.80000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":204.80000019073486,"responseEnd":553.2000007629395,"responseStart":553.2000007629395,"secureConnectionStart":204.80000019073486},{"duration":598.4000005722046,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/1.0/_/download/batch/jira.webresources:bigpipe-init/jira.webresources:bigpipe-init.js","startTime":209.30000019073486,"connectEnd":209.30000019073486,"connectStart":209.30000019073486,"domainLookupEnd":209.30000019073486,"domainLookupStart":209.30000019073486,"fetchStart":209.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":209.30000019073486,"responseEnd":807.7000007629395,"responseStart":807.7000007629395,"secureConnectionStart":209.30000019073486},{"duration":107.40000057220459,"initiatorType":"xmlhttprequest","name":"https://jira.mariadb.org/rest/webResources/1.0/resources","startTime":446.30000019073486,"connectEnd":446.30000019073486,"connectStart":446.30000019073486,"domainLookupEnd":446.30000019073486,"domainLookupStart":446.30000019073486,"fetchStart":446.30000019073486,"redirectEnd":0,"redirectStart":0,"requestStart":446.30000019073486,"responseEnd":553.7000007629395,"responseStart":553.6000003814697,"secureConnectionStart":446.30000019073486},{"duration":85.80000019073486,"initiatorType":"link","name":"https://jira.mariadb.org/s/d5715adaadd168a9002b108b2b039b50-CDN/lu2cib/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/css/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.css?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":738,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":738,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":823.8000001907349,"responseStart":0,"secureConnectionStart":0},{"duration":127.30000019073486,"initiatorType":"script","name":"https://jira.mariadb.org/s/d41d8cd98f00b204e9800998ecf8427e-CDN/lu2cib/820016/12ta74/e65b778d185daf5aee24936755b43da6/_/download/contextbatch/js/browser-metrics-plugin.contrib,-_super,-project.issue.navigator,-jira.view.issue,-atl.general/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&slack-enabled=true&whisper-enabled=true","startTime":738.9000005722046,"connectEnd":738.9000005722046,"connectStart":738.9000005722046,"domainLookupEnd":738.9000005722046,"domainLookupStart":738.9000005722046,"fetchStart":738.9000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":738.9000005722046,"responseEnd":866.2000007629395,"responseStart":866.2000007629395,"secureConnectionStart":738.9000005722046},{"duration":134.5999994277954,"initiatorType":"script","name":"https://jira.mariadb.org/s/097ae97cb8fbec7d6ea4bbb1f26955b9-CDN/lu2cib/820016/12ta74/be4b45e9cec53099498fa61c8b7acba4/_/download/contextbatch/js/jira.project.sidebar,-_super,-project.issue.navigator,-jira.general,-jira.browse.project,-jira.view.issue,-jira.global,-atl.general,-com.atlassian.jira.projects.sidebar.init/batch.js?agile_global_admin_condition=true&jag=true&jira.create.linked.issue=true&locale=en&slack-enabled=true&whisper-enabled=true","startTime":739.2000007629395,"connectEnd":739.2000007629395,"connectStart":739.2000007629395,"domainLookupEnd":739.2000007629395,"domainLookupStart":739.2000007629395,"fetchStart":739.2000007629395,"redirectEnd":0,"redirectStart":0,"requestStart":739.2000007629395,"responseEnd":873.8000001907349,"responseStart":873.8000001907349,"secureConnectionStart":739.2000007629395},{"duration":146.0999994277954,"initiatorType":"script","name":"https://www.google-analytics.com/analytics.js","startTime":811.9000005722046,"connectEnd":0,"connectStart":0,"domainLookupEnd":0,"domainLookupStart":0,"fetchStart":811.9000005722046,"redirectEnd":0,"redirectStart":0,"requestStart":0,"responseEnd":958,"responseStart":0,"secureConnectionStart":0}],"fetchStart":0,"domainLookupStart":0,"domainLookupEnd":0,"connectStart":0,"connectEnd":0,"requestStart":12,"responseStart":196,"responseEnd":201,"domLoading":199,"domInteractive":977,"domContentLoadedEventStart":978,"domContentLoadedEventEnd":1025,"domComplete":1220,"loadEventStart":1220,"loadEventEnd":1221,"userAgent":"Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)","marks":[{"name":"bigPipe.sidebar-id.start","time":923.9000005722046},{"name":"bigPipe.sidebar-id.end","time":924.7000007629395},{"name":"bigPipe.activity-panel-pipe-id.start","time":924.8000001907349},{"name":"bigPipe.activity-panel-pipe-id.end","time":929.1000003814697},{"name":"activityTabFullyLoaded","time":1045.5}],"measures":[],"correlationId":"5c7ce8688d3b1","effectiveType":"4g","downlink":9.5,"rtt":0,"serverDuration":127,"dbReadsTimeInMs":13,"dbConnsTimeInMs":23,"applicationHash":"9d11dbea5f4be3d4cc21f03a88dd11d8c8687422","experiments":[]}}
In terms of code, the current state is as follows:
# if SIZEOF_SIZE_T < 8
{
}
# else
# define ut_fold_ull(d) d
The 32-bit version is equivalent to the existing definition. The numeric constants seem to be arbitrary. I remember that Heikki Tuuri had a habit of creating "random numbers" by typing them on the upper row of the keyboard. Especially the 1463735687 does not look very random: it contains a long sequence of near-consecutive digits.
In fact, this function looks like "obfuscated hashing" mentioned by https://sortingsearching.com/2020/05/21/hashing.html. That function also mentions Universal hashing and a hash function devised by Carter and Wegman back in 1977:
Here, p would be a prime number and a and b would be random integers between 0 and p-1. The m applied to this case could be 1<<32, and a suitable p could be 0x1000000F. What if we "randomly" choose a=0 to avoid one expensive multiplication?
#include <cstdint>
uint32_t ut_fold_ull(uint64_t num) noexcept
{
}
On IA-32, the above would emit add and adc for the addition (no matter which constant we choose) and a call to the runtime library function __umoddi3, which looks very expensive. (It is unavoidable; it has to perform 64-bit division arithmetics on a 32-bit ISA.)
We know that GCC knows how to optimize mach_read_from_4() and friends, What if we used a single carry-less addition, a.k.a. exclusive OR?
{
}
{
}
The main function would translate to the following IA-32 instructions:
imul 123456,0x4(%esp),%eax
ret
I think that the above solution should be good
We should keep in mind that the only use of ut_fold_ull is to shrink 64-bit table or index identifiers to 32 bits. On 32-bit systems, I would assume that the most significant half of these IDs would typically be 0; nobody should be creating billions of tables on such a small machine. So, I would opt for the following simple function for narrower-than-64-bit ISA:
#include <cstdint>
uint32_t ut_fold_ull(uint64_t num) noexcept
{
}