benchmark silo added
[c11concurrency-benchmarks.git] / silo / masstree / kvrandom.cc
1 /* Masstree
2  * Eddie Kohler, Yandong Mao, Robert Morris
3  * Copyright (c) 2012-2013 President and Fellows of Harvard College
4  * Copyright (c) 2012-2013 Massachusetts Institute of Technology
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, subject to the conditions
9  * listed in the Masstree LICENSE file. These conditions include: you must
10  * preserve this copyright notice, and you cannot mention the copyright
11  * holders in advertising related to the Software without their permission.
12  * The Software is provided WITHOUT ANY WARRANTY, EXPRESS OR IMPLIED. This
13  * notice is a summary of the Masstree LICENSE file; the license in that file
14  * is legally binding.
15  */
16 #include "kvrandom.hh"
17 #include "compiler.hh"
18 #include <stdio.h>
19
20 const uint32_t kvrandom_psdes_nr::c1[] = {
21     0xBAA96887U, 0x1E17D32CU, 0x03BCDC3CU, 0x0F33D1B2U
22 };
23 const uint32_t kvrandom_psdes_nr::c2[] = {
24     0x4B0F3B58U, 0xE874F0C3U, 0x6955C5A6U, 0x55A7CA46U
25 };
26
27 uint32_t kvrandom_psdes_nr::psdes(uint32_t lword, uint32_t irword) {
28     for (int i = 0; i < niter; ++i) {
29         uint32_t iswap = irword;
30         uint32_t ia = irword ^ c1[i];
31         uint32_t il = ia & 0xFFFF, ih = ia >> 16;
32         uint32_t ib = il * il + ~(ih * ih);
33         ia = (ib >> 16) | (ib << 16);
34         irword = lword ^ ((ia ^ c2[i]) + il * ih);
35         lword = iswap;
36     }
37     return irword;
38 }