> -----Original Message-----
> From: Anton Johansson <a...@rev.ng>
> Sent: Friday, December 17, 2021 2:01 AM
> To: qemu-devel@nongnu.org
> Cc: a...@rev.ng; Taylor Simpson <tsimp...@quicinc.com>; Brian Cain
> <bc...@quicinc.com>; bab...@rev.ng; ni...@rev.ng;
> richard.hender...@linaro.org
> Subject: [PATCH v7 09/13] target/hexagon: import lexer for idef-parser
> 
> From: Paolo Montesel <bab...@rev.ng>
> 
> Signed-off-by: Alessandro Di Federico <a...@rev.ng>
> Signed-off-by: Paolo Montesel <bab...@rev.ng>
> Signed-off-by: Anton Johansson <a...@rev.ng>
> ---
>  target/hexagon/idef-parser/idef-parser.h   | 259 ++++++++++
>  target/hexagon/idef-parser/idef-parser.lex | 571
> +++++++++++++++++++++
>  target/hexagon/meson.build                 |   4 +
>  3 files changed, 834 insertions(+)
>  create mode 100644 target/hexagon/idef-parser/idef-parser.h
>  create mode 100644 target/hexagon/idef-parser/idef-parser.lex
> 
> diff --git a/target/hexagon/idef-parser/idef-parser.lex
> b/target/hexagon/idef-parser/idef-parser.lex
> new file mode 100644
> index 0000000000..c7466c47f4
> --- /dev/null
> +++ b/target/hexagon/idef-parser/idef-parser.lex
> +"fSATN"                  { yylval->sat.set_overflow = true;
> +                           yylval->sat.signedness = SIGNED;
> +                           return SAT; }
> +"fVSATN"                 { yylval->sat.set_overflow = false;
> +                           yylval->sat.signedness = SIGNED;
> +                           return SAT; }
> +"fSATUN"                 { yylval->sat.set_overflow = false;

This should be true, just like fSATN.  Take a look at the satuh and satub 
instructions.

I tried changing it to true to make satuh and satub work.  However, the 
vaddubs, vadduhs, vsatub, vsatwuh, vsububs, and other instructions don't work.  
I've attached a test case that demonstrates this problem.

When the value is set to false, the test case prints
ERROR at line 71: 0x00000000 != 0x00000001
ERROR at line 75: 0x00000000 != 0x00000001
ERROR at line 106: 0x00000000 != 0x00000001
FAIL

When the value is set to true, the test case prints
ERROR at line 105: 0x000000000000007f != 0x00000000000000ff
ERROR at line 106: 0x00000000 != 0x00000001
FAIL

Without your changes, the test case prints
PASS



> +                           yylval->sat.signedness = UNSIGNED;
> +                           return SAT; }
/*
 *  Copyright(c) 2019-2021 Qualcomm Innovation Center, Inc. All Rights Reserved.
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, see <http://www.gnu.org/licenses/>.
 */

#include <stdio.h>
#include <stdint.h>

int err;

static void __check32(int line, int val, int expect)
{
    if (val != expect) {
        printf("ERROR at line %d: 0x%08x != 0x%08x\n", line, val, expect);
        err++;
    }
}

#define check32(RES, EXP) __check32(__LINE__, RES, EXP)

static void __check64(int line, long long val, long long expect)
{
    if (val != expect) {
        printf("ERROR at line %d: 0x%016llx != 0x%016llx\n", line, val, expect);
        err++;
    }
}

#define check64(RES, EXP) __check64(__LINE__, RES, EXP)

static uint32_t satub(uint32_t src, int *ovf_result)
{
    uint32_t result;
    uint32_t usr;

    /*
     * This instruction can set bit 0 (OVF/overflow) in usr
     * Clear the bit first, then return that bit to the caller
     */
    asm volatile("r2 = usr\n\t"
                 "r2 = clrbit(r2, #0)\n\t"        /* clear overflow bit */
                 "usr = r2\n\t"
                 "%0 = satub(%2)\n\t"
                 "%1 = usr\n\t"
                 : "=r"(result), "=r"(usr)
                 : "r"(src)
                 : "r2", "usr");
    *ovf_result = (usr & 1);
    return result;
}

static void test_satub(void)
{
    uint32_t result;
    int ovf_result;

    result = satub(0xfff, &ovf_result);
    check32(result, 0xff);
    check32(ovf_result, 1);

    result = satub(-1, &ovf_result);
    check32(result, 0);
    check32(ovf_result, 1);
}

static uint64_t vaddubs(uint64_t src1, uint64_t src2, int *ovf_result)
{
    uint64_t result;
    uint32_t usr;

    /*
     * This instruction can set bit 0 (OVF/overflow) in usr
     * Clear the bit first, then return that bit to the caller
     */
    asm volatile("r2 = usr\n\t"
                 "r2 = clrbit(r2, #0)\n\t"        /* clear overflow bit */
                 "usr = r2\n\t"
                 "%0 = vaddub(%2, %3):sat\n\t"
                 "%1 = usr\n\t"
                 : "=r"(result), "=r"(usr)
                 : "r"(src1), "r"(src2)
                 : "r2", "usr");
    *ovf_result = (usr & 1);
    return result;
}

static void test_vaddubs(void)
{
    uint64_t result;
    int ovf_result;

    result = vaddubs(0xffLL, 0xffLL, &ovf_result);
    check64(result, 0xffLL);
    check32(ovf_result, 1);
}

int main()
{
    test_satub();
    test_vaddubs();

    puts(err ? "FAIL" : "PASS");
    return err;
}

Reply via email to