From: Eric Love Date: Thu, 20 Feb 2014 19:51:21 +0000 (-0800) Subject: Added TAV sort benchmarks X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0661b47765081c710af3df66ec698aa58ff14d5d;p=riscv-tests.git Added TAV sort benchmarks --- diff --git a/benchmarks/sort/bmark.mk b/benchmarks/sort/bmark.mk new file mode 100644 index 0000000..1e76b68 --- /dev/null +++ b/benchmarks/sort/bmark.mk @@ -0,0 +1,21 @@ + +sort_c_src = \ + sort_main.c \ + sort.c \ + syscalls.c \ + +sort_riscv_src = \ + crt.S + +sort_c_objs = $(patsubst %.c, %.o, $(sort_c_src)) +sort_riscv_objs = $(patsubst %.S, %.o, $(sort_riscv_src)) + +sort_host_bin = sort.host +$(sort_host_bin): $(sort_c_src) + $(HOST_COMP) $^ -o $(sort_host_bin) + +sort_riscv_bin = sort.riscv +$(sort_riscv_bin): $(sort_c_objs) $(sort_riscv_objs) + $(RISCV_LINK) $(sort_c_objs) $(sort_riscv_objs) -o $(sort_riscv_bin) $(RISCV_LINK_OPTS) + +junk += $(sort_c_objs) $(sort_riscv_objs) $(sort_host_bin) $(sort_riscv_bin) diff --git a/benchmarks/sort/dataset.h b/benchmarks/sort/dataset.h new file mode 100644 index 0000000..7bd40a1 --- /dev/null +++ b/benchmarks/sort/dataset.h @@ -0,0 +1,2055 @@ +#define DATA_SIZE_SORT 1024 +float input_data_sort[1024] = { + 0.1757304, + 0.11887336, + 0.31508863, + 0.87429434, + 0.32998228, + 0.8617061, + 0.6609412, + 0.19959801, + 0.98842853, + 0.119490266, + 0.9348168, + 0.65575826, + 0.45825773, + 0.97723013, + 0.38904178, + 0.8539795, + 0.033690035, + 0.019101262, + 0.05240947, + 0.5234229, + 0.14557135, + 0.60703784, + 0.451209, + 0.6935377, + 0.44013077, + 0.33798885, + 0.89433634, + 0.49943197, + 0.23044586, + 0.121301234, + 0.8689161, + 0.593277, + 0.05368501, + 0.053545654, + 0.6745325, + 0.20875269, + 0.21469009, + 0.866569, + 0.49906075, + 0.84484196, + 0.7888443, + 0.6592707, + 0.83318657, + 0.5413125, + 0.32197475, + 0.69631076, + 0.32559925, + 0.49555874, + 0.5204319, + 0.6475523, + 0.80377436, + 0.70680165, + 0.32925904, + 0.95852894, + 0.39906925, + 0.7697948, + 0.59992826, + 0.37073708, + 0.20802563, + 0.42008877, + 0.841509, + 0.56534445, + 0.14839774, + 0.953649, + 0.5110267, + 0.6773647, + 0.098240376, + 0.9053897, + 0.751437, + 0.039974272, + 0.7747411, + 0.027303576, + 0.141011, + 0.06908399, + 0.3673455, + 0.5137753, + 0.72853225, + 0.11327422, + 0.7037065, + 0.8889426, + 0.63771373, + 0.378645, + 0.729311, + 0.011300623, + 0.715438, + 0.52502894, + 0.6201543, + 0.22995687, + 0.84622484, + 0.130499, + 0.73602027, + 0.01398164, + 0.574775, + 0.17442858, + 0.4388845, + 0.99323124, + 0.8751872, + 0.81291664, + 0.14141601, + 0.6210417, + 0.22579539, + 0.6596801, + 0.67486, + 0.8746262, + 0.42942703, + 0.26417083, + 0.5497203, + 0.029295504, + 0.8377925, + 0.54845864, + 0.06822199, + 0.5123382, + 0.16383338, + 0.25521147, + 0.6917526, + 0.79923284, + 0.90598094, + 0.42891055, + 0.9922046, + 0.84964263, + 0.46281397, + 0.13739341, + 0.86184824, + 0.48731065, + 0.3256001, + 0.90518177, + 0.12615639, + 0.65359414, + 0.73031837, + 0.116200924, + 0.017603576, + 0.5591563, + 0.901283, + 0.22194791, + 0.11122882, + 0.32557893, + 0.4873348, + 0.3105452, + 0.7956536, + 0.85483134, + 0.081272185, + 0.12918323, + 0.42289335, + 0.94918406, + 0.3169291, + 0.2620939, + 0.22891188, + 0.3899988, + 0.08985239, + 0.93141407, + 0.49229932, + 0.9866693, + 0.9713107, + 0.97022545, + 0.26418108, + 0.9457844, + 0.04641038, + 0.404957, + 0.18758827, + 0.15739709, + 0.7610722, + 0.84558177, + 0.27376753, + 0.72531575, + 0.1058197, + 0.41215366, + 0.12662953, + 0.8098971, + 0.68366545, + 0.19882846, + 0.6307104, + 0.33636945, + 0.13238782, + 0.5933682, + 0.9342456, + 0.5338107, + 0.61633843, + 0.011111796, + 0.074463665, + 0.49725115, + 0.92839295, + 0.4755246, + 0.47984606, + 0.848783, + 0.2981748, + 0.76883674, + 0.032342672, + 0.15697998, + 0.57827556, + 0.70021665, + 0.33549112, + 0.5544396, + 0.7565379, + 0.08777094, + 0.28177768, + 0.17104203, + 0.040839553, + 0.8449312, + 0.1797567, + 0.7289034, + 0.2951395, + 0.7001151, + 0.33938986, + 0.28042507, + 0.7243572, + 0.48768485, + 0.6393749, + 0.42288208, + 0.154113, + 0.1330601, + 0.7451335, + 0.9043403, + 0.41326004, + 0.74838066, + 0.10847622, + 0.8121712, + 0.47688937, + 0.06848621, + 0.97322446, + 0.17598373, + 0.5801384, + 0.5294491, + 0.41435915, + 0.9434934, + 0.27433473, + 0.94084144, + 0.046301603, + 0.72588295, + 0.8130598, + 0.07384592, + 0.80906665, + 0.23691052, + 0.66352403, + 0.80386925, + 0.05524379, + 0.9488235, + 0.81575716, + 0.26023787, + 0.65764946, + 0.59261876, + 0.7766895, + 0.87673867, + 0.6942928, + 0.87804097, + 0.19702464, + 0.26321357, + 0.36684746, + 0.2907554, + 0.3852964, + 0.4662627, + 0.6096073, + 0.3343132, + 0.055701077, + 0.820616, + 0.55202353, + 0.8699163, + 0.46486145, + 0.15427285, + 0.8291023, + 0.7177797, + 0.18890625, + 0.3706004, + 0.17553282, + 0.823405, + 0.638046, + 0.23785275, + 0.7924014, + 0.66676295, + 0.60373807, + 0.74777824, + 0.4063158, + 0.26180196, + 0.6767176, + 0.41501343, + 0.5319598, + 0.82056034, + 0.89642483, + 0.9608185, + 0.24835157, + 0.65626585, + 0.018087804, + 0.6195284, + 0.3698889, + 0.09212071, + 0.9779671, + 0.8131314, + 0.564712, + 0.39904678, + 0.5557016, + 0.7260277, + 0.0897426, + 0.18171531, + 0.57159394, + 0.7737707, + 0.9843066, + 0.19601238, + 0.802962, + 0.57008445, + 0.9184999, + 0.5441584, + 0.88489395, + 0.5574478, + 0.32001197, + 0.2405588, + 0.8950428, + 0.357908, + 0.81120723, + 0.65982735, + 0.86827475, + 0.330557, + 0.54972917, + 0.7090974, + 0.79445344, + 0.07639384, + 0.46921813, + 0.25367773, + 0.51144004, + 0.32437116, + 0.116015196, + 0.36537987, + 0.49618554, + 0.9566592, + 0.2426961, + 0.056644797, + 0.7008652, + 0.90707433, + 0.2852854, + 0.9642434, + 0.99028367, + 0.3928305, + 0.5690222, + 0.81026703, + 0.263789, + 0.84305465, + 0.5741867, + 0.7049292, + 0.2328471, + 0.97272724, + 0.880976, + 0.47806334, + 0.95803076, + 0.5508898, + 0.79859036, + 0.19994617, + 0.40088493, + 0.43822384, + 0.98203504, + 0.046141088, + 0.33197814, + 0.6607148, + 0.12975866, + 0.29752463, + 0.26210827, + 0.46045, + 0.7308636, + 0.8707063, + 0.5753832, + 0.06716925, + 0.6525864, + 0.62402165, + 0.5776601, + 0.088626266, + 0.50303984, + 0.26159447, + 0.70914066, + 0.97588015, + 0.31242466, + 0.8972134, + 0.07394469, + 0.61121166, + 0.30529517, + 0.8786339, + 0.72101295, + 0.1494422, + 0.8098419, + 0.9022279, + 0.6691359, + 0.3541749, + 0.6060176, + 0.5615999, + 0.5443052, + 0.67311776, + 0.95678174, + 0.51894265, + 0.3206038, + 0.63358235, + 0.91549635, + 0.4147135, + 0.097782075, + 0.08098441, + 0.2429266, + 0.34299248, + 0.07141602, + 0.6783291, + 0.90036285, + 0.32308286, + 0.9576585, + 0.6100172, + 0.8776784, + 0.25210178, + 0.61723447, + 0.8437233, + 0.34890807, + 0.59118164, + 0.61628354, + 0.6825995, + 0.37102014, + 0.73527753, + 0.9893386, + 0.8477641, + 0.6174343, + 0.062403858, + 0.697178, + 0.457215, + 0.79562217, + 0.9244678, + 0.7551755, + 0.0793398, + 0.28252542, + 0.9039292, + 0.9423733, + 0.43258083, + 0.23290926, + 0.046612978, + 0.47474664, + 0.25120294, + 0.6000957, + 0.22257942, + 0.26553988, + 0.64223933, + 0.5474061, + 0.44858456, + 0.019308567, + 0.80046266, + 0.029304922, + 0.8150408, + 0.6731813, + 0.9346345, + 0.5565309, + 0.4383297, + 0.7582761, + 0.47546828, + 0.51790357, + 0.649773, + 0.39620972, + 0.1979565, + 0.86710715, + 0.93260723, + 0.55088305, + 0.49033952, + 0.46529734, + 0.1281203, + 0.14550799, + 0.15954506, + 0.13521653, + 0.30502337, + 0.9410681, + 0.47703332, + 0.28059918, + 0.7785871, + 0.0076212883, + 0.5664016, + 0.27261585, + 0.88764375, + 0.9472175, + 0.2197172, + 0.23516148, + 0.8009327, + 0.13051206, + 0.13636571, + 0.1707949, + 0.2952808, + 0.36281192, + 0.8173559, + 0.87255853, + 0.79568845, + 0.014349699, + 0.6587728, + 0.8428508, + 0.11362362, + 0.5396856, + 0.48779655, + 0.58371586, + 0.089894235, + 0.91859597, + 0.018912792, + 0.49370837, + 0.52069956, + 0.21252477, + 0.7002744, + 0.080859244, + 0.30129594, + 0.6241863, + 0.7223723, + 0.9208161, + 0.09572613, + 0.041391194, + 0.7031407, + 0.41118395, + 0.17094243, + 0.5483958, + 0.7033474, + 0.82030004, + 0.41023225, + 0.19847465, + 0.7997489, + 0.83961886, + 0.2380647, + 1.937151E-5, + 0.8152733, + 0.027657509, + 0.9933987, + 0.5059405, + 0.9178185, + 0.39978993, + 0.63131595, + 0.18378079, + 0.4226243, + 0.4574275, + 0.91688704, + 0.34365255, + 0.11622691, + 0.16326135, + 0.106895626, + 0.41542965, + 0.9394962, + 0.5228724, + 0.5539972, + 0.7887161, + 0.6780639, + 0.30936033, + 0.47677714, + 0.8927699, + 0.99359006, + 0.11455941, + 0.033814907, + 0.22319984, + 0.34991652, + 0.89136845, + 0.73920286, + 0.28290445, + 0.13347423, + 0.795832, + 0.5330783, + 0.95205945, + 0.10473251, + 0.78958845, + 0.54880697, + 0.33227074, + 0.642511, + 0.7335111, + 0.82681596, + 0.2101984, + 0.5292472, + 0.7177714, + 0.1451698, + 0.68357784, + 0.074589014, + 0.023769975, + 0.4533769, + 0.3057692, + 0.5668371, + 0.3066178, + 0.4963051, + 0.09254807, + 0.584813, + 0.4959759, + 0.44029474, + 0.5462275, + 0.88280004, + 0.22653967, + 0.20752531, + 0.27740353, + 0.9925594, + 0.78139514, + 0.7844979, + 0.024319768, + 0.5614426, + 0.031600356, + 0.6963251, + 0.7053268, + 0.78481346, + 0.41900802, + 0.78369737, + 0.3030963, + 0.1929881, + 0.90752304, + 0.24037105, + 0.72266537, + 0.94446266, + 0.03728348, + 0.8753557, + 0.53220785, + 0.66320276, + 0.7888865, + 0.7683766, + 0.5694369, + 0.57122767, + 0.19861305, + 0.85545987, + 0.552156, + 0.11976898, + 0.37410325, + 0.68259144, + 0.9837329, + 0.7521709, + 0.32220656, + 0.2213903, + 0.09883273, + 0.6568185, + 0.41150188, + 0.57682574, + 0.29790616, + 0.034230173, + 0.21160305, + 0.91150093, + 0.3075992, + 0.23267019, + 0.25581092, + 0.44537747, + 0.15596777, + 0.15298265, + 0.10455203, + 0.89859325, + 0.33431584, + 0.21570057, + 0.101569355, + 0.8659252, + 0.24040687, + 0.37985235, + 0.83587176, + 0.93528867, + 0.06015235, + 0.73940843, + 0.48846513, + 0.6833951, + 0.68668723, + 0.964232, + 0.65799284, + 0.24637389, + 0.52766764, + 0.7401162, + 0.64332944, + 0.9220043, + 0.18496239, + 0.6674981, + 0.49924678, + 0.11651373, + 0.9675673, + 0.14938504, + 0.97449046, + 0.0091305375, + 0.12109083, + 0.3126558, + 0.956561, + 0.13129687, + 0.018705726, + 0.21810287, + 0.5664185, + 0.90735143, + 0.49282104, + 0.60635805, + 0.11707395, + 0.29539943, + 0.018318713, + 0.3603375, + 0.83606917, + 0.41994262, + 0.7520571, + 0.22930062, + 0.38228273, + 0.3737226, + 0.045132577, + 0.22242886, + 0.6070589, + 0.7603197, + 0.17040175, + 0.33650416, + 0.8286921, + 0.5796803, + 0.7349129, + 0.9064294, + 0.73378366, + 0.457354, + 0.8027157, + 0.16074997, + 0.2805302, + 0.16938221, + 0.75617754, + 0.4068821, + 0.064817786, + 0.8061867, + 0.63221943, + 0.37044573, + 0.19295168, + 0.59128076, + 0.23321503, + 0.35605943, + 0.97340614, + 0.36811262, + 0.020702302, + 0.1974544, + 0.64824784, + 0.5879169, + 0.3342108, + 0.11516988, + 0.90259147, + 0.47329968, + 0.15869552, + 0.12092799, + 0.25293672, + 0.049723983, + 0.7042008, + 0.09767079, + 0.3734914, + 0.28655404, + 0.81300086, + 0.06994432, + 0.4902075, + 0.48041505, + 0.41573375, + 0.9657087, + 0.68747103, + 0.7590387, + 0.30275953, + 0.6907548, + 0.13004315, + 0.64930385, + 0.6345381, + 0.0018425584, + 0.11642903, + 0.70779675, + 0.30028176, + 0.21370721, + 0.62845016, + 0.377976, + 0.25315416, + 0.5255868, + 0.7201452, + 0.3401265, + 0.74914914, + 0.8504162, + 0.057572365, + 0.43704957, + 0.33240592, + 0.6979439, + 0.05561161, + 0.7713009, + 0.9196396, + 0.45351148, + 6.979704E-5, + 0.2133339, + 0.30875033, + 0.43698066, + 0.9504976, + 0.47181886, + 0.3803134, + 0.3793028, + 0.013994575, + 0.14851558, + 0.5749565, + 0.4536326, + 0.20137453, + 0.12432206, + 0.45463926, + 0.10795635, + 0.7284957, + 0.9475713, + 0.2222321, + 0.60930604, + 0.5270535, + 0.070504844, + 0.55282706, + 0.19628751, + 0.36603934, + 0.20842707, + 0.44382614, + 0.89547896, + 0.35836428, + 0.38479155, + 0.62157434, + 0.5650307, + 0.50342965, + 0.43395442, + 0.34330404, + 0.34038484, + 0.07793331, + 0.6242497, + 0.8382207, + 0.9554563, + 0.18176848, + 0.35321295, + 0.66510236, + 0.0589965, + 0.13699096, + 0.473154, + 0.59084594, + 0.62946135, + 0.0545941, + 0.10092139, + 0.27063727, + 0.4799099, + 0.07096887, + 0.82581013, + 0.7321341, + 0.032769382, + 0.123788476, + 0.08245695, + 0.020152152, + 0.50636065, + 0.81162196, + 0.33269376, + 0.07236695, + 0.19263196, + 0.75444776, + 0.28625458, + 0.088656306, + 0.9984882, + 0.85063785, + 0.072654545, + 0.08569819, + 0.0794332, + 0.08275825, + 0.39629877, + 0.6437189, + 0.50009686, + 0.74817204, + 0.80788136, + 0.84389865, + 0.02585423, + 0.6350247, + 0.30446804, + 0.24354726, + 0.57554376, + 0.19947416, + 0.22851866, + 0.26305282, + 0.5677659, + 0.9613484, + 0.52581614, + 0.27569318, + 0.4710188, + 0.37374723, + 0.70027125, + 0.85122544, + 0.747772, + 0.35405284, + 0.5794416, + 0.24989307, + 0.069361866, + 0.5216087, + 0.29102802, + 0.2789054, + 0.0053359866, + 0.26880872, + 0.6134187, + 0.7829644, + 0.26869857, + 0.9109975, + 0.271482, + 0.25907463, + 0.26668042, + 0.8955092, + 0.42433316, + 0.66934276, + 0.9825553, + 0.99609894, + 0.8599187, + 0.4200377, + 0.74315673, + 0.4362995, + 0.550286, + 0.51775914, + 0.93275, + 0.349836, + 0.71279025, + 0.081686676, + 0.2485407, + 0.03976655, + 0.3007995, + 0.052720666, + 0.28623503, + 0.297701, + 0.5503877, + 0.10466653, + 0.55371666, + 0.01314348, + 0.42787945, + 0.32887244, + 0.97320575, + 0.37917942, + 0.35086995, + 0.27194273, + 0.4114716, + 0.88848966, + 0.6395578, + 0.7869816, + 0.21616459, + 0.73274297, + 0.74610305, + 0.98356473, + 0.40462768, + 0.15415418, + 0.31056094, + 0.2921989, + 0.39827055, + 0.25136715, + 0.6092073, + 0.3979556, + 0.69749975, + 0.97943527, + 0.55431855, + 0.03841853, + 0.9041813, + 0.8877537, + 0.33640724, + 0.5368486, + 0.103672504, + 0.058197737, + 0.28634816, + 0.4769684, + 0.9777305, + 0.80191493, + 0.9947238, + 0.2860303, + 0.62234914, + 0.77631384, + 0.031121552, + 0.23352933, + 0.95816517, + 0.13850504, + 0.33224243, + 0.6703381, + 0.7410319, + 0.268143, + 0.0028386116, + 0.31409484, + 0.4803009, + 0.09725857, + 0.62913793, + 0.25890052, + 0.35405165, + 0.5688682, + 0.4251055, + 0.7689477, + 0.35383534, + 0.6171222, + 0.5053309, + 0.06539601, + 0.10447335, + 0.9923581, + 0.14533323, + 0.38304198, + 0.8731929, + 0.43314546, + 0.094596446, + 0.848147, + 0.32115936, + 0.068326, + 0.3467437, + 0.8918461, + 0.25165737, + 0.4849192, + 0.44514078, + 0.28615254, + 0.4932829, + 0.8579076, + 0.5641911, + 0.6836139, + 0.7221809, + 0.6563289, + 0.61310744, + 0.10970473, + 0.40134054, + 0.23338151, + 0.26957536, + 0.9422157, + 0.6021412, + 0.6086167, + 0.6781688, + 0.89802104, + 0.60672015, + 0.7556083, + 0.008446217, + 0.70907634, + 0.28045171, + 0.032221913, + 0.8293057, + 0.92136437, + 0.9911397, + 0.11186421, + 0.44146562, + 0.39842975, + 0.65281165, + 0.98759604, + 0.7440712, + 0.10141212, + 0.4327789, + 0.68709916, + 0.6727177, + 0.8870143, + 0.004516542, + 0.13116664, + 0.71608186, + 0.89117455, + 0.507684, + 0.73324865, + 0.93142414, + 0.41749775, + 0.7201321, + 0.5298479, + 0.37317383, + 0.63455087, + 0.3130343, + 0.77408105, + 0.014445007, + 0.2043333, + 0.4854672, + 0.45597613, + 0.37260664, + 0.7556518, + 0.123116136, + 0.33716398, + 0.8940141 +}; + +float verify_data_sort[1024] = { + 1.937151E-5, + 6.979704E-5, + 0.0018425584, + 0.0028386116, + 0.004516542, + 0.0053359866, + 0.0076212883, + 0.008446217, + 0.0091305375, + 0.011111796, + 0.011300623, + 0.01314348, + 0.01398164, + 0.013994575, + 0.014349699, + 0.014445007, + 0.017603576, + 0.018087804, + 0.018318713, + 0.018705726, + 0.018912792, + 0.019101262, + 0.019308567, + 0.020152152, + 0.020702302, + 0.023769975, + 0.024319768, + 0.02585423, + 0.027303576, + 0.027657509, + 0.029295504, + 0.029304922, + 0.031121552, + 0.031600356, + 0.032221913, + 0.032342672, + 0.032769382, + 0.033690035, + 0.033814907, + 0.034230173, + 0.03728348, + 0.03841853, + 0.03976655, + 0.039974272, + 0.040839553, + 0.041391194, + 0.045132577, + 0.046141088, + 0.046301603, + 0.04641038, + 0.046612978, + 0.049723983, + 0.05240947, + 0.052720666, + 0.053545654, + 0.05368501, + 0.0545941, + 0.05524379, + 0.05561161, + 0.055701077, + 0.056644797, + 0.057572365, + 0.058197737, + 0.0589965, + 0.06015235, + 0.062403858, + 0.064817786, + 0.06539601, + 0.06716925, + 0.06822199, + 0.068326, + 0.06848621, + 0.06908399, + 0.069361866, + 0.06994432, + 0.070504844, + 0.07096887, + 0.07141602, + 0.07236695, + 0.072654545, + 0.07384592, + 0.07394469, + 0.074463665, + 0.074589014, + 0.07639384, + 0.07793331, + 0.0793398, + 0.0794332, + 0.080859244, + 0.08098441, + 0.081272185, + 0.081686676, + 0.08245695, + 0.08275825, + 0.08569819, + 0.08777094, + 0.088626266, + 0.088656306, + 0.0897426, + 0.08985239, + 0.089894235, + 0.09212071, + 0.09254807, + 0.094596446, + 0.09572613, + 0.09725857, + 0.09767079, + 0.097782075, + 0.098240376, + 0.09883273, + 0.10092139, + 0.10141212, + 0.101569355, + 0.103672504, + 0.10447335, + 0.10455203, + 0.10466653, + 0.10473251, + 0.1058197, + 0.106895626, + 0.10795635, + 0.10847622, + 0.10970473, + 0.11122882, + 0.11186421, + 0.11327422, + 0.11362362, + 0.11455941, + 0.11516988, + 0.116015196, + 0.116200924, + 0.11622691, + 0.11642903, + 0.11651373, + 0.11707395, + 0.11887336, + 0.119490266, + 0.11976898, + 0.12092799, + 0.12109083, + 0.121301234, + 0.123116136, + 0.123788476, + 0.12432206, + 0.12615639, + 0.12662953, + 0.1281203, + 0.12918323, + 0.12975866, + 0.13004315, + 0.130499, + 0.13051206, + 0.13116664, + 0.13129687, + 0.13238782, + 0.1330601, + 0.13347423, + 0.13521653, + 0.13636571, + 0.13699096, + 0.13739341, + 0.13850504, + 0.141011, + 0.14141601, + 0.1451698, + 0.14533323, + 0.14550799, + 0.14557135, + 0.14839774, + 0.14851558, + 0.14938504, + 0.1494422, + 0.15298265, + 0.154113, + 0.15415418, + 0.15427285, + 0.15596777, + 0.15697998, + 0.15739709, + 0.15869552, + 0.15954506, + 0.16074997, + 0.16326135, + 0.16383338, + 0.16938221, + 0.17040175, + 0.1707949, + 0.17094243, + 0.17104203, + 0.17442858, + 0.17553282, + 0.1757304, + 0.17598373, + 0.1797567, + 0.18171531, + 0.18176848, + 0.18378079, + 0.18496239, + 0.18758827, + 0.18890625, + 0.19263196, + 0.19295168, + 0.1929881, + 0.19601238, + 0.19628751, + 0.19702464, + 0.1974544, + 0.1979565, + 0.19847465, + 0.19861305, + 0.19882846, + 0.19947416, + 0.19959801, + 0.19994617, + 0.20137453, + 0.2043333, + 0.20752531, + 0.20802563, + 0.20842707, + 0.20875269, + 0.2101984, + 0.21160305, + 0.21252477, + 0.2133339, + 0.21370721, + 0.21469009, + 0.21570057, + 0.21616459, + 0.21810287, + 0.2197172, + 0.2213903, + 0.22194791, + 0.2222321, + 0.22242886, + 0.22257942, + 0.22319984, + 0.22579539, + 0.22653967, + 0.22851866, + 0.22891188, + 0.22930062, + 0.22995687, + 0.23044586, + 0.23267019, + 0.2328471, + 0.23290926, + 0.23321503, + 0.23338151, + 0.23352933, + 0.23516148, + 0.23691052, + 0.23785275, + 0.2380647, + 0.24037105, + 0.24040687, + 0.2405588, + 0.2426961, + 0.2429266, + 0.24354726, + 0.24637389, + 0.24835157, + 0.2485407, + 0.24989307, + 0.25120294, + 0.25136715, + 0.25165737, + 0.25210178, + 0.25293672, + 0.25315416, + 0.25367773, + 0.25521147, + 0.25581092, + 0.25890052, + 0.25907463, + 0.26023787, + 0.26159447, + 0.26180196, + 0.2620939, + 0.26210827, + 0.26305282, + 0.26321357, + 0.263789, + 0.26417083, + 0.26418108, + 0.26553988, + 0.26668042, + 0.268143, + 0.26869857, + 0.26880872, + 0.26957536, + 0.27063727, + 0.271482, + 0.27194273, + 0.27261585, + 0.27376753, + 0.27433473, + 0.27569318, + 0.27740353, + 0.2789054, + 0.28042507, + 0.28045171, + 0.2805302, + 0.28059918, + 0.28177768, + 0.28252542, + 0.28290445, + 0.2852854, + 0.2860303, + 0.28615254, + 0.28623503, + 0.28625458, + 0.28634816, + 0.28655404, + 0.2907554, + 0.29102802, + 0.2921989, + 0.2951395, + 0.2952808, + 0.29539943, + 0.29752463, + 0.297701, + 0.29790616, + 0.2981748, + 0.30028176, + 0.3007995, + 0.30129594, + 0.30275953, + 0.3030963, + 0.30446804, + 0.30502337, + 0.30529517, + 0.3057692, + 0.3066178, + 0.3075992, + 0.30875033, + 0.30936033, + 0.3105452, + 0.31056094, + 0.31242466, + 0.3126558, + 0.3130343, + 0.31409484, + 0.31508863, + 0.3169291, + 0.32001197, + 0.3206038, + 0.32115936, + 0.32197475, + 0.32220656, + 0.32308286, + 0.32437116, + 0.32557893, + 0.32559925, + 0.3256001, + 0.32887244, + 0.32925904, + 0.32998228, + 0.330557, + 0.33197814, + 0.33224243, + 0.33227074, + 0.33240592, + 0.33269376, + 0.3342108, + 0.3343132, + 0.33431584, + 0.33549112, + 0.33636945, + 0.33640724, + 0.33650416, + 0.33716398, + 0.33798885, + 0.33938986, + 0.3401265, + 0.34038484, + 0.34299248, + 0.34330404, + 0.34365255, + 0.3467437, + 0.34890807, + 0.349836, + 0.34991652, + 0.35086995, + 0.35321295, + 0.35383534, + 0.35405165, + 0.35405284, + 0.3541749, + 0.35605943, + 0.357908, + 0.35836428, + 0.3603375, + 0.36281192, + 0.36537987, + 0.36603934, + 0.36684746, + 0.3673455, + 0.36811262, + 0.3698889, + 0.37044573, + 0.3706004, + 0.37073708, + 0.37102014, + 0.37260664, + 0.37317383, + 0.3734914, + 0.3737226, + 0.37374723, + 0.37410325, + 0.377976, + 0.378645, + 0.37917942, + 0.3793028, + 0.37985235, + 0.3803134, + 0.38228273, + 0.38304198, + 0.38479155, + 0.3852964, + 0.38904178, + 0.3899988, + 0.3928305, + 0.39620972, + 0.39629877, + 0.3979556, + 0.39827055, + 0.39842975, + 0.39904678, + 0.39906925, + 0.39978993, + 0.40088493, + 0.40134054, + 0.40462768, + 0.404957, + 0.4063158, + 0.4068821, + 0.41023225, + 0.41118395, + 0.4114716, + 0.41150188, + 0.41215366, + 0.41326004, + 0.41435915, + 0.4147135, + 0.41501343, + 0.41542965, + 0.41573375, + 0.41749775, + 0.41900802, + 0.41994262, + 0.4200377, + 0.42008877, + 0.4226243, + 0.42288208, + 0.42289335, + 0.42433316, + 0.4251055, + 0.42787945, + 0.42891055, + 0.42942703, + 0.43258083, + 0.4327789, + 0.43314546, + 0.43395442, + 0.4362995, + 0.43698066, + 0.43704957, + 0.43822384, + 0.4383297, + 0.4388845, + 0.44013077, + 0.44029474, + 0.44146562, + 0.44382614, + 0.44514078, + 0.44537747, + 0.44858456, + 0.451209, + 0.4533769, + 0.45351148, + 0.4536326, + 0.45463926, + 0.45597613, + 0.457215, + 0.457354, + 0.4574275, + 0.45825773, + 0.46045, + 0.46281397, + 0.46486145, + 0.46529734, + 0.4662627, + 0.46921813, + 0.4710188, + 0.47181886, + 0.473154, + 0.47329968, + 0.47474664, + 0.47546828, + 0.4755246, + 0.47677714, + 0.47688937, + 0.4769684, + 0.47703332, + 0.47806334, + 0.47984606, + 0.4799099, + 0.4803009, + 0.48041505, + 0.4849192, + 0.4854672, + 0.48731065, + 0.4873348, + 0.48768485, + 0.48779655, + 0.48846513, + 0.4902075, + 0.49033952, + 0.49229932, + 0.49282104, + 0.4932829, + 0.49370837, + 0.49555874, + 0.4959759, + 0.49618554, + 0.4963051, + 0.49725115, + 0.49906075, + 0.49924678, + 0.49943197, + 0.50009686, + 0.50303984, + 0.50342965, + 0.5053309, + 0.5059405, + 0.50636065, + 0.507684, + 0.5110267, + 0.51144004, + 0.5123382, + 0.5137753, + 0.51775914, + 0.51790357, + 0.51894265, + 0.5204319, + 0.52069956, + 0.5216087, + 0.5228724, + 0.5234229, + 0.52502894, + 0.5255868, + 0.52581614, + 0.5270535, + 0.52766764, + 0.5292472, + 0.5294491, + 0.5298479, + 0.5319598, + 0.53220785, + 0.5330783, + 0.5338107, + 0.5368486, + 0.5396856, + 0.5413125, + 0.5441584, + 0.5443052, + 0.5462275, + 0.5474061, + 0.5483958, + 0.54845864, + 0.54880697, + 0.5497203, + 0.54972917, + 0.550286, + 0.5503877, + 0.55088305, + 0.5508898, + 0.55202353, + 0.552156, + 0.55282706, + 0.55371666, + 0.5539972, + 0.55431855, + 0.5544396, + 0.5557016, + 0.5565309, + 0.5574478, + 0.5591563, + 0.5614426, + 0.5615999, + 0.5641911, + 0.564712, + 0.5650307, + 0.56534445, + 0.5664016, + 0.5664185, + 0.5668371, + 0.5677659, + 0.5688682, + 0.5690222, + 0.5694369, + 0.57008445, + 0.57122767, + 0.57159394, + 0.5741867, + 0.574775, + 0.5749565, + 0.5753832, + 0.57554376, + 0.57682574, + 0.5776601, + 0.57827556, + 0.5794416, + 0.5796803, + 0.5801384, + 0.58371586, + 0.584813, + 0.5879169, + 0.59084594, + 0.59118164, + 0.59128076, + 0.59261876, + 0.593277, + 0.5933682, + 0.59992826, + 0.6000957, + 0.6021412, + 0.60373807, + 0.6060176, + 0.60635805, + 0.60672015, + 0.60703784, + 0.6070589, + 0.6086167, + 0.6092073, + 0.60930604, + 0.6096073, + 0.6100172, + 0.61121166, + 0.61310744, + 0.6134187, + 0.61628354, + 0.61633843, + 0.6171222, + 0.61723447, + 0.6174343, + 0.6195284, + 0.6201543, + 0.6210417, + 0.62157434, + 0.62234914, + 0.62402165, + 0.6241863, + 0.6242497, + 0.62845016, + 0.62913793, + 0.62946135, + 0.6307104, + 0.63131595, + 0.63221943, + 0.63358235, + 0.6345381, + 0.63455087, + 0.6350247, + 0.63771373, + 0.638046, + 0.6393749, + 0.6395578, + 0.64223933, + 0.642511, + 0.64332944, + 0.6437189, + 0.6475523, + 0.64824784, + 0.64930385, + 0.649773, + 0.6525864, + 0.65281165, + 0.65359414, + 0.65575826, + 0.65626585, + 0.6563289, + 0.6568185, + 0.65764946, + 0.65799284, + 0.6587728, + 0.6592707, + 0.6596801, + 0.65982735, + 0.6607148, + 0.6609412, + 0.66320276, + 0.66352403, + 0.66510236, + 0.66676295, + 0.6674981, + 0.6691359, + 0.66934276, + 0.6703381, + 0.6727177, + 0.67311776, + 0.6731813, + 0.6745325, + 0.67486, + 0.6767176, + 0.6773647, + 0.6780639, + 0.6781688, + 0.6783291, + 0.68259144, + 0.6825995, + 0.6833951, + 0.68357784, + 0.6836139, + 0.68366545, + 0.68668723, + 0.68709916, + 0.68747103, + 0.6907548, + 0.6917526, + 0.6935377, + 0.6942928, + 0.69631076, + 0.6963251, + 0.697178, + 0.69749975, + 0.6979439, + 0.7001151, + 0.70021665, + 0.70027125, + 0.7002744, + 0.7008652, + 0.7031407, + 0.7033474, + 0.7037065, + 0.7042008, + 0.7049292, + 0.7053268, + 0.70680165, + 0.70779675, + 0.70907634, + 0.7090974, + 0.70914066, + 0.71279025, + 0.715438, + 0.71608186, + 0.7177714, + 0.7177797, + 0.7201321, + 0.7201452, + 0.72101295, + 0.7221809, + 0.7223723, + 0.72266537, + 0.7243572, + 0.72531575, + 0.72588295, + 0.7260277, + 0.7284957, + 0.72853225, + 0.7289034, + 0.729311, + 0.73031837, + 0.7308636, + 0.7321341, + 0.73274297, + 0.73324865, + 0.7335111, + 0.73378366, + 0.7349129, + 0.73527753, + 0.73602027, + 0.73920286, + 0.73940843, + 0.7401162, + 0.7410319, + 0.74315673, + 0.7440712, + 0.7451335, + 0.74610305, + 0.747772, + 0.74777824, + 0.74817204, + 0.74838066, + 0.74914914, + 0.751437, + 0.7520571, + 0.7521709, + 0.75444776, + 0.7551755, + 0.7556083, + 0.7556518, + 0.75617754, + 0.7565379, + 0.7582761, + 0.7590387, + 0.7603197, + 0.7610722, + 0.7683766, + 0.76883674, + 0.7689477, + 0.7697948, + 0.7713009, + 0.7737707, + 0.77408105, + 0.7747411, + 0.77631384, + 0.7766895, + 0.7785871, + 0.78139514, + 0.7829644, + 0.78369737, + 0.7844979, + 0.78481346, + 0.7869816, + 0.7887161, + 0.7888443, + 0.7888865, + 0.78958845, + 0.7924014, + 0.79445344, + 0.79562217, + 0.7956536, + 0.79568845, + 0.795832, + 0.79859036, + 0.79923284, + 0.7997489, + 0.80046266, + 0.8009327, + 0.80191493, + 0.8027157, + 0.802962, + 0.80377436, + 0.80386925, + 0.8061867, + 0.80788136, + 0.80906665, + 0.8098419, + 0.8098971, + 0.81026703, + 0.81120723, + 0.81162196, + 0.8121712, + 0.81291664, + 0.81300086, + 0.8130598, + 0.8131314, + 0.8150408, + 0.8152733, + 0.81575716, + 0.8173559, + 0.82030004, + 0.82056034, + 0.820616, + 0.823405, + 0.82581013, + 0.82681596, + 0.8286921, + 0.8291023, + 0.8293057, + 0.83318657, + 0.83587176, + 0.83606917, + 0.8377925, + 0.8382207, + 0.83961886, + 0.841509, + 0.8428508, + 0.84305465, + 0.8437233, + 0.84389865, + 0.84484196, + 0.8449312, + 0.84558177, + 0.84622484, + 0.8477641, + 0.848147, + 0.848783, + 0.84964263, + 0.8504162, + 0.85063785, + 0.85122544, + 0.8539795, + 0.85483134, + 0.85545987, + 0.8579076, + 0.8599187, + 0.8617061, + 0.86184824, + 0.8659252, + 0.866569, + 0.86710715, + 0.86827475, + 0.8689161, + 0.8699163, + 0.8707063, + 0.87255853, + 0.8731929, + 0.87429434, + 0.8746262, + 0.8751872, + 0.8753557, + 0.87673867, + 0.8776784, + 0.87804097, + 0.8786339, + 0.880976, + 0.88280004, + 0.88489395, + 0.8870143, + 0.88764375, + 0.8877537, + 0.88848966, + 0.8889426, + 0.89117455, + 0.89136845, + 0.8918461, + 0.8927699, + 0.8940141, + 0.89433634, + 0.8950428, + 0.89547896, + 0.8955092, + 0.89642483, + 0.8972134, + 0.89802104, + 0.89859325, + 0.90036285, + 0.901283, + 0.9022279, + 0.90259147, + 0.9039292, + 0.9041813, + 0.9043403, + 0.90518177, + 0.9053897, + 0.90598094, + 0.9064294, + 0.90707433, + 0.90735143, + 0.90752304, + 0.9109975, + 0.91150093, + 0.91549635, + 0.91688704, + 0.9178185, + 0.9184999, + 0.91859597, + 0.9196396, + 0.9208161, + 0.92136437, + 0.9220043, + 0.9244678, + 0.92839295, + 0.93141407, + 0.93142414, + 0.93260723, + 0.93275, + 0.9342456, + 0.9346345, + 0.9348168, + 0.93528867, + 0.9394962, + 0.94084144, + 0.9410681, + 0.9422157, + 0.9423733, + 0.9434934, + 0.94446266, + 0.9457844, + 0.9472175, + 0.9475713, + 0.9488235, + 0.94918406, + 0.9504976, + 0.95205945, + 0.953649, + 0.9554563, + 0.956561, + 0.9566592, + 0.95678174, + 0.9576585, + 0.95803076, + 0.95816517, + 0.95852894, + 0.9608185, + 0.9613484, + 0.964232, + 0.9642434, + 0.9657087, + 0.9675673, + 0.97022545, + 0.9713107, + 0.97272724, + 0.97320575, + 0.97322446, + 0.97340614, + 0.97449046, + 0.97588015, + 0.97723013, + 0.9777305, + 0.9779671, + 0.97943527, + 0.98203504, + 0.9825553, + 0.98356473, + 0.9837329, + 0.9843066, + 0.9866693, + 0.98759604, + 0.98842853, + 0.9893386, + 0.99028367, + 0.9911397, + 0.9922046, + 0.9923581, + 0.9925594, + 0.99323124, + 0.9933987, + 0.99359006, + 0.9947238, + 0.99609894, + 0.9984882 +}; + diff --git a/benchmarks/sort/sort.c b/benchmarks/sort/sort.c new file mode 100644 index 0000000..53e83c4 --- /dev/null +++ b/benchmarks/sort/sort.c @@ -0,0 +1,253 @@ +#include "sort.h" + +int +n_squared_sort (float * value, int * index, int len) +{ + int i, j; + + for (i = 0; i < len-1; i++) + { + for (j = 0; j < len-1; j++) + { + if (value[j] > value[j+1]) + { + double val_tmp; + int idx_tmp; + + val_tmp = value[j]; + value[j] = value[j+1]; + value[j+1] = val_tmp; + + idx_tmp = index[j]; + index[j] = index[j+1]; + index[j+1] = idx_tmp; + } + } + } + + return 0; +} + + +extern void* fake_malloc_radix(size_t size); + +int +radix_sort_tuples (int * value, int * index, int len, int radix_bits) +{ + int i, j; + int max, min; + int numBuckets = 1 << radix_bits; + int bitMask = numBuckets - 1; + int denShift; + + int * buckets = fake_malloc_radix ((numBuckets + 2) * sizeof(int)); + int * copy1_value = fake_malloc_radix (sizeof(int) * len); + int * copy1_index = fake_malloc_radix (sizeof(int) * len); + int * copy2_value = fake_malloc_radix (sizeof(int) * len); + int * copy2_index = fake_malloc_radix (sizeof(int) * len); + int * tmp_value; + int * tmp_index; + + max = value[0]; + min = value[0]; + for (i = 0; i < len; i++) { + copy1_value[i] = value[i]; + copy1_index[i] = index[i]; + if (max < value[i]) { + max = value[i]; + } + if (min > value[i]) { + min = value[i]; + } + } + min = -min; + max += min; + + for (i = 0; i < len; i++) + { + copy1_value[i] += min; + } + + denShift = 0; + for (i = 0; max != 0; max = max / numBuckets, i++) + { + for (j = 0; j < numBuckets + 2; j++) + { + buckets[j] = 0; + } + + buckets += 2; + + for (j = 0; j < len; j++) + { + int myBucket = (int) (((int) copy1_value[j]) >> denShift) & bitMask; + buckets[myBucket]++; + } + + for (j = 1; j < numBuckets; j++) + { + buckets[j] += buckets[j-1]; + } + + buckets--; + + for (j = 0; j < len; j++) + { + int myBucket = (int) (((int) copy1_value[j]) >> denShift) & bitMask; + int index = buckets[myBucket]++; + copy2_value[index] = copy1_value[j]; + copy2_index[index] = copy1_index[j]; + } + + buckets--; + denShift += radix_bits; + + tmp_value = copy1_value; + copy1_value = copy2_value; + copy2_value = tmp_value; + + tmp_index = copy1_index; + copy1_index = copy2_index; + copy2_index = tmp_index; + } + + max = copy1_value[0]; + for (i = 0; i < len; i++) { + if (max < copy1_value[i]) { + max = copy1_value[i]; + } + } + + for (i = 0; i < len; i++) + { + copy1_value[i] -= min; + } + + for (i = 0; i < len; i++) + { + value[i] = copy1_value[i]; + index[i] = copy1_index[i]; + } + + return 0; +} + +int +insertion_sort (float * value, int * index, int len) +{ + int i; + + for (i = 1; i < len; i++) + { + double current; + int cur_index; + int empty; + + current = value[i]; + cur_index = index[i]; + empty = i; + + while (empty > 0 && current < value[empty-1]) + { + value[empty] = value[empty-1]; + index[empty] = index[empty-1]; + empty--; + } + + value[empty] = current; + index[empty] = cur_index; + } + + return 0; +} + + +int +partition (float * array, int * index, int low, int high) +{ + int left, right, mid; + int pivot; + float cur; + int idx; + + mid = (low + high) / 2; + left = low; + right = high; + + /* choose pivot as median of 3: low, high, and mid */ + if ((array[low] - array[mid]) * (array[high] - array[low]) >= 0) + pivot = low; + else if ((array[mid] - array[low]) * (array[high] - array[mid]) >= 0) + pivot = mid; + else + pivot = high; + + /* store value,index at the pivot */ + cur = array[pivot]; + idx = index[pivot]; + + /* swap pivot with the first entry in the list */ + array[pivot] = array[low]; + array[low] = cur; + + index[pivot] = array[pivot]; + index[low] = idx; + + /* the quicksort itself */ + while (left < right) + { + while (array[left] <= cur && left < high) + left++; + while (array[right] > cur) + right--; + if (left < right) + { + float tmp_val; + int tmp_idx; + + tmp_val = array[right]; + array[right] = array[left]; + array[left] = tmp_val; + + tmp_idx = index[right]; + index[right] = index[left]; + index[left] = tmp_idx; + } + } + + /* pivot was in low, but now moves into position at right */ + array[low] = array[right]; + array[right] = cur; + + index[low] = index[right]; + index[right] = idx; + + return right; +} + + +int +quicksort_inner (float * array, int * index, int low, int high) +{ + int pivot; + int length = high - low + 1; + + if (high > low) + { + if (length > MAX_THRESH) { + pivot = partition (array, index, low, high); + quicksort_inner (array, index, low, pivot-1); + quicksort_inner (array, index, pivot+1, high); + } + } + + return 0; +} + +int quicksort (float * array, int * index, int len) +{ + quicksort_inner (array, index, 0, len-1); + insertion_sort (array, index, len); + + return 0; +} diff --git a/benchmarks/sort/sort.h b/benchmarks/sort/sort.h new file mode 100644 index 0000000..326d0de --- /dev/null +++ b/benchmarks/sort/sort.h @@ -0,0 +1,53 @@ +#include +#include +#include + +#define FAKE_MALLOC_INIT(words, name) \ + uint32_t heap_##name[words]; \ + const size_t max_alloc_##name = (words) * sizeof(uint32_t); \ + size_t cur_pos_##name; \ + void* fake_malloc_##name( size_t size ) \ + { \ + static bool init = false; \ + if(!init) { \ + cur_pos_##name = 0; \ + init = true; \ + } \ + if(cur_pos_##name < (words)) { \ + void *ptr = (void*) &heap_##name[cur_pos_##name]; \ + cur_pos_##name += size & ~((uint32_t)3) + 1; \ + return ptr; \ + } else { \ + return NULL; \ + } \ + } + + + +#ifndef _TAV_SORT_H_ +#define _TAV_SORT_H_ + + +int +n_squared_sort (float * value, int * index, int len); + +int +radix_sort_tuples (int * value, int * index, int len, int radix_bits); + +int +insertion_sort (float * value, int * index, int len); + +int +quicksort (float * array, int * index, int len); + +/* This defines the length at quicksort switches to insertion sort */ +#ifndef MAX_THRESH +#define MAX_THRESH 10 +#endif + +#ifndef RADIX_BITS +#define RADIX_BITS (8) +#endif + + +#endif /* _TAV_SORT_H_ */ diff --git a/benchmarks/sort/sort_gendata.scala b/benchmarks/sort/sort_gendata.scala new file mode 100755 index 0000000..820dbc8 --- /dev/null +++ b/benchmarks/sort/sort_gendata.scala @@ -0,0 +1,26 @@ +#!/usr/bin/env scala + +import scala.util.Sorting + +val size = args(0).toInt + +def rand_array(size: Int) = { + var r = new scala.util.Random + Array.fill(size) { r.nextFloat() } +} + +def print_array(name: String, size: Int, arr: Array[Float]) { + println("float "+name+"["+size+"] = {") + for(i <- 0 to size-2) + println(" "+arr(i)+",") + println(" "+arr(size-1)+"\n};\n") +} + +println("#define DATA_SIZE_SORT " + size) + +val a = rand_array(size) +val sorted = a.clone() +Sorting.quickSort(sorted) + +print_array("input_data_sort", size, a) +print_array("verify_data_sort", size, sorted) diff --git a/benchmarks/sort/sort_main.c b/benchmarks/sort/sort_main.c new file mode 100644 index 0000000..a4df38d --- /dev/null +++ b/benchmarks/sort/sort_main.c @@ -0,0 +1,93 @@ +// **************************************************************************** +// sort benchmark from DARPA PERFECT TAV suite +// ---------------------------------------------------------------------------- +#include "sort.h" +#include "util.h" +#include "dataset.h" + +#define USE_RADIX_SORT + +// Need 7 times the input size for: input data, indices, +// four copies, and buckets. +FAKE_MALLOC_INIT( (8 * DATA_SIZE_SORT), radix ) + +int main( int argc, char* argv[] ) +{ + int err; + + int* index = fake_malloc_radix (sizeof(int) * DATA_SIZE_SORT); + for ( int i = 0; i < DATA_SIZE_SORT; i++ ) + index[i] = i; + +#ifdef PREALLOCATE + // Access every element of input_data_sort to make sure it's in cache + // (or at least that as much as possible of its beginning is). + float sum = 0; + for(int i = DATA_SIZE_SORT-1; i >= 0; i--) { + sum += input_data_sort[i]; + } + if(sum < 0.1) + return 1; + + const bool prealloc = true; +#else + const bool prealloc = false; +#endif + + setStats(1); + +#define read_csr_safe(reg) ({ long __tmp = 0; \ + asm volatile ("csrr %0, " #reg : "+r"(__tmp)); \ + __tmp; }) + + + long cycles = read_csr_safe(cycle); + long instret = read_csr_safe(instret); + + // Do sorting +#if defined(USE_N_SQUARED_SORT) + const char* algo = "N_SQUARED"; + err = n_squared_sort ( input_data_sort, index, DATA_SIZE_SORT ); +#elif defined(USE_RADIX_SORT) + const char* algo = "RADIX"; + err = radix_sort_tuples ( (int *) input_data_sort, index, DATA_SIZE_SORT, RADIX_BITS ); +#elif defined(USE_INSERTION_SORT) + const char* algo = "INSERTION"; + err = insertion_sort ( input_data_sort, index, DATA_SIZE_SORT ); +#else + const char* algo = "QUICKSORT"; + err = quicksort ( input_data_sort, index, DATA_SIZE_SORT ); +#endif + + cycles = read_csr_safe(cycle) - cycles; + instret = read_csr_safe(instret) - instret; + + setStats(0); + + // Validate result + err = 0; + for(int i = 0; i < DATA_SIZE_SORT-1; i++) + { + if((unsigned int) input_data_sort[i] > (unsigned int) input_data_sort[i+1]) + { + err = i; + for(int j = 0; j < DATA_SIZE_SORT; j++) + printf("%d:\t%d\n", j, input_data_sort[j]); + break; + } + } + + /*printf("sort_cycles = %ld\n", cycles); + printf("sort_instret = %d\n", instret); + printf("sort_size = %d\n", DATA_SIZE_SORT); + printf("sort_algo = %s\n", algo); + printf("sort_radix_bits = %d\n", RADIX_BITS); + printf("sort_prealloc = %s\n", prealloc ? "true" : "false"); + printf("sort_err = %d\n", err); + */ + + return err; +} + + +