1b78f13911bfe6eda303e91ef215c87a165aae8aeAlexandre Rames// Copyright 2014, VIXL authors 2ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// All rights reserved. 3ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// 4ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// Redistribution and use in source and binary forms, with or without 5ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// modification, are permitted provided that the following conditions are met: 6ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// 7ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// * Redistributions of source code must retain the above copyright notice, 8ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// this list of conditions and the following disclaimer. 9ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// * Redistributions in binary form must reproduce the above copyright notice, 10ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// this list of conditions and the following disclaimer in the documentation 11ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// and/or other materials provided with the distribution. 12ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// * Neither the name of ARM Limited nor the names of its contributors may be 13ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// used to endorse or promote products derived from this software without 14ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// specific prior written permission. 15ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// 16ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS CONTRIBUTORS "AS IS" AND 17ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 18ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 19ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 20ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 22ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 23ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 25ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 2732cf254c0b40b0908b7459060647c57a1bb78ee7Vincent Belliard#include <sys/time.h> 281f9074de150536670464a85ef8e0ede60d26e3f9Alexandre Rames#include "globals-vixl.h" 29ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 30d3832965c62a8ad461b9ea9eb0994ca6b0a3da2cAlexandre Rames#include "aarch64/instructions-aarch64.h" 31d3832965c62a8ad461b9ea9eb0994ca6b0a3da2cAlexandre Rames#include "aarch64/macro-assembler-aarch64.h" 32b68bacb75c1ab265fc539afa93964c7f51f35589Alexandre Rames 334e7c93cc256c7719d69279d64e4f5d09044b8b2cAlexandre Ramesusing namespace vixl; 3488c46b84df005638546de5e4e965bdcc31352f48Pierre Langloisusing namespace vixl::aarch64; 35ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 36ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlstatic const unsigned kDefaultInstructionCount = 100000; 37ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 38ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// This program focuses on emitting simple instructions. 39ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// 40ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// This code will emit a given number of 'add x0, x1, x2' in a fixed size 41ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// buffer, looping over the buffer if necessary. This code therefore focuses 42ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl// on Emit and Operand. 43ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixlint main(int argc, char* argv[]) { 44ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl unsigned instructions = 0; 45ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 46ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl switch (argc) { 470f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl case 1: 480f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl instructions = kDefaultInstructionCount; 490f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl break; 500f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl case 2: 510f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl instructions = atoi(argv[1]); 520f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl break; 53ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl default: 54ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl printf("Usage: %s [#instructions]\n", argv[0]); 55ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl exit(1); 56ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 57ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 58ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl const unsigned buffer_size = 256 * KBytes; 59330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl const unsigned buffer_instruction_count = buffer_size / kInstructionSize; 6032cf254c0b40b0908b7459060647c57a1bb78ee7Vincent Belliard timeval start; 6132cf254c0b40b0908b7459060647c57a1bb78ee7Vincent Belliard gettimeofday(&start, NULL); 62330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl MacroAssembler masm(buffer_size); 63ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 640f35e36b7f5d1d2f4d95989b418447e1a4bcc8cdarmvixl#define __ masm. 65ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 66ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl unsigned rounds = instructions / buffer_instruction_count; 67ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl for (unsigned i = 0; i < rounds; ++i) { 68330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl { 6907d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames ExactAssemblyScope scope(&masm, buffer_size); 70330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl for (unsigned j = 0; j < buffer_instruction_count; ++j) { 71330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl __ add(x0, x1, Operand(x2)); 72330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl } 73ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 74330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl masm.Reset(); 75ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 76ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 77ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl unsigned remaining = instructions % buffer_instruction_count; 78330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl { 7907d1aa5b941ace15deb01e5df2c79e677039c4aeAlexandre Rames ExactAssemblyScope scope(&masm, remaining * kInstructionSize); 80330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl for (unsigned i = 0; i < remaining; ++i) { 81330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl __ add(x0, x1, Operand(x2)); 82330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl } 83ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl } 84ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 85330dc7153e671968beb67f09ed2cb7b5bda334dbarmvixl masm.FinalizeCode(); 8632cf254c0b40b0908b7459060647c57a1bb78ee7Vincent Belliard timeval end; 8732cf254c0b40b0908b7459060647c57a1bb78ee7Vincent Belliard gettimeofday(&end, NULL); 8832cf254c0b40b0908b7459060647c57a1bb78ee7Vincent Belliard double delta = (end.tv_sec - start.tv_sec) + 8932cf254c0b40b0908b7459060647c57a1bb78ee7Vincent Belliard static_cast<double>(end.tv_usec - start.tv_usec) / 1000000; 9032cf254c0b40b0908b7459060647c57a1bb78ee7Vincent Belliard printf("A64: time for %d instructions: %gs\n", instructions, delta); 91ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl 92ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl return 0; 93ad96eda8944ab1c1ba55715c50d9d6f0a3ed1dcarmvixl} 94