From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM03-BY2-obe.outbound.protection.outlook.com (mail-by2nam03on0068.outbound.protection.outlook.com [104.47.42.68]) by dpdk.org (Postfix) with ESMTP id 5FE207CCA for ; Sun, 3 Sep 2017 14:37:10 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=BYdEUNn9VND745guVeHAo2ZywOdm+RDl3/hO81aXg8c=; b=hq9QvHDC27A7Yy9dOIk/89VXX/f/0SVlAre0DM09NvjkVMuhZVj+eOc9Q1GjayQy0TojGXR7mleExWV48vjJCNBiyHBb5v5AU4HDIc5jSXt58eSLDSQYaz8xSjc3BK9+aYPshpiucSHHldp+T/UoWQntPgwTu2fHIfEenRcrwus= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Pavan.Bhagavatula@cavium.com; Received: from localhost.localdomain (103.16.71.101) by BN6PR07MB3457.namprd07.prod.outlook.com (10.161.153.20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.13.10; Sun, 3 Sep 2017 12:37:07 +0000 From: Pavan Nikhilesh To: dev@dpdk.org Cc: cristian.dumitrescu@intel.com, stephen@networkplumber.org, Pavan Nikhilesh Date: Sun, 3 Sep 2017 18:06:29 +0530 Message-Id: <1504442189-4384-3-git-send-email-pbhagavatula@caviumnetworks.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1504442189-4384-1-git-send-email-pbhagavatula@caviumnetworks.com> References: <1504442189-4384-1-git-send-email-pbhagavatula@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [103.16.71.101] X-ClientProxiedBy: SG2PR0601CA0005.apcprd06.prod.outlook.com (10.170.128.15) To BN6PR07MB3457.namprd07.prod.outlook.com (10.161.153.20) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 80fc1591-dfce-439f-ed92-08d4f2c87e0b X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(300000500095)(300135000095)(300000501095)(300135300095)(300000502095)(300135100095)(22001)(2017030254152)(300000503095)(300135400095)(2017052603199)(201703131423075)(201703031133081)(201702281549075)(300000504095)(300135200095)(300000505095)(300135600095)(300000506095)(300135500095); SRVR:BN6PR07MB3457; X-Microsoft-Exchange-Diagnostics: 1; BN6PR07MB3457; 3:W4a/E+joJWi68NTvTWKgPnAt69kZ+xRkBniw7JHOT9NKpLlrzwsTI4a3K/PnKhWHr++vu57QGT5W1U5Df73dE15xpuVqzHUqA+Es32dacngUBiaIR4pD4MNtYr05xMnhQeJi9bvh0Guy9puTFZJd9nl6VJ0qpZDQd65VLyD4kE9z7hwmvnOyD3JrFkugh91MlRN2EUeh1bsagJrtFEIztmrCodWFq6HHE5bN31/UdXp/B1O7hlYWKDBP6RewiIL/; 25:nUEtw2j5B9XFMIWOAUHZNbVu2SovccVvZfFzfoaHGEkPTQzKV8T5+DLps+PQwuNQk0nCqgqVYpFi/55xOz7q9GP9iUyHOhmci0ze1o91LOOwekpvMLVi6FQFaV4Tk2CBkz77zV2zTyraWUkJLIdawh3Zmzc8O4gIIqSTv0VC/9138A1SYX1YgA8IgBfQ19w8C21c3BtjKu8ETMZv2JS0y/Va0wEEeTXQQynb/9tyN05CD2nBiaQxw7BftNk0eSwCbf+OcTCl1taK3Wqr+QtRG/QwFmHLq9zDXRkhHxSiLNINmm/nlzc2Hfie7xEO4tTFpZH/knhvLeQavzyPS2YwJg==; 31:KMbH5pRWsgv9tju/czBYtMKk9E7Kc1MIgxtWa5drUk1vQMJHokMoPc7WkcLU9V5lkQS81OKtR4Ud+/rIlHy/vRuQ+X8kQSF8O3XyE8maH8InxFtBKgd3XMdQUIiBdug+m0xhqW513Iy2OWQmQF36RQh58eiKmCA1spKWjJgwpq7hzfkvrYhvDMJOLgnKaCfP7R1RfKL0s3WIhYGufXr5yVI6igHqz+qxqOHKZuRGuDI= X-MS-TrafficTypeDiagnostic: BN6PR07MB3457: X-Microsoft-Exchange-Diagnostics: 1; BN6PR07MB3457; 20:MD9IxbncTpPos8URYgg0xkXhfYpBPgriGgKLyTsjE9/66YQE8I+cCDe2ouVmZsgqsNkpGtDeikm1xsPGcZTIhQ+BOD5rVOKNh86BQsJTXctWbCJII3r4USYQk2nCMsaiiv+nxPLbEYW+GitpeUtW9AR3HBdW7NOUCHvA8xVR4tzIHxQ5jY4GbV7kV3Fq3eha/eARDn9M/y+YAORsEeLAp6ZGvDUtgxV66mnffqCpPlhl4fVLVg9Y8KEnNaY5yTpfq2xmET+URS4F8g1GwIr2WwfvHqv72SL2M72if2hywcdgiLSeOXEflVn007jOiT74jGRStkTGNxhds4tISSyvOmH2XGBJUbhCc9GqWt0ZuVr0LITG0aEjkLpIbOIqCWo/QDTHuUd8PAAPZoTjfLyuHZFspDgXD7U5+Fzbc7QSmzuXmzddMjRYHhnsR1qYHSrrHcLwF9MpxHFbeWlgXSI3JIRP+eEKL9xpIeL/pLiAJS7nUqadO8MbgBnfqnuRDvxaTrCOtTeVAnmUAlppQxd69aXp3kZBFYed6vc0JCTG/LHpO/UTfXkrsFFbO+W3xlhx6Ap1vytftLkpZjykVbpSA15+UtOQsaX0jmilNIGbyoA=; 4:qapLyRE6++x9Tydy0Ty9ckwDxTVNAuQWPaVlWgQ5RAFfVelSsGIRMtA4/0bzm7WG4woteEnH+AcW8qSw5PXrfbCbUO1vwjf7QDkzW52TPFV3rpK8Mhyy5JNWCAxU/fqFP/vB758UrCn0mHCqSL8TuS77NC4D0ICWnLuEyf6NWFQg2E/3sKnA9T66RLw0acFfOgDcCAuSKoUYNDxHb4i89oMHmg1lVSoz5Se98A6Fu6V5tcch0u0WRX1FUtFDkKFt X-Exchange-Antispam-Report-Test: UriScan:; X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(100000700101)(100105000095)(100000701101)(100105300095)(100000702101)(100105100095)(6040450)(601004)(2401047)(8121501046)(5005006)(3002001)(10201501046)(100000703101)(100105400095)(93006095)(6041248)(20161123555025)(20161123560025)(20161123562025)(20161123564025)(20161123558100)(201703131423075)(201702281528075)(201703061421075)(201703061406153)(6072148)(201708071742011)(100000704101)(100105200095)(100000705101)(100105500095); SRVR:BN6PR07MB3457; BCL:0; PCL:0; RULEID:(100000800101)(100110000095)(100000801101)(100110300095)(100000802101)(100110100095)(100000803101)(100110400095)(100000804101)(100110200095)(100000805101)(100110500095); SRVR:BN6PR07MB3457; X-Forefront-PRVS: 041963B986 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6009001)(6069001)(189002)(199003)(107886003)(5003940100001)(6116002)(3846002)(2906002)(189998001)(5660300001)(110136004)(48376002)(53936002)(6512007)(97736004)(50466002)(33646002)(66066001)(2351001)(106356001)(2361001)(105586002)(36756003)(76176999)(6506006)(50986999)(42186005)(47776003)(101416001)(478600001)(6486002)(25786009)(81156014)(50226002)(68736007)(8936002)(305945005)(72206003)(8676002)(81166006)(7736002)(6666003)(42882006)(2950100002)(6916009)(4326008)(42262002); DIR:OUT; SFP:1101; SCL:1; SRVR:BN6PR07MB3457; H:localhost.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; MX:1; A:1; LANG:en; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BN6PR07MB3457; 23:IHmRmXBwurdBn5R9VrJI/up1NBFhrP68kn6sWQ3ak?= =?us-ascii?Q?Cv5K8jaS4UESYEwo2Lg3nxLdXjIca1drm3tD4HbsSLS3IGv+UgKczQW6WMSo?= =?us-ascii?Q?78HqMZJQ0dd13AdLe7W+Bf+YHFVVmpmhyBm/1Wh2coBX4g94TFQfZvPOU5YO?= =?us-ascii?Q?MsqGQF30ZU/uWR0EuxSsr01y1ojK4h6OlzCPJJdgTxUlzz5mig0RnW6xX0Gb?= =?us-ascii?Q?UqB5GKKqaVFw3u5XA7wK6zkWXHOAkIgZWzXSWcec7TS9YhQuRF02tWEZcNui?= =?us-ascii?Q?zjJclaMxoqj1yG9s6ykYAJr24qE/XfpBjhVIIUeq/3zPRsIOBzcRECTMokXn?= =?us-ascii?Q?ophRvjNW5ivQFq/AubPJvBGVbjvjCBTPkjGw3nkY7DZvnYYblzMTyCt5hcqQ?= =?us-ascii?Q?6/rWbPt+PZpmeK1OKoJsq+Iy+AWrv7Wp6Q8umxzw0Ma2XWUeA4X9pyzCGddI?= =?us-ascii?Q?xpTeMsqI3oT3OnqbmzlEmYAgEtcR0XTDCAhOK6bDSRFzZlOPuvnsJPNkoRUz?= =?us-ascii?Q?8Z/C4akvekd9ZIuSyabEemxi+JevfmVYtvG9OcNqyoRLmRzHcaFnPwsHzp2S?= =?us-ascii?Q?g7OvaXcVGd7Wnvm+FIGyP5stKfSxxocOxGQNZwMOA3jjTO2xZimHmVx0Xa+A?= =?us-ascii?Q?kx0IXjyOz/LFHrY9ncJBUC8Cnlnj5Xscr+XoSeK4FqG2iETRSrE5+PH/RnNg?= =?us-ascii?Q?hR/fFayaZ5FENr4Bmc7S9UY4OUnxjcuqy/EJO1cGdm0QO3MrdHVxptMSxAcT?= =?us-ascii?Q?ZdoCPZ/fSKZ1Ol4osE60OeeLERi+z2cF7NASlbji5bokjmwj+O8iCDV/0LYv?= =?us-ascii?Q?zniPnZTk6KYoWai9QZN9oh0SUnjRnkfTwQkyFSNTbYT+AmluqzQMQqYCozxo?= =?us-ascii?Q?ah8IpX1GBcW2qi9H1XQWMRsqvtX+s/ul3rYPIvTnmkjC7C/4JDM6VEsJhIaz?= =?us-ascii?Q?PM9pB3xM/MbbuMXja0npZeAItc8a3z7mXFshc09GBHrc/GqW37J43cUs/Uq8?= =?us-ascii?Q?ZvQ44gnNLjcCtOdvmLn5dHwZxnkroqRWDRlls4pF2ANdA4+vA7DtP0vy/zwk?= =?us-ascii?Q?AUj1gj3MBnRMf9uDA9NjJITzv1LoWTRJVm8X1xbvpBpFlcu+woihfNqbBtSj?= =?us-ascii?Q?GSsYpKgw9kR+3bjqzMa+9L5yDFD6rWj?= X-Microsoft-Exchange-Diagnostics: 1; BN6PR07MB3457; 6:6U6cQxkYpZg03V0O0njfeerOe9mQwo1l1UsnATYpDJEDa7aSRRPNfnSpfIvz6TPjSMM5zoHpAl8cs4TNqtfeEuP0UG+evqPVNMKWUVrEbxtwvBBfA9T1CcjYTwqDBpUNQ5+dbspNNjTX80i6ohze/BFMWs/pW2drAJVJPfujetg5gmIbLz49VZD41ktgHWjBY8ov2Q4UGp2Yiz7vY3HNu83ZIqI2/3NqBypU42OUEz1hnlZJokUB0Fq8dus4ebdfYhaowatSHwZDMlsIkqrWnj+vUE3jsg3zvjAll43cS/kxJbngmLdOX6KwJQxrPNFj7cvIH2uvKKTjYi5+KgZcFg==; 5:KbwRP7sTWU2USnL6bWgWiHSsgqTC8/y0DKnFABJc5oNSL4svVvdOFksFXrgOCbsJ4GHm9xdgsm5vkJvIenzCt9RTgfUbB0KzNKmSS+q+HFwmCL7tmx0ibklJ9Vtq8zGqXVGHJrD80sXm7JZ2PvKDmg==; 24:h7+JmKLVrh/hFuZXwEelrstORd1aSD4Z2tPHCP4mAK8wa7hWwqb8rTEBkVe9ywqRAx/zCrwfj4XcCpBAk43RAqakXW/yin0LfxsOy1gjlT4=; 7:g1Ij17e6samz1PX5KgMu8oTZmdq+ZSSsPIU6/ymXv3YQhaOeFzBkRydGjOog3W7HZu5upLhXsISenbIL+haysR+vvMZ4XO6a/CD3KZMfnRssRAb2OKSg9e6AK0GbKiOv/iM90s8qglVT34jfnl13E1CBsU2Xv4Y848ZGj/G9mO0iWSj09zY/3hgSfUWNDqwP+1eJWa4W5QIY4Zu1KdadANdBbyXKeL2tm5d52reDkMA= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Sep 2017 12:37:07.2705 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR07MB3457 Subject: [dpdk-dev] [PATCH v3 3/3] test: add tests for reciprocal based division X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Sep 2017 12:37:11 -0000 This commit provides a set of tests for verifying the correctness and performance of both unsigned 32 and 64bit reciprocal based division. Signed-off-by: Pavan Nikhilesh --- test/test/Makefile | 2 + test/test/test_reciprocal_division.c | 109 ++++++++++++++++++ test/test/test_reciprocal_division_perf.c | 181 ++++++++++++++++++++++++++++++ 3 files changed, 292 insertions(+) create mode 100644 test/test/test_reciprocal_division.c create mode 100644 test/test/test_reciprocal_division_perf.c diff --git a/test/test/Makefile b/test/test/Makefile index 42d9a49..6017862 100644 --- a/test/test/Makefile +++ b/test/test/Makefile @@ -94,6 +94,8 @@ SRCS-y += test_cycles.c SRCS-y += test_spinlock.c SRCS-y += test_memory.c SRCS-y += test_memzone.c +SRCS-y += test_reciprocal_division.c +SRCS-y += test_reciprocal_division_perf.c SRCS-y += test_ring.c SRCS-y += test_ring_perf.c diff --git a/test/test/test_reciprocal_division.c b/test/test/test_reciprocal_division.c new file mode 100644 index 0000000..771ea64 --- /dev/null +++ b/test/test/test_reciprocal_division.c @@ -0,0 +1,109 @@ +/* + * BSD LICENSE + * + * Copyright (C) Cavium, Inc. 2017. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Cavium, Inc nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "test.h" + +#include +#include +#include + +#include +#include +#include +#include + +#define MAX_ITERATIONS 1000000 +#define DIVIDE_ITER 100 + +static int +test_reciprocal_division(void) +{ + int i; + int result = 0; + uint32_t divisor_u32 = 0; + uint32_t dividend_u32; + uint32_t nresult_u32; + uint32_t rresult_u32; + uint64_t divisor_u64 = 0; + uint64_t dividend_u64; + uint64_t nresult_u64; + uint64_t rresult_u64; + struct rte_reciprocal_u32 reci_u32; + struct rte_reciprocal_u64 reci_u64; + + rte_srand(rte_rdtsc()); + printf("Validating unsigned 32bit division.\n"); + for (i = 0; i < MAX_ITERATIONS; i++) { + /* Change divisor every DIVIDE_ITER iterations. */ + if (i % DIVIDE_ITER == 0) { + divisor_u32 = rte_rand(); + reci_u32 = rte_reciprocal_value_u32(divisor_u32); + } + + dividend_u32 = rte_rand(); + nresult_u32 = dividend_u32 / divisor_u32; + rresult_u32 = rte_reciprocal_divide_u32(dividend_u32, + &reci_u32); + if (nresult_u32 != rresult_u32) { + printf("Division failed, expected %"PRIu32" " + "result %"PRIu32"", + nresult_u32, rresult_u32); + result = 1; + break; + } + } + + printf("Validating unsigned 64bit division.\n"); + for (i = 0; i < MAX_ITERATIONS; i++) { + /* Change divisor every DIVIDE_ITER iterations. */ + if (i % DIVIDE_ITER == 0) { + divisor_u64 = rte_rand(); + reci_u64 = rte_reciprocal_value_u64(divisor_u64); + } + + dividend_u64 = rte_rand(); + nresult_u64 = dividend_u64 / divisor_u64; + rresult_u64 = rte_reciprocal_divide_u64(dividend_u64, + &reci_u64); + if (nresult_u64 != rresult_u64) { + printf("Division failed, expected %"PRIu64" " + "result %"PRIu64"", + nresult_u64, rresult_u64); + result = 1; + break; + } + } + + return result; +} + +REGISTER_TEST_COMMAND(reciprocal_division, test_reciprocal_division); diff --git a/test/test/test_reciprocal_division_perf.c b/test/test/test_reciprocal_division_perf.c new file mode 100644 index 0000000..31f069d --- /dev/null +++ b/test/test/test_reciprocal_division_perf.c @@ -0,0 +1,181 @@ +/* + * BSD LICENSE + * + * Copyright (C) Cavium, Inc. 2017. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Cavium, Inc nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include "test.h" + +#include +#include +#include + +#include +#include +#include +#include + +#define MAX_ITERATIONS 1000000 +#define DIVIDE_ITER 100 + +static int +test_reciprocal_division_perf(void) +{ + int result = 0; + uint32_t divisor_u32 = 0; + uint32_t dividend_u32; + uint32_t nresult_u32; + uint32_t rresult_u32; + uint64_t divisor_u64 = 0; + uint64_t dividend_u64; + uint64_t nresult_u64; + uint64_t rresult_u64; + uint64_t cur_cyc; + uint64_t tot_cyc_n = 0; + uint64_t tot_cyc_r = 0; + uint64_t i; + struct rte_reciprocal_u32 reci_u32 = {0}; + struct rte_reciprocal_u64 reci_u64 = {0}; + + rte_srand(rte_rdtsc()); + printf("Validating unsigned 32bit division.\n"); + for (i = 0; i < MAX_ITERATIONS; i++) { + /* Change divisor every DIVIDE_ITER iterations. */ + if (i % DIVIDE_ITER == 0) { + divisor_u32 = rte_rand(); + reci_u32 = rte_reciprocal_value_u32(divisor_u32); + } + + dividend_u32 = rte_rand(); + cur_cyc = rte_rdtsc(); + nresult_u32 = dividend_u32 / divisor_u32; + tot_cyc_n += rte_rdtsc() - cur_cyc; + + cur_cyc = rte_rdtsc(); + rresult_u32 = rte_reciprocal_divide_u32(dividend_u32, + &reci_u32); + tot_cyc_r += rte_rdtsc() - cur_cyc; + if (nresult_u32 != rresult_u32) { + printf("Division failed, expected %"PRIu32" " + "result %"PRIu32"", + nresult_u32, rresult_u32); + result = 1; + break; + } + } + printf("32bit Division results:\n"); + printf("Total number of cycles normal division : %"PRIu64"\n", + tot_cyc_n); + printf("Total number of cycles reciprocal division : %"PRIu64"\n", + tot_cyc_r); + printf("Cycles per division(normal) : %3.2f\n", + ((double)tot_cyc_n)/i); + printf("Cycles per division(normal) : %3.2f\n\n", + ((double)tot_cyc_r)/i); + + tot_cyc_n = 0; + tot_cyc_r = 0; + printf("Validating unsigned 64bit division.\n"); + + for (i = 0; i < MAX_ITERATIONS; i++) { + /* Change divisor every DIVIDE_ITER iterations. */ + if (i % DIVIDE_ITER == 0) { + divisor_u64 = rte_rand(); + reci_u64 = rte_reciprocal_value_u64(divisor_u64); + } + + dividend_u64 = rte_rand(); + cur_cyc = rte_rdtsc(); + nresult_u64 = dividend_u64 / divisor_u64; + tot_cyc_n += rte_rdtsc() - cur_cyc; + + cur_cyc = rte_rdtsc(); + rresult_u64 = rte_reciprocal_divide_u64(dividend_u64, + &reci_u64); + tot_cyc_r += rte_rdtsc() - cur_cyc; + if (nresult_u64 != rresult_u64) { + printf("Division failed, expected %"PRIu64" " + "result %"PRIu64"", + nresult_u64, rresult_u64); + result = 1; + break; + } + } + printf("64bit Division results:\n"); + printf("Total number of cycles normal division : %"PRIu64"\n", + tot_cyc_n); + printf("Total number of cycles reciprocal division : %"PRIu64"\n", + tot_cyc_r); + printf("Cycles per division(normal) : %3.2f\n", + ((double)tot_cyc_n)/i); + printf("Cycles per division(normal) : %3.2f\n\n", + ((double)tot_cyc_r)/i); + + printf("Validating unsigned 64bit division with 32bit divisor.\n"); + for (i = 0; i < MAX_ITERATIONS; i++) { + /* Change divisor every DIVIDE_ITER iterations. */ + if (i % DIVIDE_ITER == 0) { + divisor_u64 = rte_rand() >> 32; + reci_u64 = rte_reciprocal_value_u64(divisor_u64); + } + + dividend_u64 = rte_rand(); + cur_cyc = rte_rdtsc(); + nresult_u64 = dividend_u64 / divisor_u64; + tot_cyc_n += rte_rdtsc() - cur_cyc; + + cur_cyc = rte_rdtsc(); + rresult_u64 = rte_reciprocal_divide_u64(dividend_u64, + &reci_u64); + tot_cyc_r += rte_rdtsc() - cur_cyc; + if (nresult_u64 != rresult_u64) { + printf("Division failed, expected %"PRIu64" " + "result %"PRIu64"", + nresult_u64, rresult_u64); + result = 1; + break; + } + } + printf("64bit Division results:\n"); + printf("Total number of cycles normal division : %"PRIu64"\n", + tot_cyc_n); + printf("Total number of cycles reciprocal division : %"PRIu64"\n", + tot_cyc_r); + printf("Cycles per division(normal) : %3.2f\n", + ((double)tot_cyc_n)/i); + printf("Cycles per division(normal) : %3.2f\n", + ((double)tot_cyc_r)/i); + + tot_cyc_n = 0; + tot_cyc_r = 0; + + return result; +} + +REGISTER_TEST_COMMAND(reciprocal_division_perf, test_reciprocal_division_perf); -- 2.7.4