#BEGIN_LEGAL
#
#Copyright (c) 2025 Intel Corporation
#
#  Licensed under the Apache License, Version 2.0 (the "License");
#  you may not use this file except in compliance with the License.
#  You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
#  Unless required by applicable law or agreed to in writing, software
#  distributed under the License is distributed on an "AS IS" BASIS,
#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#  See the License for the specific language governing permissions and
#  limitations under the License.
#  
#END_LEGAL

###################################################
# Extends avx512-evex-dec.txt XED NT
# This NT enables EGPRs encoding using the EVEX.R4 bit when APX enabled. 
# We're using NT in order to imply #UD on non-apx mode with EGPRs EVEX.R4 instructions

EVEXR4_ONE()::
    ### Extend an existing NT ###
    ############# New rules: #############
    NO_APX=0 REXR4=1   | 
    NO_APX=1 REXR4=1   | error       # Not mandatory, but easy to understand
    ##### Origin NT will expends to: #####
    # NO_APX=0 REXR4=0   | 
    # NO_APX=1 REXR4=0   | 
    # Default: otherwise | error 

###################################################

EVAPX()::
    # 1. Clean legacy-EVEX operands which reinterpreted with APX-promoted instructions.
    # 2. Set the EVVSPACE to APX so the encoder will choose the right EVEX path
    # 3. Check that the lower MASK bits are zeroed.
    #
    # (MASK[0-1] == 0) & (MASK[2] == NF) & (APX Enabled)
    NO_APX=0 NF=0 MASK=0 | EVEX_APX         SCC=0 BCRC=0
    NO_APX=0 NF=1 MASK=4 | EVEX_APX  MASK=0 SCC=0 BCRC=0
    # Default: otherwise | error 

DFV_PARSER()::
    # The DFV xed-operand is an integer representation for default flags values - (OF, SF, ZF, CF). 
    # For example: DFV=10 == 0b1010  ->  OF=1, SF=0, ZF=1, CF=0
    VEXDEST3=0 VEXDEST210=0 | DFV=0
    VEXDEST3=0 VEXDEST210=1 | DFV=1
    VEXDEST3=0 VEXDEST210=2 | DFV=2
    VEXDEST3=0 VEXDEST210=3 | DFV=3
    VEXDEST3=0 VEXDEST210=4 | DFV=4
    VEXDEST3=0 VEXDEST210=5 | DFV=5
    VEXDEST3=0 VEXDEST210=6 | DFV=6
    VEXDEST3=0 VEXDEST210=7 | DFV=7
    
    VEXDEST3=1 VEXDEST210=0 | DFV=8
    VEXDEST3=1 VEXDEST210=1 | DFV=9
    VEXDEST3=1 VEXDEST210=2 | DFV=10
    VEXDEST3=1 VEXDEST210=3 | DFV=11
    VEXDEST3=1 VEXDEST210=4 | DFV=12
    VEXDEST3=1 VEXDEST210=5 | DFV=13
    VEXDEST3=1 VEXDEST210=6 | DFV=14
    VEXDEST3=1 VEXDEST210=7 | DFV=15

EVAPX_SCC()::
    # - Clear Legacy reinterpreted bits by the SCC field and set EVEX sub-encoding space
    # - Set the DFV operand value
    true DFV_PARSER() | EVEX_APX_SCC MASK=0 VEXDEST4=0 NF=0 BCRC=0
