cachepc-qemu

Fork of AMDESE/qemu with changes for cachepc side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-qemu
Log | Files | Refs | Submodules | LICENSE | sfeed.txt

test_msa_nloc_b.c (6992B)


      1/*
      2 *  Test program for MSA instruction NLOC.B
      3 *
      4 *  Copyright (C) 2019  Wave Computing, Inc.
      5 *  Copyright (C) 2019  Aleksandar Markovic <amarkovic@wavecomp.com>
      6 *
      7 *  This program is free software: you can redistribute it and/or modify
      8 *  it under the terms of the GNU General Public License as published by
      9 *  the Free Software Foundation, either version 2 of the License, or
     10 *  (at your option) any later version.
     11 *
     12 *  This program is distributed in the hope that it will be useful,
     13 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     14 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15 *  GNU General Public License for more details.
     16 *
     17 *  You should have received a copy of the GNU General Public License
     18 *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
     19 *
     20 */
     21
     22#include <sys/time.h>
     23#include <stdint.h>
     24
     25#include "../../../../include/wrappers_msa.h"
     26#include "../../../../include/test_inputs_128.h"
     27#include "../../../../include/test_utils_128.h"
     28
     29#define TEST_COUNT_TOTAL (PATTERN_INPUTS_COUNT + RANDOM_INPUTS_COUNT)
     30
     31
     32int32_t main(void)
     33{
     34    char *isa_ase_name = "MSA";
     35    char *group_name = "Bit Count";
     36    char *instruction_name =  "NLOC.B";
     37    int32_t ret;
     38    uint32_t i;
     39    struct timeval start, end;
     40    double elapsed_time;
     41
     42    uint64_t b128_result[TEST_COUNT_TOTAL][2];
     43    uint64_t b128_expect[TEST_COUNT_TOTAL][2] = {
     44        { 0x0808080808080808ULL, 0x0808080808080808ULL, },    /*   0  */
     45        { 0x0000000000000000ULL, 0x0000000000000000ULL, },
     46        { 0x0101010101010101ULL, 0x0101010101010101ULL, },
     47        { 0x0000000000000000ULL, 0x0000000000000000ULL, },
     48        { 0x0202020202020202ULL, 0x0202020202020202ULL, },
     49        { 0x0000000000000000ULL, 0x0000000000000000ULL, },
     50        { 0x0301000301000301ULL, 0x0003010003010003ULL, },
     51        { 0x0000020000020000ULL, 0x0200000200000200ULL, },
     52        { 0x0404040404040404ULL, 0x0404040404040404ULL, },    /*   8  */
     53        { 0x0000000000000000ULL, 0x0000000000000000ULL, },
     54        { 0x0500000103050000ULL, 0x0103050000010305ULL, },
     55        { 0x0002040000000204ULL, 0x0000000204000000ULL, },
     56        { 0x0600020600020600ULL, 0x0206000206000206ULL, },
     57        { 0x0004000004000004ULL, 0x0000040000040000ULL, },
     58        { 0x0700050003000107ULL, 0x0005000300010700ULL, },
     59        { 0x0006000400020000ULL, 0x0600040002000006ULL, },
     60        { 0x0800080008000800ULL, 0x0800080008000800ULL, },    /*  16  */
     61        { 0x0008000800080008ULL, 0x0008000800080008ULL, },
     62        { 0x0801000300050007ULL, 0x0008010003000500ULL, },
     63        { 0x0000020004000600ULL, 0x0800000200040006ULL, },
     64        { 0x0802000600080200ULL, 0x0600080200060008ULL, },
     65        { 0x0000040008000004ULL, 0x0008000004000800ULL, },
     66        { 0x0803000801000700ULL, 0x0005000803000801ULL, },
     67        { 0x0000060000040008ULL, 0x0200080000060000ULL, },
     68        { 0x0804000804000804ULL, 0x0008040008040008ULL, },    /*  24  */
     69        { 0x0000080000080000ULL, 0x0800000800000800ULL, },
     70        { 0x0805000007000008ULL, 0x0100080300080500ULL, },
     71        { 0x0000080200080400ULL, 0x0006000008000008ULL, },
     72        { 0x0806000008020008ULL, 0x0600000802000806ULL, },
     73        { 0x0000080400000800ULL, 0x0008040000080000ULL, },
     74        { 0x0807000008050000ULL, 0x0803000008010008ULL, },
     75        { 0x0000080600000804ULL, 0x0000080200000800ULL, },
     76        { 0x0808000008080000ULL, 0x0808000008080000ULL, },    /*  32  */
     77        { 0x0000080800000808ULL, 0x0000080800000808ULL, },
     78        { 0x0808010000080300ULL, 0x0008050000080700ULL, },
     79        { 0x0000000802000008ULL, 0x0400000806000008ULL, },
     80        { 0x0808020000080600ULL, 0x0008080200000806ULL, },
     81        { 0x0000000804000008ULL, 0x0800000008040000ULL, },
     82        { 0x0808030000080801ULL, 0x0000080700000008ULL, },
     83        { 0x0000000806000000ULL, 0x0804000008080200ULL, },
     84        { 0x0808040000080804ULL, 0x0000080804000008ULL, },    /*  40  */
     85        { 0x0000000808000000ULL, 0x0808000000080800ULL, },
     86        { 0x0808050000000807ULL, 0x0000000808010000ULL, },
     87        { 0x0000000808020000ULL, 0x0808040000000806ULL, },
     88        { 0x0808060000000808ULL, 0x0200000808060000ULL, },
     89        { 0x0000000808040000ULL, 0x0008080000000808ULL, },
     90        { 0x0808070000000808ULL, 0x0500000008080300ULL, },
     91        { 0x0000000808060000ULL, 0x0008080400000008ULL, },
     92        { 0x0808080000000808ULL, 0x0800000008080800ULL, },    /*  48  */
     93        { 0x0000000808080000ULL, 0x0008080800000008ULL, },
     94        { 0x0808080100000008ULL, 0x0803000000080805ULL, },
     95        { 0x0000000008080200ULL, 0x0000080804000000ULL, },
     96        { 0x0808080200000008ULL, 0x0806000000080808ULL, },
     97        { 0x0000000008080400ULL, 0x0000080808000000ULL, },
     98        { 0x0808080300000008ULL, 0x0808010000000808ULL, },
     99        { 0x0000000008080600ULL, 0x0000000808040000ULL, },
    100        { 0x0808080400000008ULL, 0x0808040000000808ULL, },    /*  56  */
    101        { 0x0000000008080800ULL, 0x0000000808080000ULL, },
    102        { 0x0808080500000000ULL, 0x0808070000000008ULL, },
    103        { 0x0000000008080802ULL, 0x0000000808080400ULL, },
    104        { 0x0808080600000000ULL, 0x0808080200000008ULL, },
    105        { 0x0000000008080804ULL, 0x0000000008080800ULL, },
    106        { 0x0808080700000000ULL, 0x0808080500000000ULL, },
    107        { 0x0000000008080806ULL, 0x0000000008080804ULL, },
    108        { 0x0100030200000000ULL, 0x0000000007000100ULL, },    /*  64  */
    109        { 0x0501000000010200ULL, 0x0004010000000006ULL, },
    110        { 0x0100010101020101ULL, 0x0002020801000000ULL, },
    111        { 0x0000000000000300ULL, 0x0104010201000301ULL, },
    112        { 0x0101000000010000ULL, 0x0100000102020001ULL, },
    113        { 0x0200010108000005ULL, 0x0000000007010000ULL, },
    114        { 0x0100000000020100ULL, 0x0100000001040100ULL, },
    115        { 0x0601000401010101ULL, 0x0106000000000001ULL, },
    116        { 0x0000000200010300ULL, 0x0300030001010000ULL, },    /*  72  */
    117        { 0x0100020000020302ULL, 0x0100010101030100ULL, },
    118        { 0x0103040402020200ULL, 0x0102000000000000ULL, },
    119        { 0x0101040400010001ULL, 0x0201030000010103ULL, },
    120        { 0x0300000301000300ULL, 0x0100010200000200ULL, },
    121        { 0x0100000600000001ULL, 0x0401000100000000ULL, },
    122        { 0x0000000000010401ULL, 0x0300010402000000ULL, },
    123        { 0x0100010104000201ULL, 0x0200020200000003ULL, },
    124    };
    125
    126    reset_msa_registers();
    127
    128    gettimeofday(&start, NULL);
    129
    130    for (i = 0; i < TEST_COUNT_TOTAL; i++) {
    131        if (i < PATTERN_INPUTS_COUNT) {
    132            do_msa_NLOC_B(b128_pattern[i], b128_result[i]);
    133        } else {
    134            do_msa_NLOC_B(b128_random[i - PATTERN_INPUTS_COUNT],
    135                          b128_result[i]);
    136        }
    137    }
    138
    139    gettimeofday(&end, NULL);
    140
    141    elapsed_time = (end.tv_sec - start.tv_sec) * 1000.0;
    142    elapsed_time += (end.tv_usec - start.tv_usec) / 1000.0;
    143
    144    ret = check_results_128(isa_ase_name, group_name, instruction_name,
    145                            TEST_COUNT_TOTAL, elapsed_time,
    146                            &b128_result[0][0], &b128_expect[0][0]);
    147
    148    return ret;
    149}