1b78f13911bfe6eda303e91ef215c87a165aae8aeAlexandre Rames// Copyright 2015, VIXL authors 24a102baf640077d6794c0b33bb976f94b86c532barmvixl// All rights reserved. 34a102baf640077d6794c0b33bb976f94b86c532barmvixl// 44a102baf640077d6794c0b33bb976f94b86c532barmvixl// Redistribution and use in source and binary forms, with or without 54a102baf640077d6794c0b33bb976f94b86c532barmvixl// modification, are permitted provided that the following conditions are met: 64a102baf640077d6794c0b33bb976f94b86c532barmvixl// 74a102baf640077d6794c0b33bb976f94b86c532barmvixl// * Redistributions of source code must retain the above copyright notice, 84a102baf640077d6794c0b33bb976f94b86c532barmvixl// this list of conditions and the following disclaimer. 94a102baf640077d6794c0b33bb976f94b86c532barmvixl// * Redistributions in binary form must reproduce the above copyright notice, 104a102baf640077d6794c0b33bb976f94b86c532barmvixl// this list of conditions and the following disclaimer in the documentation 114a102baf640077d6794c0b33bb976f94b86c532barmvixl// and/or other materials provided with the distribution. 124a102baf640077d6794c0b33bb976f94b86c532barmvixl// * Neither the name of ARM Limited nor the names of its contributors may be 134a102baf640077d6794c0b33bb976f94b86c532barmvixl// used to endorse or promote products derived from this software without 144a102baf640077d6794c0b33bb976f94b86c532barmvixl// specific prior written permission. 154a102baf640077d6794c0b33bb976f94b86c532barmvixl// 164a102baf640077d6794c0b33bb976f94b86c532barmvixl// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND 174a102baf640077d6794c0b33bb976f94b86c532barmvixl// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 184a102baf640077d6794c0b33bb976f94b86c532barmvixl// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 194a102baf640077d6794c0b33bb976f94b86c532barmvixl// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 204a102baf640077d6794c0b33bb976f94b86c532barmvixl// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 214a102baf640077d6794c0b33bb976f94b86c532barmvixl// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 224a102baf640077d6794c0b33bb976f94b86c532barmvixl// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 234a102baf640077d6794c0b33bb976f94b86c532barmvixl// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 244a102baf640077d6794c0b33bb976f94b86c532barmvixl// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 254a102baf640077d6794c0b33bb976f94b86c532barmvixl// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 264a102baf640077d6794c0b33bb976f94b86c532barmvixl 278c70cd60ecab6e60c00756f77265e8d1078674c5Georgia Kouveli#include <sys/time.h> 281f9074de150536670464a85ef8e0ede60d26e3f9Alexandre Rames#include "globals-vixl.h" 294a102baf640077d6794c0b33bb976f94b86c532barmvixl 30d3832965c62a8ad461b9ea9eb0994ca6b0a3da2cAlexandre Rames#include "aarch64/instructions-aarch64.h" 31d3832965c62a8ad461b9ea9eb0994ca6b0a3da2cAlexandre Rames#include "aarch64/macro-assembler-aarch64.h" 32b68bacb75c1ab265fc539afa93964c7f51f35589Alexandre Rames 3307d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Ramesusing namespace vixl; 3488c46b84df005638546de5e4e965bdcc31352f48Pierre Langloisusing namespace vixl::aarch64; 354a102baf640077d6794c0b33bb976f94b86c532barmvixl 365289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixlstatic const int kDefaultInstructionCount = 100000; 374a102baf640077d6794c0b33bb976f94b86c532barmvixl 384a102baf640077d6794c0b33bb976f94b86c532barmvixl// Bind many branches to the same label, like bench-branch.cc but with a single 394a102baf640077d6794c0b33bb976f94b86c532barmvixl// label. This stresses the label-linking mechanisms. 404a102baf640077d6794c0b33bb976f94b86c532barmvixlint main(int argc, char* argv[]) { 415289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl int instructions = 0; 424a102baf640077d6794c0b33bb976f94b86c532barmvixl 434a102baf640077d6794c0b33bb976f94b86c532barmvixl switch (argc) { 440f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl case 1: 450f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl instructions = kDefaultInstructionCount; 460f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl break; 470f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl case 2: 480f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl instructions = atoi(argv[1]); 490f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl break; 504a102baf640077d6794c0b33bb976f94b86c532barmvixl default: 514a102baf640077d6794c0b33bb976f94b86c532barmvixl printf("Usage: %s [#instructions]\n", argv[0]); 524a102baf640077d6794c0b33bb976f94b86c532barmvixl exit(1); 534a102baf640077d6794c0b33bb976f94b86c532barmvixl } 544a102baf640077d6794c0b33bb976f94b86c532barmvixl 558c70cd60ecab6e60c00756f77265e8d1078674c5Georgia Kouveli timeval start; 568c70cd60ecab6e60c00756f77265e8d1078674c5Georgia Kouveli gettimeofday(&start, NULL); 57330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl MacroAssembler masm(instructions * kInstructionSize); 5807d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames ExactAssemblyScope scope(&masm, instructions * kInstructionSize); 594a102baf640077d6794c0b33bb976f94b86c532barmvixl 600f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl#define __ masm. 614a102baf640077d6794c0b33bb976f94b86c532barmvixl 624a102baf640077d6794c0b33bb976f94b86c532barmvixl Label target; 635289c5900fb214f2f6aa61e2a9263730dcf4cc17armvixl for (int i = 0; i < instructions; i++) { 644a102baf640077d6794c0b33bb976f94b86c532barmvixl __ b(&target); 654a102baf640077d6794c0b33bb976f94b86c532barmvixl } 664a102baf640077d6794c0b33bb976f94b86c532barmvixl __ bind(&target); 674a102baf640077d6794c0b33bb976f94b86c532barmvixl 68330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl masm.FinalizeCode(); 694a102baf640077d6794c0b33bb976f94b86c532barmvixl 708c70cd60ecab6e60c00756f77265e8d1078674c5Georgia Kouveli timeval end; 718c70cd60ecab6e60c00756f77265e8d1078674c5Georgia Kouveli gettimeofday(&end, NULL); 728c70cd60ecab6e60c00756f77265e8d1078674c5Georgia Kouveli double delta = (end.tv_sec - start.tv_sec) + 738c70cd60ecab6e60c00756f77265e8d1078674c5Georgia Kouveli static_cast<double>(end.tv_usec - start.tv_usec) / 1000000; 748c70cd60ecab6e60c00756f77265e8d1078674c5Georgia Kouveli printf("A64: time for %d instructions: %gs\n", instructions, delta); 758c70cd60ecab6e60c00756f77265e8d1078674c5Georgia Kouveli 764a102baf640077d6794c0b33bb976f94b86c532barmvixl return 0; 774a102baf640077d6794c0b33bb976f94b86c532barmvixl} 78