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_pcnt_b.c (6992B)


      1/*
      2 *  Test program for MSA instruction PCNT.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 =  "PCNT.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        { 0x0404040404040404ULL, 0x0404040404040404ULL, },
     47        { 0x0404040404040404ULL, 0x0404040404040404ULL, },
     48        { 0x0404040404040404ULL, 0x0404040404040404ULL, },
     49        { 0x0404040404040404ULL, 0x0404040404040404ULL, },
     50        { 0x0504030504030504ULL, 0x0305040305040305ULL, },
     51        { 0x0304050304050304ULL, 0x0503040503040503ULL, },
     52        { 0x0404040404040404ULL, 0x0404040404040404ULL, },    /*   8  */
     53        { 0x0404040404040404ULL, 0x0404040404040404ULL, },
     54        { 0x0505040303050504ULL, 0x0303050504030305ULL, },
     55        { 0x0303040505030304ULL, 0x0505030304050503ULL, },
     56        { 0x0604020604020604ULL, 0x0206040206040206ULL, },
     57        { 0x0204060204060204ULL, 0x0602040602040602ULL, },
     58        { 0x0702050403060107ULL, 0x0205040306010702ULL, },
     59        { 0x0106030405020701ULL, 0x0603040502070106ULL, },
     60        { 0x0800080008000800ULL, 0x0800080008000800ULL, },    /*  16  */
     61        { 0x0008000800080008ULL, 0x0008000800080008ULL, },
     62        { 0x0801060304050207ULL, 0x0008010603040502ULL, },
     63        { 0x0007020504030601ULL, 0x0800070205040306ULL, },
     64        { 0x0802040600080204ULL, 0x0600080204060008ULL, },
     65        { 0x0006040208000604ULL, 0x0208000604020800ULL, },
     66        { 0x0803020801040700ULL, 0x0605000803020801ULL, },
     67        { 0x0005060007040108ULL, 0x0203080005060007ULL, },
     68        { 0x0804000804000804ULL, 0x0008040008040008ULL, },    /*  24  */
     69        { 0x0004080004080004ULL, 0x0800040800040800ULL, },
     70        { 0x0805000607000408ULL, 0x0102080300080500ULL, },
     71        { 0x0003080201080400ULL, 0x0706000508000308ULL, },
     72        { 0x0806000408020008ULL, 0x0600040802000806ULL, },
     73        { 0x0002080400060800ULL, 0x0208040006080002ULL, },
     74        { 0x0807000208050004ULL, 0x0803000608010008ULL, },
     75        { 0x0001080600030804ULL, 0x0005080200070800ULL, },
     76        { 0x0808000008080000ULL, 0x0808000008080000ULL, },    /*  32  */
     77        { 0x0000080800000808ULL, 0x0000080800000808ULL, },
     78        { 0x0808010006080300ULL, 0x0408050002080700ULL, },
     79        { 0x0000070802000508ULL, 0x0400030806000108ULL, },
     80        { 0x0808020004080600ULL, 0x0008080200040806ULL, },
     81        { 0x0000060804000208ULL, 0x0800000608040002ULL, },
     82        { 0x0808030002080801ULL, 0x0004080700000608ULL, },
     83        { 0x0000050806000007ULL, 0x0804000108080200ULL, },
     84        { 0x0808040000080804ULL, 0x0000080804000008ULL, },    /*  40  */
     85        { 0x0000040808000004ULL, 0x0808000004080800ULL, },
     86        { 0x0808050000060807ULL, 0x0000040808010002ULL, },
     87        { 0x0000030808020001ULL, 0x0808040000070806ULL, },
     88        { 0x0808060000040808ULL, 0x0200000808060000ULL, },
     89        { 0x0000020808040000ULL, 0x0608080000020808ULL, },
     90        { 0x0808070000020808ULL, 0x0500000408080300ULL, },
     91        { 0x0000010808060000ULL, 0x0308080400000508ULL, },
     92        { 0x0808080000000808ULL, 0x0800000008080800ULL, },    /*  48  */
     93        { 0x0000000808080000ULL, 0x0008080800000008ULL, },
     94        { 0x0808080100000608ULL, 0x0803000004080805ULL, },
     95        { 0x0000000708080200ULL, 0x0005080804000003ULL, },
     96        { 0x0808080200000408ULL, 0x0806000000080808ULL, },
     97        { 0x0000000608080400ULL, 0x0002080808000000ULL, },
     98        { 0x0808080300000208ULL, 0x0808010000040808ULL, },
     99        { 0x0000000508080600ULL, 0x0000070808040000ULL, },
    100        { 0x0808080400000008ULL, 0x0808040000000808ULL, },    /*  56  */
    101        { 0x0000000408080800ULL, 0x0000040808080000ULL, },
    102        { 0x0808080500000006ULL, 0x0808070000000408ULL, },
    103        { 0x0000000308080802ULL, 0x0000010808080400ULL, },
    104        { 0x0808080600000004ULL, 0x0808080200000008ULL, },
    105        { 0x0000000208080804ULL, 0x0000000608080800ULL, },
    106        { 0x0808080700000002ULL, 0x0808080500000004ULL, },
    107        { 0x0000000108080806ULL, 0x0000000308080804ULL, },
    108        { 0x0204050402030401ULL, 0x0405030507060302ULL, },    /*  64  */
    109        { 0x0706000404040501ULL, 0x0207060303060306ULL, },
    110        { 0x0404050405060401ULL, 0x0404040805040302ULL, },
    111        { 0x0305030405030404ULL, 0x0405020404020402ULL, },
    112        { 0x0503050506060203ULL, 0x0302050505050405ULL, },
    113        { 0x0304060308020406ULL, 0x0403020207040204ULL, },
    114        { 0x0405030204040503ULL, 0x0303010207040503ULL, },
    115        { 0x0605030404040602ULL, 0x0407040502020505ULL, },
    116        { 0x0104020504050503ULL, 0x0705030404040403ULL, },    /*  72  */
    117        { 0x0405050304050506ULL, 0x0402050302050504ULL, },
    118        { 0x0304060604050404ULL, 0x0403040305030502ULL, },
    119        { 0x0304050503030305ULL, 0x0404040505050306ULL, },
    120        { 0x0502030504030502ULL, 0x0303030504050403ULL, },
    121        { 0x0303040703030303ULL, 0x0603040404030405ULL, },
    122        { 0x0302020402060704ULL, 0x0604030705030204ULL, },
    123        { 0x0404050305040605ULL, 0x0404050504030405ULL, },
    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_PCNT_B(b128_pattern[i], b128_result[i]);
    133        } else {
    134            do_msa_PCNT_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}