From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from NAM01-SN1-obe.outbound.protection.outlook.com (mail-sn1nam01on0078.outbound.protection.outlook.com [104.47.32.78]) by dpdk.org (Postfix) with ESMTP id 726481B2E2 for ; Fri, 26 Jan 2018 06:05:30 +0100 (CET) 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=Bq216R57Sspcoa1fXSRFBMDLiC7U1rRO9l73PIsPK/4=; b=attd5QuIZZ+mI923ASa3AlHPkrHKBhGUl56r3nfGD76Da8dYdpAIufTsp7AsXWO2YVrPHhLIne1spvIr19MZgY9J1I98jB4dI6S400v5y+jlKc29icGHr4B+pp5xEGEFTRzxodVwdE/QGHPoEcVFrZo4lJ4dShzKh7badcs/eDM= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Pavan.Bhagavatula@cavium.com; Received: from localhost.localdomain (111.93.218.67) by MWHPR07MB3471.namprd07.prod.outlook.com (10.164.192.22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.444.14; Fri, 26 Jan 2018 05:05:26 +0000 From: Pavan Nikhilesh To: thomas@monjalon.net, cristian.dumitrescu@intel.com, stephen@networkplumber.org Cc: dev@dpdk.org, Pavan Nikhilesh Date: Fri, 26 Jan 2018 10:34:51 +0530 Message-Id: <20180126050451.5953-3-pbhagavatula@caviumnetworks.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180126050451.5953-1-pbhagavatula@caviumnetworks.com> References: <1504032378-5483-1-git-send-email-pbhagavatula@caviumnetworks.com> <20180126050451.5953-1-pbhagavatula@caviumnetworks.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [111.93.218.67] X-ClientProxiedBy: BM1PR0101CA0012.INDPRD01.PROD.OUTLOOK.COM (10.174.220.22) To MWHPR07MB3471.namprd07.prod.outlook.com (10.164.192.22) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 370b80dd-eb2f-426c-a8b9-08d5647a6ac5 X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020); SRVR:MWHPR07MB3471; X-Microsoft-Exchange-Diagnostics: 1; MWHPR07MB3471; 3:SQN0AgXpd6JhpOTu6vSJTZLXOmL/KkeKlANx8n2MlP5/qZwBxd8fy87HAYYBJ6HU/EN48UNKUqBrp7rLhJ+B3mzgZ7oRam2Z6ywCPRuVl+SEmCLSNPwfovV95DkaY5eIGxnBE1rvkOsY8pVhGab1Rf/FgIWRJ8CRWJEhvFjuehCn9E6r9fLiAb6V1Z4nP5Sr+k1Pi5YKNApsMkI9bJkm38J4JmEwmNrp+R8Z+Yi035cTkL988TlIrif1CRNAlL1C; 25:5XPS7FhX/0CZmW4kuGFsDWMAk//hquh/DoYy1eXMLv6g72mpKgM3QzvvL1eCOzmD5DLCRpReFjZ/WzBQDm85tWDFB8n66eiBoNfF3duDuWugG2vt6edvoavmuViPJp0Fq7yDt0lCoGwNIr2Xp3rthd+/5iz8dPKPLOmrDnr/NRdO3zxFF86WqOLMKQpOQZjMgaod0f5SYfeth0yC07XXDWJgB258mtHxbgccfrZ09QwkVISJvtkn5GIb4OyIO6DP3WxsJcOqkx767mQ2ed4y+sMZ/tH48B2wITbJXVRBHtW/P6KHoZ9FUBmLL7VtDO4MGaWtLg1oVMfkGLK2aP9hIA==; 31:tH0+srF4VPys0yULk5Zl5liBuA3RBR9LtXkGChz3qX+K9HqgayhtX/R4Ka9DTd4bXG86bDLLMTudRdluq92hR1GaUd/0HzI47aJFHfTLGqybywBwI4JsWxKqtMRpQBs/O1MzKxdqMEk/Xjhx5BnMbpLIK3VOveOlqtvb6RS3FcAd/rraGghjZFiy3LY/SjjGH0e9r05zTD/tt4FteSY23HzyiQtpSAedetFZuvrm0zg= X-MS-TrafficTypeDiagnostic: MWHPR07MB3471: X-Microsoft-Exchange-Diagnostics: 1; MWHPR07MB3471; 20:6y7NiA7NLXp+EG7DTw225CSeN/inkB0yIPdZuZ/bwOxqeNrNKTmrH0+3toFh0PMlWLnLQyznDzPmnzWYvaVxncDBXCMbtr1x2YLSkvyWuEslmj/DOGdYHtSt+xlpQIMqz3htd4tNC34zFFGDAO9g8Nsw88jF1BQQRsjuedmQZTHComRC0eXmuQ/2M/CQuggQqXwULyHGs814PnadQhm/NjbcoHHRqHukqCdohIrppazfrId5Qlw+EYM1Z30bAGPoXnVj5hugh/LdEk4eqVDTbXahrxdFYlFFv59X91j5wafFIgsSRDVsmQ6ihcVl49ewfh6dYlogFIALBKJi+kroEIi9h+a16WnJcK03w+qk+pZISectqqhTovGnBZbekCevgITdE/WAyFqVtWrEijIR5vJhyD3zGWk48szT0PXbZVtcdtOvbA6GM8xB+nxhqfZCNMCF/FVe4r93fGNhW0SeB49xWX/5kPD5Ex/ubkFsFd+nrUoPM385HEs/eBFcMhRhEvp/ttVs7aqzmY5Qx5pnZe3ajasIyHPUL4T7MOQh+a+A0QX4bakPQoDPhlryZ+MXlEaGMZBysFTbUBcek1LN9zP+nJRYOkDiciwOOwmS1oo=; 4:8alHJCv+UFOCxEzE27F4iSC/H7YPyvkxzT4j+wymArFRg9GL+FJHnXpImFW5yW+yMWf5/3dLSVv3FOCLDeLJcgRitN5DVLuweLRojQMGly6U9+1mRx1dWzQWB3Gk9dwS+wYFeh8sx3l//qibA8vxUQnKaECCP/rTyK+rUs84Lq/Dp9jNPH6zEQA6WyaJVmwxcN/ERNjeIZtnAvHuxb5W4AlKJ2PoNzKqcVSF5Y53kPKYUavrtaG1uFjR3m682m2MoeINEp0qvPSLX3YRC3Shng== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040501)(2401047)(5005006)(8121501046)(10201501046)(93006095)(3231023)(2400081)(944501161)(3002001)(6041288)(20161123562045)(20161123558120)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(6072148)(201708071742011); SRVR:MWHPR07MB3471; BCL:0; PCL:0; RULEID:; SRVR:MWHPR07MB3471; X-Forefront-PRVS: 05641FD966 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(6069001)(39850400004)(39380400002)(396003)(346002)(376002)(366004)(199004)(189003)(8676002)(5660300001)(8936002)(36756003)(50466002)(1076002)(26005)(6116002)(2906002)(81156014)(52116002)(42882006)(2950100002)(97736004)(16526019)(6666003)(68736007)(50226002)(81166006)(51416003)(76176011)(5009440100003)(186003)(105586002)(6512007)(3846002)(25786009)(6486002)(106356001)(16586007)(316002)(66066001)(53936002)(48376002)(386003)(7736002)(47776003)(72206003)(305945005)(6506007)(478600001)(107886003)(4326008)(42262002); DIR:OUT; SFP:1101; SCL:1; SRVR:MWHPR07MB3471; H:localhost.localdomain; FPR:; SPF:None; PTR:InfoNoRecords; A:1; MX: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; MWHPR07MB3471; 23:FLk2rGT2BEHpjV5DW+myxu/bmdWSCjT6EPnA7vxMV?= =?us-ascii?Q?STRC97ZilH2O/MrkUccDhM2qQ4OEuMyVv4MicM+LulzAxDeuTsDvdoevip0e?= =?us-ascii?Q?SPxGXzTcUA1Ps/qAJewvKsLwwxqF3Dwxl/w1NpPUw5phl0Fd5mP7Qk9maFd1?= =?us-ascii?Q?V8p/7ySbobC0FGBALt397I5PZj8WzbLjtmATOLOtGAznI/i7HBSRnWM9OkQl?= =?us-ascii?Q?+XuRu0Q4SUQRft/2cxBY3KPc9zbMfXmnxnUQpPZs5z2Uud3HtKKJRUuYiV8s?= =?us-ascii?Q?daCO5A0yQrxM+MoNlzqSFMWd7zYnkxBoe9jx9C7lJoO68eNqvvCO+3BXX3RD?= =?us-ascii?Q?K0agEvpkZBvg2HfZHZqU7s2Vedv1AjNf12Xsl4s4ipywYQK8BveRx+U71MkA?= =?us-ascii?Q?XZXKl8MUsfdZ1v2i55cFqDMutKSt4IyfTVB4VzA2QNm12FDUXvYB/+B5Loqk?= =?us-ascii?Q?xJcgDJg8RjocFm0VWJRuY1SV7V3yWAyUTTM9MZ7qGrnVrdkQDyaTYfr/bzmw?= =?us-ascii?Q?CvSbvoMMona1wsfjHPuT9xTs1tfA7LjtmtxilDpF3NYj8wUIihbHrw00LAME?= =?us-ascii?Q?cGsnha9xW1Ugw3OPOVNVo/UkohjHpNhY1gLXJN8xfjdqU70ldGbZBXNDlRms?= =?us-ascii?Q?5fhbQ1XAxOtap4Q1CfQbKwdeqy1y2ri6eSAjGr7YBUAJrNlTlkBbYxuRiOci?= =?us-ascii?Q?+96escyr1JnZd4lFyBWvw6Jeow9st8ncJ4Tt+VIdm3XfdrcPkGHzDhx7XxKw?= =?us-ascii?Q?zUF2Ah5lO24vwDyLnBZZtoooc583BAfCt0IRT1cV+QE1+A3T/cIRU2C0lz0N?= =?us-ascii?Q?QpSnCSbxKkkxuo7GchUuX3FRrHMphLyEIoG/kn1QGQ1EH63rGhRYYuZvPZ3u?= =?us-ascii?Q?mdkYnx/HTqGQedjlGv8GTx32eWRoiNs22yZTNmujFzaM9VbG7aFpquV1qKns?= =?us-ascii?Q?S3hhIO7RALzxzhRwFhTri5vvEsFf5d7irssA7Yixlc6C5M/paz+sJUcxiZol?= =?us-ascii?Q?x8FH1Wx3ofBaA46CnLidddliUqa7oQdZU6qS95fp4zoGKkELEsMxvsTPaaOY?= =?us-ascii?Q?tfAuKIX1Z7gA2e88sz02+BLNQbOs2cwndzGK+Zzxq3QyMfj81B37AjVjCpK/?= =?us-ascii?Q?MkSIwqQNHISljCV4oy5fbTTJk9NxR6inLGpP7ekb/wz+EF55bbWfFWngHtD6?= =?us-ascii?Q?Zr+7NX6Xo9AhOxQGXXwCo9HOGh2/J9cyufl?= X-Microsoft-Exchange-Diagnostics: 1; MWHPR07MB3471; 6:qEtK8dy2p+VvKRJa9M7wqJfy7UmJJMyXGMbe6+ZPE82HPfBaBj/X3T2mcVYmf6/p0EAoMWKZ/Fmsn1z4vo4byJ6Ecetai/t8oZChFDkxnShV9jVYAwqRlvnY8DtdjHVSLV3Ttw4/pb2kKlCIS9jKFPFum2Ly/EbGaNZr+xYj0+6eaUub5qwW8+XLe7cusCLLr62Kb5VcBsRMUOant+1fJO2tFbhFPMuFh08cmhvU3ygWRMaQVljxuCGS5u/uiC1UNb2grqVRhp++69iyb/Rb8YR56CcrxB3qDImv0XK2xS05poBVPUi470YCL8hOpkkRcOxs+QxgT56XdRzvUzu6Ag==; 5:pUKEEXlY39mNwJVP4z2d7WlTkVYSuvI1bOpSmj6n8GDGDpRdUnD8yHvGZ9tTIz+xajVoe4K500N0idc92zPKy+qPv3t5jm0iR4OI7u4YLhNr0MiMvsvm0Y8fEEBcZDw3qX5iDEst0dFfmn8D/5PrrMfg2P1WrnCwsRkqH00/fBo=; 24:1OtQ02z2U16kgH0ixw8Kf6ldbRPdkNdHLqI5KKp1FIRTyh7zG2YzEmpM4qNtpm7blCNRaoFZGeRd5ggUCHhD0Co7hQ54ynLB6nmSP/Wmq1k=; 7:AW9QgXS72oxFMW2Wum8MEWbXlYHHePASdLGjFdR92DdJ8VjVFknJnFpYNXvPpsDLoH1bfUM31NrJ1nXbtyZ8CyUM6sHzWectCtyjbADyDfzcdBQ1gxNKBImB0nxvbi0KjfFsn3d6/cfYg42Jc7zs99VA7NVFuliucQEoiMOPXFhykQP4is3zloRvUPASkinaOyPwAJA2ZLc901WlRE0fFU1q+gimrAofwMQPyiGm7ic2OrIvNNySO/2uOuMO/S8S SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: caviumnetworks.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jan 2018 05:05:26.3231 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 370b80dd-eb2f-426c-a8b9-08d5647a6ac5 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR07MB3471 Subject: [dpdk-dev] [PATCH v8 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: Fri, 26 Jan 2018 05:05:31 -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 | 167 +++++++++++++++++++++++++ test/test/test_reciprocal_division_perf.c | 201 ++++++++++++++++++++++++++++++ 3 files changed, 370 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 5ba5a9ac7..c943a927a 100644 --- a/test/test/Makefile +++ b/test/test/Makefile @@ -67,6 +67,8 @@ SRCS-y += test_spinlock.c SRCS-y += test_memory.c SRCS-y += test_memzone.c SRCS-y += test_bitmap.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 000000000..8ea9b1d24 --- /dev/null +++ b/test/test/test_reciprocal_division.c @@ -0,0 +1,167 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2017 Cavium, Inc + */ + +#include "test.h" + +#include +#include +#include + +#include +#include +#include +#include + +#define MAX_ITERATIONS (1ULL << 32) +#define DIVIDE_ITER (100) + +static int +test_reciprocal(void) +{ + int result = 0; + uint32_t divisor_u32 = 0; + uint32_t dividend_u32; + uint32_t nresult_u32; + uint32_t rresult_u32; + uint64_t i, j; + uint64_t divisor_u64 = 0; + uint64_t dividend_u64; + uint64_t nresult_u64; + uint64_t rresult_u64; + struct rte_reciprocal 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(divisor_u32); + } + + dividend_u32 = rte_rand(); + nresult_u32 = dividend_u32 / divisor_u32; + rresult_u32 = rte_reciprocal_divide(dividend_u32, + reci_u32); + if (nresult_u32 != rresult_u32) { + printf("Division failed, %"PRIu32"/%"PRIu32" = " + "expected %"PRIu32" result %"PRIu32"\n", + dividend_u32, divisor_u32, + 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, %"PRIu64"/%"PRIu64" = " + "expected %"PRIu64" result %"PRIu64"\n", + dividend_u64, divisor_u64, + nresult_u64, rresult_u64); + result = 1; + break; + } + } + + 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(); + + nresult_u64 = dividend_u64 / divisor_u64; + rresult_u64 = rte_reciprocal_divide_u64(dividend_u64, + &reci_u64); + + if (nresult_u64 != rresult_u64) { + printf("Division failed, %"PRIu64"/%"PRIu64" = " + "expected %"PRIu64" result %"PRIu64"\n", + dividend_u64, divisor_u64, + nresult_u64, rresult_u64); + result = 1; + break; + } + } + + printf("Validating division by power of 2.\n"); + for (i = 0; i < 32; i++) { + divisor_u64 = 1ull << i; + reci_u64 = rte_reciprocal_value_u64(divisor_u64); + reci_u32 = rte_reciprocal_value((uint32_t)divisor_u64); + + for (j = 0; j < MAX_ITERATIONS >> 4; j++) { + 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 64 failed, %"PRIu64"/%"PRIu64" = " + "expected %"PRIu64" result %"PRIu64"\n", + dividend_u64, divisor_u64, + nresult_u64, rresult_u64); + result = 1; + } + + nresult_u32 = (dividend_u64 >> 32) / divisor_u64; + rresult_u32 = rte_reciprocal_divide( + (dividend_u64 >> 32), reci_u32); + + if (nresult_u32 != rresult_u32) { + printf( + "Division 32 failed, %"PRIu64"/%"PRIu64" = " + "expected %"PRIu64" result %"PRIu64"\n", + dividend_u64 >> 32, divisor_u64, + nresult_u64, rresult_u64); + result = 1; + break; + } + } + } + + for (; i < 64; i++) { + divisor_u64 = 1ull << i; + reci_u64 = rte_reciprocal_value_u64(divisor_u64); + + for (j = 0; j < MAX_ITERATIONS >> 4; j++) { + 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, %"PRIu64"/%"PRIu64" = " + "expected %"PRIu64" result %"PRIu64"\n", + dividend_u64, divisor_u64, + nresult_u64, rresult_u64); + result = 1; + break; + } + } + } + + return result; +} + +REGISTER_TEST_COMMAND(reciprocal_division, test_reciprocal); diff --git a/test/test/test_reciprocal_division_perf.c b/test/test/test_reciprocal_division_perf.c new file mode 100644 index 000000000..a7be8aa71 --- /dev/null +++ b/test/test/test_reciprocal_division_perf.c @@ -0,0 +1,201 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2017 Cavium, Inc + */ + +#include "test.h" + +#include +#include +#include + +#include +#include +#include +#include + +#define MAX_ITERATIONS (1ULL << 32) +#define DIVIDE_ITER (1ULL << 28) + +static int +test_reciprocal_division_perf(void) +{ + int result = 0; + uint32_t divisor_u32 = 0; + uint32_t dividend_u32; + uint64_t divisor_u64 = 0; + uint64_t dividend_u64; + volatile uint32_t nresult_u32; + volatile uint32_t rresult_u32; + volatile uint64_t nresult_u64; + volatile uint64_t rresult_u64; + uint64_t start_cyc; + uint64_t split_cyc; + uint64_t end_cyc; + uint64_t tot_cyc_n = 0; + uint64_t tot_cyc_r = 0; + uint64_t i; + struct rte_reciprocal 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(divisor_u32); + } + + dividend_u32 = rte_rand(); + + start_cyc = rte_rdtsc(); + nresult_u32 = dividend_u32 / divisor_u32; + split_cyc = rte_rdtsc(); + rresult_u32 = rte_reciprocal_divide(dividend_u32, + reci_u32); + end_cyc = rte_rdtsc(); + + tot_cyc_n += split_cyc - start_cyc; + tot_cyc_r += end_cyc - split_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(reciprocal) : %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(); + + start_cyc = rte_rdtsc(); + nresult_u64 = dividend_u64 / divisor_u64; + split_cyc = rte_rdtsc(); + rresult_u64 = rte_reciprocal_divide_u64(dividend_u64, + &reci_u64); + end_cyc = rte_rdtsc(); + + tot_cyc_n += split_cyc - start_cyc; + tot_cyc_r += end_cyc - split_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(reciprocal) : %3.2f\n\n", + ((double)tot_cyc_r)/i); + + tot_cyc_n = 0; + tot_cyc_r = 0; + + 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(); + + start_cyc = rte_rdtsc(); + nresult_u64 = dividend_u64 / divisor_u64; + split_cyc = rte_rdtsc(); + rresult_u64 = rte_reciprocal_divide_u64(dividend_u64, + &reci_u64); + end_cyc = rte_rdtsc(); + + tot_cyc_n += split_cyc - start_cyc; + tot_cyc_r += end_cyc - split_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(reciprocal) : %3.2f\n\n", + ((double)tot_cyc_r)/i); + + tot_cyc_n = 0; + tot_cyc_r = 0; + + printf("Validating division by power of 2.\n"); + for (i = 0; i < 64; i++) { + divisor_u64 = 1ull << i; + reci_u64 = rte_reciprocal_value_u64(divisor_u64); + + dividend_u64 = rte_rand(); + + start_cyc = rte_rdtsc(); + nresult_u64 = dividend_u64 / divisor_u64; + split_cyc = rte_rdtsc(); + rresult_u64 = rte_reciprocal_divide_u64(dividend_u64, + &reci_u64); + end_cyc = rte_rdtsc(); + + tot_cyc_n += split_cyc - start_cyc; + tot_cyc_r += end_cyc - split_cyc; + if (nresult_u64 != rresult_u64) { + printf("Division 64 failed, %"PRIu64"/%"PRIu64" = " + "expected %"PRIu64" result %"PRIu64"\n", + dividend_u64, divisor_u64, + 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(reciprocal) : %3.2f\n", + ((double)tot_cyc_r)/i); + + return result; +} + +REGISTER_TEST_COMMAND(reciprocal_division_perf, test_reciprocal_division_perf); -- 2.14.1