Hexagon patch series
cover Hexagon patch series
This series adds support for the Hexagon processor with Linux user support
Hexagon is Qualcomm's very long instruction word (VLIW) digital signal processor(DSP). We also support Hexagon Vector eXtensions (HVX). HVX is a wide vector coprocessor designed for high performance computer vision, image processing, machine learning, and other workloads.
This series of patches supports the following versions of the Hexagon core
Scalar core: v67
https://developer.qualcomm.com/downloads/qualcomm-hexagon-v67-programmer-s-reference-manual
HVX extension: v66
https://developer.qualcomm.com/downloads/qualcomm-hexagon-v66-hvx-programmer-s-reference-manual
We presented an overview of the project at the 2019 KVM Forum.
https://kvmforum2019.sched.com/event/Tmwc/qemu-hexagon-automatic-translation-of-the-isa-manual-pseudcode-to-tiny-code-instructions-of-a-vliw-architecture-niccolo-izzo-revng-taylor-simpson-qualcomm-innovation-center
The patches up to and including "Hexagon build infractructure" implement the base Hexagon core and the remainder add HVX. Once the build infrastructure patch is applied, you can build and qemu will execute non-HVX Hexagon programs.
We have a parallel effort to make the Hexagon Linux toolchain publically available.
*** Required patches ***
In order to build, we need this patch
https://lists.nongnu.org/archive/html/qemu-devel/2020-02/msg01203.html
In order to run pthread_cancel, we need this patch series
https://lists.nongnu.org/archive/html/qemu-devel/2020-02/msg00834.html https://lists.nongnu.org/archive/html/qemu-devel/2020-02/msg00832.html https://lists.nongnu.org/archive/html/qemu-devel/2020-02/msg00833.html https://lists.nongnu.org/archive/html/qemu-devel/2020-02/msg00835.html https://lists.nongnu.org/archive/html/qemu-devel/2020-02/msg00836.html
*** Testing ***
The port passes the following tests
Directed unit tests
MUSL libc test suite (good coverage of Linux system calls) Compiler intrinsics test suite (good coverage of instructions) Hexagon machine learning library unit tests
make check-tcg TIMEOUT=60
*** Known checkpatch issues ***
The following are known checkpatch errors in the series
include/disas/dis-asm.h space prohibited
(Follow convention of other targets on prior lines)
target/hexagon/reg_fields.h Complex macro
target/hexagon/attribs.h Complex macro
target/hexagon/decode.c Complex macro
target/hexagon/q6v_decode.c Macro needs do - while
target/hexagon/printinsn.c Macro needs do - while
target/hexagon/gen_semantics.c Suspicious ; after while (0)
target/hexagon/gen_dectree_import.c Complex macro target/hexagon/gen_dectree_import.c Suspicious ; after while (0)
target/hexagon/opcodes.c Complex macro
target/hexagon/iclass.h Complex macro
scripts/qemu-binfmt-conf.sh Line over 90 characters
target/hexagon/mmvec/macros.h Suspicious ; after while (0)
The following are known checkpatch warnings in the series
target/hexagon/fma_emu.c Comments inside macro definition
scripts/qemu-binfmt-conf.sh Line over 80 characters
*** Tour of the code ***
The qemu-hexagon implementation is a combination of qemu and the Hexagon architecture library (aka archlib). The three primary directories with Hexagon-specific code are
qemu/target/hexagon
This has all the instruction and packet semantics
qemu/target/hexagon/imported
These files are imported with very little modification from archlib
*.idef Instruction semantics definition
macros.def Mapping of macros to instruction attributes
encode*.def Encoding patterns for each instruction
iclass.def Instruction class definitions used to determine
legal VLIW slots for each instruction
qemu/linux-user/hexagon
Helpers for loading the ELF file and making Linux system calls, signals, etc
We start with a script that generates qemu helper for each instruction. This is a two step process. The first step is to use the C preprocessor to expand macros inside the architecture definition files. This is done in target/hexagon/semantics.c. This step produces
<BUILD_DIR>/hexagon-linux-user/semantics_generated.pyinc.
That file is consumed by the do_qemu.py script. This script generates several files. All of the generated files end in "_generated.*". The primary file produced is
<BUILD_DIR>/hexagon-linux-user/qemu_def_generated.h
Qemu helper functions have 3 parts
DEF_HELPER declaration indicates the signature of the helper gen_helper_<NAME> will generate a TCG call to the helper function The helper implementation
In the qemu_def_generated.h file, there is a DEF_QEMU macro for each user-space instruction. The file is included several times with DEF_QEMU defined differently, depending on the context. The macro has four arguments
The instruction tag
The semantics_short code
DEF_HELPER declaration
Call to the helper
Helper implementation
Here's an example of the A2_add instruction.
Instruction tag A2_add
Assembly syntax "Rd32=add(Rs32,Rt32)"
Instruction semantics "{ RdV=RsV+RtV;}"By convention, the operands are identified by letter
RdV is the destination register
RsV, RtV are source registers
The generator uses the operand naming conventions (see large comment in do_qemu.py) to determine the signature of the helper function. Here is the result for A2_add from qemu_def_generated.h
DEF_QEMU(A2_add,{ RdV=RsV+RtV;},
#ifndef fWRAP_A2_addDEF_HELPER_3(A2_add, s32, env, s32, s32)
#endif
,
{
/* A2_add */DECL_RREG_d(RdV, RdN, 0, 0);DECL_RREG_s(RsV, RsN, 1, 0);DECL_RREG_t(RtV, RtN, 2, 0);READ_RREG_s(RsV, RsN);READ_RREG_t(RtV, RtN);
fWRAP_A2_add(
do {gen_helper_A2_add(RdV, cpu_env, RsV, RtV);
} while (0),
{ RdV=RsV+RtV;});WRITE_RREG_d(RdN, RdV);FREE_RREG_d(RdV);FREE_RREG_s(RsV);FREE_RREG_t(RtV);
/* A2_add */
},
#ifndef fWRAP_A2_addint32_t HELPER(A2_add)(CPUHexagonState *env, int32_t RsV, int32_t RtV) {uint32_t slot = 4; slot = slot;int32_t RdV = 0;
{ RdV=RsV+RtV;}COUNT_HELPER(A2_add);
return RdV;
}
#endif
)
For each operand, there are macros for DECL, FREE, READ, WRITE. These are defined in macros.h. Note that we append the operand type to the macro name, which allows us to specialize the TCG code tenerated. For read-only operands, DECL simply declares the TCGv variable (no need for tcg_temp_local_new()), and READ will assign from the TCGv corresponding to the GPR, and FREE doesn't have to do anything. Also, note that the WRITE macros update the disassembly context to be processed when the packet commits (see "Packet Semantics" below).
Note the fWRAP_A2_add macro around the gen_helper call. Each instruction has a fWRAP_<tag> macro that takes 2 arguments
gen_helper call
C semantics (aka short code)
This allows the code generator to override the auto-generated code. In some cases this is necessary for correct execution. We can also override for faster emulation. For example, calling a helper for add is more expensive than generating a TCG add operation.
The qemu_wrap_generated.h file contains a default fWRAP_<tag> for each instruction. The default is to invoke the gen_helper code.
#ifndef fWRAP_A2_add
#define fWRAP_A2_add(GENHLPR, SHORTCODE) GENHLPR
#endifThe helper_overrides.h file has any overrides. For example,
#define fWRAP_A2_add(GENHLPR, SHORTCODE) \
tcg_gen_add_tl(RdV, RsV, RtV)
This file is included twice
1) In genptr.c, it overrides the semantics of the desired instructions
2) In helper.h, it prevents the generation of helpers for overridden instructions. Notice the #ifndef fWRAP_A2_add above.
The instruction semantics C code heavily on macros. In cases where the C semantics are specified only with macros, we can override the default with the short semantics option and #define the macros to generate TCG code. One example is Y2_dczeroa (dc == data cache, zero == zero out the cache line, a == address: zero out the data cache line at the given address):
Instruction tag Y2_dczeroa
Assembly syntax "dczeroa(Rs32)"
Instruction semantics "{fEA_REG(RsV); fDCZEROA(EA);}"In helper_overrides.h, we use the shortcode #define fWRAP_Y2_dczeroa(GENHLPR, SHORTCODE) SHORTCODE
In other cases, just a little bit of wrapper code needs to be written.
#define fWRAP_tmp(SHORTCODE) \
{ \
TCGv tmp = tcg_temp_new(); \
SHORTCODE; \
tcg_temp_free(tmp); \
}For example, some load instructions use a temporary for address computation. The SL2_loadrd_sp instruction needs a temporary to hold the value of the stack pointer (r29)
Instruction tag SL2_loadrd_sp
Assembly syntax "Rdd8=memd(r29+#u5:3)"
Instruction semantics "{fEA_RI(fREAD_SP(),uiV); fLOAD(1,8,u,EA,RddV);}"In helper_overrides.h you'll see
#define fWRAP_SL2_loadrd_sp(GENHLPR, SHORTCODE) fWRAP_tmp(SHORTCODE)
There are also cases where we brute force the TCG code generation. The allocframe and deallocframe instructions are examples. Other examples are instructions with multiple definitions. These require special handling because qemu helpers can only return a single value.
In addition to instruction semantics, we use a generator to create the decode tree. This generation is also a two step process. The first step is to run target/hexagon/gen_dectree_import.c to produce
<BUILD_DIR>/hexagon-linux-user/iset.py
This file is imported by target/hexagon/dectree.py to produce
<BUILD_DIR>/hexagon-linux-user/dectree_generated.h
*** Key Files ***
cpu.h
This file contains the definition of the CPUHexagonState struct. It is the runtime information for each thread and contains stuff like the GPR and predicate registers.
macros.hmmvec/macros.h
The Hexagon arch lib relies heavily on macros for the instruction semantics. This is a great advantage for qemu because we can override them for different purposes. You will also notice there are sometimes two definitions of a macro. The QEMU_GENERATE variable determines whether we want the macro to generate TCG code. If QEMU_GENERATE is not defined, we want the macro to generate vanilla C code that will work in the helper implementation.
translate.c
The functions in this file generate TCG code for a translation block. Some important functions in this file are
gen_start_packet - initialize the data structures for packet semantics gen_commit_packet - commit the register writes, stores, etc for a packet decode_packet - disassemble a packet and generate code
genptr.cgenptr_helpers.hhelper_overrides.h
These file create a function for each instruction. It is mostly composed of fWRAP_<tag> definitions followed by including qemu_def_generated.h. The genptr_helpers.h file contains helper functions that are invoked by the macros in helper_overrides.h and macros.h
op_helper.c
This file contains the implementations of all the helpers. There are a few general purpose helpers, but most of them are generated by including qemu_def_generated.h. There are also several helpers used for debugging.
*** Packet Semantics ***
VLIW packet semantics differ from serial semantics in that all input operands are read, then the operations are performed, then all the results are written. For exmaple, this packet performs a swap of registers r0 and r1
{ r0 = r1; r1 = r0 }Note that the result is different if the instructions are executed serially.
Packet semantics dictate that we defer any changes of state until the entire packet is committed. We record the results of each instruction in a side data structure, and update the visible processor state when we commit the packet.
The data structures are divided between the runtime state and the translation context.
During the TCG generation (see translate.[ch]), we use the DisasContext to track what needs to be done during packet commit. Here are the relevant fields
ctx_reg_log list of registers written
ctx_reg_log_idx index into ctx_reg_log
ctx_pred_log list of predicates written
ctx_pred_log_idx index into ctx_pred_log
ctx_store_width width of stores (indexed by slot)During runtime, the following fields in CPUHexagonState (see cpu.h) are used
new_value new value of a given register
reg_written boolean indicating if register was written
new_pred_value new value of a predicate register
new_pred_written boolean indicating if predicate was written
mem_log_stores record of the stores (indexed by slot)For Hexagon Vector eXtensions (HVX), the following fields are used
future_VRegs
tmp_VRegs
future_ZRegs
ZRegs_updated
VRegs_updated_tmp
VRegs_updated
VRegs_select
*** Debugging ***
You can turn on a lot of debugging by changing the HEX_DEBUG macro to 1 in internal.h. This will stream a lot of information as it generates TCG and executes the code.
To track down nasty issues with Hexagon->TCG generation, we compare the execution results with actual hardware running on a Hexagon Linux target. Run qemu with the "-d cpu" option. Then, we can diff the results and figure out where qemu and hardware behave differently.
The stacks are located at different locations. We handle this by changing env->stack_adjust in translate.c. First, set this to zero and run qemu. Then, change env->stack_adjust to the difference between the two stack locations. Then rebuild qemu and run again. That will produce a very clean diff.
Here are some handy places to set breakpoints
At the call to gen_start_packet for a given PC (note that the line number
might change in the future)
br translate.c:602 if ctx->base.pc_next == 0xdeadbeef
The helper function for each instruction is named helper_<TAG>, so here's
an example that will set a breakpoint at the start
br helper_V6_vgathermh
If you have the HEX_DEBUG macro set, the following will be useful
At the start of execution of a packet for a given PC
br helper_debug_start_packet if env->gpr[41] == 0xdeadbeef
At the end of execution of a packet for a given PC
br helper_debug_commit_end if env->this_PC == 0xdeadbeef
Taylor Simpson (66):
Hexagon Maintainers
Hexagon ELF Machine Definition
Hexagon CPU Scalar Core Definition
Hexagon register names
Hexagon Disassembler
Hexagon CPU Scalar Core Helpers
Hexagon GDB Stub
Hexagon instruction and packet types
Hexagon architecture types
Hexagon register fields
Hexagon instruction attributes
Hexagon register map
Hexagon instruction/packet decode
Hexagon instruction printing
Hexagon arch import - instruction semantics definitions Hexagon arch import - macro definitions
Hexagon arch import - instruction encoding
Hexagon instruction class definitions
Hexagon instruction utility functions
Hexagon generator phase 1 - C preprocessor for semantics Hexagon generator phase 2 - qemu_def_generated.h
Hexagon generator phase 2 - qemu_wrap_generated.h
Hexagon generator phase 2 - opcodes_def_generated.h Hexagon generator phase 2 - op_attribs_generated.h
Hexagon generator phase 2 - op_regs_generated.h
Hexagon generator phase 2 - printinsn-generated.h
Hexagon generator phase 3 - C preprocessor for decode tree Hexagon generater phase 4 - Decode tree
Hexagon opcode data structures
Hexagon macros to interface with the generator
Hexagon macros referenced in instruction semantics
Hexagon instruction classes
Hexagon TCG generation helpers - step 1
Hexagon TCG generation helpers - step 2
Hexagon TCG generation helpers - step 3
Hexagon TCG generation helpers - step 4
Hexagon TCG generation helpers - step 5
Hexagon TCG generation - step 01
Hexagon TCG generation - step 02
Hexagon TCG generation - step 03
Hexagon TCG generation - step 04
Hexagon TCG generation - step 05
Hexagon TCG generation - step 06
Hexagon TCG generation - step 07
Hexagon TCG generation - step 08
Hexagon TCG generation - step 09
Hexagon TCG generation - step 10
Hexagon TCG generation - step 11
Hexagon TCG generation - step 12
Hexagon translation
Hexagon Linux user emulation
Hexagon build infrastructure
Hexagon - Add Hexagon Vector eXtensions (HVX) to core definition Hexagon HVX support in gdbstub
Hexagon HVX import instruction encodings
Hexagon HVX import semantics
Hexagon HVX import macro definitions
Hexagon HVX semantics generator
Hexagon HVX instruction decoding
Hexagon HVX instruction utility functions
Hexagon HVX macros to interface with the generator
Hexagon HVX macros referenced in instruction semantics Hexagon HVX helper to commit vector stores (masked and scatter/gather) Hexagon HVX TCG generation
Hexagon HVX translation
Hexagon HVX build infrastructure
MAINTAINERS | 8 + configure | 9 + default-configs/hexagon-linux-user.mak | 1 + disas/Makefile.objs | 1 + disas/hexagon.c | 56 + include/disas/dis-asm.h | 1 + include/elf.h | 2 + linux-user/elfload.c | 16 + linux-user/hexagon/cpu_loop.c | 173 ++ linux-user/hexagon/signal.c | 276 ++ linux-user/hexagon/sockbits.h | 18 + linux-user/hexagon/syscall_nr.h | 346 +++ linux-user/hexagon/target_cpu.h | 44 + linux-user/hexagon/target_elf.h | 38 + linux-user/hexagon/target_fcntl.h | 18 + linux-user/hexagon/target_signal.h | 34 + linux-user/hexagon/target_structs.h | 46 + linux-user/hexagon/target_syscall.h | 32 + linux-user/hexagon/termbits.h | 18 + linux-user/syscall.c | 2 + linux-user/syscall_defs.h | 33 + scripts/qemu-binfmt-conf.sh | 6 +- target/hexagon/Makefile.objs | 109 + target/hexagon/arch.c | 664 +++++ target/hexagon/arch.h | 62 + target/hexagon/attribs.h | 32 + target/hexagon/attribs_def.h | 404 +++ target/hexagon/conv_emu.c | 370 +++ target/hexagon/conv_emu.h | 50 + target/hexagon/cpu-param.h | 26 + target/hexagon/cpu.c | 356 +++ target/hexagon/cpu.h | 207 ++ target/hexagon/cpu_bits.h | 37 + target/hexagon/decode.c | 792 +++++ target/hexagon/decode.h | 39 + target/hexagon/dectree.py | 354 +++ target/hexagon/do_qemu.py | 1198 ++++++++ target/hexagon/fma_emu.c | 918 ++++++ target/hexagon/fma_emu.h | 30 + target/hexagon/gdbstub.c | 111 + target/hexagon/gen_dectree_import.c | 205 ++ target/hexagon/gen_semantics.c | 101 + target/hexagon/genptr.c | 62 + target/hexagon/genptr.h | 25 + target/hexagon/genptr_helpers.h | 1022 +++++++ target/hexagon/helper.h | 38 + target/hexagon/helper_overrides.h | 1850 ++++++++++++ target/hexagon/hex_arch_types.h | 42 + target/hexagon/hex_regs.h | 97 + target/hexagon/iclass.c | 109 + target/hexagon/iclass.h | 46 + target/hexagon/imported/allext.idef | 25 + target/hexagon/imported/allext_macros.def | 25 + target/hexagon/imported/allextenc.def | 20 + target/hexagon/imported/allidefs.def | 92 + target/hexagon/imported/alu.idef | 1335 +++++++++ target/hexagon/imported/branch.idef | 344 +++ target/hexagon/imported/compare.idef | 639 +++++ target/hexagon/imported/encode.def | 126 + target/hexagon/imported/encode_pp.def | 2283 +++++++++++++++ target/hexagon/imported/encode_subinsn.def | 150 + target/hexagon/imported/float.idef | 498 ++++ target/hexagon/imported/iclass.def | 52 + target/hexagon/imported/ldst.idef | 421 +++ target/hexagon/imported/macros.def | 3970 ++++++++++++++++++++++++++ target/hexagon/imported/mmvec/encode_ext.def | 830 ++++++ target/hexagon/imported/mmvec/ext.idef | 2809 ++++++++++++++++++ target/hexagon/imported/mmvec/macros.def | 1110 +++++++ target/hexagon/imported/mpy.idef | 1269 ++++++++ target/hexagon/imported/shift.idef | 1211 ++++++++ target/hexagon/imported/subinsns.idef | 152 + target/hexagon/imported/system.idef | 302 ++ target/hexagon/insn.h | 149 + target/hexagon/internal.h | 54 + target/hexagon/macros.h | 1499 ++++++++++ target/hexagon/mmvec/decode_ext_mmvec.c | 673 +++++ target/hexagon/mmvec/decode_ext_mmvec.h | 24 + target/hexagon/mmvec/macros.h | 668 +++++ target/hexagon/mmvec/mmvec.h | 87 + target/hexagon/mmvec/system_ext_mmvec.c | 265 ++ target/hexagon/mmvec/system_ext_mmvec.h | 38 + target/hexagon/op_helper.c | 507 ++++ target/hexagon/opcodes.c | 223 ++ target/hexagon/opcodes.h | 67 + target/hexagon/printinsn.c | 93 + target/hexagon/printinsn.h | 26 + target/hexagon/q6v_decode.c | 416 +++ target/hexagon/reg_fields.c | 28 + target/hexagon/reg_fields.h | 40 + target/hexagon/reg_fields_def.h | 109 + target/hexagon/regmap.h | 38 + target/hexagon/translate.c | 906 ++++++ target/hexagon/translate.h | 112 + tests/tcg/configure.sh | 4 +- tests/tcg/hexagon/float_convs.ref | 748 +++++ tests/tcg/hexagon/float_madds.ref | 768 +++++ 96 files changed, 35737 insertions(+), 2 deletions(-) create mode 100644 default-configs/hexagon-linux-user.mak create mode 100644 disas/hexagon.c create mode 100644 linux-user/hexagon/cpu_loop.c create mode 100644 linux-user/hexagon/signal.c create mode 100644 linux-user/hexagon/sockbits.h create mode 100644 linux-user/hexagon/syscall_nr.h create mode 100644 linux-user/hexagon/target_cpu.h create mode 100644 linux-user/hexagon/target_elf.h create mode 100644 linux-user/hexagon/target_fcntl.h create mode 100644 linux-user/hexagon/target_signal.h create mode 100644 linux-user/hexagon/target_structs.h create mode 100644 linux-user/hexagon/target_syscall.h create mode 100644 linux-user/hexagon/termbits.h create mode 100644 target/hexagon/Makefile.objs create mode 100644 target/hexagon/arch.c create mode 100644 target/hexagon/arch.h create mode 100644 target/hexagon/attribs.h create mode 100644 target/hexagon/attribs_def.h create mode 100644 target/hexagon/conv_emu.c create mode 100644 target/hexagon/conv_emu.h create mode 100644 target/hexagon/cpu-param.h create mode 100644 target/hexagon/cpu.c create mode 100644 target/hexagon/cpu.h create mode 100644 target/hexagon/cpu_bits.h create mode 100644 target/hexagon/decode.c create mode 100644 target/hexagon/decode.h create mode 100755 target/hexagon/dectree.py create mode 100755 target/hexagon/do_qemu.py create mode 100644 target/hexagon/fma_emu.c create mode 100644 target/hexagon/fma_emu.h create mode 100644 target/hexagon/gdbstub.c create mode 100644 target/hexagon/gen_dectree_import.c create mode 100644 target/hexagon/gen_semantics.c create mode 100644 target/hexagon/genptr.c create mode 100644 target/hexagon/genptr.h create mode 100644 target/hexagon/genptr_helpers.h create mode 100644 target/hexagon/helper.h create mode 100644 target/hexagon/helper_overrides.h create mode 100644 target/hexagon/hex_arch_types.h create mode 100644 target/hexagon/hex_regs.h create mode 100644 target/hexagon/iclass.c create mode 100644 target/hexagon/iclass.h create mode 100644 target/hexagon/imported/allext.idef create mode 100644 target/hexagon/imported/allext_macros.def create mode 100644 target/hexagon/imported/allextenc.def create mode 100644 target/hexagon/imported/allidefs.def create mode 100644 target/hexagon/imported/alu.idef create mode 100644 target/hexagon/imported/branch.idef create mode 100644 target/hexagon/imported/compare.idef create mode 100644 target/hexagon/imported/encode.def create mode 100644 target/hexagon/imported/encode_pp.def create mode 100644 target/hexagon/imported/encode_subinsn.def create mode 100644 target/hexagon/imported/float.idef create mode 100644 target/hexagon/imported/iclass.def create mode 100644 target/hexagon/imported/ldst.idef create mode 100755 target/hexagon/imported/macros.def create mode 100644 target/hexagon/imported/mmvec/encode_ext.def create mode 100644 target/hexagon/imported/mmvec/ext.idef create mode 100755 target/hexagon/imported/mmvec/macros.def create mode 100644 target/hexagon/imported/mpy.idef create mode 100644 target/hexagon/imported/shift.idef create mode 100644 target/hexagon/imported/subinsns.idef create mode 100644 target/hexagon/imported/system.idef create mode 100644 target/hexagon/insn.h create mode 100644 target/hexagon/internal.h create mode 100644 target/hexagon/macros.h create mode 100644 target/hexagon/mmvec/decode_ext_mmvec.c create mode 100644 target/hexagon/mmvec/decode_ext_mmvec.h create mode 100644 target/hexagon/mmvec/macros.h create mode 100644 target/hexagon/mmvec/mmvec.h create mode 100644 target/hexagon/mmvec/system_ext_mmvec.c create mode 100644 target/hexagon/mmvec/system_ext_mmvec.h create mode 100644 target/hexagon/op_helper.c create mode 100644 target/hexagon/opcodes.c create mode 100644 target/hexagon/opcodes.h create mode 100644 target/hexagon/printinsn.c create mode 100644 target/hexagon/printinsn.h create mode 100644 target/hexagon/q6v_decode.c create mode 100644 target/hexagon/reg_fields.c create mode 100644 target/hexagon/reg_fields.h create mode 100644 target/hexagon/reg_fields_def.h create mode 100644 target/hexagon/regmap.h create mode 100644 target/hexagon/translate.c create mode 100644 target/hexagon/translate.h create mode 100644 tests/tcg/hexagon/float_convs.ref create mode 100644 tests/tcg/hexagon/float_madds.ref
Signature · 1 line
2.7.4
RFC PATCH 1/66 Hexagon Maintainers
Add Taylor Simpson as the Hexagon target maintainer
--- MAINTAINERS | 8 ++++++++ 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
@@ -172,6 +172,14 @@ F: include/hw/cris/ F: tests/tcg/cris/ F: disas/cris.c +Hexagon TCG CPUs +M: Taylor Simpson <[email protected]> +S: Supported +F: target/hexagon/ +F: linux-user/hexagon/ +F: disas/hexagon.c +F: default-configs/hexagon-linux-user.mak + HPPA (PA-RISC) TCG CPUs M: Richard Henderson <[email protected]> S: Maintained
Signature · 1 line
2.7.4
RFC PATCH 2/66 Hexagon ELF Machine Definition
In reply to Taylor SimpsonDefine EM_HEXAGON 164
--- include/elf.h | 2 ++ 1 file changed, 2 insertions(+)
include/elf.h +2 -0
@@ -170,6 +170,8 @@ typedef struct mips_elf_abiflags_v0 {#define EM_UNICORE32 110/* UniCore32 */ +#define EM_HEXAGON 164/* Qualcomm Hexagon */ +#define EM_RISCV 243/* RISC-V */ #define EM_NANOMIPS 249/* Wave Computing nanoMIPS */
Signature · 1 line
2.7.4
Re: [RFC PATCH 02/66] Hexagon ELF Machine Definition
Quoted 13 lines · Taylor Simpson
Define
EM_HEXAGON164Signed-off-by Taylor Simpson <[email protected]>--- include/elf.h | 2 ++ 1 file changed, 2 insertions(+)include/elf.h +0
-0
include/elf.h typedef struct mips_elf_abiflags_v0 { · line 177
Quoted 8 lines
include/elf.h +2
-0@@ -170,6 +170,8 @@ typedef struct mips_elf_abiflags_v0 {#define EM_UNICORE32 110/* UniCore32 */ +#define EM_HEXAGON 164/* Qualcomm Hexagon */ +#define EM_RISCV 243/* RISC-V */ #define EM_NANOMIPS 249/* Wave Computing nanoMIPS */
RFC PATCH 3/66 Hexagon CPU Scalar Core Definition
In reply to Taylor SimpsonAdd CPU state header, CPU definitions and initialization routines
--- target/hexagon/cpu-param.h | 26 ++++ target/hexagon/cpu.c | 304 +++++++++++++++++++++++++++++++++++++++++++++ target/hexagon/cpu.h | 165 ++++++++++++++++++++++++ target/hexagon/cpu_bits.h | 37 ++++++ target/hexagon/internal.h | 52 ++++++++ 5 files changed, 584 insertions(+) create mode 100644 target/hexagon/cpu-param.h create mode 100644 target/hexagon/cpu.c create mode 100644 target/hexagon/cpu.h create mode 100644 target/hexagon/cpu_bits.h create mode 100644 target/hexagon/internal.h
target/hexagon/cpu-param.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* Copyright (c) 2019 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/>. +*/ + +#ifndef HEXAGON_CPU_PARAM_H +#define HEXAGON_CPU_PARAM_H + +#define TARGET_PHYS_ADDR_SPACE_BITS 36 +#define TARGET_VIRT_ADDR_SPACE_BITS 32 + +#define NB_MMU_MODES 1 + +#endif
target/hexagon/cpu.c new file +304 -0
304 lines not on this page · raw message
target/hexagon/cpu.h new file +165 -0
165 lines not on this page · raw message
target/hexagon/cpu_bits.h new file +37 -0
@@ -0,0 +1,37 @@ +/* +* Copyright (c) 2019 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/>. +*/ + +#ifndef HEXAGON_CPU_BITS_H +#define HEXAGON_CPU_BITS_H + +#define HEX_EXCP_FETCH_NO_UPAGE 0x012 +#define HEX_EXCP_INVALID_PACKET 0x015 +#define HEX_EXCP_INVALID_OPCODE 0x015 +#define HEX_EXCP_PRIV_NO_UREAD 0x024 +#define HEX_EXCP_PRIV_NO_UWRITE 0x025 + +#define HEX_EXCP_TRAP0 0x172 +#define HEX_EXCP_TRAP1 0x173 +#define HEX_EXCP_SC4 0x100 +#define HEX_EXCP_SC8 0x200 + +#define PACKET_WORDS_MAX 4 + +extern int disassemble_hexagon (uint32_t *words,int nwords, +char *buf,int bufsize); + +#endif
target/hexagon/internal.h new file +52 -0
52 lines not on this page · raw message
Signature · 1 line
2.7.4
RFC PATCH 4/66 Hexagon register names
In reply to Taylor Simpson--- target/hexagon/hex_regs.h | 97 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 target/hexagon/hex_regs.h
target/hexagon/hex_regs.h new file +97 -0
@@ -0,0 +1,97 @@ +/* +* Copyright (c) 2019 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/>. +*/ + +#ifndef HEX_REGS_H +#define HEX_REGS_H + +#define HEX_REG_R00 0 +#define HEX_REG_R01 1 +#define HEX_REG_R02 2 +#define HEX_REG_R03 3 +#define HEX_REG_R04 4 +#define HEX_REG_R05 5 +#define HEX_REG_R06 6 +#define HEX_REG_R07 7 +#define HEX_REG_R08 8 +#define HEX_REG_R09 9 +#define HEX_REG_R10 10 +#define HEX_REG_R11 11 +#define HEX_REG_R12 12 +#define HEX_REG_R13 13 +#define HEX_REG_R14 14 +#define HEX_REG_R15 15 +#define HEX_REG_R16 16 +#define HEX_REG_R17 17 +#define HEX_REG_R18 18 +#define HEX_REG_R19 19 +#define HEX_REG_R20 20 +#define HEX_REG_R21 21 +#define HEX_REG_R22 22 +#define HEX_REG_R23 23 +#define HEX_REG_R24 24 +#define HEX_REG_R25 25 +#define HEX_REG_R26 26 +#define HEX_REG_R27 27 +#define HEX_REG_R28 28 +#define HEX_REG_R29 29 +#define HEX_REG_SP 29 +#define HEX_REG_FP 30 +#define HEX_REG_R30 30 +#define HEX_REG_LR 31 +#define HEX_REG_R31 31 +#define HEX_REG_SA0 32 +#define HEX_REG_LC0 33 +#define HEX_REG_SA1 34 +#define HEX_REG_LC1 35 +#define HEX_REG_P3_0 36 +#define HEX_REG_M0 38 +#define HEX_REG_M1 39 +#define HEX_REG_USR 40 +#define HEX_REG_PC 41 +#define HEX_REG_UGP 42 +#define HEX_REG_GP 43 +#define HEX_REG_CS0 44 +#define HEX_REG_CS1 45 +#define HEX_REG_UPCYCLELO 46 +#define HEX_REG_UPCYCLEHI 47 +#define HEX_REG_FRAMELIMIT 48 +#define HEX_REG_FRAMEKEY 49 +#define HEX_REG_PKTCNTLO 50 +#define HEX_REG_PKTCNTHI 51 +/* Use reserved control registers for qemu execution counts */ +#define HEX_REG_QEMU_PKT_CNT 52 +#define HEX_REG_QEMU_INSN_CNT 53 +#define HEX_REG_QEMU_HVX_CNT 54 +#define HEX_REG_UTIMERLO 62 +#define HEX_REG_UTIMERHI 63 + +#ifndef CONFIG_USER_ONLY +#define HEX_REG_SGP0 64 +#define HEX_REG_SGP1 65 +#define HEX_REG_STID 66 +#define HEX_REG_ELR 67 +#define HEX_REG_BADVA0 68 +#define HEX_REG_BADVA1 69 +#define HEX_REG_SSR 70 +#define HEX_REG_CCR 71 +#define HEX_REG_HTID 72 +#define HEX_REG_BADVA 73 +#define HEX_REG_IMASK 74 +#define HEX_REG_GEVB 75 +#endif + +#endif
Signature · 1 line
2.7.4
Re: [RFC PATCH 04/66] Hexagon register names
Quoted 22 lines · Taylor Simpson
Signed-off-by Taylor Simpson <[email protected]>--- target/hexagon/hex_regs.h | 97 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+)create mode 100644
target/hexagon/hex_regs.htarget/hexagon/hex_regs.h new file +10
-0@@ -0,0 +1,97 @@ +/* +* Copyright (c) 2019 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
target/hexagon/hex_regs.h line 20
Quoted 10 lines
target/hexagon/hex_regs.h new file +10
-0+* 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/>. +*/ + +#ifndef HEX_REGS_H +#define HEX_REGS_H +
If this isn't generated I'd rather use an enum.
Quoted 78 lines
target/hexagon/hex_regs.h new file +77
-0+#define HEX_REG_R00 0 +#define HEX_REG_R01 1 +#define HEX_REG_R02 2 +#define HEX_REG_R03 3 +#define HEX_REG_R04 4 +#define HEX_REG_R05 5 +#define HEX_REG_R06 6 +#define HEX_REG_R07 7 +#define HEX_REG_R08 8 +#define HEX_REG_R09 9 +#define HEX_REG_R10 10 +#define HEX_REG_R11 11 +#define HEX_REG_R12 12 +#define HEX_REG_R13 13 +#define HEX_REG_R14 14 +#define HEX_REG_R15 15 +#define HEX_REG_R16 16 +#define HEX_REG_R17 17 +#define HEX_REG_R18 18 +#define HEX_REG_R19 19 +#define HEX_REG_R20 20 +#define HEX_REG_R21 21 +#define HEX_REG_R22 22 +#define HEX_REG_R23 23 +#define HEX_REG_R24 24 +#define HEX_REG_R25 25 +#define HEX_REG_R26 26 +#define HEX_REG_R27 27 +#define HEX_REG_R28 28 +#define HEX_REG_R29 29 +#define HEX_REG_SP 29 +#define HEX_REG_FP 30 +#define HEX_REG_R30 30 +#define HEX_REG_LR 31 +#define HEX_REG_R31 31 +#define HEX_REG_SA0 32 +#define HEX_REG_LC0 33 +#define HEX_REG_SA1 34 +#define HEX_REG_LC1 35 +#define HEX_REG_P3_0 36 +#define HEX_REG_M0 38 +#define HEX_REG_M1 39 +#define HEX_REG_USR 40 +#define HEX_REG_PC 41 +#define HEX_REG_UGP 42 +#define HEX_REG_GP 43 +#define HEX_REG_CS0 44 +#define HEX_REG_CS1 45 +#define HEX_REG_UPCYCLELO 46 +#define HEX_REG_UPCYCLEHI 47 +#define HEX_REG_FRAMELIMIT 48 +#define HEX_REG_FRAMEKEY 49 +#define HEX_REG_PKTCNTLO 50 +#define HEX_REG_PKTCNTHI 51 +/* Use reserved control registers for qemu execution counts */ +#define HEX_REG_QEMU_PKT_CNT 52 +#define HEX_REG_QEMU_INSN_CNT 53 +#define HEX_REG_QEMU_HVX_CNT 54 +#define HEX_REG_UTIMERLO 62 +#define HEX_REG_UTIMERHI 63 + +#ifndef CONFIG_USER_ONLY +#define HEX_REG_SGP0 64 +#define HEX_REG_SGP1 65 +#define HEX_REG_STID 66 +#define HEX_REG_ELR 67 +#define HEX_REG_BADVA0 68 +#define HEX_REG_BADVA1 69 +#define HEX_REG_SSR 70 +#define HEX_REG_CCR 71 +#define HEX_REG_HTID 72 +#define HEX_REG_BADVA 73 +#define HEX_REG_IMASK 74 +#define HEX_REG_GEVB 75 +#endif + +#endif
RFC PATCH 5/66 Hexagon Disassembler
In reply to Taylor SimpsonThe Hexagon disassembler calls disassemble_hexagon to decode a packet and format it for printing
--- disas/Makefile.objs | 1 + disas/hexagon.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ include/disas/dis-asm.h | 1 + 3 files changed, 58 insertions(+) create mode 100644 disas/hexagon.c
disas/Makefile.objs +1 -0
@@ -24,6 +24,7 @@ common-obj-$(CONFIG_SH4_DIS) += sh4.o common-obj-$(CONFIG_SPARC_DIS) += sparc.o common-obj-$(CONFIG_LM32_DIS) += lm32.o common-obj-$(CONFIG_XTENSA_DIS) += xtensa.o +common-obj-$(CONFIG_HEXAGON_DIS) += hexagon.o # TODO: As long as the TCG interpreter and its generated code depend # on the QEMU target, we cannot compile the disassembler here.
disas/hexagon.c new file +56 -0
56 lines not on this page · raw message
include/disas/dis-asm.h +1 -0
@@ -436,6 +436,7 @@ int print_insn_little_nios2 (bfd_vma, disassemble_info*);int print_insn_xtensa (bfd_vma ,disassemble_info *);int print_insn_riscv32 (bfd_vma ,disassemble_info *);int print_insn_riscv64 (bfd_vma ,disassemble_info *); +int print_insn_hexagon (bfd_vma ,disassemble_info *);#if 0 /* Fetch the disassembler for a given BFD, if that support is available. */
Signature · 1 line
2.7.4
Re: [RFC PATCH 05/66] Hexagon Disassembler
Quoted 49 lines · Taylor Simpson
The Hexagon disassembler calls
disassemble_hexagonto decode a packet and format it for printingSigned-off-by Taylor Simpson <[email protected]>--- disas/Makefile.objs | 1 + disas/hexagon.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++ include/disas/dis-asm.h | 1 + 3 files changed, 58 insertions(+)create mode 100644
disas/hexagon.cdisas/Makefile.objs +1
-0@@ -24,6 +24,7 @@ common-obj-$(CONFIG_SH4_DIS) += sh4.o common-obj-$(CONFIG_SPARC_DIS) += sparc.o common-obj-$(CONFIG_LM32_DIS) += lm32.o common-obj-$(CONFIG_XTENSA_DIS) += xtensa.o +common-obj-$(CONFIG_HEXAGON_DIS) += hexagon.o # TODO: As long as the TCG interpreter and its generated code depend # on the QEMU target, we cannot compile the disassembler here.disas/hexagon.c new file +20
-0@@ -0,0 +1,56 @@ +/* +* Copyright (c) 2019 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/>. +*/ + +/* +* QEMU Hexagon Disassembler +*/
disas/hexagon.c line 30
Quoted 10 lines
disas/hexagon.c new file +10
-0+ +#include "qemu/osdep.h" +#include "disas/dis-asm.h" +#include "target/hexagon/cpu_bits.h" + +int print_insn_hexagon (bfd_vma memaddr,struct disassemble_info *info) +{ +uint32_t words[PACKET_WORDS_MAX ]; +int len, slen; +char buf[1028 ];
Why 1028?
Quoted 7 lines
disas/hexagon.c new file +7
-0+int status; +int i; + +for (i =0 ; i <PACKET_WORDS_MAX ; i++) { + status = (*info->read_memory_func)(memaddr + i *sizeof (uint32_t ), + (bfd_byte *)&words[i], +sizeof (uint32_t ), info);
disas/hexagon.c line 47
Quoted 10 lines
disas/hexagon.c new file +10
-0+if (status) { +if (i >0 ) { +break ; + } + (*info->memory_error_func)(status, memaddr, info); +return status; + } + } + + len =disassemble_hexagon (words, i, buf,1028 );
1028 -> sizeof(buf)
Quoted 22 lines
disas/hexagon.c new file +9
-0+ slen =strlen (buf); +if (buf[slen -1 ] =='\n' ) { + buf[slen -1 ] ='\0' ; + } + (*info->fprintf_func)(info->stream,"%s" , buf); + +return len; +} +include/disas/dis-asm.h +1
-0@@ -436,6 +436,7 @@ int print_insn_little_nios2 (bfd_vma, disassemble_info*);int print_insn_xtensa (bfd_vma ,disassemble_info *);int print_insn_riscv32 (bfd_vma ,disassemble_info *);int print_insn_riscv64 (bfd_vma ,disassemble_info *); +int print_insn_hexagon (bfd_vma ,disassemble_info *);#if 0 /* Fetch the disassembler for a given BFD, if that support is available. */
RFC PATCH 6/66 Hexagon CPU Scalar Core Helpers
In reply to Taylor SimpsonThe majority of helpers are generated. Define the helper functions needed then include the generated file
--- target/hexagon/helper.h | 37 ++++ target/hexagon/op_helper.c | 432 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 469 insertions(+) create mode 100644 target/hexagon/helper.h create mode 100644 target/hexagon/op_helper.c
target/hexagon/helper.h new file +37 -0
@@ -0,0 +1,37 @@ +/* +* Copyright (c) 2019 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 "helper_overrides.h" + +DEF_HELPER_2(raise_exception, noreturn, env, i32) +DEF_HELPER_1(debug_start_packet, void, env) +DEF_HELPER_2(new_value, s32, env, int) +DEF_HELPER_3(debug_check_store_width, void, env, int, int) +DEF_HELPER_3(debug_commit_end, void, env, int, int) +DEF_HELPER_3(sfrecipa_val, s32, env, s32, s32) +DEF_HELPER_3(sfrecipa_pred, s32, env, s32, s32) +DEF_HELPER_2(sfinvsqrta_val, s32, env, s32) +DEF_HELPER_2(sfinvsqrta_pred, s32, env, s32) +DEF_HELPER_4(vacsh_val, s64, env, s64, s64, s64) +DEF_HELPER_4(vacsh_pred, s32, env, s64, s64, s64) + +#define DEF_QEMU (TAG ,SHORTCODE ,HELPER ,GENFN ,HELPFN ) HELPER +#include "qemu_def_generated.h" +#undef DEF_QEMU + +DEF_HELPER_2(debug_value, void, env, s32) +DEF_HELPER_2 (debug_value_i64, void, env, s64)
target/hexagon/op_helper.c new file +432 -0
432 lines not on this page · raw message
Signature · 1 line
2.7.4
RFC PATCH 7/66 Hexagon GDB Stub
In reply to Taylor SimpsonGDB register read and write routines
--- target/hexagon/cpu.c | 3 +++ target/hexagon/gdbstub.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 target/hexagon/gdbstub.c
target/hexagon/cpu.c +3 -0
@@ -270,6 +270,9 @@ static void hexagon_cpu_class_init(ObjectClass *c, void *data) cc->dump_state = hexagon_dump_state; cc->set_pc = hexagon_cpu_set_pc; cc->synchronize_from_tb = hexagon_cpu_synchronize_from_tb; + cc->gdb_core_xml_file ="hexagon-core.xml" ; + cc->gdb_read_register = hexagon_gdb_read_register; + cc->gdb_write_register = hexagon_gdb_write_register; cc->gdb_num_core_regs =TOTAL_PER_THREAD_REGS ; cc->gdb_stop_before_watchpoint = true; cc->disas_set_info = hexagon_cpu_disas_set_info;
target/hexagon/gdbstub.c new file +49 -0
49 lines not on this page · raw message
Signature · 1 line
2.7.4
RFC PATCH 8/66 Hexagon instruction and packet types
In reply to Taylor SimpsonThe insn_t and packet_t are the interface between instruction decoding and TCG code generation
--- target/hexagon/insn.h | 133 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 133 insertions(+) create mode 100644 target/hexagon/insn.h
target/hexagon/insn.h new file +133 -0
@@ -0,0 +1,133 @@ +/* +* Copyright (c) 2019 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/>. +*/ + +#ifndef INSN_H +#define INSN_H + +#include "cpu.h" +#include "hex_arch_types.h" +#include "translate.h" + +#define INSTRUCTIONS_MAX 7/* 2 pairs + loopend */ +#define REG_OPERANDS_MAX 5 +#define IMMEDS_MAX 2 + +struct Instruction ; + +typedef void (*semantic_insn_t )(CPUHexagonState *env, +DisasContext *ctx, +struct Instruction *insn); + +struct Instruction { +semantic_insn_t generate;/* pointer to genptr routine */ +size1u_t regno[REG_OPERANDS_MAX ];/* reg operands including predicates */ +size2u_t opcode; + +size4u_t iclass:6 ; +size4u_t slot:3 ; +size4u_t part1:1 ;/* +* cmp-jumps are split into two insns. +* set for the compare and clear for the jump +*/ +size4u_t extension_valid:1 ;/* Has a constant extender attached */ +size4u_t which_extended:1 ;/* If has an extender, which immediate */ +size4u_t is_dcop:1 ;/* Is a dcacheop */ +size4u_t is_dcfetch:1 ;/* Has an A_DCFETCH attribute */ +size4u_t is_load:1 ;/* Has A_LOAD attribute */ +size4u_t is_store:1 ;/* Has A_STORE attribute */ +size4u_t is_memop:1 ;/* Has A_MEMOP attribute */ +size4u_t is_dealloc:1 ;/* Is a dealloc return or dealloc frame */ +size4u_t is_aia:1 ;/* Is a post increment */ +size4u_t is_endloop:1 ;/* This is an end of loop */ +size4u_t is_2nd_jump:1 ;/* This is the second jump of a dual-jump packet */ +size4u_t new_value_producer_slot:4 ; +size4s_t immed[IMMEDS_MAX ];/* immediate field */ +}; + +typedef struct Instruction insn_t ; + +struct Packet { +size2u_t num_insns; +size2u_t encod_pkt_size_in_bytes; + +/* Pre-decodes about LD/ST */ +size8u_t single_load:1 ; +size8u_t dual_load:1 ; +size8u_t single_store:1 ; +size8u_t dual_store:1 ; +size8u_t load_and_store:1 ; +size8u_t memop_or_nvstore:1 ; + +/* Pre-decodes about COF */ +size8u_t pkt_has_cof:1 ;/* Has any change-of-flow */ +size8u_t pkt_has_dual_jump:1 ; +size8u_t pkt_has_initloop:1 ; +size8u_t pkt_has_initloop0:1 ; +size8u_t pkt_has_initloop1:1 ; +size8u_t pkt_has_endloop:1 ; +size8u_t pkt_has_endloop0:1 ; +size8u_t pkt_has_endloop1:1 ; +size8u_t pkt_has_endloop01:1 ; +size8u_t pkt_has_call:1 ; +size8u_t pkt_has_jumpr:1 ; +size8u_t pkt_has_cjump:1 ; +size8u_t pkt_has_cjump_dotnew:1 ; +size8u_t pkt_has_cjump_dotold:1 ; +size8u_t pkt_has_cjump_newval:1 ; +size8u_t pkt_has_duplex:1 ; +size8u_t pkt_has_payload:1 ;/* Contains a constant extender */ +size8u_t pkt_has_dealloc_return:1 ; + +/* Pre-decodes about SLOTS */ +size8u_t slot0_valid:1 ; +size8u_t slot1_valid:1 ; +size8u_t slot2_valid:1 ; +size8u_t slot3_valid:1 ; + +/* When a predicate cancels something, track that */ +size8u_t pkt_has_fp_op:1 ; +size8u_t pkt_has_fpsp_op:1 ; +size8u_t pkt_has_fpdp_op:1 ; + +/* Contains a cacheop */ +size8u_t pkt_has_cacheop:1 ; +size8u_t pkt_has_dczeroa:1 ; +size8u_t pkt_has_ictagop:1 ; +size8u_t pkt_has_icflushop:1 ; +size8u_t pkt_has_dcflushop:1 ; +size8u_t pkt_has_dctagop:1 ; +size8u_t pkt_has_l2flushop:1 ; +size8u_t pkt_has_l2tagop:1 ; + +/* load store for slots */ +size8u_t pkt_has_load_s0:1 ; +size8u_t pkt_has_load_s1:1 ; +size8u_t pkt_has_store_s0:1 ; +size8u_t pkt_has_store_s1:1 ; + +/* Misc */ +size8u_t num_rops:4 ;/* Num risc ops in the packet */ +size8u_t pkt_access_count:2 ;/* Is a vmem access going to VTCM */ +size8u_t pkt_ldaccess_l2:2 ;/* vmem ld access to l2 */ +size8u_t pkt_ldaccess_vtcm:2 ;/* vmem ld access to vtcm */ + +insn_t insn[INSTRUCTIONS_MAX ]; +}; + +typedef struct Packet packet_t ; + +#endif
Signature · 1 line
2.7.4
RFC PATCH 9/66 Hexagon architecture types
In reply to Taylor SimpsonDefine types used in files imported from the Hexagon architecture library
--- target/hexagon/hex_arch_types.h | 42 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 target/hexagon/hex_arch_types.h
target/hexagon/hex_arch_types.h new file +42 -0
@@ -0,0 +1,42 @@ +/* +* Copyright (c) 2019 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/>. +*/ + +#ifndef HEXAGON_ARCH_TYPES_H +#define HEXAGON_ARCH_TYPES_H + +/* +* These types are used by the code generated from the Hexagon +* architecture library. +*/ +typedef unsigned char size1u_t ; +typedef char size1s_t ; +typedef unsigned short int size2u_t ; +typedef short size2s_t ; +typedef unsigned int size4u_t ; +typedef int size4s_t ; +typedef unsigned long long int size8u_t ; +typedef long long int size8s_t ; +typedef size8u_t paddr_t ; +typedef size4u_t vaddr_t ; +typedef size8u_t pcycles_t ; + +typedef struct size16s { +size8s_t hi; +size8u_t lo; +}size16s_t ; + +#endif
Signature · 1 line
2.7.4
Re: [RFC PATCH 09/66] Hexagon architecture types
Quoted 47 lines · Taylor Simpson
Define types used in files imported from the Hexagon architecture library
Signed-off-by Taylor Simpson <[email protected]>--- target/hexagon/hex_arch_types.h | 42 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+)create mode 100644
target/hexagon/hex_arch_types.htarget/hexagon/hex_arch_types.h new file +32
-0@@ -0,0 +1,42 @@ +/* +* Copyright (c) 2019 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/>. +*/ + +#ifndef HEXAGON_ARCH_TYPES_H +#define HEXAGON_ARCH_TYPES_H + +/* +* These types are used by the code generated from the Hexagon +* architecture library. +*/ +typedef unsigned char size1u_t ; +typedef char size1s_t ; +typedef unsigned short int size2u_t ; +typedef short size2s_t ; +typedef unsigned int size4u_t ; +typedef int size4s_t ; +typedef unsigned long long int size8u_t ; +typedef long long int size8s_t ;
target/hexagon/hex_arch_types.h line 42
Quoted 10 lines
target/hexagon/hex_arch_types.h new file +10
-0+typedef size8u_t paddr_t ; +typedef size4u_t vaddr_t ; +typedef size8u_t pcycles_t ; + +typedef struct size16s { +size8s_t hi; +size8u_t lo; +}size16s_t ; + +#endif
Please introduce this patch before the previous one, it makes review smoother:
[PATCH 08/66] Hexagon architecture types [PATCH 09/66] Hexagon instruction and packet types
RFC PATCH 10/66 Hexagon register fields
In reply to Taylor SimpsonDeclare bitfields within registers such as user status register (USR)
--- target/hexagon/reg_fields.c | 28 +++++++++++ target/hexagon/reg_fields.h | 40 +++++++++++++++ target/hexagon/reg_fields_def.h | 109 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 177 insertions(+) create mode 100644 target/hexagon/reg_fields.c create mode 100644 target/hexagon/reg_fields.h create mode 100644 target/hexagon/reg_fields_def.h
target/hexagon/reg_fields.c new file +28 -0
@@ -0,0 +1,28 @@ +/* +* Copyright (c) 2019 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 <string.h> +#include "reg_fields.h" + +reg_field_t reg_field_info[] = { +#define DEF_REG_FIELD(TAG, NAME, START, WIDTH, DESCRIPTION) \ + {NAME, START, WIDTH, DESCRIPTION}, +#include "reg_fields_def.h" + {NULL, 0, 0} +#undef DEF_REG_FIELD +}; +
target/hexagon/reg_fields.h new file +40 -0
@@ -0,0 +1,40 @@ +/* +* Copyright (c) 2019 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/>. +*/ + +#ifndef REGS_H +#define REGS_H + +#define NUM_GEN_REGS 32 + +typedef struct { +const char *name; +int offset; +int width; +const char *description; +}reg_field_t ; + +extern reg_field_t reg_field_info[]; + +enum reg_fields_enum { +#define DEF_REG_FIELD(TAG, NAME, START, WIDTH, DESCRIPTION) \ + TAG, +#include "reg_fields_def.h" + NUM_REG_FIELDS +#undef DEF_REG_FIELD +}; + +#endif
target/hexagon/reg_fields_def.h new file +109 -0
109 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [RFC PATCH 10/66] Hexagon register fields
Quoted 26 lines · Taylor Simpson
Declare bitfields within registers such as user status register (USR)
Signed-off-by Taylor Simpson <[email protected]>--- target/hexagon/reg_fields.c | 28 +++++++++++ target/hexagon/reg_fields.h | 40 +++++++++++++++ target/hexagon/reg_fields_def.h | 109 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 177 insertions(+)create mode 100644
target/hexagon/reg_fields.ccreate mode 100644target/hexagon/reg_fields.hcreate mode 100644target/hexagon/reg_fields_def.htarget/hexagon/reg_fields.c new file +8
-0@@ -0,0 +1,28 @@ +/* +* Copyright (c) 2019 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. +*
target/hexagon/reg_fields.c line 18
Quoted 10 lines
target/hexagon/reg_fields.c new file +10
-0+* 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 <string.h>
Replace by:
#include "qemu/osdep.h"
Quoted 25 lines
target/hexagon/reg_fields.c new file +10
-0+#include "reg_fields.h" + +reg_field_t reg_field_info[] = { +#define DEF_REG_FIELD(TAG, NAME, START, WIDTH, DESCRIPTION) \ + {NAME, START, WIDTH, DESCRIPTION}, +#include "reg_fields_def.h" + {NULL, 0, 0} +#undef DEF_REG_FIELD +}; +target/hexagon/reg_fields.h new file +9
-0@@ -0,0 +1,40 @@ +/* +* Copyright (c) 2019 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,
target/hexagon/reg_fields.h line 19
Quoted 10 lines
target/hexagon/reg_fields.h new file +10
-0+* 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/>. +*/ + +#ifndef REGS_H +#define REGS_H
Maybe HEXAGON_REG_FIELDS?
Quoted 137 lines
target/hexagon/reg_fields.h new file +21
-0+ +#define NUM_GEN_REGS 32 + +typedef struct { +const char *name; +int offset; +int width; +const char *description; +}reg_field_t ; + +extern reg_field_t reg_field_info[]; + +enum reg_fields_enum { +#define DEF_REG_FIELD(TAG, NAME, START, WIDTH, DESCRIPTION) \ + TAG, +#include "reg_fields_def.h" + NUM_REG_FIELDS +#undef DEF_REG_FIELD +}; + +#endif target/hexagon/reg_fields_def.h new file +109
-0@@ -0,0 +1,109 @@ +/* +* Copyright (c) 2019 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/>. +*/ + +/* +* For registers that have individual fields, explain them here +* DEF_REG_FIELD(tag, +* name, +* bit start offset, +* width, +* description +*/ + +/* USR fields */ +DEF_REG_FIELD (USR_OVF , +"ovf" ,0 ,1 , +"Sticky Saturation Overflow - " +"Set when saturation occurs while executing instruction that specifies " +"optional saturation, remains set until explicitly cleared by a USR=Rs " + "instruction.") +DEF_REG_FIELD (USR_FPINVF , +"fpinvf" ,1 ,1 , + "Floating-point IEEE Invalid Sticky Flag.") +DEF_REG_FIELD (USR_FPDBZF , +"fpdbzf" ,2 ,1 , + "Floating-point IEEE Divide-By-Zero Sticky Flag.") +DEF_REG_FIELD (USR_FPOVFF , +"fpovff" ,3 ,1 , + "Floating-point IEEE Overflow Sticky Flag.") +DEF_REG_FIELD (USR_FPUNFF , +"fpunff" ,4 ,1 , + "Floating-point IEEE Underflow Sticky Flag.") +DEF_REG_FIELD (USR_FPINPF , +"fpinpf" ,5 ,1 , + "Floating-point IEEE Inexact Sticky Flag.") + +DEF_REG_FIELD (USR_LPCFG , +"lpcfg" ,8 ,2 , +"Hardware Loop Configuration: " +"Number of loop iterations (0-3) remaining before pipeline predicate " + "should be set.") +DEF_REG_FIELD (USR_PKTCNT_U , +"pktcnt_u" ,10 ,1 , + "Enable packet counting in User mode.") +DEF_REG_FIELD (USR_PKTCNT_G , +"pktcnt_g" ,11 ,1 , + "Enable packet counting in Guest mode.") +DEF_REG_FIELD (USR_PKTCNT_M , +"pktcnt_m" ,12 ,1 , + "Enable packet counting in Monitor mode.") +DEF_REG_FIELD (USR_HFD , +"hfd" ,13 ,2 , +"Two bits that let the user control the amount of L1 hardware data cache " +"prefetching (up to 4 cache lines): " +"00: No prefetching, " +"01: Prefetch Loads with post-updating address mode when execution is " +"within a hardware loop, " +"10: Prefetch any hardware-detected striding Load when execution is within " +"a hardware loop, " + "11: Prefetch any hardware-detected striding Load.") +DEF_REG_FIELD (USR_HFI , +"hfi" ,15 ,2 , +"Two bits that let the user control the amount of L1 instruction cache " +"prefetching. " +"00: No prefetching, " +"01: Allow prefetching of at most 1 additional cache line, " + "10: Allow prefetching of at most 2 additional cache lines.") + +DEF_REG_FIELD (USR_FPRND , +"fprnd" ,22 ,2 , +"Rounding Mode for Floating-Point Instructions: " +"00: Round to nearest, ties to even (default), " +"01: Toward zero, " +"10: Downward (toward negative infinity), " + "11: Upward (toward positive infinity).") + +DEF_REG_FIELD (USR_FPINVE , +"fpinve" ,25 ,1 , + "Enable trap on IEEE Invalid.") +DEF_REG_FIELD (USR_FPDBZE , + "fpdbze", 26, 1, "Enable trap on IEEE Divide-By-Zero.") +DEF_REG_FIELD (USR_FPOVFE , +"fpovfe" ,27 ,1 , + "Enable trap on IEEE Overflow.") +DEF_REG_FIELD (USR_FPUNFE , +"fpunfe" ,28 ,1 , + "Enable trap on IEEE Underflow.") +DEF_REG_FIELD (USR_FPINPE , +"fpinpe" ,29 ,1 , + "Enable trap on IEEE Inexact.") +DEF_REG_FIELD (USR_PFA , +"pfa" ,31 ,1 , +"L2 Prefetch Active: Set when non-blocking l2fetch instruction is " +"prefetching requested data, remains set until l2fetch prefetch operation " +"is completed (or not active)." )/* read-only */ +
RFC PATCH 11/66 Hexagon instruction attributes
In reply to Taylor Simpson--- target/hexagon/attribs.h | 32 ++++ target/hexagon/attribs_def.h | 404 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 436 insertions(+) create mode 100644 target/hexagon/attribs.h create mode 100644 target/hexagon/attribs_def.h
target/hexagon/attribs.h new file +32 -0
@@ -0,0 +1,32 @@ +/* +* Copyright (c) 2019 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/>. +*/ + +#ifndef ATTRIBS_H +#define ATTRIBS_H 1 + +enum { +#define DEF_ATTRIB(NAME, ...) A_##NAME, +#include "attribs_def.h" +#undef DEF_ATTRIB +}; + +#define ATTRIB_WIDTH 32 +#define GET_ATTRIB (opcode, attrib) \ + (((opcode_attribs[opcode][attrib / ATTRIB_WIDTH])\ + >> (attrib % ATTRIB_WIDTH)) & 0x1) + +#endif /* ATTRIBS_H */
target/hexagon/attribs_def.h new file +404 -0
404 lines not on this page · raw message
Signature · 1 line
2.7.4
RFC PATCH 12/66 Hexagon register map
In reply to Taylor SimpsonCertain operand types represent a non-contiguous set of values. For example, the compound compare-and-jump instruction can only access registers R0-R7 and R16-23.
This table represents the mapping from the encoding to the actual values.
--- target/hexagon/regmap.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 target/hexagon/regmap.h
target/hexagon/regmap.h new file +38 -0
@@ -0,0 +1,38 @@ +/* +* Copyright (c) 2019 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/>. +*/ + +/* +* Certain operand types represent a non-contiguous set of values. +* For example, the compound compare-and-jump instruction can only access +* registers R0-R7 and R16-23. +* This table represents the mapping from the encoding to the actual values. +*/ + +#ifndef REGMAP_H +#define REGMAP_H + +/* Name Num Table */ +DEF_REGMAP(R_16, 16, 0, 1, 2, 3, 4, 5, 6, 7, 16, 17, 18, 19, 20, 21, 22, 23) +DEF_REGMAP(R__8, 8, 0, 2, 4, 6, 16, 18, 20, 22) +DEF_REGMAP(R__4, 4, 0, 2, 4, 6) +DEF_REGMAP(R_4, 4, 0, 1, 2, 3) +DEF_REGMAP(R_8S, 8, 0, 1, 2, 3, 16, 17, 18, 19) +DEF_REGMAP(R_8, 8, 0, 1, 2, 3, 4, 5, 6, 7) +DEF_REGMAP(V__8, 8, 0, 4, 8, 12, 16, 20, 24, 28) +DEF_REGMAP(V__16, 16, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30) + +#endif
Signature · 1 line
2.7.4
Re: [RFC PATCH 12/66] Hexagon register map
Quoted 33 lines · Taylor Simpson
Certain operand types represent a non-contiguous set of values. For example, the compound compare-and-jump instruction can only access registers R0-R7 and R16-23.
This table represents the mapping from the encoding to the actual values.Signed-off-by Taylor Simpson <[email protected]>--- target/hexagon/regmap.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+)create mode 100644
target/hexagon/regmap.htarget/hexagon/regmap.h new file +16
-0@@ -0,0 +1,38 @@ +/* +* Copyright (c) 2019 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/>. +*/
target/hexagon/regmap.h line 26
Quoted 10 lines
target/hexagon/regmap.h new file +10
-0+ +/* +* Certain operand types represent a non-contiguous set of values. +* For example, the compound compare-and-jump instruction can only access +* registers R0-R7 and R16-23. +* This table represents the mapping from the encoding to the actual values. +*/ + +#ifndef REGMAP_H +#define REGMAP_H
I'd try to be consistent and use all header under target/hexagon/ guarded with a HEXAGON_ prefix:
#ifndef HEXAGON_REGMAP_H ...
Quoted 13 lines
target/hexagon/regmap.h new file +12
-0+ +/* Name Num Table */ +DEF_REGMAP(R_16, 16, 0, 1, 2, 3, 4, 5, 6, 7, 16, 17, 18, 19, 20, 21, 22, 23) +DEF_REGMAP(R__8, 8, 0, 2, 4, 6, 16, 18, 20, 22) +DEF_REGMAP(R__4, 4, 0, 2, 4, 6) +DEF_REGMAP(R_4, 4, 0, 1, 2, 3) +DEF_REGMAP(R_8S, 8, 0, 1, 2, 3, 16, 17, 18, 19) +DEF_REGMAP(R_8, 8, 0, 1, 2, 3, 4, 5, 6, 7) +DEF_REGMAP(V__8, 8, 0, 4, 8, 12, 16, 20, 24, 28) +DEF_REGMAP(V__16, 16, 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30) + +#endif
RFC PATCH 13/66 Hexagon instruction/packet decode
In reply to Taylor SimpsonTake the words from instruction memory and build a packet_t for TCG code generation
The following operations are performed
Convert the .new encoded offset to the register number of the producer Reorder the instructions in the packet so .new producer is before consumer Apply constant extenders
Separate subinsn's into two instructions
Break compare-jumps into two instructions
Create instructions for :endloop
--- target/hexagon/decode.c | 773 ++++++++++++++++++++++++++++++++++++++++++++ target/hexagon/decode.h | 39 +++ target/hexagon/q6v_decode.c | 402 +++++++++++++++++++++++ 3 files changed, 1214 insertions(+) create mode 100644 target/hexagon/decode.c create mode 100644 target/hexagon/decode.h create mode 100644 target/hexagon/q6v_decode.c
target/hexagon/decode.c new file +773 -0
@@ -0,0 +1,773 @@ +/* +* Copyright (c) 2019 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 <stdlib.h> +#include <string.h> +#include <ctype.h> +#include "qemu/osdep.h" +#include "qemu/log.h" +#include "iclass.h" +#include "opcodes.h" +#include "genptr.h" +#include "decode.h" +#include "insn.h" +#include "macros.h" +#include "printinsn.h" + +enum { + EXT_IDX_noext =0 , + EXT_IDX_noext_AFTER =4 , + EXT_IDX_mmvec =4 , + EXT_IDX_mmvec_AFTER =8 , +XX_LAST_EXT_IDX +}; + +#define DEF_REGMAP (NAME ,ELEMENTS , ...) \ + static const unsigned int DECODE_REGISTER_##NAME[ELEMENTS] = \ + { __VA_ARGS__ }; +#include "regmap.h" + +#define DECODE_MAPPED_REG (REGNO ,NAME ) \ + insn->regno[REGNO] = DECODE_REGISTER_##NAME[insn->regno[REGNO]]; + +typedef struct { +struct _dectree_table_struct *table_link; +struct _dectree_table_struct *table_link_b; +opcode_t opcode; +enum { +DECTREE_ENTRY_INVALID , +DECTREE_TABLE_LINK , +DECTREE_SUBINSNS , +DECTREE_EXTSPACE , +DECTREE_TERMINAL + } type; +}dectree_entry_t ; + +typedef struct _dectree_table_struct { +unsigned int (*lookup_function)(int startbit,int width,size4u_t opcode); +unsigned int size; +unsigned int startbit; +unsigned int width; +dectree_entry_t table[]; +}dectree_table_t ; + +#define DECODE_NEW_TABLE (TAG ,SIZE ,WHATNOT ) \ + static struct _dectree_table_struct dectree_table_##TAG; +#define TABLE_LINK (TABLE )/* NOTHING */ +#define TERMINAL (TAG ,ENC )/* NOTHING */ +#define SUBINSNS (TAG ,CLASSA ,CLASSB ,ENC )/* NOTHING */ +#define EXTSPACE (TAG ,ENC )/* NOTHING */ +#define INVALID ()/* NOTHING */ +#define DECODE_END_TABLE (...)/* NOTHING */ +#define DECODE_MATCH_INFO (...)/* NOTHING */ +#define DECODE_LEGACY_MATCH_INFO (...)/* NOTHING */ +#define DECODE_OPINFO (...)/* NOTHING */ + +#include "dectree_generated.h" + +#undef DECODE_OPINFO +#undef DECODE_MATCH_INFO +#undef DECODE_LEGACY_MATCH_INFO +#undef DECODE_END_TABLE +#undef INVALID +#undef TERMINAL +#undef SUBINSNS +#undef EXTSPACE +#undef TABLE_LINK +#undef DECODE_NEW_TABLE +#undef DECODE_SEPARATOR_BITS + +#define DECODE_SEPARATOR_BITS (START ,WIDTH ) NULL, START, WIDTH +#define DECODE_NEW_TABLE_HELPER (TAG ,SIZE ,FN ,START ,WIDTH ) \ + static dectree_table_t dectree_table_##TAG = { \ + .size = SIZE, \ + .lookup_function = FN, \ + .startbit = START, \ + .width = WIDTH, \ + .table = { +#define DECODE_NEW_TABLE (TAG ,SIZE ,WHATNOT ) \ + DECODE_NEW_TABLE_HELPER(TAG, SIZE, WHATNOT) + +#define TABLE_LINK (TABLE ) \ + { .type = DECTREE_TABLE_LINK, .table_link = &dectree_table_##TABLE }, +#define TERMINAL (TAG ,ENC ) \ + { .type = DECTREE_TERMINAL, .opcode = TAG }, +#define SUBINSNS (TAG ,CLASSA ,CLASSB ,ENC ) \ + { \ + .type = DECTREE_SUBINSNS, \ + .table_link = &dectree_table_DECODE_SUBINSN_##CLASSA, \ + .table_link_b = &dectree_table_DECODE_SUBINSN_##CLASSB \ + }, +#define EXTSPACE (TAG ,ENC ) { .type = DECTREE_EXTSPACE }, +#define INVALID () { .type = DECTREE_ENTRY_INVALID, .opcode = XX_LAST_OPCODE }, + +#define DECODE_END_TABLE (...) } }; + +#define DECODE_MATCH_INFO (...)/* NOTHING */ +#define DECODE_LEGACY_MATCH_INFO (...)/* NOTHING */ +#define DECODE_OPINFO (...)/* NOTHING */ + +#include "dectree_generated.h" + +#undef DECODE_OPINFO +#undef DECODE_MATCH_INFO +#undef DECODE_LEGACY_MATCH_INFO +#undef DECODE_END_TABLE +#undef INVALID +#undef TERMINAL +#undef SUBINSNS +#undef EXTSPACE +#undef TABLE_LINK +#undef DECODE_NEW_TABLE +#undef DECODE_NEW_TABLE_HELPER +#undef DECODE_SEPARATOR_BITS + +static dectree_table_t dectree_table_DECODE_EXT_EXT_noext = { + .size =1 , .lookup_function =NULL , .startbit =0 , .width =0 , + .table = { + { .type =DECTREE_ENTRY_INVALID , .opcode =XX_LAST_OPCODE }, + } +}; + +static dectree_table_t *ext_trees[XX_LAST_EXT_IDX ]; + +static void decode_ext_init (void ) +{ +int i; +for (i = EXT_IDX_noext; i < EXT_IDX_noext_AFTER; i++) { + ext_trees[i] = &dectree_table_DECODE_EXT_EXT_noext; + } +} + +typedef struct { +size4u_t mask; +size4u_t match; +}decode_itable_entry_t ; + +#define DECODE_NEW_TABLE (TAG ,SIZE ,WHATNOT )/* NOTHING */ +#define TABLE_LINK (TABLE )/* NOTHING */ +#define TERMINAL (TAG ,ENC )/* NOTHING */ +#define SUBINSNS (TAG ,CLASSA ,CLASSB ,ENC )/* NOTHING */ +#define EXTSPACE (TAG ,ENC )/* NOTHING */ +#define INVALID ()/* NOTHING */ +#define DECODE_END_TABLE (...)/* NOTHING */ +#define DECODE_OPINFO (...)/* NOTHING */ + +#define DECODE_MATCH_INFO_NORMAL (TAG ,MASK ,MATCH ) \ + [TAG] = { \ + .mask = MASK, \ + .match = MATCH, \ + }, + +#define DECODE_MATCH_INFO_NULL (TAG ,MASK ,MATCH ) \ + [TAG] = { .match = ~0 }, + +#define DECODE_MATCH_INFO (...) DECODE_MATCH_INFO_NORMAL(__VA_ARGS__) +#define DECODE_LEGACY_MATCH_INFO (...)/* NOTHING */ + +static const decode_itable_entry_t decode_itable[XX_LAST_OPCODE ] = { +#include "dectree_generated.h" +}; + +#undef DECODE_MATCH_INFO +#define DECODE_MATCH_INFO (...) DECODE_MATCH_INFO_NULL(__VA_ARGS__) + +#undef DECODE_LEGACY_MATCH_INFO +#define DECODE_LEGACY_MATCH_INFO (...) DECODE_MATCH_INFO_NORMAL(__VA_ARGS__) + +static const decode_itable_entry_t decode_legacy_itable[XX_LAST_OPCODE ] = { +#include "dectree_generated.h" +}; + +#undef DECODE_OPINFO +#undef DECODE_MATCH_INFO +#undef DECODE_LEGACY_MATCH_INFO +#undef DECODE_END_TABLE +#undef INVALID +#undef TERMINAL +#undef SUBINSNS +#undef EXTSPACE +#undef TABLE_LINK +#undef DECODE_NEW_TABLE +#undef DECODE_SEPARATOR_BITS + +void decode_init (void ) +{ +decode_ext_init (); +} + +void decode_send_insn_to (packet_t *packet,int start,int newloc) +{ +insn_t tmpinsn; +int direction; +int i; +if (start == newloc) { +return ; + } +if (start < newloc) { +/* Move towards end */ + direction =1 ; + }else { +/* move towards beginning */ + direction =-1 ; + } +for (i = start; i != newloc; i += direction) { + tmpinsn = packet->insn[i]; + packet->insn[i] = packet->insn[i + direction]; + packet->insn[i + direction] = tmpinsn; + } +} + +/* Fill newvalue registers with the correct regno */ +static int +decode_fill_newvalue_regno (packet_t *packet) +{ +int i, def_regnum, use_regidx, def_idx; +size2u_t def_opcode, use_opcode; +char *dststr; + +for (i =1 ; i < packet->num_insns; i++) { +if (GET_ATTRIB (packet->insn[i].opcode,A_DOTNEWVALUE ) && + !GET_ATTRIB (packet->insn[i].opcode,A_EXTENSION )) { + use_opcode = packet->insn[i].opcode; + +/* It's a store, so we're adjusting the Nt field */ +if (GET_ATTRIB (use_opcode,A_STORE )) { + use_regidx =strchr (opcode_reginfo[use_opcode],'t' ) - + opcode_reginfo[use_opcode]; + }else {/* It's a Jump, so we're adjusting the Ns field */ + use_regidx =strchr (opcode_reginfo[use_opcode],'s' ) - + opcode_reginfo[use_opcode]; + } + +/* +* What's encoded at the N-field is the offset to who's producing +* the value. Shift off the LSB which indicates odd/even register. +*/ + def_idx = i - ((packet->insn[i].regno[use_regidx]) >>1 ); + +/* +* Check for a badly encoded N-field which points to an instruction +* out-of-range +*/ +if ((def_idx <0 ) || (def_idx > (packet->num_insns -1 ))) { +g_assert_not_reached (); +return 1 ; + } + +/* previous insn is the producer */ + def_opcode = packet->insn[def_idx].opcode; + dststr =strstr (opcode_wregs[def_opcode],"Rd" ); +if (dststr) { + dststr =strchr (opcode_reginfo[def_opcode],'d' ); + }else { + dststr =strstr (opcode_wregs[def_opcode],"Rx" ); +if (dststr) { + dststr =strchr (opcode_reginfo[def_opcode],'x' ); + }else { + dststr =strstr (opcode_wregs[def_opcode],"Re" ); +if (dststr) { + dststr =strchr (opcode_reginfo[def_opcode],'e' ); + }else { + dststr =strstr (opcode_wregs[def_opcode],"Ry" ); +if (dststr) { + dststr =strchr (opcode_reginfo[def_opcode],'y' ); + }else { +g_assert_not_reached (); +return 1 ; + } + } + } + } +g_assert (dststr !=NULL ); + def_regnum = + packet->insn[def_idx].regno[dststr - + opcode_reginfo[def_opcode]]; + +/* Now patch up the consumer with the register number */ + packet->insn[i].regno[use_regidx] = def_regnum; +/* +* We need to remember who produces this value to later +* check if it was dynamically cancelled +*/ + packet->insn[i].new_value_producer_slot = + packet->insn[def_idx].slot; + } + } +return 0 ; +} + +/* Split CJ into a compare and a jump */ +static int decode_split_cmpjump (packet_t *pkt) +{ +int last, i; +int numinsns = pkt->num_insns; + +/* +* First, split all compare-jumps. +* The compare is sent to the end as a new instruction. +* Do it this way so we don't reorder dual jumps. Those need to stay in +* original order. +*/ +for (i =0 ; i < numinsns; i++) { +/* It's a cmp-jump */ +if (GET_ATTRIB (pkt->insn[i].opcode,A_NEWCMPJUMP )) { + last = pkt->num_insns; + pkt->insn[last] = pkt->insn[i];/* copy the instruction */ + pkt->insn[last].part1 =1 ;/* last instruction does the CMP */ + pkt->insn[i].part1 =0 ;/* existing instruction does the JUMP */ + pkt->num_insns++; + } + } + +/* Now re-shuffle all the compares back to the beginning */ +for (i =0 ; i < pkt->num_insns; i++) { +if (pkt->insn[i].part1) { +decode_send_insn_to (pkt, i,0 ); + } + } +return 0 ; +} + +static inline int decode_opcode_can_jump (int opcode) +{ +if ((GET_ATTRIB (opcode,A_JUMP )) || + (GET_ATTRIB (opcode,A_CALL )) || + (opcode == J2_trap0) || + (opcode == J2_trap1) || + (opcode == J2_rte) || + (opcode == J2_pause)) { +/* Exception to A_JUMP attribute */ +if (opcode == J4_hintjumpr) { +return 0 ; + } +return 1 ; + } + +return 0 ; +} + +static inline int decode_opcode_ends_loop (int opcode) +{ +return GET_ATTRIB (opcode,A_HWLOOP0_END ) || +GET_ATTRIB (opcode,A_HWLOOP1_END ); +} + +/* Set the is_* fields in each instruction */ +static int decode_set_insn_attr_fields (packet_t *pkt) +{ +int i; +int numinsns = pkt->num_insns; +size2u_t opcode; +int loads =0 ; +int stores =0 ; +int canjump; +int total_slots_valid =0 ; + + pkt->num_rops =0 ; + pkt->pkt_has_cof =0 ; + pkt->pkt_has_call =0 ; + pkt->pkt_has_jumpr =0 ; + pkt->pkt_has_cjump =0 ; + pkt->pkt_has_cjump_dotnew =0 ; + pkt->pkt_has_cjump_dotold =0 ; + pkt->pkt_has_cjump_newval =0 ; + pkt->pkt_has_endloop =0 ; + pkt->pkt_has_endloop0 =0 ; + pkt->pkt_has_endloop01 =0 ; + pkt->pkt_has_endloop1 =0 ; + pkt->pkt_has_cacheop =0 ; + pkt->memop_or_nvstore =0 ; + pkt->pkt_has_dczeroa =0 ; + pkt->pkt_has_dealloc_return =0 ; + +for (i =0 ; i < numinsns; i++) { + opcode = pkt->insn[i].opcode; +if (pkt->insn[i].part1) { +continue ;/* Skip compare of cmp-jumps */ + } + +if (GET_ATTRIB (opcode,A_ROPS_3 )) { + pkt->num_rops +=3 ; + }else if (GET_ATTRIB (opcode,A_ROPS_2 )) { + pkt->num_rops +=2 ; + }else { + pkt->num_rops++; + } +if (pkt->insn[i].extension_valid) { + pkt->num_rops +=2 ; + } + +if (GET_ATTRIB (opcode,A_MEMOP ) || +GET_ATTRIB (opcode,A_NVSTORE )) { + pkt->memop_or_nvstore =1 ; + } + +if (GET_ATTRIB (opcode,A_CACHEOP )) { + pkt->pkt_has_cacheop =1 ; +if (GET_ATTRIB (opcode,A_DCZEROA )) { + pkt->pkt_has_dczeroa =1 ; + } +if (GET_ATTRIB (opcode,A_ICTAGOP )) { + pkt->pkt_has_ictagop =1 ; + } +if (GET_ATTRIB (opcode,A_ICFLUSHOP )) { + pkt->pkt_has_icflushop =1 ; + } +if (GET_ATTRIB (opcode,A_DCTAGOP )) { + pkt->pkt_has_dctagop =1 ; + } +if (GET_ATTRIB (opcode,A_DCFLUSHOP )) { + pkt->pkt_has_dcflushop =1 ; + } +if (GET_ATTRIB (opcode,A_L2TAGOP )) { + pkt->pkt_has_l2tagop =1 ; + } +if (GET_ATTRIB (opcode,A_L2FLUSHOP )) { + pkt->pkt_has_l2flushop =1 ; + } + } + +if (GET_ATTRIB (opcode,A_DEALLOCRET )) { + pkt->pkt_has_dealloc_return =1 ; + } + +if (GET_ATTRIB (opcode,A_STORE )) { + pkt->insn[i].is_store =1 ; + +if (pkt->insn[i].slot ==0 ) { + pkt->pkt_has_store_s0 =1 ; + }else { + pkt->pkt_has_store_s1 =1 ; + } + } +if (GET_ATTRIB (opcode,A_DCFETCH )) { + pkt->insn[i].is_dcfetch =1 ; + } +if (GET_ATTRIB (opcode,A_LOAD )) { + pkt->insn[i].is_load =1 ; + +if (pkt->insn[i].slot ==0 ) { + pkt->pkt_has_load_s0 =1 ; + }else { + pkt->pkt_has_load_s1 =1 ; + } + } +if (GET_ATTRIB (opcode,A_MEMOP )) { + pkt->insn[i].is_memop =1 ; + } +if (GET_ATTRIB (opcode,A_DEALLOCRET ) || +GET_ATTRIB (opcode,A_DEALLOCFRAME )) { + pkt->insn[i].is_dealloc =1 ; + } +if (GET_ATTRIB (opcode,A_DCFLUSHOP ) || +GET_ATTRIB (opcode,A_DCTAGOP )) { + pkt->insn[i].is_dcop =1 ; + } + + pkt->pkt_has_call |=GET_ATTRIB (opcode,A_CALL ); + pkt->pkt_has_jumpr |=GET_ATTRIB (opcode,A_INDIRECT ) && + !GET_ATTRIB (opcode,A_HINTJR ); + pkt->pkt_has_cjump |=GET_ATTRIB (opcode,A_CJUMP ); + pkt->pkt_has_cjump_dotnew |=GET_ATTRIB (opcode,A_DOTNEW ) && +GET_ATTRIB (opcode,A_CJUMP ); + pkt->pkt_has_cjump_dotold |=GET_ATTRIB (opcode,A_DOTOLD ) && +GET_ATTRIB (opcode,A_CJUMP ); + pkt->pkt_has_cjump_newval |=GET_ATTRIB (opcode,A_DOTNEWVALUE ) && +GET_ATTRIB (opcode,A_CJUMP ); + + canjump =decode_opcode_can_jump (opcode); + +if (pkt->pkt_has_cof) { +if (canjump) { + pkt->pkt_has_dual_jump =1 ; + pkt->insn[i].is_2nd_jump =1 ; + } + }else { + pkt->pkt_has_cof |= canjump; + } + + pkt->insn[i].is_endloop =decode_opcode_ends_loop (opcode); + + pkt->pkt_has_endloop |= pkt->insn[i].is_endloop; + pkt->pkt_has_endloop0 |=GET_ATTRIB (opcode,A_HWLOOP0_END ) && + !GET_ATTRIB (opcode,A_HWLOOP1_END ); + pkt->pkt_has_endloop01 |=GET_ATTRIB (opcode,A_HWLOOP0_END ) && +GET_ATTRIB (opcode,A_HWLOOP1_END ); + pkt->pkt_has_endloop1 |=GET_ATTRIB (opcode,A_HWLOOP1_END ) && + !GET_ATTRIB (opcode,A_HWLOOP0_END ); + + pkt->pkt_has_cof |= pkt->pkt_has_endloop; + +/* Now create slot valids */ +if (pkt->insn[i].is_endloop)/* Don't count endloops */ +continue ; + +switch (pkt->insn[i].slot) { +case 0 : + pkt->slot0_valid =1 ; +break ; +case 1 : + pkt->slot1_valid =1 ; +break ; +case 2 : + pkt->slot2_valid =1 ; +break ; +case 3 : + pkt->slot3_valid =1 ; +break ; + } + total_slots_valid++; + +/* And track #loads/stores */ +if (pkt->insn[i].is_store) { + stores++; + }else if (pkt->insn[i].is_load) { + loads++; + } + } + +if (stores ==2 ) { + pkt->dual_store =1 ; + }else if (loads ==2 ) { + pkt->dual_load =1 ; + }else if ((loads ==1 ) && (stores ==1 )) { + pkt->load_and_store =1 ; + }else if (loads ==1 ) { + pkt->single_load =1 ; + }else if (stores ==1 ) { + pkt->single_store =1 ; + } + +return 0 ; +} + +/* +* Shuffle for execution +* Move stores to end (in same order as encoding) +* Move compares to beginning (for use by .new insns) +*/ +static int decode_shuffle_for_execution (packet_t *packet) +{ +int changed =0 ; +int i; +int flag;/* flag means we've seen a non-memory instruction */ +int n_mems; +int last_insn = packet->num_insns -1 ; + +/* +* Skip end loops, somehow an end loop is getting in and messing +* up the order +*/ +if (decode_opcode_ends_loop (packet->insn[last_insn].opcode)) { + last_insn--; + } + +do { + changed =0 ; +/* +* Stores go last, must not reorder. +* Cannot shuffle stores past loads, either. +* Iterate backwards. If we see a non-memory instruction, +* then a store, shuffle the store to the front. Don't shuffle +* stores wrt each other or a load. +*/ +for (flag = n_mems =0 , i = last_insn; i >=0 ; i--) { +int opcode = packet->insn[i].opcode; + +if (flag &&GET_ATTRIB (opcode,A_STORE )) { +decode_send_insn_to (packet, i, last_insn - n_mems); + n_mems++; + changed =1 ; + }else if (GET_ATTRIB (opcode,A_STORE )) { + n_mems++; + }else if (GET_ATTRIB (opcode,A_LOAD )) { +/* +* Don't set flag, since we don't want to shuffle a +* store pasta load +*/ + n_mems++; + }else if (GET_ATTRIB (opcode,A_DOTNEWVALUE )) { +/* +* Don't set flag, since we don't want to shuffle past +* a .new value +*/ + }else { + flag =1 ; + } + } + +if (changed) { +continue ; + } +/* Compares go first, may be reordered wrt each other */ +for (flag =0 , i =0 ; i < last_insn +1 ; i++) { +int opcode = packet->insn[i].opcode; + +if ((strstr (opcode_wregs[opcode],"Pd4" ) || +strstr (opcode_wregs[opcode],"Pe4" )) && +GET_ATTRIB (opcode,A_STORE ) ==0 ) { +/* This should be a compare (not a store conditional) */ +if (flag) { +decode_send_insn_to (packet, i,0 ); + changed =1 ; +continue ; + } + }else if (GET_ATTRIB (opcode,A_IMPLICIT_WRITES_P3 ) && + !decode_opcode_ends_loop (packet->insn[i].opcode)) { +/* +* spNloop instruction +* Don't reorder endloops; they are not valid for .new uses, +* and we want to match HW +*/ +if (flag) { +decode_send_insn_to (packet, i,0 ); + changed =1 ; +continue ; + } + }else if (GET_ATTRIB (opcode,A_IMPLICIT_WRITES_P0 ) && + !GET_ATTRIB (opcode,A_NEWCMPJUMP )) { +/* CABAC instruction */ +if (flag) { +decode_send_insn_to (packet, i,0 ); + changed =1 ; +continue ; + } + }else { + flag =1 ; + } + } +if (changed) { +continue ; + } + }while (changed); + +/* +* If we have a .new register compare/branch, move that to the very +* very end, past stores +*/ +for (i =0 ; i < last_insn; i++) { +if (GET_ATTRIB (packet->insn[i].opcode,A_DOTNEWVALUE )) { +decode_send_insn_to (packet, i, last_insn); +break ; + } + } + +/* +* And at the very very very end, move any RTE's, since they update +* user/supervisor mode. +*/ +for (i =0 ; i < last_insn; i++) { +if ((packet->insn[i].opcode == J2_rte)) { +decode_send_insn_to (packet, i, last_insn); +break ; + } + } +return 0 ; +} + +static void decode_assembler_count_fpops (packet_t *pkt) +{ +int i; +for (i =0 ; i < pkt->num_insns; i++) { +if (GET_ATTRIB (pkt->insn[i].opcode,A_FPOP )) { + pkt->pkt_has_fp_op =1 ; + } +if (GET_ATTRIB (pkt->insn[i].opcode,A_FPDOUBLE )) { + pkt->pkt_has_fpdp_op =1 ; + }else if (GET_ATTRIB (pkt->insn[i].opcode,A_FPSINGLE )) { + pkt->pkt_has_fpsp_op =1 ; + } + } +} + +static int +apply_extender (packet_t *pkt,int i,size4u_t extender) +{ +int immed_num; +size4u_t base_immed; + + immed_num =opcode_which_immediate_is_extended (pkt->insn[i].opcode); + base_immed = pkt->insn[i].immed[immed_num]; + + pkt->insn[i].immed[immed_num] = extender |fZXTN (6 ,32 , base_immed); +return 0 ; +} + +static int decode_apply_extenders (packet_t *packet) +{ +int i; +for (i =0 ; i < packet->num_insns; i++) { +if (GET_ATTRIB (packet->insn[i].opcode,A_IT_EXTENDER )) { + packet->insn[i +1 ].extension_valid =1 ; + packet->pkt_has_payload =1 ; +apply_extender (packet, i +1 , packet->insn[i].immed[0 ]); + } + } +return 0 ; +} + +static int decode_remove_extenders (packet_t *packet) +{ +int i, j; +for (i =0 ; i < packet->num_insns; i++) { +if (GET_ATTRIB (packet->insn[i].opcode,A_IT_EXTENDER )) { +for (j = i; + (j < packet->num_insns -1 ) && (j <INSTRUCTIONS_MAX -1 ); + j++) { + packet->insn[j] = packet->insn[j +1 ]; + } + packet->num_insns--; + } + } +return 0 ; +} + +static const char * +get_valid_slot_str (const packet_t *pkt,unsigned int slot) +{ +return find_iclass_slots (pkt->insn[slot].opcode, + pkt->insn[slot].iclass); +} + +#include "q6v_decode.c" + +packet_t *decode_this (int max_words,size4u_t *words,packet_t *decode_pkt) +{ +int ret; + ret =do_decode_packet (max_words, words, decode_pkt); +if (ret <=0 ) { +/* ERROR or BAD PARSE */ +return NULL ; + } +return decode_pkt; +} + +/* Used for "-d in_asm" logging */ +int disassemble_hexagon (uint32_t *words,int nwords,char *buf,int bufsize) +{ +packet_t pkt; + +if (decode_this (nwords, words, &pkt)) { +snprint_a_pkt (buf, bufsize, &pkt); +return pkt.encod_pkt_size_in_bytes; + }else { +snprintf (buf, bufsize,"<invalid>" ); +return 0 ; + } +}
target/hexagon/decode.h new file +39 -0
@@ -0,0 +1,39 @@ +/* +* Copyright (c) 2019 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/>. +*/ + +#ifndef DECODE_H +#define DECODE_H + +#include "cpu.h" +#include "opcodes.h" +#include "hex_arch_types.h" +#include "insn.h" + +extern void decode_init (void ); + +static inline int is_packet_end (uint32_t word) +{ +uint32_t bits = (word >>14 ) &0x3 ; +return ((bits ==0x3 ) || (bits ==0x0 )); +} + +extern void decode_send_insn_to (packet_t *packet,int start,int newloc); + +extern packet_t *decode_this (int max_words,size4u_t *words, +packet_t *decode_pkt); + +#endif
target/hexagon/q6v_decode.c new file +402 -0
402 lines not on this page · raw message
Signature · 1 line
2.7.4
RFC PATCH 14/66 Hexagon instruction printing
In reply to Taylor Simpson--- target/hexagon/printinsn.c | 93 ++++++++++++++++++++++++++++++++++++++++++++++ target/hexagon/printinsn.h | 26 +++++++++++++ 2 files changed, 119 insertions(+) create mode 100644 target/hexagon/printinsn.c create mode 100644 target/hexagon/printinsn.h
target/hexagon/printinsn.c new file +93 -0
@@ -0,0 +1,93 @@ +/* +* Copyright (c) 2019 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 <string.h> +#include "qemu/osdep.h" +#include "opcodes.h" +#include "printinsn.h" +#include "insn.h" +#include "macros.h" +#include "internal.h" + +static const char *sreg2str (unsigned int reg) +{ +if (reg <TOTAL_PER_THREAD_REGS ) { +return hexagon_regnames[reg]; + }else { +return "???" ; + } +} + +static const char *creg2str (unsigned int reg) +{ +return sreg2str (reg +NUM_GEN_REGS ); +} + +static void snprintinsn (char *buf,int n,insn_t * insn) +{ +switch (insn->opcode) { +#define DEF_VECX_PRINTINFO (TAG ,FMT , ...) DEF_PRINTINFO(TAG, FMT, __VA_ARGS__) +#define DEF_PRINTINFO (TAG ,FMT , ...) \ + case TAG: \ + snprintf(buf, n, FMT, __VA_ARGS__);\ + break; +#include "printinsn_generated.h" +#undef DEF_VECX_PRINTINFO +#undef DEF_PRINTINFO + } +} + +void snprint_a_pkt (char *buf,int n,packet_t * pkt) +{ +char tmpbuf[128 ]; + buf[0 ] ='\0' ; +int i, slot, opcode; + +if (pkt ==NULL ) { +snprintf (buf, n,"<printpkt: NULL ptr>" ); +return ; + } + +if (pkt->num_insns >1 ) { +strncat (buf,"\n{\n" , n); + } +for (i =0 ; i < pkt->num_insns; i++) { +if (pkt->insn[i].part1) { +continue ; + } +snprintinsn (tmpbuf,127 , &(pkt->insn[i])); +strncat (buf,"\t" , n); +strncat (buf, tmpbuf, n); +if (GET_ATTRIB (pkt->insn[i].opcode,A_SUBINSN )) { +strncat (buf," //subinsn" , n); + } +if (pkt->insn[i].extension_valid) { +strncat (buf," //constant extended" , n); + } + slot = pkt->insn[i].slot; + opcode = pkt->insn[i].opcode; +snprintf (tmpbuf,127 ," //slot=%d:tag=%s" , slot, opcode_names[opcode]); +strncat (buf, tmpbuf, n); + +strncat (buf,"\n" , n); + } +if (pkt->num_insns >1 ) { +strncat (buf,"}\n" , n); + } +} +
target/hexagon/printinsn.h new file +26 -0
@@ -0,0 +1,26 @@ +/* +* Copyright (c) 2019 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/>. +*/ + +#ifndef PRINTINSN_H +#define PRINTINSN_H + +#include <stdio.h> +#include "insn.h" + +extern void snprint_a_pkt (char *buf,int n,packet_t *pkt); + +#endif
Signature · 1 line
2.7.4
RFC PATCH 15/66 Hexagon arch import - instruction semantics definitions
In reply to Taylor SimpsonImported from the Hexagon architecture library
imported/allidefs.def Top level instruction definition file
imported/*.idef Instruction definition files
These files are input to the first phase of the generator (gen_semantics.c) to create a python include file with the instruction semantics and attributes. The python include file is fed to the second phase (do_qemu.py).
--- target/hexagon/imported/allidefs.def | 91 +++ target/hexagon/imported/alu.idef | 1335 +++++++++++++++++++++++++++++++++ target/hexagon/imported/branch.idef | 344 +++++++++ target/hexagon/imported/compare.idef | 639 ++++++++++++++++ target/hexagon/imported/float.idef | 498 ++++++++++++ target/hexagon/imported/ldst.idef | 421 +++++++++++ target/hexagon/imported/mpy.idef | 1269 +++++++++++++++++++++++++++++++ target/hexagon/imported/shift.idef | 1211 ++++++++++++++++++++++++++++++ target/hexagon/imported/subinsns.idef | 152 ++++ target/hexagon/imported/system.idef | 302 ++++++++ 10 files changed, 6262 insertions(+) create mode 100644 target/hexagon/imported/allidefs.def create mode 100644 target/hexagon/imported/alu.idef create mode 100644 target/hexagon/imported/branch.idef create mode 100644 target/hexagon/imported/compare.idef create mode 100644 target/hexagon/imported/float.idef create mode 100644 target/hexagon/imported/ldst.idef create mode 100644 target/hexagon/imported/mpy.idef create mode 100644 target/hexagon/imported/shift.idef create mode 100644 target/hexagon/imported/subinsns.idef create mode 100644 target/hexagon/imported/system.idef
target/hexagon/imported/allidefs.def new file +91 -0
@@ -0,0 +1,91 @@ +/* + * Copyright (c) 2019 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/>. + */ + +/* + * Top level instruction definition file + */ + +#define DEF_MAPPING(TAG,FROMSYN,TOSYN) \ + Q6INSN(TAG,FROMSYN,ATTRIBS(A_MAPPING), \ + "Mapping from " FROMSYN " to " TOSYN, \ + fASM_MAP(FROMSYN,TOSYN)) + +#define DEF_COND_MAPPING(TAG,FROMSYN,COND,TOSYNA,TOSYNB) \ + Q6INSN(TAG,FROMSYN,ATTRIBS(A_MAPPING,A_CONDMAPPING), \ + "Conditional Mapping from " FROMSYN " to either " TOSYNA " or " TOSYNB, \ + fCOND_ASM_MAP(FROMSYN,COND,TOSYNA,TOSYNB)) + +#define DEF_V2_MAPPING(TAG,FROMSYN,TOSYN) \ + Q6INSN(TAG,FROMSYN,ATTRIBS(A_MAPPING,A_ARCHV2), \ + "Mapping from " FROMSYN " to " TOSYN, \ + fASM_MAP(FROMSYN,TOSYN)) + +#define DEF_V2_COND_MAPPING(TAG,FROMSYN,COND,TOSYNA,TOSYNB) \ + Q6INSN(TAG,FROMSYN,ATTRIBS(A_MAPPING,A_CONDMAPPING,A_ARCHV2), \ + "Conditional Mapping from " FROMSYN " to either " TOSYNA " or " TOSYNB, \ + fCOND_ASM_MAP(FROMSYN,COND,TOSYNA,TOSYNB)) + +#define DEF_V3_MAPPING(TAG,FROMSYN,TOSYN) \ + Q6INSN(TAG,FROMSYN,ATTRIBS(A_MAPPING,A_ARCHV3), \ + "Mapping from " FROMSYN " to " TOSYN, \ + fASM_MAP(FROMSYN,TOSYN)) + +#define DEF_V3_COND_MAPPING(TAG,FROMSYN,COND,TOSYNA,TOSYNB) \ + Q6INSN(TAG,FROMSYN,ATTRIBS(A_MAPPING,A_CONDMAPPING,A_ARCHV3), \ + "Conditional Mapping from " FROMSYN " to either " TOSYNA " or " TOSYNB, \ + fCOND_ASM_MAP(FROMSYN,COND,TOSYNA,TOSYNB)) + +#define DEF_V4_MAPPING(TAG,FROMSYN,TOSYN) \ + Q6INSN(TAG,FROMSYN,ATTRIBS(A_MAPPING,A_ARCHV4), \ + "Mapping from " FROMSYN " to " TOSYN, \ + fASM_MAP(FROMSYN,TOSYN)) + +#define DEF_V4_COND_MAPPING(TAG,FROMSYN,COND,TOSYNA,TOSYNB) \ + Q6INSN(TAG,FROMSYN,ATTRIBS(A_MAPPING,A_CONDMAPPING,A_ARCHV4), \ + "Conditional Mapping from " FROMSYN " to either " TOSYNA " or " TOSYNB, \ + fCOND_ASM_MAP(FROMSYN,COND,TOSYNA,TOSYNB)) + +#define DEF_V5_MAPPING(TAG,FROMSYN,TOSYN) \ + Q6INSN(TAG,FROMSYN,ATTRIBS(A_MAPPING,A_ARCHV5), \ + "Mapping from " FROMSYN " to " TOSYN, \ + fASM_MAP(FROMSYN,TOSYN)) + +#define DEF_V5_COND_MAPPING(TAG,FROMSYN,COND,TOSYNA,TOSYNB) \ + Q6INSN(TAG,FROMSYN,ATTRIBS(A_MAPPING,A_CONDMAPPING,A_ARCHV5), \ + "Conditional Mapping from " FROMSYN " to either " TOSYNA " or " TOSYNB, \ + fCOND_ASM_MAP(FROMSYN,COND,TOSYNA,TOSYNB)) + +#define DEF_VECX_MAPPING(TAG,FROMSYN,TOSYN) \ + EXTINSN(TAG,FROMSYN,ATTRIBS(A_MAPPING,A_VECX), \ + "VECX Mapping from " FROMSYN " to " TOSYN, \ + fASM_MAP(FROMSYN,TOSYN)) + +#define DEF_CVI_MAPPING(TAG,FROMSYN,TOSYN) \ + Q6INSN(TAG,FROMSYN,ATTRIBS(A_MAPPING,A_CVI), \ + "CVI Mapping from " FROMSYN " to " TOSYN, \ + fASM_MAP(FROMSYN,TOSYN)) + + +#include "branch.idef" +#include "ldst.idef" +#include "compare.idef" +#include "mpy.idef" +#include "alu.idef" +#include "float.idef" +#include "shift.idef" +#include "system.idef" +#include "subinsns.idef"
target/hexagon/imported/alu.idef new file +1335 -0
1,335 lines not on this page · raw message
target/hexagon/imported/branch.idef new file +344 -0
344 lines not on this page · raw message
target/hexagon/imported/compare.idef new file +639 -0
639 lines not on this page · raw message
target/hexagon/imported/float.idef new file +498 -0
498 lines not on this page · raw message
target/hexagon/imported/ldst.idef new file +421 -0
93 lines not on this page · raw message
target/hexagon/imported/mpy.idef new file +1269 -0
1,269 lines not on this page · raw message
target/hexagon/imported/shift.idef new file +1211 -0
1,211 lines not on this page · raw message
target/hexagon/imported/subinsns.idef new file +152 -0
152 lines not on this page · raw message
target/hexagon/imported/system.idef new file +302 -0
302 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.7.4
Part of the diff is not shown here. View the raw message.
RFC PATCH 16/66 Hexagon arch import - macro definitions
In reply to Taylor SimpsonImported from the Hexagon architecture library
imported/macros.def Scalar core macro definitions
The macro definition files specify instruction attributes that are applied to each instruction that reverences the macro.
--- target/hexagon/imported/macros.def | 3970 ++++++++++++++++++++++++++++++++++++ 1 file changed, 3970 insertions(+) create mode 100755 target/hexagon/imported/macros.def
target/hexagon/imported/macros.def new file +3970 -0
@@ -0,0 +1,3970 @@ +/* + * Copyright (c) 2019 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/>. + */ + +DEF_MACRO( + LIKELY, /* NAME */ + (X), /* PARAMS */ + "X", /* sdescr */ + "X", /* ldescr */ + __builtin_expect((X),1), /* BEH */ + () /* attribs */ +) + +DEF_MACRO( + UNLIKELY, /* NAME */ + (X), /* PARAMS */ + "X", /* sdescr */ + "X", /* ldescr */ + __builtin_expect((X),0), /* BEH */ + () /* attribs */ +) + +DEF_MACRO( + CANCEL, /* macro name */ + , /* parameters */ + "NOP", /* short description */ + "NOP this instruction", /* long description */ + {if (thread->last_pkt) thread->last_pkt->slot_cancelled |= (1<<insn->slot); return;} , /* behavior */ + (A_CONDEXEC) +) + +DEF_MACRO( + STORE_ZERO, /* macro name */ + , /* parameters */ + "Zero Store", /* short description */ + "NOP this instruction", /* long description */ + {if (thread->last_pkt) thread->last_pkt->slot_zero_byte_store |= (1<<insn->slot); } , /* behavior */ + (A_CONDEXEC) +) + +DEF_MACRO( + LOAD_CANCEL, /* macro name */ + (EA), /* parameters */ + "NOP", /* short description */ + "NOP this instruction", /* long description */ + {mem_general_load_cancelled(thread,EA,insn);CANCEL;} , /* behavior */ + (A_CONDEXEC) +) + +DEF_MACRO( + STORE_CANCEL, /* macro name */ + (EA), /* parameters */ + "NOP", /* short description */ + "NOP this instruction", /* long description */ + {mem_general_store_cancelled(thread,EA,insn);CANCEL;} , /* behavior */ + (A_CONDEXEC) +) + +DEF_MACRO( + IS_CANCELLED, /* macro name */ + (SLOT), /* parameters */ + "", /* short description */ + "", /* long description */ + ((thread->last_pkt->slot_cancelled >> SLOT)&1) , /* behavior */ + /* attrib */ +) + +DEF_MACRO( + fMAX, /* macro name */ + (A,B), /* parameters */ + "max(A,B)", /* short description */ + "the larger of A and B", /* long description */ + (((A) > (B)) ? (A) : (B)), /* behavior */ + /* optional attributes */ +) + +DEF_MACRO( + fMIN, /* macro name */ + (A,B), /* parameters */ + "min(A,B)", /* short description */ + "the smaller of A and B", /* long description */ + (((A) < (B)) ? (A) : (B)), /* behavior */ + /* optional attributes */ +) + +DEF_MACRO( + fABS, /* macro name */ + (A), /* parameters */ + "ABS(A)", /* short description */ + "if A is less than zero then A=-A", /* long description */ + (((A)<0)?(-(A)):(A)), /* behavior */ + /* optional attributes */ +) + + +/* Bit insert */ +DEF_MACRO( + fINSERT_BITS,(REG,WIDTH,OFFSET,INVAL), + "REG[(WIDTH-1+OFFSET):OFFSET]=INVAL", + "REG[(WIDTH-1+OFFSET):OFFSET]=INVAL", + { + REG = ((REG) & ~(((fCONSTLL(1)<<(WIDTH))-1)<<(OFFSET))) | (((INVAL) & ((fCONSTLL(1)<<(WIDTH))-1)) << (OFFSET)); + }, + /* attribs */ +) + +/* Bit extract */ +DEF_MACRO( + fEXTRACTU_BITS,(INREG,WIDTH,OFFSET), + "INREG[(WIDTH+OFFSET-1):OFFSET]", + "INREG[(WIDTH+OFFSET-1):OFFSET]", + (fZXTN(WIDTH,32,(INREG >> OFFSET))), + /* attribs */ +) + +DEF_MACRO( + fEXTRACTU_BIDIR,(INREG,WIDTH,OFFSET), + "INREG[(WIDTH+OFFSET-1):OFFSET]", + "INREG[(WIDTH+OFFSET-1):OFFSET]", + (fZXTN(WIDTH,32,fBIDIR_LSHIFTR((INREG),(OFFSET),4_8))), + /* attribs */ +) + +DEF_MACRO( + fEXTRACTU_RANGE,(INREG,HIBIT,LOWBIT), + "INREG[HIBIT:LOWBIT]", + "INREG[HIBIT:LOWBIT]", + (fZXTN((HIBIT-LOWBIT+1),32,(INREG >> LOWBIT))), + /* attribs */ +) + + +DEF_MACRO( + fINSERT_RANGE,(INREG,HIBIT,LOWBIT,INVAL), + "INREG[HIBIT:LOWBIT]=INVAL", + "INREG[HIBIT:LOWBIT]=INVAL", + { + int offset=LOWBIT; + int width=HIBIT-LOWBIT+1; + /* clear bits where new bits go */ + INREG &= ~(((fCONSTLL(1)<<width)-1)<<offset); + /* OR in new bits */ + INREG |= ((INVAL & ((fCONSTLL(1)<<width)-1)) << offset); + }, + /* attribs */ +) + + +DEF_MACRO( + f8BITSOF,(VAL), + "VAL ? 0xff : 0x00", + "VAL ? 0xff : 0x00", + ( (VAL) ? 0xff : 0x00), + /* attribs */ +) + +DEF_MACRO( + fLSBOLD,(VAL), + "VAL[0]", + "Least significant bit of VAL", + ((VAL) & 1), + (A_DOTOLD) +) + +DEF_MACRO( + fLSBNEW,(PNUM), + "PNUM.new[0]", + "Least significant bit of new PNUM", + predlog_read(thread,PNUM), + (A_DOTNEW) +) + +DEF_MACRO( + fLSBNEW0,, + "P0.new[0]", + "Least significant bit of new P0", + predlog_read(thread,0), + (A_DOTNEW,A_IMPLICIT_READS_P0) +) + +DEF_MACRO( + fLSBNEW1,, + "P1.new[0]", + "Least significant bit of new P1", + predlog_read(thread,1), + (A_DOTNEW,A_IMPLICIT_READS_P1) +) + +DEF_MACRO( + fLSBOLDNOT,(VAL), + "!VAL[0]", + "!Least significant bit of VAL", + (!fLSBOLD(VAL)), + (A_DOTOLD,A_INVPRED) +) + +DEF_MACRO( + fLSBNEWNOT,(PNUM), + "!PNUM.new[0]", + "!Least significant bit of new PNUM", + (!fLSBNEW(PNUM)), + (A_DOTNEW,A_INVPRED) +) + +DEF_MACRO( + fLSBNEW0NOT,, + "!P0.new[0]", + "!Least significant bit of new P0", + (!fLSBNEW0), + (A_DOTNEW,A_INVPRED,A_IMPLICIT_READS_P0) +) + +DEF_MACRO( + fLSBNEW1NOT,, + "P1.new[0]", + "Least significant bit of new P1", + (!fLSBNEW1), + (A_DOTNEW,A_INVPRED,A_IMPLICIT_READS_P1) +) + +DEF_MACRO( + fNEWREG,(RNUM), + "RNUM.new", + "Register value produced in this packet", + ({if (newvalue_missing(thread,RNUM) || + IS_CANCELLED(insn->new_value_producer_slot)) CANCEL; reglog_read(thread,RNUM);}), + (A_DOTNEWVALUE,A_RESTRICT_SLOT0ONLY) +) +// Store new with a missing newvalue or cancelled goes out as a zero byte store in V65 +// take advantage of the fact that reglog_read returns zero for not valid rnum +DEF_MACRO( + fNEWREG_ST,(RNUM), + "RNUM.new", + "Register value produced in this packet for store", + ({if (newvalue_missing(thread,RNUM) || + IS_CANCELLED(insn->new_value_producer_slot)) { STORE_ZERO; RNUM = -1; }; reglog_read(thread,RNUM);}), + (A_DOTNEWVALUE,A_RESTRICT_SLOT0ONLY) +) + +DEF_MACRO( + fMEMZNEW,(RNUM), + "RNUM.new == 0", + "Newly loaded value is zero", + (RNUM == 0), + /* attribs */ +) + +DEF_MACRO( + fMEMNZNEW,(RNUM), + "RNUM.new != 0", + "Newly loaded value is non-zero", + (RNUM != 0), + /* attribs */ +) + +DEF_MACRO( + fVSATUVALN,(N,VAL), + "N-Bit Unsigned Saturation Value for sign of VAL", + "N-Bit Unsigned Saturation Value for sign of VAL", + ({ ((VAL) < 0) ? 0 : ((1LL<<(N))-1);}), + (A_USATURATE) +) + +DEF_MACRO( + fSATUVALN,(N,VAL), + "N-Bit Unsigned Saturation Value for sign of VAL", + "N-Bit Unsigned Saturation Value for sign of VAL", + ({fSET_OVERFLOW(); ((VAL) < 0) ? 0 : ((1LL<<(N))-1);}), + (A_USATURATE) +) + +DEF_MACRO( + fSATVALN,(N,VAL), + "N-Bit Saturation Value for sign of VAL", + "N-Bit Saturation Value for sign of VAL", + ({fSET_OVERFLOW(); ((VAL) < 0) ? (-(1LL<<((N)-1))) : ((1LL<<((N)-1))-1);}), + (A_SATURATE) +) + +DEF_MACRO( + fVSATVALN,(N,VAL), + "N-Bit Saturation Value for sign of VAL", + "N-Bit Saturation Value for sign of VAL", + ({((VAL) < 0) ? (-(1LL<<((N)-1))) : ((1LL<<((N)-1))-1);}), + (A_SATURATE) +) + +DEF_MACRO( + fZXTN, /* macro name */ + (N,M,VAL), + "zxt_{N->M}(VAL)", /* short descr */ + "Zero extend N bits from VAL", + ((VAL) & ((1LL<<(N))-1)), + /* attribs */ +) + +DEF_MACRO( + fSXTN, /* macro name */ + (N,M,VAL), + "sxt_{N->M}(VAL)", /* short descr */ + "Sign extend N bits from VAL", + ((fZXTN(N,M,VAL) ^ (1LL<<((N)-1))) - (1LL<<((N)-1))), + /* attribs */ +) + +DEF_MACRO( + fSATN, + (N,VAL), + "sat_##N(VAL)", /* short descr */ + "Saturate VAL to N bits", + ((fSXTN(N,64,VAL) == (VAL)) ? (VAL) : fSATVALN(N,VAL)), + (A_SATURATE) +) +DEF_MACRO( + fVSATN, + (N,VAL), + "sat_##N(VAL)", /* short descr */ + "Saturate VAL to N bits", + ((fSXTN(N,64,VAL) == (VAL)) ? (VAL) : fVSATVALN(N,VAL)), + (A_SATURATE) +) + +DEF_MACRO( + fADDSAT64, + (DST,A,B), + "DST=sat64(A+B)", /* short descr */ + "DST=sat64(A+B)", + { + size8u_t __a = fCAST8u(A); + size8u_t __b = fCAST8u(B); + size8u_t __sum = __a + __b; + size8u_t __xor = __a ^ __b; + const size8u_t __mask = 0x8000000000000000ULL; + if (__xor & __mask) { + /* Opposite signs, OK */ + DST = __sum; + } else if ((__a ^ __sum) & __mask) { + /* Signs mismatch */ + if (__sum & __mask) { + /* overflowed to negative, make max pos */ + DST=0x7FFFFFFFFFFFFFFFLL; fSET_OVERFLOW(); + } else { + /* overflowed to positive, make max neg */ + DST=0x8000000000000000LL; fSET_OVERFLOW(); + } + } else { + /* signs did not mismatch, OK */ + DST = __sum; + } + }, + (A_SATURATE) +) + +DEF_MACRO( + fVSATUN, + (N,VAL), + "usat_##N(VAL)", /* short descr */ + "Saturate VAL to N bits", + ((fZXTN(N,64,VAL) == (VAL)) ? (VAL) : fVSATUVALN(N,VAL)), + (A_USATURATE) +) + +DEF_MACRO( + fSATUN, + (N,VAL), + "usat_##N(VAL)", /* short descr */ + "Saturate VAL to N bits", + ((fZXTN(N,64,VAL) == (VAL)) ? (VAL) : fSATUVALN(N,VAL)), + (A_USATURATE) +) + +DEF_MACRO( + fSATH, + (VAL), + "sat_16(VAL)", /* short descr */ + "Saturate VAL to a signed half", + (fSATN(16,VAL)), + (A_SATURATE) +) + + +DEF_MACRO( + fSATUH, + (VAL), + "usat_16(VAL)", /* short descr */ + "Saturate VAL to an unsigned half", + (fSATUN(16,VAL)), + (A_USATURATE) +) + +DEF_MACRO( + fVSATH, + (VAL), + "sat_16(VAL)", /* short descr */ + "Saturate VAL to a signed half", + (fVSATN(16,VAL)), + (A_SATURATE) +) + +DEF_MACRO( + fVSATUH, + (VAL), + "usat_16(VAL)", /* short descr */ + "Saturate VAL to a signed half", + (fVSATUN(16,VAL)), + (A_USATURATE) +) + + +DEF_MACRO( + fSATUB, + (VAL), + "usat_8(VAL)", /* short descr */ + "Saturate VAL to an unsigned byte", + (fSATUN(8,VAL)), + (A_USATURATE) +) +DEF_MACRO( + fSATB, + (VAL), + "sat_8(VAL)", /* short descr */ + "Saturate VAL to a signed byte", + (fSATN(8,VAL)), + (A_SATURATE) +) + + +DEF_MACRO( + fVSATUB, + (VAL), + "usat_8(VAL)", /* short descr */ + "Saturate VAL to a unsigned byte", + (fVSATUN(8,VAL)), + (A_USATURATE) +) +DEF_MACRO( + fVSATB, + (VAL), + "sat_8(VAL)", /* short descr */ + "Saturate VAL to a signed byte", + (fVSATN(8,VAL)), + (A_SATURATE) +) + + + + +/*************************************/ +/* immediate extension */ +/*************************************/ + +DEF_MACRO( + fIMMEXT, + (IMM), + "apply_extension(IMM)", + "Apply extension to IMM", + (IMM = IMM /* (insn->extension_valid?(fGET_EXTENSION | fZXTN(6,32,(IMM))):(IMM)) */ ), + (A_EXTENDABLE) +) + +DEF_MACRO( + fMUST_IMMEXT, + (IMM), + "apply_extension(IMM)", + "Apply extension to IMM", + fIMMEXT(IMM), + (A_EXTENDABLE,A_MUST_EXTEND) +) + +DEF_MACRO( + fPCALIGN, + (IMM), + "IMM=IMM & ~PCALIGN_MASK", + "", + IMM=(IMM & ~PCALIGN_MASK), + (A_EXTENDABLE) +) + +DEF_MACRO( + fGET_EXTENSION, + , + "extension", + "extension", + insn->extension, + /* attrs */ +) + +/*************************************/ +/* Read and Write Implicit Regs */ +/*************************************/ + +DEF_MACRO( + fREAD_IREG, /* read link register */ + (VAL), /* parameters */ + "I", /* short description */ + "I", /* long description */ + (fSXTN(11,64,(((VAL) & 0xf0000000)>>21) | ((VAL>>17)&0x7f) )), /* behavior */ + () +) + + +DEF_MACRO( + fREAD_R0, /* read r0 */ + (), /* parameters */ + "R0", /* short description */ + "R0", /* long description */ + (READ_RREG(0)), /* behavior */ + (A_IMPLICIT_READS_R00) +) + +DEF_MACRO( + fREAD_LR, /* read link register */ + (), /* parameters */ + "LR", /* short description */ + "LR", /* long description */ + (READ_RREG(REG_LR)), /* behavior */ + (A_IMPLICIT_READS_LR) +) + +DEF_MACRO( + fREAD_SSR, /* read link register */ + (), /* parameters */ + "SSR", /* short description */ + "SSR", /* long description */ + (READ_RREG(REG_SSR)), /* behavior */ + () +) + +DEF_MACRO( + fWRITE_R0, /* write r0 */ + (A), /* parameters */ + "R0=A", /* short description */ + "R0=A", /* long description */ + WRITE_RREG(0,A), /* behavior */ + (A_IMPLICIT_WRITES_R00) +) + +DEF_MACRO( + fWRITE_LR, /* write lr */ + (A), /* parameters */ + "LR=A", /* short description */ + "LR=A", /* long description */ + WRITE_RREG(REG_LR,A), /* behavior */ + (A_IMPLICIT_WRITES_LR) +) + +DEF_MACRO( + fWRITE_FP, /* write sp */ + (A), /* parameters */ + "FP=A", /* short description */ + "FP=A", /* long description */ + WRITE_RREG(REG_FP,A), /* behavior */ + (A_IMPLICIT_WRITES_FP) +) + +DEF_MACRO( + fWRITE_SP, /* write sp */ + (A), /* parameters */ + "SP=A", /* short description */ + "SP=A", /* long description */ + WRITE_RREG(REG_SP,A), /* behavior */ + (A_IMPLICIT_WRITES_SP) +) + +DEF_MACRO( + fWRITE_GOSP, /* write gosp */ + (A), /* parameters */ + "GOSP=A", /* short description */ + "GOSP=A", /* long description */ + WRITE_RREG(REG_GOSP,A), /* behavior */ + (A_IMPLICIT_WRITES_GOSP) +) + +DEF_MACRO( + fWRITE_GP, /* write gp */ + (A), /* parameters */ + "GP=A", /* short description */ + "GP=A", /* long description */ + WRITE_RREG(REG_GP,A), /* behavior */ + (A_IMPLICIT_WRITES_GP) +) + +DEF_MACRO( + fREAD_SP, /* read stack pointer */ + (), /* parameters */ + "SP", /* short description */ + "SP", /* long description */ + (READ_RREG(REG_SP)), /* behavior */ + (A_IMPLICIT_READS_SP) +) + +DEF_MACRO( + fREAD_GOSP, /* read guest other stack pointer */ + (), /* parameters */ + "GOSP", /* short description */ + "GOSP", /* long description */ + (READ_RREG(REG_GOSP)), /* behavior */ + (A_IMPLICIT_READS_GOSP) +) + +DEF_MACRO( + fREAD_GELR, /* read guest other stack pointer */ + (), /* parameters */ + "GELR", /* short description */ + "GELR", /* long description */ + (READ_RREG(REG_GELR)), /* behavior */ + (A_IMPLICIT_READS_GELR) +) + +DEF_MACRO( + fREAD_GEVB, /* read guest other stack pointer */ + (), /* parameters */ + "GEVB", /* short description */ + "GEVB", /* long description */ + (READ_RREG(REG_GEVB)), /* behavior */ + (A_IMPLICIT_READS_GEVB) +) + +DEF_MACRO( + fREAD_CSREG, /* read stack pointer */ + (N), /* parameters */ + "CS N", /* short description */ + "CS N", /* long description */ + (READ_RREG(REG_CSA+N)), /* behavior */ + (A_IMPLICIT_READS_CS) +) + +DEF_MACRO( + fREAD_LC0, /* read loop count */ + , /* parameters */ + "LC0", /* short description */ + "LC0", /* long description */ + (READ_RREG(REG_LC0)), /* behavior */ + (A_IMPLICIT_READS_LC0) +) + +DEF_MACRO( + fREAD_LC1, /* read loop count */ + , /* parameters */ + "LC1", /* short description */ + "LC1", /* long description */ + (READ_RREG(REG_LC1)), /* behavior */ + (A_IMPLICIT_READS_LC1) +) + +DEF_MACRO( + fREAD_SA0, /* read start addr */ + , /* parameters */ + "SA0", /* short description */ + "SA0", /* long description */ + (READ_RREG(REG_SA0)), /* behavior */ + (A_IMPLICIT_READS_SA0) +) + +DEF_MACRO( + fREAD_SA1, /* read start addr */ + , /* parameters */ + "SA1", /* short description */ + "SA1", /* long description */ + (READ_RREG(REG_SA1)), /* behavior */ + (A_IMPLICIT_READS_SA1) +) + + +DEF_MACRO( + fREAD_FP, /* read stack pointer */ + (), /* parameters */ + "FP", /* short description */ + "FP", /* long description */ + (READ_RREG(REG_FP)), /* behavior */ + (A_IMPLICIT_READS_FP) +) + +DEF_MACRO( + fREAD_GP, /* read global pointer */ + (), /* parameters */ + "(Constant_extended ? (0) : GP)", /* short description */ + "(Constant_extended ? (0) : GP)", /* long description */ + (insn->extension_valid ? 0 : READ_RREG(REG_GP)), /* behavior */ + (A_IMPLICIT_READS_GP) +) + +DEF_MACRO( + fREAD_PC, /* read PC */ + (), /* parameters */ + "PC", /* short description */ + "PC", /* long description */ + (READ_RREG(REG_PC)), /* behavior */ + (A_IMPLICIT_READS_PC) +) + +DEF_MACRO( + fREAD_NPC, /* read PC */ + (), /* parameters */ + "NPC", /* short description */ + "NPC", /* long description */ + (thread->next_PC & (0xfffffffe)), /* behavior */ + () +) + +DEF_MACRO( + fREAD_P0, /* read Predicate 0 */ + (), /* parameters */ + "P0", /* short description */ + "P0", /* long description */ + (READ_PREG(0)), /* behavior */ + (A_IMPLICIT_READS_P0) +) + +DEF_MACRO( + fREAD_P3, /* read Predicate 0 */ + (), /* parameters */ + "P3", /* short description */ + "P3", /* long description */ + (READ_PREG(3)), /* behavior */ + (A_IMPLICIT_READS_P3) +) + +DEF_MACRO( + fNOATTRIB_READ_P3, /* read Predicate 0 */ + (), /* parameters */ + "P3", /* short description */ + "P3", /* long description */ + (READ_PREG(3)), /* behavior */ + () +) + +DEF_MACRO( + fINVALID,(), + "Invalid instruction!", + "Invalid instruction!", + (register_error_exception(thread,PRECISE_CAUSE_INVALID_PACKET,thread->Regs[REG_BADVA0],thread->Regs[REG_BADVA1],GET_SSR_FIELD(SSR_BVS),GET_SSR_FIELD(SSR_V0),GET_SSR_FIELD(SSR_V1),0)), + () +) + +DEF_MACRO( + fCHECK_PCALIGN, (A), + "", + "", + /* EJP: if exception already detected, do not trigger pc unaligned exception since we will be rewinding PC anyway. */ + /* Maybe this will screw up prioritization logic... but probably it is ok? Otherwise we can ditch out of dealloc_return early if EXCEPTION_DETECTED */ + if (((A) & PCALIGN_MASK)) { + register_error_exception(thread,PRECISE_CAUSE_PC_NOT_ALIGNED,thread->Regs[REG_BADVA0],thread->Regs[REG_BADVA1],GET_SSR_FIELD(SSR_BVS),GET_SSR_FIELD(SSR_V0),GET_SSR_FIELD(SSR_V1),0); + }, + () +) + +DEF_MACRO( + fCUREXT,(), + "", + "", + GET_SSR_FIELD(SSR_XA), + () +) + +DEF_MACRO( + fCUREXT_WRAP,(EXT_NO), + "", + "", + { + EXT_NO = fCUREXT(); + if (thread->processor_ptr->arch_proc_options->ext_contexts) + EXT_NO &= (thread->processor_ptr->arch_proc_options->ext_contexts-1); + else + EXT_NO = 0; + EXT_NO = thread->processor_ptr->features->QDSP6_CP_PRESENT ? (EXT_NO & 0x3) : (EXT_NO+4); + }, + () +) + +DEF_MACRO( + fWRITE_NPC, /* write next PC */ + (A), /* parameters */ + "PC=A", /* short description */ + "PC=A", /* long description */ + if (!thread->branch_taken) { + if (A != thread->next_PC) { + thread->next_pkt_guess=thread->last_pkt->taken_ptr; + } + fCHECK_PCALIGN(A); + thread->branched = 1; thread->branch_taken = 1; thread->next_PC = A; \ + thread->branch_offset = insn->encoding_offset; thread->branch_opcode = insn->opcode; + } + , /* behavior */ + (A_IMPLICIT_WRITES_PC,A_COF) +) + + +DEF_MACRO( + fLOOPSTATS, + (A), + "", + "", + /* INC_TSTAT(tloopends); + INC_TSTATN(tloopend_same_line,(thread->Regs[REG_PC] & -32) == ((A) & -32)); + INC_TSTATN(tloopend_samepc,(thread->Regs[REG_PC]) == (A));*/ , + () +) + + +DEF_MACRO( + fCOF_CALLBACK, + (LOC,TYPE), + "", + "", + { + thread->cof_log_to_va = (LOC); + thread->cof_log_coftype = (TYPE); + thread->cof_log_valid = 1; + }, + () +) + +DEF_MACRO( + fBRANCH, + (LOC,TYPE), + "PC=LOC", + "PC=LOC", + fWRITE_NPC(LOC); fCOF_CALLBACK(LOC,TYPE), + () +) + +DEF_MACRO( + fTIME_JUMPR, + (REGNO,TARGET,TYPE), + "", + "", + { sys_branch_return(thread, insn->slot, TARGET, REGNO); }, + (A_INDIRECT) +) + + +DEF_MACRO( + fJUMPR, /* A jumpr has executed */ + (REGNO,TARGET,TYPE), + "PC=TARGET", + "PC=TARGET", + { fTIME_JUMPR(REGNO,TARGET,TYPE); fBRANCH(TARGET,COF_TYPE_JUMPR);}, + (A_INDIRECT) +) + +DEF_MACRO( + fHINTJR, /* A hintjr instruction has executed */ + (TARGET), + "", + "", + { }, +) + +DEF_MACRO( + fBP_RAS_CALL, + (A), + "", + "", + { sys_branch_call(thread, insn->slot, A, fREAD_NPC()); }, +) + +DEF_MACRO( + fCALL, /* Do a call */ + (A), + "fWRITE_LR(fREAD_NPC()); fWRITE_NPC(A);", + "fWRITE_LR(fREAD_NPC()); fWRITE_NPC(A);", + if (!thread->branch_taken) {fBP_RAS_CALL(A); fWRITE_LR(fREAD_NPC()); fBRANCH(A,COF_TYPE_CALL);}, + (A_IMPLICIT_WRITES_PC,A_COF,A_IMPLICIT_WRITES_LR,A_CALL) +) + +DEF_MACRO( + fCALLR, /* Do a call Register */ + (A), + "fWRITE_LR(fREAD_NPC()); fWRITE_NPC(A);", + "fWRITE_LR(fREAD_NPC()); fWRITE_NPC(A);", + if (!thread->branch_taken) {fBP_RAS_CALL(A); fWRITE_LR(fREAD_NPC()); fBRANCH(A,COF_TYPE_CALLR);}, + (A_IMPLICIT_WRITES_PC,A_COF,A_IMPLICIT_WRITES_LR,A_CALL) +) + +DEF_MACRO( + fWRITE_LOOP_REGS0, /* write ln,sa,ea,lc */ + (START,COUNT), /* parameters */ + "SA0=START; LC0=COUNT", /* short description */ + "SA0=START; LC0=COUNT", /* short description */ + {WRITE_RREG(REG_LC0,COUNT); + WRITE_RREG(REG_SA0,START);}, + (A_IMPLICIT_WRITES_LC0,A_IMPLICIT_WRITES_SA0) +) + +DEF_MACRO( + fWRITE_LOOP_REGS1, /* write ln,sa,ea,lc */ + (START,COUNT), /* parameters */ + "SA1=START; LC1=COUNT", /* short description */ + "SA1=START; LC1=COUNT", /* short description */ + {WRITE_RREG(REG_LC1,COUNT); + WRITE_RREG(REG_SA1,START);}, + (A_IMPLICIT_WRITES_LC1,A_IMPLICIT_WRITES_SA1) +) + +DEF_MACRO( + fWRITE_LC0, + (VAL), /* parameters */ + "LC0=VAL", /* short description */ + "LC0=VAL", + WRITE_RREG(REG_LC0,VAL), + (A_IMPLICIT_WRITES_LC0) +) + +DEF_MACRO( + fWRITE_LC1, + (VAL), /* parameters */ + "LC1=VAL", /* short description */ + "LC1=VAL", + WRITE_RREG(REG_LC1,VAL), + (A_IMPLICIT_WRITES_LC1) +) + +DEF_MACRO( + fCARRY_FROM_ADD, + (A,B,C), + "carry_from_add(A,B,C)", + "carry_from_add(A,B,C)", + carry_from_add64(A,B,C), + /* NOTHING */ +) + +DEF_MACRO( + fSETCV_ADD, + (A,B,CARRY), + "SR[CV]=FLAGS(A+B)", + "SR[CV]=FLAGS(A+B)", + do { + SET_USR_FIELD(USR_C,gen_carry_add((A),(B),((A)+(B)))); + SET_USR_FIELD(USR_V,gen_overflow_add((A),(B),((A)+(B)))); + } while (0), + (A_IMPLICIT_WRITES_CVBITS,A_NOTE_CVFLAGS,A_RESTRICT_NOSRMOVE) +) +DEF_MACRO( + fSETCV_SUB, + (A,B,CARRY), + "SR[CV]=FLAGS(A-B)", + "SR[CV]=FLAGS(A-B)", + do { + SET_USR_FIELD(USR_C,gen_carry_add((A),(B),((A)-(B)))); + SET_USR_FIELD(USR_V,gen_overflow_add((A),(B),((A)-(B)))); + } while (0), + (A_IMPLICIT_WRITES_CVBITS,A_NOTE_CVFLAGS,A_RESTRICT_NOSRMOVE) +) + +DEF_MACRO( + fSET_OVERFLOW, + (), + "USR.OVF=1", + "USR.OVF=1", + SET_USR_FIELD(USR_OVF,1), + (A_IMPLICIT_WRITES_SRBIT,A_NOTE_SR_OVF_WHEN_SATURATING,A_RESTRICT_NOSRMOVE) +) + +DEF_MACRO( + fSET_LPCFG, + (VAL), /* parameters */ + "USR.LPCFG=VAL", + "USR.LPCFG=VAL", + SET_USR_FIELD(USR_LPCFG,(VAL)), + (A_IMPLICIT_WRITES_LPCFG,A_RESTRICT_NOSRMOVE) +) + + +DEF_MACRO( + fGET_LPCFG, + , /* parameters */ + "USR.LPCFG", + "USR.LPCFG", + (GET_USR_FIELD(USR_LPCFG)), + () +) + + + +DEF_MACRO( + fWRITE_P0, /* write Predicate 0 */ + (VAL), /* parameters */ + "P0=VAL", /* short description */ + "P0=VAL", /* long description */ + WRITE_PREG(0,VAL), /* behavior */ + (A_IMPLICIT_WRITES_P0) +) + +DEF_MACRO( + fWRITE_P1, /* write Predicate 0 */ + (VAL), /* parameters */ + "P1=VAL", /* short description */ + "P1=VAL", /* long description */ + WRITE_PREG(1,VAL), /* behavior */ + (A_IMPLICIT_WRITES_P1) +) + +DEF_MACRO( + fWRITE_P2, /* write Predicate 0 */ + (VAL), /* parameters */ + "P2=VAL", /* short description */ + "P2=VAL", /* long description */ + WRITE_PREG(2,VAL), /* behavior */ + (A_IMPLICIT_WRITES_P2) +) + +DEF_MACRO( + fWRITE_P3, /* write Predicate 0 */ + (VAL), /* parameters */ + "P3=VAL", /* short description */ + "P3=VAL", /* long description */ + WRITE_PREG(3,VAL), /* behavior */ + (A_IMPLICIT_WRITES_P3) +) + +DEF_MACRO( + fWRITE_P3_LATE, /* write Predicate 0 */ + (VAL), /* parameters */ + "P3=VAL", /* short description */ + "P3=VAL", /* long description */ + {WRITE_PREG(3,VAL); fHIDE(MARK_LATE_PRED_WRITE(3))} , /* behavior */ + (A_IMPLICIT_WRITES_P3,A_RESTRICT_LATEPRED) +) + + +DEF_MACRO( + fPART1, /* write Predicate 0 */ + (WORK), /* parameters */ + "WORK", /* short description */ + "WORK", /* long description */ + if (insn->part1) { WORK; return; }, /* behavior */ + /* optional attributes */ +) + + +/*************************************/ +/* Casting, Sign-Zero extension, etc */ +/*************************************/ + +DEF_MACRO( + fCAST4u, /* macro name */ + (A), /* parameters */ + "A.uw[0]", /* short description */ + "unsigned 32-bit A", /* long description */ + ((size4u_t)(A)), /* behavior */ + /* optional attributes */ +) + +DEF_MACRO( + fCAST4s, /* macro name */ + (A), /* parameters */ + "A.s32", /* short description */ + "signed 32-bit A", /* long description */ + ((size4s_t)(A)), /* behavior */ + /* optional attributes */ +) + +DEF_MACRO( + fCAST8u, /* macro name */ + (A), /* parameters */ + "A.u64", /* short description */ + "unsigned 64-bit A", /* long description */ + ((size8u_t)(A)), /* behavior */ + /* optional attributes */ +) + +DEF_MACRO( + fCAST8s, /* macro name */ + (A), /* parameters */ + "A.s64", /* short description */ + "signed 64-bit A", /* long description */ + ((size8s_t)(A)), /* behavior */ + /* optional attributes */ +) + +DEF_MACRO( + fCAST2_2s, /* macro name */ + (A), /* params */ + "A", + "signed 16-bit A", + ((size2s_t)(A)), + /* optional attributes */ +) + +DEF_MACRO( + fCAST2_2u, /* macro name */ + (A), /* params */ + "A", + "unsigned 16-bit A", + ((size2u_t)(A)), + /* optional attributes */ +) + +DEF_MACRO( + fCAST4_4s, /* macro name */ + (A), /* params */ + "A", + "signed 32-bit A", + ((size4s_t)(A)), + /* optional attributes */ +) + +DEF_MACRO( + fCAST4_4u, /* macro name */ + (A), /* params */ + "A", + "unsigned 32-bit A", + ((size4u_t)(A)), + /* optional attributes */ +) + + +DEF_MACRO( + fCAST4_8s, /* macro name */ + (A), /* params */ + "fSXTN(32,64,A)", + "32-bit A sign-extended to signed 64-bit", + ((size8s_t)((size4s_t)(A))), + /* optional attributes */ +) + +DEF_MACRO( + fCAST4_8u, /* macro name */ + (A), /* params */ + "fZXTN(32,64,A)", + "32-bit A zero-extended to unsigned 64-bit", + ((size8u_t)((size4u_t)(A))), + /* optional attributes */ +) + +DEF_MACRO( + fCAST8_8s, /* macro name */ + (A), /* params */ + "A", + "signed 64-bit A", + ((size8s_t)(A)), + /* optional attributes */ +) + +DEF_MACRO( + fCAST8_8u, /* macro name */ + (A), /* params */ + "A", + "unsigned 64-bit A", + ((size8u_t)(A)), + /* optional attributes */ +) + +DEF_MACRO( + fCAST2_8s, /* macro name */ + (A), /* params */ + "fSXTN(16,64,A)", + "16-bit A sign-extended to signed 64-bit", + ((size8s_t)((size2s_t)(A))), + /* optional attributes */ +) + +DEF_MACRO( + fCAST2_8u, /* macro name */ + (A), /* params */ + "fZXTN(16,64,A)", + "16-bit A zero-extended to unsigned 64-bit", + ((size8u_t)((size2u_t)(A))), + /* optional attributes */ +) + +DEF_MACRO( + fZE8_16, /* zero-extend 8 to 16 */ + (A), + "A", + "Unsigned low 8 bits of A", + ((size2s_t)((size1u_t)(A))), + /* optional attributes */ +) +DEF_MACRO( + fSE8_16, /* sign-extend 8 to 16 */ + (A), + "A", + "Signed low 8 bits of A", + ((size2s_t)((size1s_t)(A))), + /* optional attributes */ +) + + +DEF_MACRO( + fSE16_32, /* sign-extend 16 to 32 */ + (A), /* parameters */ + "A", /* short description */ + "signed low 16-bits of A", /* long description */ + ((size4s_t)((size2s_t)(A))), /* behavior */ + /* optional attributes */ +) + +DEF_MACRO( + fZE16_32, /* zero-extend 16 to 32 */ + (A), /* parameters */ + "A", /* short description */ + "signed low 16-bits of A", /* long description */ + ((size4u_t)((size2u_t)(A))), /* behavior */ + /* optional attributes */ +) + +DEF_MACRO( + fSE32_64, + (A), /* parameters */ + "A", /* short description */ + "A", /* long description */ + ( (size8s_t)((size4s_t)(A)) ), /* behavior */ + /* optional attributes */ +) + +DEF_MACRO( + fZE32_64, + (A), /* parameters */ + "A", /* short description */ + "zero-extend A from 32 to 64", /* long description */ + ( (size8u_t)((size4u_t)(A)) ), /* behavior */ + /* optional attributes */ +) + +DEF_MACRO( + fSE8_32, /* sign-extend 8 to 32 */ + (A), + "A", + "Signed low 8 bits of A", + ((size4s_t)((size1s_t)(A))), + /* optional attributes */ +) + +DEF_MACRO( + fZE8_32, /* zero-extend 8 to 32 */ + (A), + "A", + "Unsigned low 8 bits of A", + ((size4s_t)((size1u_t)(A))), + /* optional attributes */ +) + +/*************************************/ +/* DSP arithmetic support */ +/************************************/ +DEF_MACRO( + fMPY8UU, /* multiply half integer */ + (A,B), /* parameters */ + "(A * B)", /* short description */ + "unsigned 8-bit multiply of A by B", /* long description */ + (int)(fZE8_16(A)*fZE8_16(B)), /* behavior */ + (A_MPY) +) +DEF_MACRO( + fMPY8US, /* multiply half integer */ + (A,B), /* parameters */ + "(A * B)", /* short description */ + "unsigned 8-bit multiply of A by signed B", /* long description */ + (int)(fZE8_16(A)*fSE8_16(B)), /* behavior */ + (A_MPY) +) +DEF_MACRO( + fMPY8SU, /* multiply half integer */ + (A,B), /* parameters */ + "(A * B)", /* short description */ + "signed 8-bit multiply of A by unsigned B", /* long description */ + (int)(fSE8_16(A)*fZE8_16(B)), /* behavior */ + (A_MPY) +) + +DEF_MACRO( + fMPY8SS, /* multiply half integer */ + (A,B), /* parameters */ + "(A * B)", /* short description */ + "signed 8-bit multiply of A by B", /* long description */ + (int)((short)(A)*(short)(B)), /* behavior */ + (A_MPY) +) + +DEF_MACRO( + fMPY16SS, /* multiply half integer */ + (A,B), /* parameters */ + "(A * B)", /* short description */ + "signed 16-bit multiply of A by B", /* long description */ + fSE32_64(fSE16_32(A)*fSE16_32(B)), /* behavior */ + (A_MPY) +) + +DEF_MACRO( + fMPY16UU, /* multiply unsigned half integer */ + (A,B), /* parameters */ + "(A * B)", /* short description */ + "multiply unsigned A by unsigned B", /* long description */ + fZE32_64(fZE16_32(A)*fZE16_32(B)), /* behavior */ + (A_MPY) +) + +DEF_MACRO( + fMPY16SU, /* multiply half integer */ + (A,B), /* parameters */ + "(A * B)", /* short description */ + "signed 16-bit A times unsigned 16-bit B", /* long description */ + fSE32_64(fSE16_32(A)*fZE16_32(B)), /* behavior */ + (A_MPY) +) + +DEF_MACRO( + fMPY16US, /* multiply half integer */ + (A,B), /* parameters */ + "(A * B)", /* short description */ + "unsigned 16-bit A times signed 16-bit B", /* long description */ + fMPY16SU(B,A), + (A_MPY) +) + +DEF_MACRO( + fMPY32SS, /* multiply half integer */ + (A,B), /* parameters */ + "(A * B)", /* short description */ + "signed 32-bit multiply of A by B", /* long description */ + (fSE32_64(A)*fSE32_64(B)), /* behavior */ + (A_MPY) +) + +DEF_MACRO( + fMPY32UU, /* multiply half integer */ + (A,B), /* parameters */ + "(A * B)", /* short description */ + "unsigned 32-bit multiply of A by B", /* long description */ + (fZE32_64(A)*fZE32_64(B)), /* behavior */ + (A_MPY) +) + +DEF_MACRO( + fMPY32SU, /* multiply half integer */ + (A,B), /* parameters */ + "(A * B)", /* short description */ + "32-bit multiply of signed A by unsigned B", /* long description */ + (fSE32_64(A)*fZE32_64(B)), /* behavior */ + (A_MPY) +) + +DEF_MACRO( + fMPY3216SS, /* multiply mixed precision */ + (A,B), /* parameters */ + "(A * B)", /* short description */ + "signed 16-bit multiply of A by B", /* long description */ + (fSE32_64(A)*fSXTN(16,64,B)), /* behavior */ + (A_MPY) +) + +DEF_MACRO( + fMPY3216SU, /* multiply mixed precision */ + (A,B), /* parameters */ + "(A * B)", /* short description */ + "signed 16-bit multiply of A by unsigned B", /* long description */ + (fSE32_64(A)*fZXTN(16,64,B)), /* behavior */ + (A_MPY) +) + +DEF_MACRO( + fROUND, /* optional rounding */ + (A), /* parameters */ + "round(A)", /* short description */ + "round(A)", /* long description */ + (A+0x8000), + /* optional attributes */ +) + +DEF_MACRO( + fCLIP, /* optional rounding */ + (DST,SRC,U), /* parameters */ + "DST=MIN((1<<U)-1,MAX(SRC,-(1<<U)))", /* short description */ + "DST=IN((1<<U)-1,MAX(SRC,-(1<<U)))", /* long description */ + { size4s_t maxv = (1<<U)-1; + size4s_t minv = -(1<<U); + DST = fMIN(maxv,fMAX(SRC,minv)); + }, + /* optional attributes */ +) + +DEF_MACRO( + fCRND, /* optional rounding */ + (A), /* parameters */ + "convround(A)", /* short description */ + "convround(A)", /* long description */ + ((((A)&0x3)==0x3)?((A)+1):((A))), + /* optional attributes */ +) + +DEF_MACRO( + fRNDN, /* Rounding to a boundary */ + (A,N), /* parameters */ + "(N==0)?(A):round(A,2**(N-1))", /* short description */ + "(N==0)?(A):round(A,2**(N-1))", /* long description */ + ((((N)==0)?(A):(((fSE32_64(A))+(1<<((N)-1)))))), + /* optional attributes */ +) + +DEF_MACRO( + fCRNDN, /* Rounding to a boundary */ + (A,N), /* parameters */ + "(N==0)?A:convround(A,2**(N-1))>>N", /* short description */ + "(N==0)?A:convround(A,2**(N-1))>>N", /* long description */ + (conv_round(A,N)), + /* optional attributes */ +) + +DEF_MACRO( + fCRNDN64, /* Rounding to a boundary */ + (A,N), /* parameters */ + "(N==0)?A:convround(A,2**(N-1))>>N", /* short description */ + "(N==0)?A:convround(A,2**(N-1))>>N", /* long description */ + (conv_round64(A,N)), + /* optional attributes */ +) +DEF_MACRO( + fADD128, /* Rounding to a boundary */ + (A,B), /* parameters */ + "A+B", /* short description */ + "", /* long description */ + (add128(A, B)), + /* optional attributes */ +) +DEF_MACRO( + fSUB128, /* Rounding to a boundary */ + (A,B), /* parameters */ + "A-B", /* short description */ + "", /* long description */ + (sub128(A, B)), + /* optional attributes */ +) +DEF_MACRO( + fSHIFTR128, /* Rounding to a boundary */ + (A,B), /* parameters */ + "(size8s_t) (A >> B)", /* short description */ + "", /* long description */ + (shiftr128(A, B)), + /* optional attributes */ +) + +DEF_MACRO( + fSHIFTL128, /* Rounding to a boundary */ + (A,B), /* parameters */ + "(A << B)", /* short description */ + "", /* long description */ + (shiftl128(A, B)), + /* optional attributes */ +) + +DEF_MACRO( + fAND128, /* Rounding to a boundary */ + (A,B), /* parameters */ + "(A & B)", /* short description */ + "", /* long description */ + (and128(A, B)), + /* optional attributes */ +) + +DEF_MACRO( + fCAST8S_16S, /* Rounding to a boundary */ + (A), /* parameters */ + "sxt_{64->128}(A)", /* short description */ + "", /* long description */ + (cast8s_to_16s(A)), + /* optional attributes */ +) +DEF_MACRO( + fCAST16S_8S, /* Rounding to a boundary */ + (A), /* parameters */ + "sxt_{128->64}(A)", /* short description */ + "", /* long description */ + (cast16s_to_8s(A)), + /* optional attributes */ +) +DEF_MACRO( + fCAST16S_4S, /* Rounding to a boundary */ + (A), /* parameters */ + "sxt_{128->32}(A)", /* short description */ + "", /* long description */ + (cast16s_to_4s(A)), + /* optional attributes */ +) + + + +DEF_MACRO( + fEA_RI, /* Calculate EA with Register + Immediate Offset */ + (REG,IMM), + "EA=REG+IMM", /* short descr */ + "EA=REG+IMM", /* long descr */ + do { EA=REG+IMM; fDOCHKPAGECROSS(REG,EA); } while (0), + (A_EA_REG_PLUS_IMM) +) + +DEF_MACRO( + fEA_RRs, /* Calculate EA with Register + Registers scaled Offset */ + (REG,REG2,SCALE), + "EA=REG+(REG2<<SCALE)", /* short descr */ + "EA=REG+(REG2<<SCALE)", /* long descr */ + do { EA=REG+(REG2<<SCALE); fDOCHKPAGECROSS(REG,EA); } while (0), + (A_EA_REG_PLUS_REGSCALED) +) + +DEF_MACRO( + fEA_IRs, /* Calculate EA with Immediate + Registers scaled Offset */ + (IMM,REG,SCALE), + "EA=IMM+(REG<<SCALE)", /* short descr */ + "EA=IMM+(REG<<SCALE)", /* long descr */ + do { EA=IMM+(REG<<SCALE); fDOCHKPAGECROSS(IMM,EA); } while (0), + (A_EA_IMM_PLUS_REGSCALED) +) + +DEF_MACRO( + fEA_IMM, /* Calculate EA with Immediate */ + (IMM), + "EA=IMM", /* short descr */ + "EA=IMM", /* long descr */ + EA=IMM, + (A_EA_IMM_ONLY) +) + +DEF_MACRO( + fEA_REG, /* Calculate EA with REGISTER */ + (REG), + "EA=REG", /* short descr */ + "EA=REG", /* long descr */ + EA=REG, + (A_EA_REG_ONLY) +) + +DEF_MACRO( + fEA_BREVR, /* Calculate EA with bit reversed bottom of REGISTER */ + (REG), + "EA=fbrev(REG)", /* short descr */ + "EA=fbrev(REG)", /* long descr */ + EA=fbrev(REG), + (A_EA_BREV_REG) +) + +DEF_MACRO( + fEA_GPI, /* Calculate EA with Global Poitner + Immediate */ + (IMM), + "EA=fREAD_GP()+IMM", /* short descr */ + "EA=fREAD_GP()+IMM", /* long descr */ + do { EA=fREAD_GP()+IMM; fGP_DOCHKPAGECROSS(fREAD_GP(),EA); } while (0), + (A_EA_GP_IMM) +) + +DEF_MACRO( + fPM_I, /* Post Modify Register by Immediate*/ + (REG,IMM), + "REG=REG+IMM", /* short descr */ + "REG=REG+IMM", /* long descr */ + do { REG = REG + IMM; fTIMING_AIA(EA,REG); } while (0), + (A_PM_I) +) + +DEF_MACRO( + fPM_M, /* Post Modify Register by M register */ + (REG,MVAL), + "REG=REG+MVAL", /* short descr */ + "REG=REG+MVAL", /* long descr */ + do { REG = REG + MVAL; fTIMING_AIA(EA,REG); } while (0), + (A_PM_M) +) + +DEF_MACRO( + fPM_CIRI, /* Post Modify Register using Circular arithmetic by Immediate */ + (REG,IMM,MVAL), + "REG=fcirc_add(REG,IMM,MVAL)", /* short descr */ + "REG=fcirc_add(REG,IMM,MVAL)", /* long descr */ + do { fcirc_add(REG,siV,MuV); fTIMING_AIA(EA,REG); } while (0), + (A_PM_CIRI) +) + +DEF_MACRO( + fPM_CIRR, /* Post Modify Register using Circular arithmetic by register */ + (REG,VAL,MVAL), + "REG=fcirc_add(REG,VAL,MVAL)", /* short descr */ + "REG=fcirc_add(REG,VAL,MVAL)", /* long descr */ + do { fcirc_add(REG,VAL,MuV); fTIMING_AIA(EA,REG); } while (0), + (A_PM_CIRR) +) + + + +DEF_MACRO( + fMODCIRCU, /* modulo power of 2, positive output */ + (N,P), /* parameters */ + "N modulo 2^P", /* short description */ + "N modulo 2^P ", /* long description */ + ((N) & ((1<<(P))-1)), + /* optional attributes */ +) + +DEF_MACRO( + fSCALE, /* scale by N */ + (N,A), /* parameters */ + "A<<N", /* short description */ + "A<<N", /* long description */ + (((size8s_t)(A))<<N), + /* optional attributes */ +) +DEF_MACRO( + fVSATW, /* saturating to 32-bits*/ + (A), /* parameters */ + "sat_32(A)", /* short description */ + "saturate A to 32-bits", /* long description */ + fVSATN(32,((long long)A)), + (A_SATURATE) +) + +DEF_MACRO( + fSATW, /* saturating to 32-bits*/ + (A), /* parameters */ + "sat_32(A)", /* short description */ + "saturate A to 32-bits", /* long description */ + fSATN(32,((long long)A)), + (A_SATURATE) +) + +DEF_MACRO( + fVSAT, /* saturating to 32-bits*/ + (A), /* parameters */ + "sat_32(A)", /* short description */ + "saturate A to 32-bits", /* long description */ + fVSATN(32,(A)), + (A_SATURATE) +) + +DEF_MACRO( + fSAT, /* saturating to 32-bits*/ + (A), /* parameters */ + "sat_32(A)", /* short description */ + "saturate A to 32-bits", /* long description */ + fSATN(32,(A)), + (A_SATURATE) +) + +DEF_MACRO( + fSAT_ORIG_SHL, /* Saturating to 32-bits, with original value, for shift left */ + (A,ORIG_REG), /* parameters */ + "sat_32(A)", /* short description */ + "saturate A to 32-bits for left shift", /* long description */ + ((((size4s_t)((fSAT(A)) ^ ((size4s_t)(ORIG_REG)))) < 0) ? + fSATVALN(32,((size4s_t)(ORIG_REG))) : + ((((ORIG_REG) > 0) && ((A) == 0)) ? + fSATVALN(32,(ORIG_REG)) : + fSAT(A))), + (A_SATURATE) +) + +DEF_MACRO( + fPASS, + (A), + "A", /* short description */ + "", /* long description */ + A, +) + +DEF_MACRO( + fRND, /* saturating to 32-bits*/ + (A), /* parameters */ + "((A)+1)>>1", /* short description */ + "round(A)", /* long description */ + (((A)+1)>>1), +) + + +DEF_MACRO( + fBIDIR_SHIFTL, + (SRC,SHAMT,REGSTYPE), + "bidir_shiftl(SRC,SHAMT)", + "bidir_shiftl(SRC,SHAMT)", + (((SHAMT) < 0) ? ((fCAST##REGSTYPE(SRC) >> ((-(SHAMT))-1)) >>1) : (fCAST##REGSTYPE(SRC) << (SHAMT))), + (A_BIDIRSHIFTL) +) + +DEF_MACRO( + fBIDIR_ASHIFTL, + (SRC,SHAMT,REGSTYPE), + "(SHAMT>0)?(fCAST##REGSTYPE##s(SRC)<<SHAMT):(fCAST##REGSTYPE##s(SRC)>>SHAMT)", + "bidir_asl(fCAST##REGSTYPE##s(SRC),SHAMT)", + fBIDIR_SHIFTL(SRC,SHAMT,REGSTYPE##s), + (A_BIDIRSHIFTL) +) + +DEF_MACRO( + fBIDIR_LSHIFTL, + (SRC,SHAMT,REGSTYPE), + "(SHAMT>0)?(fCAST##REGSTYPE##u(SRC)<<SHAMT):(fCAST##REGSTYPE##u(SRC)>>>SHAMT)", + "bidir_lsl(fCAST##REGSTYPE##u(SRC),SHAMT)", + fBIDIR_SHIFTL(SRC,SHAMT,REGSTYPE##u), + (A_BIDIRSHIFTL) +) + +DEF_MACRO( + fBIDIR_ASHIFTL_SAT, + (SRC,SHAMT,REGSTYPE), + "bidir_shiftl(SRC,SHAMT)", + "bidir_shiftl(SRC,SHAMT)", + (((SHAMT) < 0) ? ((fCAST##REGSTYPE##s(SRC) >> ((-(SHAMT))-1)) >>1) : fSAT_ORIG_SHL(fCAST##REGSTYPE##s(SRC) << (SHAMT),(SRC))), + (A_BIDIRSHIFTL) +) + + +DEF_MACRO( + fBIDIR_SHIFTR, + (SRC,SHAMT,REGSTYPE), + "bidir_shiftr(SRC,SHAMT)", + "bidir_shiftr(SRC,SHAMT)", + (((SHAMT) < 0) ? ((fCAST##REGSTYPE(SRC) << ((-(SHAMT))-1)) << 1) : (fCAST##REGSTYPE(SRC) >> (SHAMT))), + (A_BIDIRSHIFTR) +) + +DEF_MACRO( + fBIDIR_ASHIFTR, + (SRC,SHAMT,REGSTYPE), + "(SHAMT>0)?(fCAST##REGSTYPE##s(SRC)>>SHAMT):(fCAST##REGSTYPE##s(SRC)<<SHAMT)", + "bidir_asr(fCAST##REGSTYPE##s(SRC),SHAMT)", + fBIDIR_SHIFTR(SRC,SHAMT,REGSTYPE##s), + (A_BIDIRSHIFTR) +) + +DEF_MACRO( + fBIDIR_LSHIFTR, + (SRC,SHAMT,REGSTYPE), + "(SHAMT>0)?(fCAST##REGSTYPE##u(SRC)>>>SHAMT):(fCAST##REGSTYPE##u(SRC)<<SHAMT)", + "bidir_lsr(fCAST##REGSTYPE##u(SRC),SHAMT)", + fBIDIR_SHIFTR(SRC,SHAMT,REGSTYPE##u), + (A_BIDIRSHIFTR) +) + +DEF_MACRO( + fBIDIR_ASHIFTR_SAT, + (SRC,SHAMT,REGSTYPE), + "bidir_shiftr(SRC,SHAMT)", + "bidir_shiftr(SRC,SHAMT)", + (((SHAMT) < 0) ? fSAT_ORIG_SHL((fCAST##REGSTYPE##s(SRC) << ((-(SHAMT))-1)) << 1,(SRC)) : (fCAST##REGSTYPE##s(SRC) >> (SHAMT))), + (A_BIDIRSHIFTR) +) + +DEF_MACRO( + fASHIFTR, + (SRC,SHAMT,REGSTYPE), + "SRC >> SHAMT", + "asr(SRC,SHAMT)", + (fCAST##REGSTYPE##s(SRC) >> (SHAMT)), + /* */ +) + +DEF_MACRO( + fLSHIFTR, + (SRC,SHAMT,REGSTYPE), + "SRC >>> SHAMT", + "lsr(SRC,SHAMT)", + (((SHAMT) >= 64)?0:(fCAST##REGSTYPE##u(SRC) >> (SHAMT))), + /* */ +) + +DEF_MACRO( + fROTL, + (SRC,SHAMT,REGSTYPE), + "SRC <<_{R} SHAMT", + "rol(SRC,SHAMT)", + (((SHAMT)==0) ? (SRC) : ((fCAST##REGSTYPE##u(SRC) << (SHAMT)) | \ + ((fCAST##REGSTYPE##u(SRC) >> ((sizeof(SRC)*8)-(SHAMT)))))), + /* */ +) + +DEF_MACRO( + fROTR, + (SRC,SHAMT,REGSTYPE), + "SRC >>_{R} SHAMT", + "ror(SRC,SHAMT)", + (((SHAMT)==0) ? (SRC) : ((fCAST##REGSTYPE##u(SRC) >> (SHAMT)) | \ + ((fCAST##REGSTYPE##u(SRC) << ((sizeof(SRC)*8)-(SHAMT)))))), + /* */ +) + +DEF_MACRO( + fASHIFTL, + (SRC,SHAMT,REGSTYPE), + "fCAST##REGSTYPE##s(SRC) << SHAMT", + "asl(SRC,SHAMT)", + (((SHAMT) >= 64)?0:(fCAST##REGSTYPE##s(SRC) << (SHAMT))), + /* */ +) + +/*************************************/ +/* Floating-Point Support */ +/************************************/ + +DEF_MACRO( + fFLOAT, /* name */ + (A), /* parameters */ + "A", /* short description */ + "A", /* long description */ + ({ union { float f; size4u_t i; } _fipun; _fipun.i = (A); _fipun.f; }), /* behavior */ + (A_FPOP,A_FPSINGLE,A_IMPLICIT_WRITES_FPFLAGS,A_IMPLICIT_READS_FPRND) +) + +DEF_MACRO( + fUNFLOAT, /* multiply half integer */ + (A), /* parameters */ + "A", /* short description */ + "A", /* long description */ + ({ union { float f; size4u_t i; } _fipun; _fipun.f = (A); isnan(_fipun.f) ? 0xFFFFFFFFU : _fipun.i; }), /* behavior */ + (A_FPOP,A_FPSINGLE,A_IMPLICIT_WRITES_FPFLAGS,A_IMPLICIT_READS_FPRND) +) + +DEF_MACRO( + fSFNANVAL,(), + "NaN", + "NaN", + 0xffffffff, + () +) + +DEF_MACRO( + fSFINFVAL,(A), + "sign(A) * Inf", + "sign(A) * Inf", + (((A) & 0x80000000) | 0x7f800000), + () +) + +DEF_MACRO( + fSFONEVAL,(A), + "sign(A) * 1.0", + "sign(A) * 1.0", + (((A) & 0x80000000) | fUNFLOAT(1.0)), + () +) + +DEF_MACRO( + fCHECKSFNAN,(DST,A), + "if (isnan(A)) DST = NaN;", + "if (isnan(A)) DST = NaN;", + do { + if (isnan(fFLOAT(A))) { + if ((fGETBIT(22,A)) == 0) fRAISEFLAGS(FE_INVALID); + DST = fSFNANVAL(); + } + } while (0), + () +) + +DEF_MACRO( + fCHECKSFNAN3,(DST,A,B,C), + "if (isnan(A) || isnan(B) || isnan(C)) DST = NaN;", + "if (isnan(A) || isnan(B) || isnan(C)) DST = NaN;", + do { + fCHECKSFNAN(DST,A); + fCHECKSFNAN(DST,B); + fCHECKSFNAN(DST,C); + } while (0), + () +) + +DEF_MACRO( + fSF_BIAS,(), + "127", + "single precision bias", + 127, + () +) + +DEF_MACRO( + fSF_MANTBITS,(), + "23", + "single mantissa bits", + 23, + () +) + +DEF_MACRO( + fSF_RECIP_LOOKUP,(IDX), + "recip_lut[IDX]", + "Single Precision reciprocal Estimate", + arch_recip_lookup(IDX), + () +) + +DEF_MACRO( + fSF_INVSQRT_LOOKUP,(IDX), + "invsqrt_lut[IDX]", + "Single Precision reciprocal Estimate", + arch_invsqrt_lookup(IDX), + () +) + +DEF_MACRO( + fSF_MUL_POW2,(A,B), + "A * 2**B", + "A * 2**B", + (fUNFLOAT(fFLOAT(A) * fFLOAT((fSF_BIAS() + (B)) << fSF_MANTBITS()))), + () +) + +DEF_MACRO( + fSF_GETEXP,(A), + "exponent(A)", + "exponent(A)", + (((A) >> fSF_MANTBITS()) & 0xff), + () +) + +DEF_MACRO( + fSF_MAXEXP,(), + "254", + "SF maximum exponent", + (254), + () +) + +DEF_MACRO( + fSF_RECIP_COMMON,(N,D,O,A), + "(N,D,O,A)=recip_common(N,D)", + "(N,D,O,A)=recip_common(N,D)", + arch_sf_recip_common(&N,&D,&O,&A), + (A_FPOP,A_IMPLICIT_WRITES_FPFLAGS) +) + +DEF_MACRO( + fSF_INVSQRT_COMMON,(N,O,A), + "(N,O,A)=invsqrt_common(N)", + "(N,O,A)=invsqrt_common(N)", + arch_sf_invsqrt_common(&N,&O,&A), + (A_FPOP,A_IMPLICIT_WRITES_FPFLAGS) +) + +DEF_MACRO( + fFMAFX,(A,B,C,ADJ), + "fmaf(A,B,C) * 2**(ADJ)", + "Fused Multiply Add w/ Scaling: (A*B+C)*2**ADJ", + internal_fmafx(A,B,C,fSXTN(8,64,ADJ)), + (A_MPY) +) + +DEF_MACRO( + fFMAF,(A,B,C), + "fmaf(A,B,C)", + "Fused Multiply Add: (A*B+C)", + internal_fmafx(A,B,C,0), + (A_MPY) +) + +DEF_MACRO( + fSFMPY,(A,B), + "A*B", + "Multiply: A*B", + internal_mpyf(A,B), + (A_MPY) +) + +DEF_MACRO( + fMAKESF,(SIGN,EXP,MANT), + "-1**SIGN * 1.MANT * 2**(EXP-BIAS)", + "-1**SIGN * 1.MANT * 2**(EXP-BIAS)", + ((((SIGN) & 1) << 31) | (((EXP) & 0xff) << fSF_MANTBITS()) | + ((MANT) & ((1<<fSF_MANTBITS())-1))), + () +) + + +DEF_MACRO( + fDOUBLE, /* multiply half integer */ + (A), /* parameters */ + "A", /* short description */ + "A", /* long description */ + ({ union { double f; size8u_t i; } _fipun; _fipun.i = (A); _fipun.f; }), /* behavior */ + (A_FPOP,A_FPDOUBLE,A_IMPLICIT_WRITES_FPFLAGS,A_IMPLICIT_READS_FPRND) +) + +DEF_MACRO( + fUNDOUBLE, /* multiply half integer */ + (A), /* parameters */ + "A", /* short description */ + "A", /* long description */ + ({ union { double f; size8u_t i; } _fipun; _fipun.f = (A); isnan(_fipun.f) ? 0xFFFFFFFFFFFFFFFFULL : _fipun.i; }), /* behavior */ + (A_FPOP,A_FPDOUBLE,A_IMPLICIT_WRITES_FPFLAGS,A_IMPLICIT_READS_FPRND) +) + +DEF_MACRO( + fDFNANVAL,(), + "NaN", + "NaN", + 0xffffffffffffffffULL, + () +) + +DEF_MACRO( + fDFINFVAL,(A), + "sign(A) * Inf", + "sign(A) * Inf", + (((A) & 0x8000000000000000ULL) | 0x7ff0000000000000ULL), + () +) + +DEF_MACRO( + fDFONEVAL,(A), + "sign(A) * 1.0", + "sign(A) * 1.0", + (((A) & 0x8000000000000000ULL) | fUNDOUBLE(1.0)), + () +) + +DEF_MACRO( + fCHECKDFNAN,(DST,A), + "if (isnan(A)) DST = NaN;", + "if (isnan(A)) DST = NaN;", + do { + if (isnan(fDOUBLE(A))) { + if ((fGETBIT(51,A)) == 0) fRAISEFLAGS(FE_INVALID); + DST = fDFNANVAL(); + } + } while (0), + () +) + +DEF_MACRO( + fCHECKDFNAN3,(DST,A,B,C), + "if (isnan(A) || isnan(B) || isnan(C)) DST = NaN;", + "if (isnan(A) || isnan(B) || isnan(C)) DST = NaN;", + do { + fCHECKDFNAN(DST,A); + fCHECKDFNAN(DST,B); + fCHECKDFNAN(DST,C); + } while (0), + () +) + +DEF_MACRO( + fDF_BIAS,(), + "1023", + "double precision bias", + 1023, + () +) + +DEF_MACRO( + fDF_ISNORMAL,(X), + "is_normal(X)", + "is X normal?", + (fpclassify(fDOUBLE(X)) == FP_NORMAL), + () +) + +DEF_MACRO( + fDF_ISDENORM,(X), + "is_denormal(X)", + "is X denormal?", + (fpclassify(fDOUBLE(X)) == FP_SUBNORMAL), + () +) + +DEF_MACRO( + fDF_ISBIG,(X), + "(df_exponent(X) >= 512)", + "is X sufficiently large for mpyfix (exp >= 512)?", + (fDF_GETEXP(X) >= 512), + () +) + +DEF_MACRO( + fDF_MANTBITS,(), + "52", + "single mantissa bits", + 52, + () +) + +DEF_MACRO( + fDF_RECIP_LOOKUP,(IDX), + "recip_lut[IDX]", + "Single Precision reciprocal Estimate", + (size8u_t)(arch_recip_lookup(IDX)), + () +) + +DEF_MACRO( + fDF_INVSQRT_LOOKUP,(IDX), + "invsqrt_lut[IDX]", + "Single Precision reciprocal square root Estimate", + (size8u_t)(arch_invsqrt_lookup(IDX)), + () +) + +DEF_MACRO( + fDF_MUL_POW2,(A,B), + "A * 2**B", + "A * 2**B", + (fUNDOUBLE(fDOUBLE(A) * fDOUBLE((0ULL + fDF_BIAS() + (B)) << fDF_MANTBITS()))), + () +) + +DEF_MACRO( + fDF_GETEXP,(A), + "exponent(A)", + "exponent(A)", + (((A) >> fDF_MANTBITS()) & 0x7ff), + () +) + +DEF_MACRO( + fDF_MAXEXP,(), + "2046", + "SF maximum exponent", + (2046), + () +) + +DEF_MACRO( + fDF_RECIP_COMMON,(N,D,O,A), + "(N,D,O,A)=recip_common(N,D)", + "(N,D,O,A)=recip_common(N,D)", + arch_df_recip_common(&N,&D,&O,&A), + (A_FPOP) +) + +DEF_MACRO( + fDF_INVSQRT_COMMON,(N,O,A), + "(N,O,A)=invsqrt_common(N)", + "(N,O,A)=invsqrt_common(N)", + arch_df_invsqrt_common(&N,&O,&A), + (A_FPOP) +) + +DEF_MACRO( + fFMA, (A,B,C), + "fma(A,B,C)", + "Fused Multiply Add: A*B+C", + internal_fma(A,B,C), + /* nothing */ +) + +DEF_MACRO( + fDFMPY, (A,B), + "A*B", + "Multiply: A*B", + internal_mpy(A,B), + /* nothing */ +) + +DEF_MACRO( + fDF_MPY_HH, (A,B,ACC), + "A*B with partial product ACC", + "Multiply: A*B with partial product ACC", + internal_mpyhh(A,B,ACC), + /* nothing */ +) + +DEF_MACRO( + fFMAX, (A,B,C,ADJ), + "fma(A,B,C)*2**(2*ADJ)", + "Fused Multiply Add: (A*B+C)*2**(2*ADJ)", + internal_fmax(A,B,C,fSXTN(8,64,ADJ)*2), + /* nothing */ +) + +DEF_MACRO( + fMAKEDF,(SIGN,EXP,MANT), + "-1**SIGN * 1.MANT * 2**(EXP-BIAS)", + "-1**SIGN * 1.MANT * 2**(EXP-BIAS)", + ((((SIGN) & 1ULL) << 63) | (((EXP) & 0x7ffULL) << fDF_MANTBITS()) | + ((MANT) & ((1ULL<<fDF_MANTBITS())-1))), + () +) + +DEF_MACRO( + fFPOP_START, + (), + "fpop_start", + "Begin floating point operation", + arch_fpop_start(thread), + /* nothing */ +) + +DEF_MACRO( + fFPOP_END, + (), + "fpop_end", + "End floating point operation", + arch_fpop_end(thread), + /* nothing */ +) + +DEF_MACRO( + fFPSETROUND_NEAREST, + (), + "round_to_nearest()", + "Set rounding mode to Nearest", + fesetround(FE_TONEAREST), + /* nothing */ +) + +DEF_MACRO( + fFPSETROUND_CHOP, + (), + "round_to_zero()", + "Set rounding mode to Chop", + fesetround(FE_TOWARDZERO), + /* nothing */ +) + +DEF_MACRO( + fFPCANCELFLAGS, + (), + "cancel_flags()", + "Do not update Floating Point Flags", + feclearexcept(FE_ALL_EXCEPT), + /* nothing */ +) + +DEF_MACRO( + fISINFPROD, + (A,B), + "isinf(A*B)", + "True if the product of A and B is truly infinite", + ((isinf(A) && isinf(B)) || + (isinf(A) && isfinite(B) && ((B) != 0.0)) || + (isinf(B) && isfinite(A) && ((A) != 0.0))), + /* nothing */ +) + +DEF_MACRO( + fISZEROPROD, + (A,B), + "is_true_zero(A*B)", + "True if the product of A and B is truly zero", + ((((A) == 0.0) && isfinite(B)) || (((B) == 0.0) && isfinite(A))), + /* nothing */ +) + +DEF_MACRO( + fRAISEFLAGS, + (A), + "fpflags |= A", + "Raise Floating Point Flags", + arch_raise_fpflag(A), + /* NOTHING */ +) + +DEF_MACRO( + fDF_MAX, + (A,B), + "fmax(A,B)", + "Floating Point Maximum", + (((A)==(B)) + ? fDOUBLE(fUNDOUBLE(A) & fUNDOUBLE(B)) + : fmax(A,B)), + (A_FPOP) +) + +DEF_MACRO( + fDF_MIN, + (A,B), + "fmin(A,B)", + "Floating Point Maximum", + (((A)==(B)) + ? fDOUBLE(fUNDOUBLE(A) | fUNDOUBLE(B)) + : fmin(A,B)), + (A_FPOP) +) + +DEF_MACRO( + fSF_MAX, + (A,B), + "fmaxf(A,B)", + "Floating Point Maximum", + (((A)==(B)) + ? fFLOAT(fUNFLOAT(A) & fUNFLOAT(B)) + : fmaxf(A,B)), + (A_FPOP) +) + +DEF_MACRO( + fSF_MIN, + (A,B), + "fmin(A,B)", + "Floating Point Maximum", + (((A)==(B)) + ? fFLOAT(fUNFLOAT(A) | fUNFLOAT(B)) + : fminf(A,B)), + (A_FPOP) +) + +/*************************************/ +/* Load/Store support */ +/*************************************/ + +DEF_MACRO(fMMU,(ADDR), + "ADDR", + "ADDR", + /* mmu xlate */ ADDR, + (A_EXCEPTION_TLB,A_EXCEPTION_ACCESS) +) + +DEF_MACRO(fcirc_add,(REG,INCR,IMMED), + "REG=circ_add(REG,INCR,IMMED)", + "REG=circ_add(REG,INCR,IMMED)", + (REG=fcircadd(thread, REG,INCR,IMMED, fREAD_CSREG(MuN))), + (A_CIRCADDR,A_IMPLICIT_READS_CS) +) + +DEF_MACRO(fbrev,(REG), + "REG.h[1] | brev(REG.h[0])", + "REG.h[1] | brev(REG.h[0])", + (fbrevaddr(REG)), + (A_BREVADDR) +) + + +DEF_MACRO(fLOAD,(NUM,SIZE,SIGN,EA,DST), + "DST = *EA", + "Get SIZE bytes from memory at EA and save in DST.", + { DST = (size##SIZE##SIGN##_t)MEM_LOAD##SIZE(thread,EA,insn); }, + (A_LOAD,A_MEMLIKE,A_RESTRICT_SINGLE_MEM_FIRST) +) + +DEF_MACRO(fMEMOP,(NUM,SIZE,SIGN,EA,FNTYPE,VALUE), + "DST = *EA", + "Get SIZE bytes from memory at EA and save in DST.", + { memop##SIZE##_##FNTYPE(thread,EA,VALUE); }, + (A_LOAD,A_STORE,A_MEMLIKE,A_RESTRICT_SINGLE_MEM_FIRST) +) + +DEF_MACRO(fGET_FRAMEKEY,(), + "FRAMEKEY", + "FRAMEKEY", + READ_RREG(REG_FRAMEKEY), + (A_IMPLICIT_READS_FRAMEKEY) +) + +DEF_MACRO(fFRAME_SCRAMBLE,(VAL), + "frame_scramble(VAL)", + "frame_scramble(VAL)", + ((VAL) ^ (fCAST8u(fGET_FRAMEKEY()) << 32)), + /* ATTRIBS */ +) + +DEF_MACRO(fFRAME_UNSCRAMBLE,(VAL), + "frame_unscramble(VAL)", + "frame_unscramble(VAL)", + fFRAME_SCRAMBLE(VAL), + /* ATTRIBS */ +) + +DEF_MACRO(fFRAMECHECK,(ADDR,EA), + "frame_check_limit(ADDR)", + "frame_check_limit(ADDR)", + sys_check_framelimit(thread,ADDR,EA), + (A_IMPLICIT_READS_FRAMELIMIT) +) + +DEF_MACRO(fLOAD_LOCKED,(NUM,SIZE,SIGN,EA,DST), + "DST = *EA; ", + "Get SIZE bytes from memory at EA and save in DST.", + { DST = (size##SIZE##SIGN##_t)mem_load_locked(thread,EA,SIZE,insn); + }, + (A_LOAD,A_MEMLIKE,A_RESTRICT_SINGLE_MEM_FIRST) +) + +DEF_MACRO(fLOAD_PHYS,(NUM,SIZE,SIGN,SRC1,SRC2,DST), + "DST = *((SRC1&0x7ff) | (SRC2<<11))", + "Load from physical address", + { DST = (size##SIZE##SIGN##_t)mem_load_phys(thread,SRC1,SRC2,insn); + }, + (A_LOAD,A_MEMLIKE,A_RESTRICT_SINGLE_MEM_FIRST) +) + + +DEF_MACRO(fSTORE,(NUM,SIZE,EA,SRC), + "*EA = SRC", + "Store SIZE bytes from SRC into memory at EA", + { MEM_STORE##SIZE(thread,EA,SRC,insn); }, + (A_STORE,A_MEMLIKE,A_RESTRICT_SINGLE_MEM_FIRST) +) + + +DEF_MACRO(fSTORE_LOCKED,(NUM,SIZE,EA,SRC,PRED), + "if (lock_valid) { *EA = SRC; PRED = 0xff; lock_valid = 0; } else { PRED = 0; }", + "if the lock is valid, Store SIZE bytes from SRC into memory at EA, and invalidate the lock. PRED is set to all 1s if the write actually took place.", + { PRED = (mem_store_conditional(thread,EA,SRC,SIZE,insn) ? 0xff : 0); }, + (A_STORE,A_MEMLIKE,A_RESTRICT_SINGLE_MEM_FIRST) +) + +DEF_MACRO(fVTCM_MEMCPY,(DST,SRC,SIZE), + "for (i = 0; i <= SIZE; i++) { *(DST + i) = *(SRC + i); }", + "Copy SIZE+1 bytes from memory at SRC to memory at DST", + mem_vtcm_memcpy(thread, insn, DST, SRC, SIZE);, + /* ATTRIBS */ +) + + +/*************************************/ +/* Permute Handler */ +/*************************************/ + +DEF_MACRO(fPERMUTEH,(SRC0,SRC1,CTRL), + "permute(SRC0,SRC1,CTRL)", + "Permute SRC0 and SRC1 according to CTRL", + fpermuteh((SRC0),(SRC1),CTRL), + (A_PERM) +) + +DEF_MACRO(fPERMUTEB,(SRC0,SRC1,CTRL), + "permute(SRC0,SRC1,CTRL)", + "Permute SRC0 and SRC1 according to CTRL", + fpermuteb((SRC0),(SRC1),CTRL), + (A_PERM) +) + +/*************************************/ +/* Functions to help with bytes */ +/*************************************/ + +DEF_MACRO(fGETBYTE,(N,SRC), + "SRC.b[N]", + "Byte N from SRC", + ((size1s_t)((SRC>>((N)*8))&0xff)), + /* nothing */ +) + +DEF_MACRO(fGETUBYTE,(N,SRC), + "SRC.ub[N]", + "Byte N from SRC", + ((size1u_t)((SRC>>((N)*8))&0xff)), + /* nothing */ +) + +DEF_MACRO(fSETBYTE,(N,DST,VAL), + "DST.b[N]=VAL", + "Byte N from DST = VAL", + { + DST = (DST & ~(0x0ffLL<<((N)*8))) | (((size8u_t)((VAL) & 0x0ffLL)) << ((N)*8)); + }, + /* nothing */ +) + +DEF_MACRO(fGETHALF,(N,SRC), + "SRC.h[N]", + "Halfword N from SRC", + ((size2s_t)((SRC>>((N)*16))&0xffff)), + /* nothing */ +) + +DEF_MACRO(fGETUHALF,(N,SRC), + "SRC.uh[N]", + "Halfword N from SRC", + ((size2u_t)((SRC>>((N)*16))&0xffff)), + /* nothing */ +) + +DEF_MACRO(fSETHALF,(N,DST,VAL), + "DST.h[N]=VAL", + "Halfword N from DST = VAL", + { + DST = (DST & ~(0x0ffffLL<<((N)*16))) | (((size8u_t)((VAL) & 0x0ffff)) << ((N)*16)); + }, + /* nothing */ +) + + + +DEF_MACRO(fGETWORD,(N,SRC), + "SRC.w[N]", + "Word N from SRC", + ((size8s_t)((size4s_t)((SRC>>((N)*32))&0x0ffffffffLL))), + /* nothing */ +) + +DEF_MACRO(fGETUWORD,(N,SRC), + "SRC.uw[N]", + "Word N from SRC", + ((size8u_t)((size4u_t)((SRC>>((N)*32))&0x0ffffffffLL))), + /* nothing */ +) + +DEF_MACRO(fSETWORD,(N,DST,VAL), + "DST.w[N]=VAL", + "Word N from DST = VAL", + { + DST = (DST & ~(0x0ffffffffLL<<((N)*32))) | (((VAL) & 0x0ffffffffLL) << ((N)*32)); + }, + /* nothing */ +) + +DEF_MACRO(fACC,(), + "", + "", + , + (A_ACC) +) + +DEF_MACRO(fEXTENSION_AUDIO,(A), + "A", + "A", + A, + (A_EXTENSION_AUDIO,A_NOTE_EXTENSION_AUDIO) +) + +DEF_MACRO(fSETBIT,(N,DST,VAL), + "DST.N = VAL", + "Set bit N in DST to VAL", + { + DST = (DST & ~(1ULL<<(N))) | (((size8u_t)(VAL))<<(N)); + }, + /* nothing */ +) + +DEF_MACRO(fGETBIT,(N,SRC), + "SRC.N", + "Get bit N from SRC", + (((SRC)>>N)&1), + /* nothing */ +) + + +DEF_MACRO(fSETBITS,(HI,LO,DST,VAL), + "DST[HI:LO] = VAL", + "Set bits from HI to LO in DST to VAL", + do { + int j; + for (j=LO;j<=HI;j++) { + fSETBIT(j,DST,VAL); + } + } while (0), + /* nothing */ +) + +DEF_MACRO(fUNDEFINED,(), + "UNDEFINED", + "UNDEFINED", + warn("[UNDEFINED]: architecturally undefined"), + /* NOTHING */ +) + +/*************************************/ +/* Used for parity, etc........ */ +/*************************************/ +DEF_MACRO(fCOUNTONES_2,(VAL), + "count_ones(VAL)", + "Count the number of bits set in VAL", + count_ones_2(VAL), + /* nothing */ +) + +DEF_MACRO(fCOUNTONES_4,(VAL), + "count_ones(VAL)", + "Count the number of bits set in VAL", + count_ones_4(VAL), + /* nothing */ +) + +DEF_MACRO(fCOUNTONES_8,(VAL), + "count_ones(VAL)", + "Count the number of bits set in VAL", + count_ones_8(VAL), + /* nothing */ +) + +DEF_MACRO(fBREV_8,(VAL), + "reverse_bits(VAL)", + "Count the number of bits set in VAL", + reverse_bits_8(VAL), + /* nothing */ +) + +DEF_MACRO(fBREV_4,(VAL), + "reverse_bits(VAL)", + "Count the number of bits set in VAL", + reverse_bits_4(VAL), + /* nothing */ +) + +DEF_MACRO(fBREV_2,(VAL), + "reverse_bits(VAL)", + "Count the number of bits set in VAL", + reverse_bits_2(VAL), + /* nothing */ +) + +DEF_MACRO(fBREV_1,(VAL), + "reverse_bits(VAL)", + "Count the number of bits set in VAL", + reverse_bits_1(VAL), + /* nothing */ +) + +DEF_MACRO(fCL1_8,(VAL), + "count_leading_ones(VAL)", + "Count the number of bits set in VAL", + count_leading_ones_8(VAL), + /* nothing */ +) + +DEF_MACRO(fCL1_4,(VAL), + "count_leading_ones(VAL)", + "Count the number of bits set in VAL", + count_leading_ones_4(VAL), + /* nothing */ +) + +DEF_MACRO(fCL1_2,(VAL), + "count_leading_ones(VAL)", + "Count the number of bits set in VAL", + count_leading_ones_2(VAL), + /* nothing */ +) + +DEF_MACRO(fCL1_1,(VAL), + "count_leading_ones(VAL)", + "Count the number of bits set in VAL", + count_leading_ones_1(VAL), + /* nothing */ +) + +DEF_MACRO(fINTERLEAVE,(ODD,EVEN), + "interleave(ODD,EVEN)", + "Interleave odd bits from ODD with even bits from EVEN", + interleave(ODD,EVEN), + /* nothing */ +) + +DEF_MACRO(fDEINTERLEAVE,(MIXED), + "deinterleave(ODD,EVEN)", + "Deinterleave odd bits into high half even bits to low half", + deinterleave(MIXED), + /* nothing */ +) + +DEF_MACRO(fNORM16,(VAL), + "get norm of 16bit value(VAL)", + "the number of leading sign bits in VAL", + ((VAL == 0) ? (31) : (fMAX(fCL1_2( VAL),fCL1_2(~VAL))-1)), + /* nothing */ +) + + + +DEF_MACRO(fHIDE,(A), + "", + "", + A, + () +) + +DEF_MACRO(fASM_MAP,(A,B), + "Assembler mapped to: B", + "Assembler mapped to: B", + fatal("ASM_MAP instruction " A "->" B " executed.");, + () +) + +DEF_MACRO(fCOND_ASM_MAP,(A,C,X,Y), + "if (C) {Assembler mapped to: X;} else {Assembler mapped to: Y;}@", + "if (C) {Assembler mapped to: Y;} else {Assembler mapped to: Y;}@", + fatal("ASM_MAP instruction " A "->" X "/" Y " executed.");, + () +) + +DEF_MACRO(fCONSTLL,(A), + "A", + "A", + A##LL, +) + +DEF_MACRO(fCONSTULL,(A), + "A", + "A", + A##ULL, +) + +/* Do the things in the parens, but don't print the parens. */ +DEF_MACRO(fECHO,(A), + "A", + "A", + (A), + /* nothing */ +) + + +/********************************************/ +/* OS interface and stop/wait */ +/********************************************/ + +DEF_MACRO(RUNNABLE_THREADS_MAX,, + "THREADS_MAX", + "THREADS_MAX", + (thread->processor_ptr->runnable_threads_max), + () +) + +DEF_MACRO(THREAD_IS_ON,(PROC,TNUM), + "THREAD IS ENABLE", + "Thread is enabled in the revid", + ((PROC->arch_proc_options->thread_enable_mask>>TNUM) & 0x1), + () +) + +DEF_MACRO(THREAD_EN_MASK,(PROC), + "THREAD IS ENABLE MASK", + "Thread is enabled in the revid", + ((PROC->arch_proc_options->thread_enable_mask)), + () +) + + + +DEF_MACRO(READ_IMASK,(TH), + "IMASK[TH]", + "IMASK[TH]", + (((TH) >= (thread->processor_ptr->runnable_threads_max)) ? 0 : (thread->processor_ptr->thread[TH]->Regs[REG_IMASK])), + (A_IMPLICIT_READS_IMASK_ANYTHREAD) +) +DEF_MACRO(WRITE_IMASK,(TH,VAL), + "IMASK[TH]=VAL", + "IMASK[TH]=VAL", + if ((TH) < (thread->processor_ptr->runnable_threads_max)) { thread->processor_ptr->thread[TH]->Regs[REG_IMASK]=(VAL & reg_mutability[REG_IMASK] ); }, + (A_IMPLICIT_WRITES_IMASK_ANYTHREAD) +) + + +DEF_MACRO(WRITE_PRIO,(TH,VAL), + "TID[TH].PRIO=VAL", + "TID[TH].PRIO=VAL", + { + if ((TH) < (thread->processor_ptr->runnable_threads_max)) { + size4u_t tid_reg = thread->processor_ptr->thread[TH]->Regs[REG_TID]; + fINSERT_BITS(tid_reg, reg_field_info[STID_PRIO].width, reg_field_info[STID_PRIO].offset, VAL); + LOG_OTHER_THREAD_REG_WRITE(thread,REG_TID,tid_reg,TH); + } + }, + (A_IMPLICIT_WRITES_STID_PRIO_ANYTHREAD) +) + + +DEF_MACRO(DO_IASSIGNW,(REG), + "IASSIGNW(REG)", + "IASSIGNW(REG)", + { + int i; + int intbitpos = ((REG>>16)&0xF); + for (i=0;i<RUNNABLE_THREADS_MAX;i++) { + if(( (thread->processor_ptr->arch_proc_options->thread_enable_mask>>i) & 0x1)) { + fINSERT_BITS(thread->processor_ptr->thread[i]->Regs[REG_IMASK],1, intbitpos, (REG>>i) & 1); + } + } + }, + (A_IMPLICIT_WRITES_IMASK_ANYTHREAD) +) + + + + +DEF_MACRO(fDO_NMI,(SREG), + "Raise NMI on threads", + "Raise NMI on threads", + { + int i; + for (i=0;i<RUNNABLE_THREADS_MAX;i++) { + if( ( (thread->processor_ptr->arch_proc_options->thread_enable_mask>>i) & 0x1) ) { + if (SREG & (1<<i)) { + register_nmi_interrupt(thread->processor_ptr->thread[i]); + } + } + } + }, +) + +DEF_MACRO(fDO_TRACE,(SREG), + "Send value to ETM trace", + "Send value to ETM trace", + { + fHIDE(CALLBACK(thread->processor_ptr->options->trace_callback, + thread->system_ptr,thread->processor_ptr, + thread->threadId,SREG);) + }, +) + +DEF_MACRO(DO_IASSIGNR,(SREG,DREG), + "DREG=IASSIGNR(SREG)", + "DREG=IASSIGNR(SREG)", + { + int i; + int result=0; + int intbitpos = ((SREG>>16)&0xF); + for (i=0;i<RUNNABLE_THREADS_MAX;i++) { + if(( (thread->processor_ptr->arch_proc_options->thread_enable_mask>>i) & 0x1)) { + result |= (((thread->processor_ptr->thread[i]->Regs[REG_IMASK]>>intbitpos)&1)<<i); + } + } + DREG=result; + }, + (A_IMPLICIT_READS_IMASK_ANYTHREAD) +) + +#ifdef NEW_INTERRUPTS + +DEF_MACRO(DO_SWI,(REG), + "IPEND |= REG", + "IPEND |= REG", + {fHIDE(CALLBACK(thread->processor_ptr->options->swi_callback, + thread->system_ptr,thread->processor_ptr, + thread->threadId,REG)); + fLOG_GLOBAL_REG_FIELD(IPENDAD,IPENDAD_IPEND,fREAD_GLOBAL_REG_FIELD(IPENDAD,IPENDAD_IPEND)|(REG)); + }, + (A_EXCEPTION_SWI,A_IMPLICIT_READS_IPENDAD_IPEND,A_IMPLICIT_WRITES_IPENDAD_IPEND) +) + +DEF_MACRO(DO_CSWI,(REG), + "IPEND &= ~REG", + "IPEND &= ~REG", + fLOG_GLOBAL_REG_FIELD(IPENDAD,IPENDAD_IPEND,fREAD_GLOBAL_REG_FIELD(IPENDAD,IPENDAD_IPEND) & ~(REG));, + (A_IMPLICIT_READS_IPENDAD_IPEND,A_IMPLICIT_WRITES_IPENDAD_IPEND) +) + +DEF_MACRO(DO_CIAD,(VAL), + "IAD &= ~VAL", + "IAD &= ~VAL", + sys_ciad(thread,VAL); + fLOG_GLOBAL_REG_FIELD(IPENDAD,IPENDAD_IAD,fREAD_GLOBAL_REG_FIELD(IPENDAD,IPENDAD_IAD) & ~(VAL));, + (A_EXCEPTION_SWI,A_IMPLICIT_READS_IPENDAD_IAD,A_IMPLICIT_WRITES_IPENDAD_IAD) +) + +DEF_MACRO(DO_SIAD,(VAL), + "IAD |= VAL", + "IAD |= VAL", + sys_siad(thread,VAL); + fLOG_GLOBAL_REG_FIELD(IPENDAD,IPENDAD_IAD,fREAD_GLOBAL_REG_FIELD(IPENDAD,IPENDAD_IAD) | (VAL));, + (A_EXCEPTION_SWI,A_IMPLICIT_READS_IPENDAD_IAD,A_IMPLICIT_WRITES_IPENDAD_IAD) +) + +#else + +DEF_MACRO(DO_SWI,(REG), + "IPEND |= REG", + "IPEND |= REG", + {fHIDE(CALLBACK(thread->processor_ptr->options->swi_callback, + thread->system_ptr,thread->processor_ptr, + thread->threadId,REG)); + LOG_GLOBAL_REG_WRITE(REG_IPEND,(GLOBAL_REG_READ(REG_IPEND) | (REG & GLOBAL_REG_READ(REG_IEL)))); + }, + (A_EXCEPTION_SWI) +) + +DEF_MACRO(DO_CSWI,(REG), + "IPEND &= ~REG", + "IPEND &= ~REG", + LOG_GLOBAL_REG_WRITE(REG_IPEND,GLOBAL_REG_READ(REG_IPEND) & ~((REG) & GLOBAL_REG_READ(REG_IEL)));, + () +) + +DEF_MACRO(DO_CIAD,(VAL), + "IAD &= ~VAL", + "IAD &= ~VAL", + sys_ciad(thread,VAL); LOG_GLOBAL_REG_WRITE(REG_IAD,GLOBAL_REG_READ(REG_IAD) & ~(VAL));, + (A_EXCEPTION_SWI) +) + +DEF_MACRO(DO_SIAD,(VAL), + "IAD |= VAL", + "IAD |= VAL", + sys_siad(thread,VAL); LOG_GLOBAL_REG_WRITE(REG_IAD,GLOBAL_REG_READ(REG_IAD) | (VAL));, + (A_EXCEPTION_SWI) +) + + +#endif + +DEF_MACRO(fBREAK,(), + "Enter Debug mode", + "Enter Debug mode", + {isdb_brkpt_insn(thread->processor_ptr,thread->threadId);}, + () +) + +DEF_MACRO(fGP_DOCHKPAGECROSS,(BASE,SUM), + "", + "", + if (!(insn->extension_valid)) { + fDOCHKPAGECROSS(BASE,SUM); + }, + (A_EA_PAGECROSS) +) + +DEF_MACRO(fDOCHKPAGECROSS,(BASE,SUM), + "", + "", + if (thread->bq_on) { + thread->mem_access[insn->slot].check_page_crosses = 1; + thread->mem_access[insn->slot].page_cross_base = BASE; + thread->mem_access[insn->slot].page_cross_sum = SUM; + }, + (A_EA_PAGECROSS) +) + +DEF_MACRO(fTIMING_AIA,(OLDVA,NEWVA), + "", + "", + if(thread->bq_on){ + thread->mem_access[insn->slot].post_updated = 1; + thread->mem_access[insn->slot].post_updated_va = NEWVA; + insn->is_aia = 1; + }, + (A_PM_ANY) +) + + +DEF_MACRO(fPAUSE,(IMM), + "Pause for IMM cycles", + "Pause for IMM cycles", + {sys_pause(thread, insn->slot, IMM);}, + () +) + + +#if 1 +/* The way it should be */ +DEF_MACRO(fTRAP,(TRAPTYPE,IMM), + "SSR.CAUSE = IMM; TRAP # TRAPTYPE", + "SSR.CAUSE = IMM; TRAP # TRAPTYPE", + warn("Trap NPC=%x ",fREAD_NPC()); + warn("Trap exception, PCYCLE=%lld TYPE=%d NPC=%x IMM=0x%x",thread->processor_ptr->pstats[pcycles],TRAPTYPE,fREAD_NPC(),IMM); + register_trap_exception(thread,fREAD_NPC(),TRAPTYPE,IMM);, + (A_EXCEPTION_SWI) +) +#else +DEF_MACRO(fTRAP,(TRAPTYPE,IMM), + "SSR.CAUSE = IMM; TRAP # TRAPTYPE", + "SSR.CAUSE = IMM; TRAP # TRAPTYPE", + if ((TRAPTYPE == 0) && (IMM == 0) && + (!thread->sandbox_execution) && + (!thread->processor_ptr->options->disable_angelswi)) { + sim_handle_trap(thread->system_ptr,thread->processor_ptr,thread->threadId,0); + /*thread->status |= EXEC_STATUS_SWI;*/ + } else if ((TRAPTYPE == 0) && (IMM == 0xdb) && + (!thread->sandbox_execution) && + (!thread->processor_ptr->options->disable_angelswi)) { + sim_handle_debug(thread->system_ptr,thread->processor_ptr,thread->threadId,0xdb); + } else { + warn("Trap exception, TYPE=%d NPC=%x IMM=0x%x",TRAPTYPE,fREAD_NPC(),IMM); + register_trap_exception(thread,fREAD_NPC(),TRAPTYPE,IMM); + }, + (A_EXCEPTION_SWI) +) +#endif + +DEF_MACRO(fINTERNAL_CLEAR_SAMEPAGE, + (), + "", + "", + /* force re-xlate at next fetch, refresh of in_user_mode, etc */ + /* Permissions change too... */ + sys_utlb_invalidate(thread->processor_ptr,thread), + /* NOTHING */ +) + +DEF_MACRO(fCLEAR_RTE_EX,(), + "SSR.SSR_EX = 0", + "SSR.SSR_EX = 0", + { + fLOG_REG_FIELD(SSR,SSR_EX,0); + fINTERNAL_CLEAR_SAMEPAGE(); + }, + () +) + +DEF_MACRO(fTLB_LOCK_AVAILABLE,(), + "SYSCFG.TLBLOCK == 0", + "SYSCFG.TLBLOCK == 0", + (fREAD_GLOBAL_REG_FIELD(SYSCONF,SYSCFG_TLBLOCK) == 0), + () +) + +DEF_MACRO(fK0_LOCK_AVAILABLE,(), + "SYSCFG.K0LOCK == 0", + "SYSCFG.K0LOCK == 0", + (fREAD_GLOBAL_REG_FIELD(SYSCONF,SYSCFG_K0LOCK) == 0), + () +) + +DEF_MACRO(fSET_TLB_LOCK,(), + "if (can_aquire_tlb_lock) {SYSCFG.TLBLOCK = 1;} else {sleep_until_available;}", + "if (can_aquire_tlb_lock) {SYSCFG.TLBLOCK = 1;} else {sleep_until_available;}", + { + if (fTLB_LOCK_AVAILABLE()) { + fLOG_GLOBAL_REG_FIELD(SYSCONF,SYSCFG_TLBLOCK,1); + } else { + sys_waiting_for_tlb_lock(thread); + } + },
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.7.4
Part of the diff is not shown here. View the raw message.
RFC PATCH 17/66 Hexagon arch import - instruction encoding
In reply to Taylor SimpsonImported from the Hexagon architecture library
Instruction encoding bit patterns for every instruction
--- target/hexagon/imported/encode.def | 125 ++ target/hexagon/imported/encode_pp.def | 2283 ++++++++++++++++++++++++++++ target/hexagon/imported/encode_subinsn.def | 150 ++ 3 files changed, 2558 insertions(+) create mode 100644 target/hexagon/imported/encode.def create mode 100644 target/hexagon/imported/encode_pp.def create mode 100644 target/hexagon/imported/encode_subinsn.def
target/hexagon/imported/encode.def new file +125 -0
@@ -0,0 +1,125 @@ +/* + * Copyright (c) 2019 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/>. + */ + +/* + * This just includes all encoding files + */ + +#ifndef DEF_FIELD32 +#define __SELF_DEF_FIELD32 +#define DEF_FIELD32(...) /* nothing */ +#endif + +#ifndef DEF_CLASS32 +#define __SELF_DEF_CLASS32 +#define DEF_CLASS32(...) /* nothing */ +#endif + +#ifndef DEF_ANTICLASS32 +#define __SELF_DEF_ANTICLASS32 +#define DEF_ANTICLASS32(...) /* nothing */ +#endif + +#ifndef LEGACY_DEF_ENC32 +#define __SELF_DEF_LEGACY_DEF_ENC32 +#define LEGACY_DEF_ENC32(...) /* nothing */ +#endif + +#ifndef DEF_FIELDROW_DESC32 +#define __SELF_DEF_FIELDROW_DESC32 +#define DEF_FIELDROW_DESC32(...) /* nothing */ +#endif + +#ifndef DEF_ENC32 +#define __SELF_DEF_ENC32 +#define DEF_ENC32(...) /* nothing */ +#endif + +#ifndef DEF_PACKED32 +#define __SELF_DEF_PACKED32 +#define DEF_PACKED32(...) /* nothing */ +#endif + +#ifndef DEF_ENC_SUBINSN +#define __SELF_DEF_ENC_SUBINSN +#define DEF_ENC_SUBINSN(...) /* nothing */ +#endif + +#ifndef DEF_EXT_ENC +#define __SELF_DEF_EXT_ENC +#define DEF_EXT_ENC(...) /* nothing */ +#endif + +#ifndef DEF_EXT_SPACE +#define __SELF_DEF_EXT_SPACE +#define DEF_EXT_SPACE(...) /* nothing */ +#endif + +#include "encode_pp.def" +#include "encode_subinsn.def" + +#ifdef __SELF_DEF_FIELD32 +#undef __SELF_DEF_FIELD32 +#undef DEF_FIELD32 +#endif + +#ifdef __SELF_DEF_CLASS32 +#undef __SELF_DEF_CLASS32 +#undef DEF_CLASS32 +#endif + +#ifdef __SELF_DEF_ANTICLASS32 +#undef __SELF_DEF_ANTICLASS32 +#undef DEF_ANTICLASS32 +#endif + +#ifdef __SELF_DEF_LEGACY_DEF_ENC32 +#undef __SELF_DEF_LEGACY_DEF_ENC32 +#undef LEGACY_DEF_ENC32 +#endif + +#ifdef __SELF_DEF_FIELDROW_DESC32 +#undef __SELF_DEF_FIELDROW_DESC32 +#undef DEF_FIELDROW_DESC32 +#endif + +#ifdef __SELF_DEF_ENC32 +#undef __SELF_DEF_ENC32 +#undef DEF_ENC32 +#endif + +#ifdef __SELF_DEF_EXT_SPACE +#undef __SELF_DEF_EXT_SPACE +#undef DEF_EXT_SPACE +#endif + + +#ifdef __SELF_DEF_PACKED32 +#undef __SELF_DEF_PACKED32 +#undef DEF_PACKED32 +#endif + +#ifdef __SELF_DEF_ENC_SUBINSN +#undef __SELF_DEF_ENC_SUBINSN +#undef DEF_ENC_SUBINSN +#endif + +#ifdef __SELF_DEF_EXT_ENC +#undef __SELF_DEF_EXT_ENC +#undef DEF_EXT_ENC +#endif +
target/hexagon/imported/encode_pp.def new file +2283 -0
2,283 lines not on this page · raw message
target/hexagon/imported/encode_subinsn.def new file +150 -0
150 lines not on this page · raw message
Signature · 1 line
2.7.4
RFC PATCH 18/66 Hexagon instruction class definitions
In reply to Taylor SimpsonImported from the Hexagon architecture library
--- target/hexagon/imported/iclass.def | 52 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 target/hexagon/imported/iclass.def
target/hexagon/imported/iclass.def new file +52 -0
@@ -0,0 +1,52 @@ +/* + * Copyright (c) 2019 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/>. + */ + +/* DEF_*(TYPE,SLOTS,UNITS) */ +DEF_PP_ICLASS32(EXTENDER,0123,LDST|SUNIT|MUNIT) /* 0 */ +DEF_PP_ICLASS32(CJ,0123,CTRLFLOW) /* 1 */ +DEF_PP_ICLASS32(NCJ,01,LDST|CTRLFLOW) /* 2 */ +DEF_PP_ICLASS32(V4LDST,01,LDST) /* 3 */ +DEF_PP_ICLASS32(V2LDST,01,LDST) /* 4 */ +DEF_PP_ICLASS32(J,0123,CTRLFLOW) /* 5 */ +DEF_PP_ICLASS32(CR,3,SUNIT) /* 6 */ +DEF_PP_ICLASS32(ALU32_2op,0123,LDST|SUNIT|MUNIT) /* 7 */ +DEF_PP_ICLASS32(S_2op,23,SUNIT|MUNIT) /* 8 */ +DEF_PP_ICLASS32(LD,01,LDST) /* 9 */ +DEF_PP_ICLASS32(ST,01,LDST) /* 10 */ +DEF_PP_ICLASS32(ALU32_ADDI,0123,LDST|SUNIT|MUNIT) /* 11 */ +DEF_PP_ICLASS32(S_3op,23,SUNIT|MUNIT) /* 12 */ +DEF_PP_ICLASS32(ALU64,23,SUNIT|MUNIT) /* 13 */ +DEF_PP_ICLASS32(M,23,SUNIT|MUNIT) /* 14 */ +DEF_PP_ICLASS32(ALU32_3op,0123,LDST|SUNIT|MUNIT) /* 15 */ + +DEF_EE_ICLASS32(EE0,01,INVALID) /* 0 */ +DEF_EE_ICLASS32(EE1,01,INVALID) /* 1 */ +DEF_EE_ICLASS32(EE2,01,INVALID) /* 2 */ +DEF_EE_ICLASS32(EE3,01,INVALID) /* 3 */ +DEF_EE_ICLASS32(EE4,01,INVALID) /* 4 */ +DEF_EE_ICLASS32(EE5,01,INVALID) /* 5 */ +DEF_EE_ICLASS32(EE6,01,INVALID) /* 6 */ +DEF_EE_ICLASS32(EE7,01,INVALID) /* 7 */ +DEF_EE_ICLASS32(EE8,01,INVALID) /* 8 */ +DEF_EE_ICLASS32(EE9,01,INVALID) /* 9 */ +DEF_EE_ICLASS32(EEA,01,INVALID) /* 10 */ +DEF_EE_ICLASS32(EEB,01,INVALID) /* 11 */ +DEF_EE_ICLASS32(EEC,01,INVALID) /* 12 */ +DEF_EE_ICLASS32(EED,01,INVALID) /* 13 */ +DEF_EE_ICLASS32(EEE,01,INVALID) /* 14 */ +DEF_EE_ICLASS32(EEF,01,INVALID) /* 15 */ +
Signature · 1 line
2.7.4
RFC PATCH 19/66 Hexagon instruction utility functions
In reply to Taylor SimpsonUtility functions called by various instructions
--- target/hexagon/arch.c | 664 +++++++++++++++++++++++++++++++++ target/hexagon/arch.h | 62 ++++ target/hexagon/conv_emu.c | 370 +++++++++++++++++++ target/hexagon/conv_emu.h | 50 +++ target/hexagon/fma_emu.c | 918 ++++++++++++++++++++++++++++++++++++++++++++++ target/hexagon/fma_emu.h | 30 ++ 6 files changed, 2094 insertions(+) create mode 100644 target/hexagon/arch.c create mode 100644 target/hexagon/arch.h create mode 100644 target/hexagon/conv_emu.c create mode 100644 target/hexagon/conv_emu.h create mode 100644 target/hexagon/fma_emu.c create mode 100644 target/hexagon/fma_emu.h
target/hexagon/arch.c new file +664 -0
@@ -0,0 +1,664 @@ +/* +* Copyright (c) 2019 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 <math.h> +#include "qemu/osdep.h" +#include "fma_emu.h" +#include "arch.h" +#include "macros.h" + +/* +* These three tables are used by the cabacdecbin instruction +*/ +size1u_t rLPS_table_64x4[64 ][4 ] = { + {128 ,176 ,208 ,240 }, + {128 ,167 ,197 ,227 }, + {128 ,158 ,187 ,216 }, + {123 ,150 ,178 ,205 }, + {116 ,142 ,169 ,195 }, + {111 ,135 ,160 ,185 }, + {105 ,128 ,152 ,175 }, + {100 ,122 ,144 ,166 }, + {95 ,116 ,137 ,158 }, + {90 ,110 ,130 ,150 }, + {85 ,104 ,123 ,142 }, + {81 ,99 ,117 ,135 }, + {77 ,94 ,111 ,128 }, + {73 ,89 ,105 ,122 }, + {69 ,85 ,100 ,116 }, + {66 ,80 ,95 ,110 }, + {62 ,76 ,90 ,104 }, + {59 ,72 ,86 ,99 }, + {56 ,69 ,81 ,94 }, + {53 ,65 ,77 ,89 }, + {51 ,62 ,73 ,85 }, + {48 ,59 ,69 ,80 }, + {46 ,56 ,66 ,76 }, + {43 ,53 ,63 ,72 }, + {41 ,50 ,59 ,69 }, + {39 ,48 ,56 ,65 }, + {37 ,45 ,54 ,62 }, + {35 ,43 ,51 ,59 }, + {33 ,41 ,48 ,56 }, + {32 ,39 ,46 ,53 }, + {30 ,37 ,43 ,50 }, + {29 ,35 ,41 ,48 }, + {27 ,33 ,39 ,45 }, + {26 ,31 ,37 ,43 }, + {24 ,30 ,35 ,41 }, + {23 ,28 ,33 ,39 }, + {22 ,27 ,32 ,37 }, + {21 ,26 ,30 ,35 }, + {20 ,24 ,29 ,33 }, + {19 ,23 ,27 ,31 }, + {18 ,22 ,26 ,30 }, + {17 ,21 ,25 ,28 }, + {16 ,20 ,23 ,27 }, + {15 ,19 ,22 ,25 }, + {14 ,18 ,21 ,24 }, + {14 ,17 ,20 ,23 }, + {13 ,16 ,19 ,22 }, + {12 ,15 ,18 ,21 }, + {12 ,14 ,17 ,20 }, + {11 ,14 ,16 ,19 }, + {11 ,13 ,15 ,18 }, + {10 ,12 ,15 ,17 }, + {10 ,12 ,14 ,16 }, + {9 ,11 ,13 ,15 }, + {9 ,11 ,12 ,14 }, + {8 ,10 ,12 ,14 }, + {8 ,9 ,11 ,13 }, + {7 ,9 ,11 ,12 }, + {7 ,9 ,10 ,12 }, + {7 ,8 ,10 ,11 }, + {6 ,8 ,9 ,11 }, + {6 ,7 ,9 ,10 }, + {6 ,7 ,8 ,9 }, + {2 ,2 ,2 ,2 } +}; + +size1u_t AC_next_state_MPS_64[64 ] = { +1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10 , +11 ,12 ,13 ,14 ,15 ,16 ,17 ,18 ,19 ,20 , +21 ,22 ,23 ,24 ,25 ,26 ,27 ,28 ,29 ,30 , +31 ,32 ,33 ,34 ,35 ,36 ,37 ,38 ,39 ,40 , +41 ,42 ,43 ,44 ,45 ,46 ,47 ,48 ,49 ,50 , +51 ,52 ,53 ,54 ,55 ,56 ,57 ,58 ,59 ,60 , +61 ,62 ,62 ,63 +}; + + +size1u_t AC_next_state_LPS_64[64 ] = { +0 ,0 ,1 ,2 ,2 ,4 ,4 ,5 ,6 ,7 , +8 ,9 ,9 ,11 ,11 ,12 ,13 ,13 ,15 ,15 , +16 ,16 ,18 ,18 ,19 ,19 ,21 ,21 ,22 ,22 , +23 ,24 ,24 ,25 ,26 ,26 ,27 ,27 ,28 ,29 , +29 ,30 ,30 ,30 ,31 ,32 ,32 ,33 ,33 ,33 , +34 ,34 ,35 ,35 ,35 ,36 ,36 ,36 ,37 ,37 , +37 ,38 ,38 ,63 +}; + +size4u_t fbrevaddr (size4u_t pointer) +{ +size4u_t offset = pointer &0xffff ; +size4u_t brevoffset =0 ; +int i; + +for (i =0 ; i <16 ; i++) { +fSETBIT (i, brevoffset, (fGETBIT ((15 - i), offset))); + } +return (pointer &0xffff0000 ) | brevoffset; +} + +/* +* Counting bits set, Brian Kernighan's way +* Brian Kernighan's method goes through as many iterations as there are +* set bits. So if we have a 32-bit word with only the high bit set, +* then it will only go once through the loop. +*/ +size4u_t count_ones_2 (size2u_t src) +{ +int ret; +for (ret =0 ; src; ret++) { + src &= src -1 ;/* clear the least significant bit set */ + } +return ret; +} + +size4u_t count_ones_4 (size4u_t src) +{ +int ret; +for (ret =0 ; src; ret++) { + src &= src -1 ;/* clear the least significant bit set */ + } +return ret; +} + +size4u_t count_ones_8 (size8u_t src) +{ +int ret; +for (ret =0 ; src; ret++) { + src &= src -1 ;/* clear the least significant bit set */ + } +return ret; +} + +size4u_t count_leading_ones_8 (size8u_t src) +{ +int ret; +for (ret =0 ; src &0x8000000000000000LL ; src <<=1 ) { + ret++; + } +return ret; +} + + +size4u_t count_leading_ones_4 (size4u_t src) +{ +int ret; +for (ret =0 ; src &0x80000000 ; src <<=1 ) { + ret++; + } +return ret; +} + +size4u_t count_leading_ones_2 (size2u_t src) +{ +int ret; +for (ret =0 ; src &0x8000 ; src <<=1 ) { + ret++; + } +return ret; +} + +size4u_t count_leading_ones_1 (size1u_t src) +{ +int ret; +for (ret =0 ; src &0x80 ; src <<=1 ) { + ret++; + } +return ret; +} + +#define BITS_MASK_8 0x5555555555555555ULL +#define PAIR_MASK_8 0x3333333333333333ULL +#define NYBL_MASK_8 0x0f0f0f0f0f0f0f0fULL +#define BYTE_MASK_8 0x00ff00ff00ff00ffULL +#define HALF_MASK_8 0x0000ffff0000ffffULL +#define WORD_MASK_8 0x00000000ffffffffULL + +size8u_t reverse_bits_8 (size8u_t src) +{ + src = ((src >>1 ) &BITS_MASK_8 ) | ((src &BITS_MASK_8 ) <<1 ); + src = ((src >>2 ) &PAIR_MASK_8 ) | ((src &PAIR_MASK_8 ) <<2 ); + src = ((src >>4 ) &NYBL_MASK_8 ) | ((src &NYBL_MASK_8 ) <<4 ); + src = ((src >>8 ) &BYTE_MASK_8 ) | ((src &BYTE_MASK_8 ) <<8 ); + src = ((src >>16 ) &HALF_MASK_8 ) | ((src &HALF_MASK_8 ) <<16 ); + src = ((src >>32 ) &WORD_MASK_8 ) | ((src &WORD_MASK_8 ) <<32 ); +return src; +} + + +#define BITS_MASK_4 0x55555555ULL +#define PAIR_MASK_4 0x33333333ULL +#define NYBL_MASK_4 0x0f0f0f0fULL +#define BYTE_MASK_4 0x00ff00ffULL +#define HALF_MASK_4 0x0000ffffULL + +size4u_t reverse_bits_4 (size4u_t src) +{ + src = ((src >>1 ) &BITS_MASK_4 ) | ((src &BITS_MASK_4 ) <<1 ); + src = ((src >>2 ) &PAIR_MASK_4 ) | ((src &PAIR_MASK_4 ) <<2 ); + src = ((src >>4 ) &NYBL_MASK_4 ) | ((src &NYBL_MASK_4 ) <<4 ); + src = ((src >>8 ) &BYTE_MASK_4 ) | ((src &BYTE_MASK_4 ) <<8 ); + src = ((src >>16 ) &HALF_MASK_4 ) | ((src &HALF_MASK_4 ) <<16 ); +return src; +} + +#define BITS_MASK_2 0x5555ULL +#define PAIR_MASK_2 0x3333ULL +#define NYBL_MASK_2 0x0f0fULL +#define BYTE_MASK_2 0x00ffULL +#define HALF_MASK_2 0x0000ULL + +size4u_t reverse_bits_2 (size2u_t src) +{ + src = ((src >>1 ) &BITS_MASK_2 ) | ((src &BITS_MASK_2 ) <<1 ); + src = ((src >>2 ) &PAIR_MASK_2 ) | ((src &PAIR_MASK_2 ) <<2 ); + src = ((src >>4 ) &NYBL_MASK_2 ) | ((src &NYBL_MASK_2 ) <<4 ); + src = ((src >>8 ) &BYTE_MASK_2 ) | ((src &BYTE_MASK_2 ) <<8 ); +return src; +} + +#define BITS_MASK_1 0x55ULL +#define PAIR_MASK_1 0x33ULL +#define NYBL_MASK_1 0x0fULL +#define BYTE_MASK_1 0x00ULL +#define HALF_MASK_1 0x00ULL + +size4u_t reverse_bits_1 (size1u_t src) +{ + src = ((src >>1 ) &BITS_MASK_1 ) | ((src &BITS_MASK_1 ) <<1 ); + src = ((src >>2 ) &PAIR_MASK_1 ) | ((src &PAIR_MASK_1 ) <<2 ); + src = ((src >>4 ) &NYBL_MASK_1 ) | ((src &NYBL_MASK_1 ) <<4 ); +return src; +} + +size8u_t exchange (size8u_t bits,size4u_t cntrl) +{ +int i; +size4u_t mask =1 <<31 ; +size8u_t mask0 =0x1LL <<62 ; +size8u_t mask1 =0x2LL <<62 ; +size8u_t outbits =0 ; +size8u_t b0, b1; + +for (i =0 ; i <32 ; i++) { + b0 = (bits & mask0) >> (2 * i); + b1 = (bits & mask1) >> (2 * i); +if (cntrl & mask) { + outbits |= (b1 >>1 ) | (b0 <<1 ); + }else { + outbits |= (b1 | b0); + } + outbits <<=2 ; + mask >>=1 ; + mask0 >>=2 ; + mask1 >>=2 ; + } +return outbits; +} + +size8u_t interleave (size4u_t odd,size4u_t even) +{ +/* Convert to long long */ +size8u_t myodd = odd; +size8u_t myeven = even; +/* First, spread bits out */ + myodd = (myodd | (myodd <<16 )) &HALF_MASK_8 ; + myeven = (myeven | (myeven <<16 )) &HALF_MASK_8 ; + myodd = (myodd | (myodd <<8 )) &BYTE_MASK_8 ; + myeven = (myeven | (myeven <<8 )) &BYTE_MASK_8 ; + myodd = (myodd | (myodd <<4 )) &NYBL_MASK_8 ; + myeven = (myeven | (myeven <<4 )) &NYBL_MASK_8 ; + myodd = (myodd | (myodd <<2 )) &PAIR_MASK_8 ; + myeven = (myeven | (myeven <<2 )) &PAIR_MASK_8 ; + myodd = (myodd | (myodd <<1 )) &BITS_MASK_8 ; + myeven = (myeven | (myeven <<1 )) &BITS_MASK_8 ; +/* Now OR together */ +return myeven | (myodd <<1 ); +} + +size8u_t deinterleave (size8u_t src) +{ +/* Get odd and even bits */ +size8u_t myodd = ((src >>1 ) &BITS_MASK_8 ); +size8u_t myeven = (src &BITS_MASK_8 ); + +/* Unspread bits */ + myeven = (myeven | (myeven >>1 )) &PAIR_MASK_8 ; + myodd = (myodd | (myodd >>1 )) &PAIR_MASK_8 ; + myeven = (myeven | (myeven >>2 )) &NYBL_MASK_8 ; + myodd = (myodd | (myodd >>2 )) &NYBL_MASK_8 ; + myeven = (myeven | (myeven >>4 )) &BYTE_MASK_8 ; + myodd = (myodd | (myodd >>4 )) &BYTE_MASK_8 ; + myeven = (myeven | (myeven >>8 )) &HALF_MASK_8 ; + myodd = (myodd | (myodd >>8 )) &HALF_MASK_8 ; + myeven = (myeven | (myeven >>16 )) &WORD_MASK_8 ; + myodd = (myodd | (myodd >>16 )) &WORD_MASK_8 ; + +/* Return odd bits in upper half */ +return myeven | (myodd <<32 ); +} + +size4u_t carry_from_add64 (size8u_t a,size8u_t b,size4u_t c) +{ +size8u_t tmpa, tmpb, tmpc; + tmpa =fGETUWORD (0 , a); + tmpb =fGETUWORD (0 , b); + tmpc = tmpa + tmpb + c; + tmpa =fGETUWORD (1 , a); + tmpb =fGETUWORD (1 , b); + tmpc = tmpa + tmpb +fGETUWORD (1 , tmpc); + tmpc =fGETUWORD (1 , tmpc); +return tmpc; +} + +size4s_t conv_round (size4s_t a,int n) +{ +size8s_t val; + +if (n ==0 ) { + val = a; + }else if ((a & ((1 << (n -1 )) -1 )) ==0 ) {/* N-1..0 all zero? */ +/* Add LSB from int part */ + val = ((fSE32_64 (a)) + (size8s_t) (((size4u_t) ((1 << n) & a)) >>1 )); + }else { + val = ((fSE32_64 (a)) + (1 << (n -1 ))); + } + + val = val >> n; +return (size4s_t )val; +} + +size16s_t cast8s_to_16s (size8s_t a) +{ +size16s_t result = {.hi =0 , .lo =0 }; + result.lo = a; +if (a <0 ) { + result.hi =-1 ; + } +return result; +} + +size8s_t cast16s_to_8s (size16s_t a) +{ +return a.lo; +} + +size4s_t cast16s_to_4s (size16s_t a) +{ +return (size4s_t )a.lo; +} + +size16s_t add128 (size16s_t a,size16s_t b) +{ +size16s_t result = {.hi =0 , .lo =0 }; + result.lo = a.lo + b.lo; + result.hi = a.hi + b.hi; + +if (result.lo < b.lo) { + result.hi++; + } + +return result; +} + +size16s_t sub128 (size16s_t a,size16s_t b) +{ +size16s_t result = {.hi =0 , .lo =0 }; + result.lo = a.lo - b.lo; + result.hi = a.hi - b.hi; +if (result.lo > a.lo) { + result.hi--; + } + +return result; +} + +size16s_t shiftr128 (size16s_t a,size4u_t n) +{ +size16s_t result; + result.lo = (a.lo >> n) | (a.hi << (64 - n)); + result.hi = a.hi >> n; +return result; +} + +size16s_t shiftl128 (size16s_t a,size4u_t n) +{ +size16s_t result; + result.lo = a.lo << n; + result.hi = (a.hi << n) | (a.lo >> (64 - n)); +return result; +} + +size16s_t and128 (size16s_t a,size16s_t b) +{ +size16s_t result; + result.lo = a.lo & b.lo; + result.hi = a.hi & b.hi; +return result; +} + +/* Floating Point Stuff */ + +static const int roundingmodes[] = { +FE_TONEAREST , +FE_TOWARDZERO , +FE_DOWNWARD , +FE_UPWARD +}; + +void arch_fpop_start (CPUHexagonState *env) +{ +fegetenv (&env->fenv); +feclearexcept (FE_ALL_EXCEPT ); +fesetround (roundingmodes[fREAD_REG_FIELD (USR ,USR_FPRND )]); +} + +#define NOTHING /* Don't do anything */ + +#define TEST_FLAG (LIBCF ,MYF ,MYE ) \ + do { \ + if (fetestexcept(LIBCF)) { \ + if (GET_USR_FIELD(USR_##MYF) == 0) { \ + SET_USR_FIELD(USR_##MYF, 1); \ + if (GET_USR_FIELD(USR_##MYE)) { \ + NOTHING \ + } \ + } \ + } \ + } while (0) + +void arch_fpop_end (CPUHexagonState *env) +{ +if (fetestexcept (FE_ALL_EXCEPT )) { +TEST_FLAG (FE_INEXACT ,FPINPF ,FPINPE ); +TEST_FLAG (FE_DIVBYZERO ,FPDBZF ,FPDBZE ); +TEST_FLAG (FE_INVALID ,FPINVF ,FPINVE ); +TEST_FLAG (FE_OVERFLOW ,FPOVFF ,FPOVFE ); +TEST_FLAG (FE_UNDERFLOW ,FPUNFF ,FPUNFE ); + } +fesetenv (&env->fenv); +} + +#undef TEST_FLAG + + +void arch_raise_fpflag (unsigned int flags) +{ +feraiseexcept (flags); +} + +int arch_sf_recip_common (size4s_t *Rs,size4s_t *Rt,size4s_t *Rd,int *adjust) +{ +int n_class; +int d_class; +int n_exp; +int d_exp; +int ret =0 ; +size4s_t RsV, RtV, RdV; +int PeV =0 ; + RsV = *Rs; + RtV = *Rt; + n_class =fpclassify (fFLOAT (RsV)); + d_class =fpclassify (fFLOAT (RtV)); +if ((n_class ==FP_NAN ) && (d_class ==FP_NAN )) { +if (fGETBIT (22 , RsV & RtV) ==0 ) { +fRAISEFLAGS (FE_INVALID ); + } + RdV = RsV = RtV =fSFNANVAL (); + }else if (n_class ==FP_NAN ) { +if (fGETBIT (22 , RsV) ==0 ) { +fRAISEFLAGS (FE_INVALID ); + } + RdV = RsV = RtV =fSFNANVAL (); + }else if (d_class ==FP_NAN ) { +/* EJP: or put NaN in num/den fixup? */ +if (fGETBIT (22 , RtV) ==0 ) { +fRAISEFLAGS (FE_INVALID ); + } + RdV = RsV = RtV =fSFNANVAL (); + }else if ((n_class ==FP_INFINITE ) && (d_class ==FP_INFINITE )) { +/* EJP: or put Inf in num fixup? */ + RdV = RsV = RtV =fSFNANVAL (); +fRAISEFLAGS (FE_INVALID ); + }else if ((n_class ==FP_ZERO ) && (d_class ==FP_ZERO )) { +/* EJP: or put zero in num fixup? */ + RdV = RsV = RtV =fSFNANVAL (); +fRAISEFLAGS (FE_INVALID ); + }else if (d_class ==FP_ZERO ) { +/* EJP: or put Inf in num fixup? */ + RsV =fSFINFVAL (RsV ^ RtV); + RtV =fSFONEVAL (0 ); + RdV =fSFONEVAL (0 ); +if (n_class !=FP_INFINITE ) { +fRAISEFLAGS (FE_DIVBYZERO ); + } + }else if (d_class ==FP_INFINITE ) { + RsV =0x80000000 & (RsV ^ RtV); + RtV =fSFONEVAL (0 ); + RdV =fSFONEVAL (0 ); + }else if (n_class ==FP_ZERO ) { +/* EJP: Does this just work itself out? */ +/* EJP: No, 0/Inf causes problems. */ + RsV =0x80000000 & (RsV ^ RtV); + RtV =fSFONEVAL (0 ); + RdV =fSFONEVAL (0 ); + }else if (n_class ==FP_INFINITE ) { +/* EJP: Does this just work itself out? */ + RsV =fSFINFVAL (RsV ^ RtV); + RtV =fSFONEVAL (0 ); + RdV =fSFONEVAL (0 ); + }else { + PeV =0x00 ; +/* Basic checks passed */ + n_exp =fSF_GETEXP (RsV); + d_exp =fSF_GETEXP (RtV); +if ((n_exp - d_exp +fSF_BIAS ()) <=fSF_MANTBITS ()) { +/* Near quotient underflow / inexact Q */ + PeV =0x80 ; + RtV =fSF_MUL_POW2 (RtV,-64 ); + RsV =fSF_MUL_POW2 (RsV,64 ); + }else if ((n_exp - d_exp +fSF_BIAS ()) > (fSF_MAXEXP () -24 )) { +/* Near quotient overflow */ + PeV =0x40 ; + RtV =fSF_MUL_POW2 (RtV,32 ); + RsV =fSF_MUL_POW2 (RsV,-32 ); + }else if (n_exp <=fSF_MANTBITS () +2 ) { + RtV =fSF_MUL_POW2 (RtV,64 ); + RsV =fSF_MUL_POW2 (RsV,64 ); + }else if (d_exp <=1 ) { + RtV =fSF_MUL_POW2 (RtV,32 ); + RsV =fSF_MUL_POW2 (RsV,32 ); + }else if (d_exp >252 ) { + RtV =fSF_MUL_POW2 (RtV,-32 ); + RsV =fSF_MUL_POW2 (RsV,-32 ); + } + RdV =0 ; + ret =1 ; + } + *Rs = RsV; + *Rt = RtV; + *Rd = RdV; + *adjust = PeV; +return ret; +} + +int arch_sf_invsqrt_common (size4s_t *Rs,size4s_t *Rd,int *adjust) +{ +int r_class; +size4s_t RsV, RdV; +int PeV =0 ; +int r_exp; +int ret =0 ; + RsV = *Rs; + r_class =fpclassify (fFLOAT (RsV)); +if (r_class ==FP_NAN ) { +if (fGETBIT (22 , RsV) ==0 ) { +fRAISEFLAGS (FE_INVALID ); + } + RdV = RsV =fSFNANVAL (); + }else if (fFLOAT (RsV) <0.0 ) { +/* Negative nonzero values are NaN */ +fRAISEFLAGS (FE_INVALID ); + RsV =fSFNANVAL (); + RdV =fSFNANVAL (); + }else if (r_class ==FP_INFINITE ) { +/* EJP: or put Inf in num fixup? */ + RsV =fSFINFVAL (-1 ); + RdV =fSFINFVAL (-1 ); + }else if (r_class ==FP_ZERO ) { +/* EJP: or put zero in num fixup? */ + RsV = RsV; + RdV =fSFONEVAL (0 ); + }else { + PeV =0x00 ; +/* Basic checks passed */ + r_exp =fSF_GETEXP (RsV); +if (r_exp <=24 ) { + RsV =fSF_MUL_POW2 (RsV,64 ); + PeV =0xe0 ; + } + RdV =0 ; + ret =1 ; + } + *Rs = RsV; + *Rd = RdV; + *adjust = PeV; +return ret; +} + +int arch_recip_lookup (int index) +{ + index &=0x7f ; +unsigned const int roundrom[128 ] = { +0x0fe ,0x0fa ,0x0f6 ,0x0f2 ,0x0ef ,0x0eb ,0x0e7 ,0x0e4 , +0x0e0 ,0x0dd ,0x0d9 ,0x0d6 ,0x0d2 ,0x0cf ,0x0cc ,0x0c9 , +0x0c6 ,0x0c2 ,0x0bf ,0x0bc ,0x0b9 ,0x0b6 ,0x0b3 ,0x0b1 , +0x0ae ,0x0ab ,0x0a8 ,0x0a5 ,0x0a3 ,0x0a0 ,0x09d ,0x09b , +0x098 ,0x096 ,0x093 ,0x091 ,0x08e ,0x08c ,0x08a ,0x087 , +0x085 ,0x083 ,0x080 ,0x07e ,0x07c ,0x07a ,0x078 ,0x075 , +0x073 ,0x071 ,0x06f ,0x06d ,0x06b ,0x069 ,0x067 ,0x065 , +0x063 ,0x061 ,0x05f ,0x05e ,0x05c ,0x05a ,0x058 ,0x056 , +0x054 ,0x053 ,0x051 ,0x04f ,0x04e ,0x04c ,0x04a ,0x049 , +0x047 ,0x045 ,0x044 ,0x042 ,0x040 ,0x03f ,0x03d ,0x03c , +0x03a ,0x039 ,0x037 ,0x036 ,0x034 ,0x033 ,0x032 ,0x030 , +0x02f ,0x02d ,0x02c ,0x02b ,0x029 ,0x028 ,0x027 ,0x025 , +0x024 ,0x023 ,0x021 ,0x020 ,0x01f ,0x01e ,0x01c ,0x01b , +0x01a ,0x019 ,0x017 ,0x016 ,0x015 ,0x014 ,0x013 ,0x012 , +0x011 ,0x00f ,0x00e ,0x00d ,0x00c ,0x00b ,0x00a ,0x009 , +0x008 ,0x007 ,0x006 ,0x005 ,0x004 ,0x003 ,0x002 ,0x000 , + }; +return roundrom[index]; +}; + +int arch_invsqrt_lookup (int index) +{ + index &=0x7f ; +unsigned const int roundrom[128 ] = { +0x069 ,0x066 ,0x063 ,0x061 ,0x05e ,0x05b ,0x059 ,0x057 , +0x054 ,0x052 ,0x050 ,0x04d ,0x04b ,0x049 ,0x047 ,0x045 , +0x043 ,0x041 ,0x03f ,0x03d ,0x03b ,0x039 ,0x037 ,0x036 , +0x034 ,0x032 ,0x030 ,0x02f ,0x02d ,0x02c ,0x02a ,0x028 , +0x027 ,0x025 ,0x024 ,0x022 ,0x021 ,0x01f ,0x01e ,0x01d , +0x01b ,0x01a ,0x019 ,0x017 ,0x016 ,0x015 ,0x014 ,0x012 , +0x011 ,0x010 ,0x00f ,0x00d ,0x00c ,0x00b ,0x00a ,0x009 , +0x008 ,0x007 ,0x006 ,0x005 ,0x004 ,0x003 ,0x002 ,0x001 , +0x0fe ,0x0fa ,0x0f6 ,0x0f3 ,0x0ef ,0x0eb ,0x0e8 ,0x0e4 , +0x0e1 ,0x0de ,0x0db ,0x0d7 ,0x0d4 ,0x0d1 ,0x0ce ,0x0cb , +0x0c9 ,0x0c6 ,0x0c3 ,0x0c0 ,0x0be ,0x0bb ,0x0b8 ,0x0b6 , +0x0b3 ,0x0b1 ,0x0af ,0x0ac ,0x0aa ,0x0a8 ,0x0a5 ,0x0a3 , +0x0a1 ,0x09f ,0x09d ,0x09b ,0x099 ,0x097 ,0x095 ,0x093 , +0x091 ,0x08f ,0x08d ,0x08b ,0x089 ,0x087 ,0x086 ,0x084 , +0x082 ,0x080 ,0x07f ,0x07d ,0x07b ,0x07a ,0x078 ,0x077 , +0x075 ,0x074 ,0x072 ,0x071 ,0x06f ,0x06e ,0x06c ,0x06b , + }; +return roundrom[index]; +}; +
target/hexagon/arch.h new file +62 -0
62 lines not on this page · raw message
target/hexagon/conv_emu.c new file +370 -0
370 lines not on this page · raw message
target/hexagon/conv_emu.h new file +50 -0
50 lines not on this page · raw message
target/hexagon/fma_emu.c new file +918 -0
918 lines not on this page · raw message
target/hexagon/fma_emu.h new file +30 -0
@@ -0,0 +1,30 @@ +/* +* Copyright (c) 2019 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/>. +*/ + +#ifndef FMA_EMU_H +#define FMA_EMU_H + +extern float internal_fmafx (float a_in,float b_in,float c_in,int scale); +extern float internal_fmaf (float a_in,float b_in,float c_in); +extern double internal_fma (double a_in,double b_in,double c_in); +extern double internal_fmax (double a_in,double b_in,double c_in,int scale); +extern float internal_mpyf (float a_in,float b_in); +extern double internal_mpy (double a_in,double b_in); +extern double internal_mpyhh (double a_in,double b_in, +unsigned long long int accumulated); + +#endif
Signature · 1 line
2.7.4
Re: [RFC PATCH 19/66] Hexagon instruction utility functions
Quoted 32 lines · Taylor Simpson
Utility functions called by various instructions
Signed-off-by Taylor Simpson <[email protected]>--- target/hexagon/arch.c | 664 +++++++++++++++++++++++++++++++++ target/hexagon/arch.h | 62 ++++ target/hexagon/conv_emu.c | 370 +++++++++++++++++++ target/hexagon/conv_emu.h | 50 +++ target/hexagon/fma_emu.c | 918 ++++++++++++++++++++++++++++++++++++++++++++++ target/hexagon/fma_emu.h | 30 ++ 6 files changed, 2094 insertions(+)create mode 100644
target/hexagon/arch.c
create mode 100644target/hexagon/arch.h
create mode 100644target/hexagon/conv_emu.c
create mode 100644target/hexagon/conv_emu.h
create mode 100644target/hexagon/fma_emu.c
create mode 100644target/hexagon/fma_emu.htarget/hexagon/arch.c new file +8
-0@@ -0,0 +1,664 @@ +/* +* Copyright (c) 2019 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. +*
target/hexagon/arch.c line 18
Quoted 10 lines
target/hexagon/arch.c new file +10
-0+* 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>
You don't need this one, "qemu/osdep.h" include it for you. Please include it first however.
Quoted 2,107 lines
target/hexagon/arch.c new file +646
-0+#include <math.h> +#include "qemu/osdep.h" +#include "fma_emu.h" +#include "arch.h" +#include "macros.h" + +/* +* These three tables are used by the cabacdecbin instruction +*/ +size1u_t rLPS_table_64x4[64 ][4 ] = { + {128 ,176 ,208 ,240 }, + {128 ,167 ,197 ,227 }, + {128 ,158 ,187 ,216 }, + {123 ,150 ,178 ,205 }, + {116 ,142 ,169 ,195 }, + {111 ,135 ,160 ,185 }, + {105 ,128 ,152 ,175 }, + {100 ,122 ,144 ,166 }, + {95 ,116 ,137 ,158 }, + {90 ,110 ,130 ,150 }, + {85 ,104 ,123 ,142 }, + {81 ,99 ,117 ,135 }, + {77 ,94 ,111 ,128 }, + {73 ,89 ,105 ,122 }, + {69 ,85 ,100 ,116 }, + {66 ,80 ,95 ,110 }, + {62 ,76 ,90 ,104 }, + {59 ,72 ,86 ,99 }, + {56 ,69 ,81 ,94 }, + {53 ,65 ,77 ,89 }, + {51 ,62 ,73 ,85 }, + {48 ,59 ,69 ,80 }, + {46 ,56 ,66 ,76 }, + {43 ,53 ,63 ,72 }, + {41 ,50 ,59 ,69 }, + {39 ,48 ,56 ,65 }, + {37 ,45 ,54 ,62 }, + {35 ,43 ,51 ,59 }, + {33 ,41 ,48 ,56 }, + {32 ,39 ,46 ,53 }, + {30 ,37 ,43 ,50 }, + {29 ,35 ,41 ,48 }, + {27 ,33 ,39 ,45 }, + {26 ,31 ,37 ,43 }, + {24 ,30 ,35 ,41 }, + {23 ,28 ,33 ,39 }, + {22 ,27 ,32 ,37 }, + {21 ,26 ,30 ,35 }, + {20 ,24 ,29 ,33 }, + {19 ,23 ,27 ,31 }, + {18 ,22 ,26 ,30 }, + {17 ,21 ,25 ,28 }, + {16 ,20 ,23 ,27 }, + {15 ,19 ,22 ,25 }, + {14 ,18 ,21 ,24 }, + {14 ,17 ,20 ,23 }, + {13 ,16 ,19 ,22 }, + {12 ,15 ,18 ,21 }, + {12 ,14 ,17 ,20 }, + {11 ,14 ,16 ,19 }, + {11 ,13 ,15 ,18 }, + {10 ,12 ,15 ,17 }, + {10 ,12 ,14 ,16 }, + {9 ,11 ,13 ,15 }, + {9 ,11 ,12 ,14 }, + {8 ,10 ,12 ,14 }, + {8 ,9 ,11 ,13 }, + {7 ,9 ,11 ,12 }, + {7 ,9 ,10 ,12 }, + {7 ,8 ,10 ,11 }, + {6 ,8 ,9 ,11 }, + {6 ,7 ,9 ,10 }, + {6 ,7 ,8 ,9 }, + {2 ,2 ,2 ,2 } +}; + +size1u_t AC_next_state_MPS_64[64 ] = { +1 ,2 ,3 ,4 ,5 ,6 ,7 ,8 ,9 ,10 , +11 ,12 ,13 ,14 ,15 ,16 ,17 ,18 ,19 ,20 , +21 ,22 ,23 ,24 ,25 ,26 ,27 ,28 ,29 ,30 , +31 ,32 ,33 ,34 ,35 ,36 ,37 ,38 ,39 ,40 , +41 ,42 ,43 ,44 ,45 ,46 ,47 ,48 ,49 ,50 , +51 ,52 ,53 ,54 ,55 ,56 ,57 ,58 ,59 ,60 , +61 ,62 ,62 ,63 +}; + + +size1u_t AC_next_state_LPS_64[64 ] = { +0 ,0 ,1 ,2 ,2 ,4 ,4 ,5 ,6 ,7 , +8 ,9 ,9 ,11 ,11 ,12 ,13 ,13 ,15 ,15 , +16 ,16 ,18 ,18 ,19 ,19 ,21 ,21 ,22 ,22 , +23 ,24 ,24 ,25 ,26 ,26 ,27 ,27 ,28 ,29 , +29 ,30 ,30 ,30 ,31 ,32 ,32 ,33 ,33 ,33 , +34 ,34 ,35 ,35 ,35 ,36 ,36 ,36 ,37 ,37 , +37 ,38 ,38 ,63 +}; + +size4u_t fbrevaddr (size4u_t pointer) +{ +size4u_t offset = pointer &0xffff ; +size4u_t brevoffset =0 ; +int i; + +for (i =0 ; i <16 ; i++) { +fSETBIT (i, brevoffset, (fGETBIT ((15 - i), offset))); + } +return (pointer &0xffff0000 ) | brevoffset; +} + +/* +* Counting bits set, Brian Kernighan's way +* Brian Kernighan's method goes through as many iterations as there are +* set bits. So if we have a 32-bit word with only the high bit set, +* then it will only go once through the loop. +*/ +size4u_t count_ones_2 (size2u_t src) +{ +int ret; +for (ret =0 ; src; ret++) { + src &= src -1 ;/* clear the least significant bit set */ + } +return ret; +} + +size4u_t count_ones_4 (size4u_t src) +{ +int ret; +for (ret =0 ; src; ret++) { + src &= src -1 ;/* clear the least significant bit set */ + } +return ret; +} + +size4u_t count_ones_8 (size8u_t src) +{ +int ret; +for (ret =0 ; src; ret++) { + src &= src -1 ;/* clear the least significant bit set */ + } +return ret; +} + +size4u_t count_leading_ones_8 (size8u_t src) +{ +int ret; +for (ret =0 ; src &0x8000000000000000LL ; src <<=1 ) { + ret++; + } +return ret; +} + + +size4u_t count_leading_ones_4 (size4u_t src) +{ +int ret; +for (ret =0 ; src &0x80000000 ; src <<=1 ) { + ret++; + } +return ret; +} + +size4u_t count_leading_ones_2 (size2u_t src) +{ +int ret; +for (ret =0 ; src &0x8000 ; src <<=1 ) { + ret++; + } +return ret; +} + +size4u_t count_leading_ones_1 (size1u_t src) +{ +int ret; +for (ret =0 ; src &0x80 ; src <<=1 ) { + ret++; + } +return ret; +} + +#define BITS_MASK_8 0x5555555555555555ULL +#define PAIR_MASK_8 0x3333333333333333ULL +#define NYBL_MASK_8 0x0f0f0f0f0f0f0f0fULL +#define BYTE_MASK_8 0x00ff00ff00ff00ffULL +#define HALF_MASK_8 0x0000ffff0000ffffULL +#define WORD_MASK_8 0x00000000ffffffffULL + +size8u_t reverse_bits_8 (size8u_t src) +{ + src = ((src >>1 ) &BITS_MASK_8 ) | ((src &BITS_MASK_8 ) <<1 ); + src = ((src >>2 ) &PAIR_MASK_8 ) | ((src &PAIR_MASK_8 ) <<2 ); + src = ((src >>4 ) &NYBL_MASK_8 ) | ((src &NYBL_MASK_8 ) <<4 ); + src = ((src >>8 ) &BYTE_MASK_8 ) | ((src &BYTE_MASK_8 ) <<8 ); + src = ((src >>16 ) &HALF_MASK_8 ) | ((src &HALF_MASK_8 ) <<16 ); + src = ((src >>32 ) &WORD_MASK_8 ) | ((src &WORD_MASK_8 ) <<32 ); +return src; +} + + +#define BITS_MASK_4 0x55555555ULL +#define PAIR_MASK_4 0x33333333ULL +#define NYBL_MASK_4 0x0f0f0f0fULL +#define BYTE_MASK_4 0x00ff00ffULL +#define HALF_MASK_4 0x0000ffffULL + +size4u_t reverse_bits_4 (size4u_t src) +{ + src = ((src >>1 ) &BITS_MASK_4 ) | ((src &BITS_MASK_4 ) <<1 ); + src = ((src >>2 ) &PAIR_MASK_4 ) | ((src &PAIR_MASK_4 ) <<2 ); + src = ((src >>4 ) &NYBL_MASK_4 ) | ((src &NYBL_MASK_4 ) <<4 ); + src = ((src >>8 ) &BYTE_MASK_4 ) | ((src &BYTE_MASK_4 ) <<8 ); + src = ((src >>16 ) &HALF_MASK_4 ) | ((src &HALF_MASK_4 ) <<16 ); +return src; +} + +#define BITS_MASK_2 0x5555ULL +#define PAIR_MASK_2 0x3333ULL +#define NYBL_MASK_2 0x0f0fULL +#define BYTE_MASK_2 0x00ffULL +#define HALF_MASK_2 0x0000ULL + +size4u_t reverse_bits_2 (size2u_t src) +{ + src = ((src >>1 ) &BITS_MASK_2 ) | ((src &BITS_MASK_2 ) <<1 ); + src = ((src >>2 ) &PAIR_MASK_2 ) | ((src &PAIR_MASK_2 ) <<2 ); + src = ((src >>4 ) &NYBL_MASK_2 ) | ((src &NYBL_MASK_2 ) <<4 ); + src = ((src >>8 ) &BYTE_MASK_2 ) | ((src &BYTE_MASK_2 ) <<8 ); +return src; +} + +#define BITS_MASK_1 0x55ULL +#define PAIR_MASK_1 0x33ULL +#define NYBL_MASK_1 0x0fULL +#define BYTE_MASK_1 0x00ULL +#define HALF_MASK_1 0x00ULL + +size4u_t reverse_bits_1 (size1u_t src) +{ + src = ((src >>1 ) &BITS_MASK_1 ) | ((src &BITS_MASK_1 ) <<1 ); + src = ((src >>2 ) &PAIR_MASK_1 ) | ((src &PAIR_MASK_1 ) <<2 ); + src = ((src >>4 ) &NYBL_MASK_1 ) | ((src &NYBL_MASK_1 ) <<4 ); +return src; +} + +size8u_t exchange (size8u_t bits,size4u_t cntrl) +{ +int i; +size4u_t mask =1 <<31 ; +size8u_t mask0 =0x1LL <<62 ; +size8u_t mask1 =0x2LL <<62 ; +size8u_t outbits =0 ; +size8u_t b0, b1; + +for (i =0 ; i <32 ; i++) { + b0 = (bits & mask0) >> (2 * i); + b1 = (bits & mask1) >> (2 * i); +if (cntrl & mask) { + outbits |= (b1 >>1 ) | (b0 <<1 ); + }else { + outbits |= (b1 | b0); + } + outbits <<=2 ; + mask >>=1 ; + mask0 >>=2 ; + mask1 >>=2 ; + } +return outbits; +} + +size8u_t interleave (size4u_t odd,size4u_t even) +{ +/* Convert to long long */ +size8u_t myodd = odd; +size8u_t myeven = even; +/* First, spread bits out */ + myodd = (myodd | (myodd <<16 )) &HALF_MASK_8 ; + myeven = (myeven | (myeven <<16 )) &HALF_MASK_8 ; + myodd = (myodd | (myodd <<8 )) &BYTE_MASK_8 ; + myeven = (myeven | (myeven <<8 )) &BYTE_MASK_8 ; + myodd = (myodd | (myodd <<4 )) &NYBL_MASK_8 ; + myeven = (myeven | (myeven <<4 )) &NYBL_MASK_8 ; + myodd = (myodd | (myodd <<2 )) &PAIR_MASK_8 ; + myeven = (myeven | (myeven <<2 )) &PAIR_MASK_8 ; + myodd = (myodd | (myodd <<1 )) &BITS_MASK_8 ; + myeven = (myeven | (myeven <<1 )) &BITS_MASK_8 ; +/* Now OR together */ +return myeven | (myodd <<1 ); +} + +size8u_t deinterleave (size8u_t src) +{ +/* Get odd and even bits */ +size8u_t myodd = ((src >>1 ) &BITS_MASK_8 ); +size8u_t myeven = (src &BITS_MASK_8 ); + +/* Unspread bits */ + myeven = (myeven | (myeven >>1 )) &PAIR_MASK_8 ; + myodd = (myodd | (myodd >>1 )) &PAIR_MASK_8 ; + myeven = (myeven | (myeven >>2 )) &NYBL_MASK_8 ; + myodd = (myodd | (myodd >>2 )) &NYBL_MASK_8 ; + myeven = (myeven | (myeven >>4 )) &BYTE_MASK_8 ; + myodd = (myodd | (myodd >>4 )) &BYTE_MASK_8 ; + myeven = (myeven | (myeven >>8 )) &HALF_MASK_8 ; + myodd = (myodd | (myodd >>8 )) &HALF_MASK_8 ; + myeven = (myeven | (myeven >>16 )) &WORD_MASK_8 ; + myodd = (myodd | (myodd >>16 )) &WORD_MASK_8 ; + +/* Return odd bits in upper half */ +return myeven | (myodd <<32 ); +} + +size4u_t carry_from_add64 (size8u_t a,size8u_t b,size4u_t c) +{ +size8u_t tmpa, tmpb, tmpc; + tmpa =fGETUWORD (0 , a); + tmpb =fGETUWORD (0 , b); + tmpc = tmpa + tmpb + c; + tmpa =fGETUWORD (1 , a); + tmpb =fGETUWORD (1 , b); + tmpc = tmpa + tmpb +fGETUWORD (1 , tmpc); + tmpc =fGETUWORD (1 , tmpc); +return tmpc; +} + +size4s_t conv_round (size4s_t a,int n) +{ +size8s_t val; + +if (n ==0 ) { + val = a; + }else if ((a & ((1 << (n -1 )) -1 )) ==0 ) {/* N-1..0 all zero? */ +/* Add LSB from int part */ + val = ((fSE32_64 (a)) + (size8s_t) (((size4u_t) ((1 << n) & a)) >>1 )); + }else { + val = ((fSE32_64 (a)) + (1 << (n -1 ))); + } + + val = val >> n; +return (size4s_t )val; +} + +size16s_t cast8s_to_16s (size8s_t a) +{ +size16s_t result = {.hi =0 , .lo =0 }; + result.lo = a; +if (a <0 ) { + result.hi =-1 ; + } +return result; +} + +size8s_t cast16s_to_8s (size16s_t a) +{ +return a.lo; +} + +size4s_t cast16s_to_4s (size16s_t a) +{ +return (size4s_t )a.lo; +} + +size16s_t add128 (size16s_t a,size16s_t b) +{ +size16s_t result = {.hi =0 , .lo =0 }; + result.lo = a.lo + b.lo; + result.hi = a.hi + b.hi; + +if (result.lo < b.lo) { + result.hi++; + } + +return result; +} + +size16s_t sub128 (size16s_t a,size16s_t b) +{ +size16s_t result = {.hi =0 , .lo =0 }; + result.lo = a.lo - b.lo; + result.hi = a.hi - b.hi; +if (result.lo > a.lo) { + result.hi--; + } + +return result; +} + +size16s_t shiftr128 (size16s_t a,size4u_t n) +{ +size16s_t result; + result.lo = (a.lo >> n) | (a.hi << (64 - n)); + result.hi = a.hi >> n; +return result; +} + +size16s_t shiftl128 (size16s_t a,size4u_t n) +{ +size16s_t result; + result.lo = a.lo << n; + result.hi = (a.hi << n) | (a.lo >> (64 - n)); +return result; +} + +size16s_t and128 (size16s_t a,size16s_t b) +{ +size16s_t result; + result.lo = a.lo & b.lo; + result.hi = a.hi & b.hi; +return result; +} + +/* Floating Point Stuff */ + +static const int roundingmodes[] = { +FE_TONEAREST , +FE_TOWARDZERO , +FE_DOWNWARD , +FE_UPWARD +}; + +void arch_fpop_start (CPUHexagonState *env) +{ +fegetenv (&env->fenv); +feclearexcept (FE_ALL_EXCEPT ); +fesetround (roundingmodes[fREAD_REG_FIELD (USR ,USR_FPRND )]); +} + +#define NOTHING /* Don't do anything */ + +#define TEST_FLAG (LIBCF ,MYF ,MYE ) \ + do { \ + if (fetestexcept(LIBCF)) { \ + if (GET_USR_FIELD(USR_##MYF) == 0) { \ + SET_USR_FIELD(USR_##MYF, 1); \ + if (GET_USR_FIELD(USR_##MYE)) { \ + NOTHING \ + } \ + } \ + } \ + } while (0) + +void arch_fpop_end (CPUHexagonState *env) +{ +if (fetestexcept (FE_ALL_EXCEPT )) { +TEST_FLAG (FE_INEXACT ,FPINPF ,FPINPE ); +TEST_FLAG (FE_DIVBYZERO ,FPDBZF ,FPDBZE ); +TEST_FLAG (FE_INVALID ,FPINVF ,FPINVE ); +TEST_FLAG (FE_OVERFLOW ,FPOVFF ,FPOVFE ); +TEST_FLAG (FE_UNDERFLOW ,FPUNFF ,FPUNFE ); + } +fesetenv (&env->fenv); +} + +#undef TEST_FLAG + + +void arch_raise_fpflag (unsigned int flags) +{ +feraiseexcept (flags); +} + +int arch_sf_recip_common (size4s_t *Rs,size4s_t *Rt,size4s_t *Rd,int *adjust) +{ +int n_class; +int d_class; +int n_exp; +int d_exp; +int ret =0 ; +size4s_t RsV, RtV, RdV; +int PeV =0 ; + RsV = *Rs; + RtV = *Rt; + n_class =fpclassify (fFLOAT (RsV)); + d_class =fpclassify (fFLOAT (RtV)); +if ((n_class ==FP_NAN ) && (d_class ==FP_NAN )) { +if (fGETBIT (22 , RsV & RtV) ==0 ) { +fRAISEFLAGS (FE_INVALID ); + } + RdV = RsV = RtV =fSFNANVAL (); + }else if (n_class ==FP_NAN ) { +if (fGETBIT (22 , RsV) ==0 ) { +fRAISEFLAGS (FE_INVALID ); + } + RdV = RsV = RtV =fSFNANVAL (); + }else if (d_class ==FP_NAN ) { +/* EJP: or put NaN in num/den fixup? */ +if (fGETBIT (22 , RtV) ==0 ) { +fRAISEFLAGS (FE_INVALID ); + } + RdV = RsV = RtV =fSFNANVAL (); + }else if ((n_class ==FP_INFINITE ) && (d_class ==FP_INFINITE )) { +/* EJP: or put Inf in num fixup? */ + RdV = RsV = RtV =fSFNANVAL (); +fRAISEFLAGS (FE_INVALID ); + }else if ((n_class ==FP_ZERO ) && (d_class ==FP_ZERO )) { +/* EJP: or put zero in num fixup? */ + RdV = RsV = RtV =fSFNANVAL (); +fRAISEFLAGS (FE_INVALID ); + }else if (d_class ==FP_ZERO ) { +/* EJP: or put Inf in num fixup? */ + RsV =fSFINFVAL (RsV ^ RtV); + RtV =fSFONEVAL (0 ); + RdV =fSFONEVAL (0 ); +if (n_class !=FP_INFINITE ) { +fRAISEFLAGS (FE_DIVBYZERO ); + } + }else if (d_class ==FP_INFINITE ) { + RsV =0x80000000 & (RsV ^ RtV); + RtV =fSFONEVAL (0 ); + RdV =fSFONEVAL (0 ); + }else if (n_class ==FP_ZERO ) { +/* EJP: Does this just work itself out? */ +/* EJP: No, 0/Inf causes problems. */ + RsV =0x80000000 & (RsV ^ RtV); + RtV =fSFONEVAL (0 ); + RdV =fSFONEVAL (0 ); + }else if (n_class ==FP_INFINITE ) { +/* EJP: Does this just work itself out? */ + RsV =fSFINFVAL (RsV ^ RtV); + RtV =fSFONEVAL (0 ); + RdV =fSFONEVAL (0 ); + }else { + PeV =0x00 ; +/* Basic checks passed */ + n_exp =fSF_GETEXP (RsV); + d_exp =fSF_GETEXP (RtV); +if ((n_exp - d_exp +fSF_BIAS ()) <=fSF_MANTBITS ()) { +/* Near quotient underflow / inexact Q */ + PeV =0x80 ; + RtV =fSF_MUL_POW2 (RtV,-64 ); + RsV =fSF_MUL_POW2 (RsV,64 ); + }else if ((n_exp - d_exp +fSF_BIAS ()) > (fSF_MAXEXP () -24 )) { +/* Near quotient overflow */ + PeV =0x40 ; + RtV =fSF_MUL_POW2 (RtV,32 ); + RsV =fSF_MUL_POW2 (RsV,-32 ); + }else if (n_exp <=fSF_MANTBITS () +2 ) { + RtV =fSF_MUL_POW2 (RtV,64 ); + RsV =fSF_MUL_POW2 (RsV,64 ); + }else if (d_exp <=1 ) { + RtV =fSF_MUL_POW2 (RtV,32 ); + RsV =fSF_MUL_POW2 (RsV,32 ); + }else if (d_exp >252 ) { + RtV =fSF_MUL_POW2 (RtV,-32 ); + RsV =fSF_MUL_POW2 (RsV,-32 ); + } + RdV =0 ; + ret =1 ; + } + *Rs = RsV; + *Rt = RtV; + *Rd = RdV; + *adjust = PeV; +return ret; +} + +int arch_sf_invsqrt_common (size4s_t *Rs,size4s_t *Rd,int *adjust) +{ +int r_class; +size4s_t RsV, RdV; +int PeV =0 ; +int r_exp; +int ret =0 ; + RsV = *Rs; + r_class =fpclassify (fFLOAT (RsV)); +if (r_class ==FP_NAN ) { +if (fGETBIT (22 , RsV) ==0 ) { +fRAISEFLAGS (FE_INVALID ); + } + RdV = RsV =fSFNANVAL (); + }else if (fFLOAT (RsV) <0.0 ) { +/* Negative nonzero values are NaN */ +fRAISEFLAGS (FE_INVALID ); + RsV =fSFNANVAL (); + RdV =fSFNANVAL (); + }else if (r_class ==FP_INFINITE ) { +/* EJP: or put Inf in num fixup? */ + RsV =fSFINFVAL (-1 ); + RdV =fSFINFVAL (-1 ); + }else if (r_class ==FP_ZERO ) { +/* EJP: or put zero in num fixup? */ + RsV = RsV; + RdV =fSFONEVAL (0 ); + }else { + PeV =0x00 ; +/* Basic checks passed */ + r_exp =fSF_GETEXP (RsV); +if (r_exp <=24 ) { + RsV =fSF_MUL_POW2 (RsV,64 ); + PeV =0xe0 ; + } + RdV =0 ; + ret =1 ; + } + *Rs = RsV; + *Rd = RdV; + *adjust = PeV; +return ret; +} + +int arch_recip_lookup (int index) +{ + index &=0x7f ; +unsigned const int roundrom[128 ] = { +0x0fe ,0x0fa ,0x0f6 ,0x0f2 ,0x0ef ,0x0eb ,0x0e7 ,0x0e4 , +0x0e0 ,0x0dd ,0x0d9 ,0x0d6 ,0x0d2 ,0x0cf ,0x0cc ,0x0c9 , +0x0c6 ,0x0c2 ,0x0bf ,0x0bc ,0x0b9 ,0x0b6 ,0x0b3 ,0x0b1 , +0x0ae ,0x0ab ,0x0a8 ,0x0a5 ,0x0a3 ,0x0a0 ,0x09d ,0x09b , +0x098 ,0x096 ,0x093 ,0x091 ,0x08e ,0x08c ,0x08a ,0x087 , +0x085 ,0x083 ,0x080 ,0x07e ,0x07c ,0x07a ,0x078 ,0x075 , +0x073 ,0x071 ,0x06f ,0x06d ,0x06b ,0x069 ,0x067 ,0x065 , +0x063 ,0x061 ,0x05f ,0x05e ,0x05c ,0x05a ,0x058 ,0x056 , +0x054 ,0x053 ,0x051 ,0x04f ,0x04e ,0x04c ,0x04a ,0x049 , +0x047 ,0x045 ,0x044 ,0x042 ,0x040 ,0x03f ,0x03d ,0x03c , +0x03a ,0x039 ,0x037 ,0x036 ,0x034 ,0x033 ,0x032 ,0x030 , +0x02f ,0x02d ,0x02c ,0x02b ,0x029 ,0x028 ,0x027 ,0x025 , +0x024 ,0x023 ,0x021 ,0x020 ,0x01f ,0x01e ,0x01c ,0x01b , +0x01a ,0x019 ,0x017 ,0x016 ,0x015 ,0x014 ,0x013 ,0x012 , +0x011 ,0x00f ,0x00e ,0x00d ,0x00c ,0x00b ,0x00a ,0x009 , +0x008 ,0x007 ,0x006 ,0x005 ,0x004 ,0x003 ,0x002 ,0x000 , + }; +return roundrom[index]; +}; + +int arch_invsqrt_lookup (int index) +{ + index &=0x7f ; +unsigned const int roundrom[128 ] = { +0x069 ,0x066 ,0x063 ,0x061 ,0x05e ,0x05b ,0x059 ,0x057 , +0x054 ,0x052 ,0x050 ,0x04d ,0x04b ,0x049 ,0x047 ,0x045 , +0x043 ,0x041 ,0x03f ,0x03d ,0x03b ,0x039 ,0x037 ,0x036 , +0x034 ,0x032 ,0x030 ,0x02f ,0x02d ,0x02c ,0x02a ,0x028 , +0x027 ,0x025 ,0x024 ,0x022 ,0x021 ,0x01f ,0x01e ,0x01d , +0x01b ,0x01a ,0x019 ,0x017 ,0x016 ,0x015 ,0x014 ,0x012 , +0x011 ,0x010 ,0x00f ,0x00d ,0x00c ,0x00b ,0x00a ,0x009 , +0x008 ,0x007 ,0x006 ,0x005 ,0x004 ,0x003 ,0x002 ,0x001 , +0x0fe ,0x0fa ,0x0f6 ,0x0f3 ,0x0ef ,0x0eb ,0x0e8 ,0x0e4 , +0x0e1 ,0x0de ,0x0db ,0x0d7 ,0x0d4 ,0x0d1 ,0x0ce ,0x0cb , +0x0c9 ,0x0c6 ,0x0c3 ,0x0c0 ,0x0be ,0x0bb ,0x0b8 ,0x0b6 , +0x0b3 ,0x0b1 ,0x0af ,0x0ac ,0x0aa ,0x0a8 ,0x0a5 ,0x0a3 , +0x0a1 ,0x09f ,0x09d ,0x09b ,0x099 ,0x097 ,0x095 ,0x093 , +0x091 ,0x08f ,0x08d ,0x08b ,0x089 ,0x087 ,0x086 ,0x084 , +0x082 ,0x080 ,0x07f ,0x07d ,0x07b ,0x07a ,0x078 ,0x077 , +0x075 ,0x074 ,0x072 ,0x071 ,0x06f ,0x06e ,0x06c ,0x06b , + }; +return roundrom[index]; +}; +target/hexagon/arch.h new file +62
-0@@ -0,0 +1,62 @@ +/* +* Copyright (c) 2019 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/>. +*/ + +#ifndef ARCH_H +#define ARCH_H + +#include "cpu.h" +#include "hex_arch_types.h" + +extern size1u_t rLPS_table_64x4[64 ][4 ]; +extern size1u_t AC_next_state_MPS_64[64 ]; +extern size1u_t AC_next_state_LPS_64[64 ]; + +extern size4u_t fbrevaddr (size4u_t pointer); +extern size4u_t count_ones_2 (size2u_t src); +extern size4u_t count_ones_4 (size4u_t src); +extern size4u_t count_ones_8 (size8u_t src); +extern size4u_t count_leading_ones_8 (size8u_t src); +extern size4u_t count_leading_ones_4 (size4u_t src); +extern size4u_t count_leading_ones_2 (size2u_t src); +extern size4u_t count_leading_ones_1 (size1u_t src); +extern size8u_t reverse_bits_8 (size8u_t src); +extern size4u_t reverse_bits_4 (size4u_t src); +extern size4u_t reverse_bits_2 (size2u_t src); +extern size4u_t reverse_bits_1 (size1u_t src); +extern size8u_t exchange (size8u_t bits,size4u_t cntrl); +extern size8u_t interleave (size4u_t odd,size4u_t even); +extern size8u_t deinterleave (size8u_t src); +extern size4u_t carry_from_add64 (size8u_t a,size8u_t b,size4u_t c); +extern size4s_t conv_round (size4s_t a,int n); +extern size16s_t cast8s_to_16s (size8s_t a); +extern size8s_t cast16s_to_8s (size16s_t a); +extern size4s_t cast16s_to_4s (size16s_t a); +extern size16s_t add128 (size16s_t a,size16s_t b); +extern size16s_t sub128 (size16s_t a,size16s_t b); +extern size16s_t shiftr128 (size16s_t a,size4u_t n); +extern size16s_t shiftl128 (size16s_t a,size4u_t n); +extern size16s_t and128 (size16s_t a,size16s_t b); +extern void arch_fpop_start (CPUHexagonState *env); +extern void arch_fpop_end (CPUHexagonState *env); +extern void arch_raise_fpflag (unsigned int flags); +extern int arch_sf_recip_common (size4s_t *Rs,size4s_t *Rt,size4s_t *Rd, +int *adjust); +extern int arch_sf_invsqrt_common (size4s_t *Rs,size4s_t *Rd,int *adjust); +extern int arch_recip_lookup (int index); +extern int arch_invsqrt_lookup (int index); + +#endif target/hexagon/conv_emu.c new file +370
-0@@ -0,0 +1,370 @@ +/* +* Copyright (c) 2019 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 "qemu/osdep.h" +#include "hex_arch_types.h" +#include "macros.h" +#include <stdio.h> +#include <math.h> +#include "conv_emu.h" + +#define isz (X ) (fpclassify(X) == FP_ZERO) +#define DF_BIAS 1023 +#define SF_BIAS 127 + +#define LL_MAX_POS 0x7fffffffffffffffULL +#define MAX_POS 0x7fffffffU + +#ifdef VCPP +/* +* Visual C isn't GNU C and doesn't have __builtin_clzll +*/ + +static int __builtin_clzll (unsigned long long int input) +{ +int total =0 ; +if (input ==0 ) { +return 64 ; + } + total += ((input >> (total +32 )) !=0 ) ?32 :0 ; + total += ((input >> (total +16 )) !=0 ) ?16 :0 ; + total += ((input >> (total +8 )) !=0 ) ?8 :0 ; + total += ((input >> (total +4 )) !=0 ) ?4 :0 ; + total += ((input >> (total +2 )) !=0 ) ?2 :0 ; + total += ((input >> (total +1 )) !=0 ) ?1 :0 ; +return 63 - total; +} +#endif + +typedef union { +double f; +size8u_t i; +struct { +size8u_t mant:52 ; +size8u_t exp:11 ; +size8u_t sign:1 ; + } x; +}df_t ; + + +typedef union { +float f; +size4u_t i; +struct { +size4u_t mant:23 ; +size4u_t exp:8 ; +size4u_t sign:1 ; + } x; +}sf_t ; + + +#define MAKE_CONV_8U_TO_XF_N (FLOATID ,BIGFLOATID ,RETTYPE ) \ +static RETTYPE conv_8u_to_##FLOATID##_n(size8u_t in, int negate) \ +{ \ + FLOATID##_t x; \ + size8u_t tmp, truncbits, shamt; \ + int leading_zeros; \ + if (in == 0) { \ + return 0.0; \ + } \ + leading_zeros = __builtin_clzll(in); \ + tmp = in << (leading_zeros); \ + tmp <<= 1; \ + shamt = 64 - f##BIGFLOATID##_MANTBITS(); \ + truncbits = tmp & ((1ULL << (shamt)) - 1); \ + tmp >>= shamt; \ + if (truncbits != 0) { \ + feraiseexcept(FE_INEXACT); \ + switch (fegetround()) { \ + case FE_TOWARDZERO: \ + break; \ + case FE_DOWNWARD: \ + if (negate) { \ + tmp += 1; \ + } \ + break; \ + case FE_UPWARD: \ + if (!negate) { \ + tmp += 1; \ + } \ + break; \ + default: \ + if ((truncbits & ((1ULL << (shamt - 1)) - 1)) == 0) { \ + tmp += (tmp & 1); \ + } else { \ + tmp += ((truncbits >> (shamt - 1)) & 1); \ + } \ + break; \ + } \ + } \ + if (((tmp << shamt) >> shamt) != tmp) { \ + leading_zeros--; \ + } \ + x.x.mant = tmp; \ + x.x.exp = BIGFLOATID##_BIAS + f##BIGFLOATID##_MANTBITS() - \ + leading_zeros + shamt - 1; \ + x.x.sign = negate; \ + return x.f; \ +} + +MAKE_CONV_8U_TO_XF_N(df, DF, double) +MAKE_CONV_8U_TO_XF_N(sf, SF, float) + +double conv_8u_to_df (size8u_t in) +{ +return conv_8u_to_df_n (in,0 ); +} + +double conv_8s_to_df (size8s_t in) +{ +if (in ==0x8000000000000000 ) { +return -0x1p63 ; + } +if (in <0 ) { +return conv_8u_to_df_n (-in,1 ); + }else { +return conv_8u_to_df_n (in,0 ); + } +} + +double conv_4u_to_df (size4u_t in) +{ +return conv_8u_to_df ((size8u_t ) in); +} + +double conv_4s_to_df (size4s_t in) +{ +return conv_8s_to_df (in); +} + +float conv_8u_to_sf (size8u_t in) +{ +return conv_8u_to_sf_n (in,0 ); +} + +float conv_8s_to_sf (size8s_t in) +{ +if (in ==0x8000000000000000 ) { +return -0x1p63 ; + } +if (in <0 ) { +return conv_8u_to_sf_n (-in,1 ); + }else { +return conv_8u_to_sf_n (in,0 ); + } +} + +float conv_4u_to_sf (size4u_t in) +{ +return conv_8u_to_sf (in); +} + +float conv_4s_to_sf (size4s_t in) +{ +return conv_8s_to_sf (in); +} + + +static size8u_t conv_df_to_8u_n (double in,int will_negate) +{ +df_t x; +int fracshift, endshift; +size8u_t tmp, truncbits; + x.f = in; +if (isinf (in)) { +feraiseexcept (FE_INVALID ); +if (in >0.0 ) { +return ~0ULL ; + }else { +return 0ULL ; + } + } +if (isnan (in)) { +feraiseexcept (FE_INVALID ); +return ~0ULL ; + } +if (isz (in)) { +return 0 ; + } +if (x.x.sign) { +feraiseexcept (FE_INVALID ); +return 0 ; + } +if (in <0.5 ) { +/* Near zero, captures large fracshifts, denorms, etc */ +feraiseexcept (FE_INEXACT ); +switch (fegetround ()) { +case FE_DOWNWARD : +if (will_negate) { +return 1 ; + }else { +return 0 ; + } +case FE_UPWARD : +if (!will_negate) { +return 1 ; + }else { +return 0 ; + } +default : +return 0 ;/* nearest or towards zero */ + } + } +if ((x.x.exp -DF_BIAS ) >=64 ) { +/* way too big */ +feraiseexcept (FE_INVALID ); +return ~0ULL ; + } + fracshift =fMAX (0 , (fDF_MANTBITS () - (x.x.exp -DF_BIAS ))); + endshift =fMAX (0 , ((x.x.exp -DF_BIAS -fDF_MANTBITS ()))); + tmp = x.x.mant | (1ULL <<fDF_MANTBITS ()); + truncbits = tmp & ((1ULL << fracshift) -1 ); + tmp >>= fracshift; +if (truncbits) { +/* Apply Rounding */ +feraiseexcept (FE_INEXACT ); +switch (fegetround ()) { +case FE_TOWARDZERO : +break ; +case FE_DOWNWARD : +if (will_negate) { + tmp +=1 ; + } +break ; +case FE_UPWARD : +if (!will_negate) { + tmp +=1 ; + } +break ; +default : +if ((truncbits & ((1ULL << (fracshift -1 )) -1 )) ==0 ) { +/* Exactly .5 */ + tmp += (tmp &1 ); + }else { + tmp += ((truncbits >> (fracshift -1 )) &1 ); + } + } + } +/* +* If we added one and it carried all the way out, +* check to see if overflow +*/ +if ((tmp & ((1ULL << (fDF_MANTBITS () +1 )) -1 )) ==0 ) { +if ((x.x.exp -DF_BIAS ) ==63 ) { +feclearexcept (FE_INEXACT ); +feraiseexcept (FE_INVALID ); +return ~0ULL ; + } + } + tmp <<= endshift; +return tmp; +} + +static size4u_t conv_df_to_4u_n (double in,int will_negate) +{ +size8u_t tmp; + tmp =conv_df_to_8u_n (in, will_negate); +if (tmp >0x00000000ffffffffULL ) { +feclearexcept (FE_INEXACT ); +feraiseexcept (FE_INVALID ); +return ~0U ; + } +return (size4u_t )tmp; +} + +size8u_t conv_df_to_8u (double in) +{ +return conv_df_to_8u_n (in,0 ); +} + +size4u_t conv_df_to_4u (double in) +{ +return conv_df_to_4u_n (in,0 ); +} + +size8s_t conv_df_to_8s (double in) +{ +size8u_t tmp; +df_t x; + x.f = in; +if (isnan (in)) { +feraiseexcept (FE_INVALID ); +return -1 ; + } +if (x.x.sign) { + tmp =conv_df_to_8u_n (-in,1 ); + }else { + tmp =conv_df_to_8u_n (in,0 ); + } +if (tmp > (LL_MAX_POS + x.x.sign)) { +feclearexcept (FE_INEXACT ); +feraiseexcept (FE_INVALID ); + tmp = (LL_MAX_POS + x.x.sign); + } +if (x.x.sign) { +return -tmp; + }else { +return tmp; + } +} + +size4s_t conv_df_to_4s (double in) +{ +size8u_t tmp; +df_t x; + x.f = in; +if (isnan (in)) { +feraiseexcept (FE_INVALID ); +return -1 ; + } +if (x.x.sign) { + tmp =conv_df_to_8u_n (-in,1 ); + }else { + tmp =conv_df_to_8u_n (in,0 ); + } +if (tmp > (MAX_POS + x.x.sign)) { +feclearexcept (FE_INEXACT ); +feraiseexcept (FE_INVALID ); + tmp = (MAX_POS + x.x.sign); + } +if (x.x.sign) { +return -tmp; + }else { +return tmp; + } +} + +size8u_t conv_sf_to_8u (float in) +{ +return conv_df_to_8u (in); +} + +size4u_t conv_sf_to_4u (float in) +{ +return conv_df_to_4u (in); +} + +size8s_t conv_sf_to_8s (float in) +{ +return conv_df_to_8s (in); +} + +size4s_t conv_sf_to_4s (float in) +{ +return conv_df_to_4s (in); +} +target/hexagon/conv_emu.h new file +50
-0@@ -0,0 +1,50 @@ +/* +* Copyright (c) 2019 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/>. +*/ + +#ifndef CONV_EMU_H +#define CONV_EMU_H + +#include "hex_arch_types.h" + +extern size8u_t conv_sf_to_8u (float in); +extern size4u_t conv_sf_to_4u (float in); +extern size8s_t conv_sf_to_8s (float in); +extern size4s_t conv_sf_to_4s (float in); + +extern size8u_t conv_df_to_8u (double in); +extern size4u_t conv_df_to_4u (double in); +extern size8s_t conv_df_to_8s (double in); +extern size4s_t conv_df_to_4s (double in); + +extern double conv_8u_to_df (size8u_t in); +extern double conv_4u_to_df (size4u_t in); +extern double conv_8s_to_df (size8s_t in); +extern double conv_4s_to_df (size4s_t in); + +extern float conv_8u_to_sf (size8u_t in); +extern float conv_4u_to_sf (size4u_t in); +extern float conv_8s_to_sf (size8s_t in); +extern float conv_4s_to_sf (size4s_t in); + +extern float conv_df_to_sf (double in); + +static inline double conv_sf_to_df (float in) +{ +return in; +} + +#endif target/hexagon/fma_emu.c new file +918
-0@@ -0,0 +1,918 @@ +/* +* Copyright (c) 2019 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 "qemu/osdep.h" + +#include <stdio.h> +#include <math.h> +#include "macros.h" +#include "conv_emu.h" +#include "fma_emu.h" + +#define DF_INF_EXP 0x7ff +#define DF_BIAS 1023 + +#define SF_INF_EXP 0xff +#define SF_BIAS 127 + +#define HF_INF_EXP 0x1f +#define HF_BIAS 15 + +#define WAY_BIG_EXP 4096 + +#define isz (X ) (fpclassify(X) == FP_ZERO) + +#define debug_fprintf (...)/* nothing */ + +typedef union { +double f; +size8u_t i; +struct { +size8u_t mant:52 ; +size8u_t exp:11 ; +size8u_t sign:1 ; + } x; +}df_t ; + +typedef union { +float f; +size4u_t i; +struct { +size4u_t mant:23 ; +size4u_t exp:8 ; +size4u_t sign:1 ; + } x; +}sf_t ; + +typedef struct { +union { +size8u_t low; +struct { +size4u_t w0; +size4u_t w1; + }; + }; +union { +size8u_t high; +struct { +size4u_t w3; +size4u_t w2; + }; + }; +}int128_t ; + +typedef struct { +int128_t mant; +size4s_t exp; +size1u_t sign; +size1u_t guard; +size1u_t round; +size1u_t sticky; +}xf_t ; + +static inline void xf_debug (const char *msg,xf_t a) +{ +debug_fprintf (stdout,"%s %c0x%016llx_%016llx /%d/%d/%d p%d\n" , msg, + a.sign ?'-' :'+' , a.mant.high, a.mant.low, a.guard, + a.round, a.sticky, a.exp); +} + +static inline void xf_init (xf_t *p) +{ + p->mant.low =0 ; + p->mant.high =0 ; + p->exp =0 ; + p->sign =0 ; + p->guard =0 ; + p->round =0 ; + p->sticky =0 ; +} + +static inline size8u_t df_getmant (df_t a) +{ +int class =fpclassify (a.f); +switch (class) { +case FP_NORMAL : +return a.x.mant |1ULL <<52 ; +case FP_ZERO : +return 0 ; +case FP_SUBNORMAL : +return a.x.mant; +default : +return -1 ; + }; +} + +static inline size4s_t df_getexp (df_t a) +{ +int class =fpclassify (a.f); +switch (class) { +case FP_NORMAL : +return a.x.exp; +case FP_SUBNORMAL : +return a.x.exp +1 ; +default : +return -1 ; + }; +} + +static inline size8u_t sf_getmant (sf_t a) +{ +int class =fpclassify (a.f); +switch (class) { +case FP_NORMAL : +return a.x.mant |1ULL <<23 ; +case FP_ZERO : +return 0 ; +case FP_SUBNORMAL : +return a.x.mant |0ULL ; +default : +return -1 ; + }; +} + +static inline size4s_t sf_getexp (sf_t a) +{ +int class =fpclassify (a.f); +switch (class) { +case FP_NORMAL : +return a.x.exp; +case FP_SUBNORMAL : +return a.x.exp +1 ; +default : +return -1 ; + }; +} + +static inline int128_t int128_mul_6464 (size8u_t ai,size8u_t bi) +{ +int128_t ret; +int128_t a, b; +size8u_t pp0, pp1a, pp1b, pp1s, pp2; + +debug_fprintf (stdout,"ai/bi: 0x%016llx/0x%016llx\n" , ai, bi); + + a.high = b.high =0 ; + a.low = ai; + b.low = bi; + pp0 = (size8u_t )a.w0 * (size8u_t )b.w0; + pp1a = (size8u_t )a.w1 * (size8u_t )b.w0; + pp1b = (size8u_t )b.w1 * (size8u_t )a.w0; + pp2 = (size8u_t )a.w1 * (size8u_t )b.w1; + +debug_fprintf (stdout, +"pp2/1b/1a/0: 0x%016llx/0x%016llx/0x%016llx/0x%016llx\n" , + pp2, pp1b, pp1a, pp0); + + pp1s = pp1a + pp1b; +if ((pp1s < pp1a) || (pp1s < pp1b)) { + pp2 += (1ULL <<32 ); + } + ret.low = pp0 + (pp1s <<32 ); +if ((ret.low < pp0) || (ret.low < (pp1s <<32 ))) { + pp2 +=1 ; + } + ret.high = pp2 + (pp1s >>32 ); + +debug_fprintf (stdout, +"pp1s/rethi/retlo: 0x%016llx/0x%016llx/0x%016llx\n" , + pp1s, ret.high, ret.low); + +return ret; +} + +static inline int128_t int128_shl (int128_t a,size4u_t amt) +{ +int128_t ret; +if (amt ==0 ) { +return a; + } +if (amt >128 ) { + ret.high =0 ; + ret.low =0 ; +return ret; + } +if (amt >=64 ) { + amt -=64 ; + a.high = a.low; + a.low =0 ; + } + ret.high = a.high << amt; + ret.high |= (a.low >> (64 - amt)); + ret.low = a.low << amt; +return ret; +} + +static inline int128_t int128_shr (int128_t a,size4u_t amt) +{ +int128_t ret; +if (amt ==0 ) { +return a; + } +if (amt >128 ) { + ret.high =0 ; + ret.low =0 ; +return ret; + } +if (amt >=64 ) { + amt -=64 ; + a.low = a.high; + a.high =0 ; + } + ret.low = a.low >> amt; + ret.low |= (a.high << (64 - amt)); + ret.high = a.high >> amt; +return ret; +} + +static inline int128_t int128_add (int128_t a,int128_t b) +{ +int128_t ret; + ret.low = a.low + b.low; +if ((ret.low < a.low) || (ret.low < b.low)) { +/* carry into high part */ + a.high +=1 ; + } + ret.high = a.high + b.high; +return ret; +} + +static inline int128_t int128_sub (int128_t a,int128_t b,int borrow) +{ +int128_t ret; + ret.low = a.low - b.low; +if (ret.low > a.low) { +/* borrow into high part */ + a.high -=1 ; + } + ret.high = a.high - b.high; +if (borrow ==0 ) { +return ret; + }else { + a.high =0 ; + a.low =1 ; +return int128_sub (ret, a,0 ); + } +} + +static inline int int128_gt (int128_t a,int128_t b) +{ +if (a.high == b.high) { +return a.low > b.low; + } +return a.high > b.high; +} + +static inline xf_t xf_norm_left (xf_t a) +{ + a.exp--; + a.mant =int128_shl (a.mant,1 ); + a.mant.low |= a.guard; + a.guard = a.round; + a.round = a.sticky; +return a; +} + +static inline xf_t xf_norm_right (xf_t a,int amt) +{ +if (amt >130 ) { + a.sticky |= + a.round | a.guard | (a.mant.low !=0 ) | (a.mant.high !=0 ); + a.guard = a.round = a.mant.high = a.mant.low =0 ; + a.exp += amt; +return a; + + } +while (amt >=64 ) { + a.sticky |= a.round | a.guard | (a.mant.low !=0 ); + a.guard = (a.mant.low >>63 ) &1 ; + a.round = (a.mant.low >>62 ) &1 ; + a.mant.low = a.mant.high; + a.mant.high =0 ; + a.exp +=64 ; + amt -=64 ; + } +while (amt >0 ) { + a.exp++; + a.sticky |= a.round; + a.round = a.guard; + a.guard = a.mant.low &1 ; + a.mant =int128_shr (a.mant,1 ); + amt--; + } +return a; +} + + +/* +* On the add/sub, we need to be able to shift out lots of bits, but need a +* sticky bit for what was shifted out, I think. +*/ +static xf_t xf_add (xf_t a,xf_t b); + +static inline xf_t xf_sub (xf_t a,xf_t b,int negate) +{ +xf_t ret; +xf_init (&ret); +int borrow; + +xf_debug ("-->Sub/a: " , a); +xf_debug ("-->Sub/b: " , b); + +if (a.sign != b.sign) { + b.sign = !b.sign; +return xf_add (a, b); + } +if (b.exp > a.exp) { +/* small - big == - (big - small) */ +return xf_sub (b, a, !negate); + } +if ((b.exp == a.exp) && (int128_gt (b.mant, a.mant))) { +/* small - big == - (big - small) */ +return xf_sub (b, a, !negate); + } + +xf_debug ("OK: Sub/a: " , a); +xf_debug ("OK: Sub/b: " , b); + +while (a.exp > b.exp) { +/* Try to normalize exponents: shrink a exponent and grow mantissa */ +if (a.mant.high & (1ULL <<62 )) { +/* Can't grow a any more */ +break ; + }else { + a =xf_norm_left (a); + } + } + +xf_debug ("norm_l: Sub/a: " , a); +xf_debug ("norm_l: Sub/b: " , b); + +while (a.exp > b.exp) { +/* Try to normalize exponents: grow b exponent and shrink mantissa */ +/* Keep around shifted out bits... we might need those later */ + b =xf_norm_right (b, a.exp - b.exp); + } + +xf_debug ("norm_r: Sub/a: " , a); +xf_debug ("norm_r: Sub/b: " , b); + +if ((int128_gt (b.mant, a.mant))) { +xf_debug ("retry: Sub/a: " , a); +xf_debug ("retry: Sub/b: " , b); +return xf_sub (b, a, !negate); + } + +/* OK, now things should be normalized! */ + ret.sign = a.sign; + ret.exp = a.exp; +assert (!int128_gt (b.mant, a.mant)); + borrow = (b.round <<2 ) | (b.guard <<1 ) | b.sticky; + ret.mant =int128_sub (a.mant, b.mant, (borrow !=0 )); + borrow =0 - borrow; + ret.guard = (borrow >>2 ) &1 ; + ret.round = (borrow >>1 ) &1 ; + ret.sticky = (borrow >>0 ) &1 ; +if (negate) { + ret.sign = !ret.sign; + } +return ret; +} + +static xf_t xf_add (xf_t a,xf_t b) +{ +xf_t ret; +xf_init (&ret); +xf_debug ("-->Add/a: " , a); +xf_debug ("-->Add/b: " , b); +if (a.sign != b.sign) { + b.sign = !b.sign; +return xf_sub (a, b,0 ); + } +if (b.exp > a.exp) { +/* small + big == (big + small) */ +return xf_add (b, a); + } +if ((b.exp == a.exp) &&int128_gt (b.mant, a.mant)) { +/* small + big == (big + small) */ +return xf_add (b, a); + } + +xf_debug ("OK? Add/a: " , a); +xf_debug ("OK? Add/b: " , b); + +while (a.exp > b.exp) { +/* Try to normalize exponents: shrink a exponent and grow mantissa */ +if (a.mant.high & (1ULL <<62 )) { +/* Can't grow a any more */ +break ; + }else { + a =xf_norm_left (a); + } + } + +xf_debug ("norm_l: Add/a: " , a); +xf_debug ("norm_l: Add/b: " , b); + +while (a.exp > b.exp) { +/* Try to normalize exponents: grow b exponent and shrink mantissa */ +/* Keep around shifted out bits... we might need those later */ + b =xf_norm_right (b, a.exp - b.exp); + } + +xf_debug ("norm_r: Add/a: " , a); +xf_debug ("norm_r: Add/b: " , b); + +/* OK, now things should be normalized! */ +if (int128_gt (b.mant, a.mant)) { +xf_debug ("retry: Add/a: " , a); +xf_debug ("retry: Add/b: " , b); +return xf_add (b, a); + }; + ret.sign = a.sign; + ret.exp = a.exp; +assert (!int128_gt (b.mant, a.mant)); + ret.mant =int128_add (a.mant, b.mant); + ret.guard = b.guard; + ret.round = b.round; + ret.sticky = b.sticky; +return ret; +} + +/* Return an infinity with the same sign as a */ +static inline df_t infinite_df_t (xf_t a) +{ +df_t ret; + ret.x.sign = a.sign; + ret.x.exp =DF_INF_EXP ; + ret.x.mant =0ULL ; +return ret; +} + +/* Return a maximum finite value with the same sign as a */ +static inline df_t maxfinite_df_t (xf_t a) +{ +df_t ret; + ret.x.sign = a.sign; + ret.x.exp =DF_INF_EXP -1 ; + ret.x.mant =0x000fffffffffffffULL ; +return ret; +} + +static inline df_t f2df_t (double in) +{ +df_t ret; + ret.f = in; +return ret; +} + +/* Return an infinity with the same sign as a */ +static inline sf_t infinite_sf_t (xf_t a) +{ +sf_t ret; + ret.x.sign = a.sign; + ret.x.exp =SF_INF_EXP ; + ret.x.mant =0ULL ; +return ret; +} + +/* Return a maximum finite value with the same sign as a */ +static inline sf_t maxfinite_sf_t (xf_t a) +{ +sf_t ret; + ret.x.sign = a.sign; + ret.x.exp =SF_INF_EXP -1 ; + ret.x.mant =0x007fffffUL ; +return ret; +} + +static inline sf_t f2sf_t (float in) +{ +sf_t ret; + ret.f = in; +return ret; +} + +#define GEN_XF_ROUND (TYPE ,MANTBITS ,INF_EXP ) \ +static inline TYPE xf_round_##TYPE(xf_t a) \ +{ \ + TYPE ret; \ + ret.i = 0; \ + ret.x.sign = a.sign; \ + if ((a.mant.high == 0) && (a.mant.low == 0) \ + && ((a.guard | a.round | a.sticky) == 0)) { \ +/* result zero */ \ + switch (fegetround()) { \ + case FE_DOWNWARD: \ + return f2##TYPE(-0.0); \ + default: \ + return f2##TYPE(0.0); \ + } \ + } \ + /* Normalize right */ \ + /* We want MANTBITS bits of mantissa plus the leading one. */ \ + /* That means that we want MANTBITS+1 bits, or 0x000000000000FF_FFFF */ \ + /* So we need to normalize right while the high word is non-zero and \ + * while the low word is nonzero when masked with 0xffe0_0000_0000_0000 */ \ + xf_debug("input: ", a); \ + while ((a.mant.high != 0) || ((a.mant.low >> (MANTBITS + 1)) != 0)) { \ + a = xf_norm_right(a, 1); \ + } \ + xf_debug("norm_right: ", a); \ + /* \ + * OK, now normalize left \ + * We want to normalize left until we have a leading one in bit 24 \ + * Theoretically, we only need to shift a maximum of one to the left if we \ + * shifted out lots of bits from B, or if we had no shift / 1 shift sticky \ + * shoudl be 0 \ + */ \ + while ((a.mant.low & (1ULL << MANTBITS)) == 0) { \ + a = xf_norm_left(a); \ + } \ + xf_debug("norm_left: ", a); \ + /* \ + * OK, now we might need to denormalize because of potential underflow. \ + * We need to do this before rounding, and rounding might make us normal \ + * again \ + */ \ + while (a.exp <= 0) { \ + a = xf_norm_right(a, 1 - a.exp); \ + /* \ + * Do we have underflow? \ + * That's when we get an inexact answer because we ran out of bits \ + * in a denormal. \ + */ \ + if (a.guard || a.round || a.sticky) { \ + feraiseexcept(FE_UNDERFLOW); \ + } \ + } \ + xf_debug("norm_denorm: ", a); \ + /* OK, we're relatively canonical... now we need to round */ \ + if (a.guard || a.round || a.sticky) { \ + feraiseexcept(FE_INEXACT); \ + switch (fegetround()) { \ + case FE_TOWARDZERO: \ + /* Chop and we're done */ \ + break; \ + case FE_UPWARD: \ + if (a.sign == 0) { \ + a.mant.low += 1; \ + } \ + break; \ + case FE_DOWNWARD: \ + if (a.sign != 0) { \ + a.mant.low += 1; \ + } \ + break; \ + default: \ + if (a.round || a.sticky) { \ + /* round up if guard is 1, down if guard is zero */ \ + a.mant.low += a.guard; \ + } else if (a.guard) { \ + /* exactly .5, round up if odd */ \ + a.mant.low += (a.mant.low & 1); \ + } \ + break; \ + } \ + } \ + xf_debug("post_round: ", a); \ + /* \ + * OK, now we might have carried all the way up. \ + * So we might need to shr once \ + * at least we know that the lsb should be zero if we rounded and \ + * got a carry out... \ + */ \ + if ((a.mant.low >> (MANTBITS + 1)) != 0) { \ + a = xf_norm_right(a, 1); \ + } \ + xf_debug("once_norm_right: ", a); \ + /* Overflow? */ \ + if (a.exp >= INF_EXP) { \ + /* Yep, inf result */ \ + xf_debug("inf: ", a); \ + feraiseexcept(FE_OVERFLOW); \ + feraiseexcept(FE_INEXACT); \ + switch (fegetround()) { \ + case FE_TOWARDZERO: \ + return maxfinite_##TYPE(a); \ + case FE_UPWARD: \ + if (a.sign == 0) { \ + return infinite_##TYPE(a); \ + } else { \ + return maxfinite_##TYPE(a); \ + } \ + case FE_DOWNWARD: \ + if (a.sign != 0) { \ + return infinite_##TYPE(a); \ + } else { \ + return maxfinite_##TYPE(a); \ + } \ + default: \ + return infinite_##TYPE(a); \ + } \ + } \ + /* Underflow? */ \ + if (a.mant.low & (1ULL << MANTBITS)) { \ + /* Leading one means: No, we're normal. So, we should be done... */ \ + xf_debug("norm: ", a); \ + ret.x.exp = a.exp; \ + ret.x.mant = a.mant.low; \ + return ret; \ + } \ + xf_debug("denorm: ", a); \ + if (a.exp != 1) { \ + printf("a.exp == %d\n", a.exp); \ + } \ + assert(a.exp == 1); \ + ret.x.exp = 0; \ + ret.x.mant = a.mant.low; \ + return ret; \ +} + +GEN_XF_ROUND(df_t, fDF_MANTBITS(), DF_INF_EXP) +GEN_XF_ROUND(sf_t, fSF_MANTBITS(), SF_INF_EXP) + +static inline double special_fma(df_t a, df_t b, df_t c) +{ + df_t ret; + ret.i = 0; + + /* + * If A multiplied by B is an exact infinity and C is also an infinity + * but with the opposite sign, FMA returns NaN and raises invalid. + */ + if (fISINFPROD(a.f, b.f) && isinf(c.f)) { + if ((a.x.sign ^ b.x.sign) != c.x.sign) { + ret.i = fDFNANVAL(); + feraiseexcept(FE_INVALID); + return ret.f; + } + } + if ((isinf(a.f) && isz(b.f)) || (isz(a.f) && isinf(b.f))) { + ret.i = fDFNANVAL(); + feraiseexcept(FE_INVALID); + return ret.f; + } + /* + * If none of the above checks are true and C is a NaN, + * a NaN shall be returned + * If A or B are NaN, a NAN shall be returned. + */ + if (isnan(a.f) || isnan(b.f) || (isnan(c.f))) { + if (isnan(a.f) && (fGETBIT(51, a.i) == 0)) { + feraiseexcept(FE_INVALID); + } + if (isnan(b.f) && (fGETBIT(51, b.i) == 0)) { + feraiseexcept(FE_INVALID); + } + if (isnan(c.f) && (fGETBIT(51, c.i) == 0)) { + feraiseexcept(FE_INVALID); + } + ret.i = fDFNANVAL(); + return ret.f; + } + /* + * We have checked for adding opposite-signed infinities. + * Other infinities return infinity with the correct sign + */ + if (isinf(c.f)) { + ret.x.exp = DF_INF_EXP; + ret.x.mant = 0; + ret.x.sign = c.x.sign; + return ret.f; + } + if (isinf(a.f) || isinf(b.f)) { + ret.x.exp = DF_INF_EXP; + ret.x.mant = 0; + ret.x.sign = (a.x.sign ^ b.x.sign); + return ret.f; + } + g_assert_not_reached(); + ret.x.exp = 0x123; + ret.x.mant = 0xdead; + return ret.f; +} + +static inline float special_fmaf(sf_t a, sf_t b, sf_t c) +{ + df_t aa, bb, cc; + aa.f = a.f; + bb.f = b.f; + cc.f = c.f; + return special_fma(aa, bb, cc); +} + +double internal_fmax(double a_in, double b_in, double c_in, int scale) +{ + df_t a, b, c; + xf_t prod; + xf_t acc; + xf_t result; + xf_init(&prod); + xf_init(&acc); + xf_init(&result); + a.f = a_in; + b.f = b_in; + c.f = c_in; + + debug_fprintf(stdout, + "internal_fmax: 0x%016llx * 0x%016llx + 0x%016llx sc: %d\n", + fUNDOUBLE(a_in), fUNDOUBLE(b_in), fUNDOUBLE(c_in), + scale); + + if (isinf(a.f) || isinf(b.f) || isinf(c.f)) { + return special_fma(a, b, c); + } + if (isnan(a.f) || isnan(b.f) || isnan(c.f)) { + return special_fma(a, b, c); + } + if ((scale == 0) && (isz(a.f) || isz(b.f))) { + return a.f * b.f + c.f; + } + + /* (a * 2**b) * (c * 2**d) == a*c * 2**(b+d) */ + prod.mant = int128_mul_6464(df_getmant(a), df_getmant(b)); + + /* + * Note: extracting the mantissa into an int is multiplying by + * 2**52, so adjust here + */ + prod.exp = df_getexp(a) + df_getexp(b) - DF_BIAS - 52; + prod.sign = a.x.sign ^ b.x.sign; + xf_debug("prod: ", prod); + if (!isz(c.f)) { + acc.mant = int128_mul_6464(df_getmant(c), 1); + acc.exp = df_getexp(c); + acc.sign = c.x.sign; + xf_debug("acc: ", acc); + result = xf_add(prod, acc); + } else { + result = prod; + } + xf_debug("sum: ", result); + debug_fprintf(stdout, "Scaling: %d\n", scale); + result.exp += scale; + xf_debug("post-scale: ", result); + return xf_round_df_t(result).f; +} + +float internal_fmafx(float a_in, float b_in, float c_in, int scale) +{ + sf_t a, b, c; + xf_t prod; + xf_t acc; + xf_t result; + xf_init(&prod); + xf_init(&acc); + xf_init(&result); + a.f = a_in; + b.f = b_in; + c.f = c_in; + + debug_fprintf(stdout, + "internal_fmax: 0x%016x * 0x%016x + 0x%016x sc: %d\n", + fUNFLOAT(a_in), fUNFLOAT(b_in), fUNFLOAT(c_in), scale); + if (isinf(a.f) || isinf(b.f) || isinf(c.f)) { + return special_fmaf(a, b, c); + } + if (isnan(a.f) || isnan(b.f) || isnan(c.f)) { + return special_fmaf(a, b, c); + } + if ((scale == 0) && (isz(a.f) || isz(b.f))) { + return a.f * b.f + c.f; + } + + /* (a * 2**b) * (c * 2**d) == a*c * 2**(b+d) */ + prod.mant = int128_mul_6464(sf_getmant(a), sf_getmant(b)); + + /* + * Note: extracting the mantissa into an int is multiplying by + * 2**23, so adjust here + */ + prod.exp = sf_getexp(a) + sf_getexp(b) - SF_BIAS - 23; + prod.sign = a.x.sign ^ b.x.sign; + if (isz(a.f) || isz(b.f)) { + prod.exp = -2 * WAY_BIG_EXP; + } + xf_debug("prod: ", prod); + if ((scale > 0) && (fpclassify(c.f) == FP_SUBNORMAL)) { + acc.mant = int128_mul_6464(0, 0); + acc.exp = -WAY_BIG_EXP; + acc.sign = c.x.sign; + acc.sticky = 1; + xf_debug("special denorm acc: ", acc); + result = xf_add(prod, acc); + } else if (!isz(c.f)) { + acc.mant = int128_mul_6464(sf_getmant(c), 1); + acc.exp = sf_getexp(c); + acc.sign = c.x.sign; + xf_debug("acc: ", acc); + result = xf_add(prod, acc); + } else { + result = prod; + } + xf_debug("sum: ", result); + debug_fprintf(stdout, "Scaling: %d\n", scale); + result.exp += scale; + xf_debug("post-scale: ", result); + return xf_round_sf_t(result).f; +} + + +float internal_fmaf(float a_in, float b_in, float c_in) +{ + return internal_fmafx(a_in, b_in, c_in, 0); +} + +double internal_fma(double a_in, double b_in, double c_in) +{ + return internal_fmax(a_in, b_in, c_in, 0); +} + +float internal_mpyf(float a_in, float b_in) +{ + if (isz(a_in) || isz(b_in)) { + return a_in * b_in; + } + return internal_fmafx(a_in, b_in, 0.0, 0); +} + +double internal_mpy(double a_in, double b_in) +{ + if (isz(a_in) || isz(b_in)) { + return a_in * b_in; + } + return internal_fmax(a_in, b_in, 0.0, 0); +} + +static inline double internal_mpyhh_special(double a, double b) +{ + return a * b; +} + +double internal_mpyhh(double a_in, double b_in, + unsigned long long int accumulated) +{ + df_t a, b; + xf_t x; + unsigned long long int prod; + unsigned int sticky; + + a.f = a_in; + b.f = b_in; + sticky = accumulated & 1; + accumulated >>= 1; + xf_init(&x); + if (isz(a_in) || isnan(a_in) || isinf(a_in)) { + return internal_mpyhh_special(a_in, b_in); + } + if (isz(b_in) || isnan(b_in) || isinf(b_in)) { + return internal_mpyhh_special(a_in, b_in); + } + x.mant = int128_mul_6464(accumulated, 1); + x.sticky = sticky; + prod = fGETUWORD(1, df_getmant(a)) * fGETUWORD(1, df_getmant(b)); + x.mant = int128_add(x.mant, int128_mul_6464(prod, 0x100000000ULL)); + x.exp = df_getexp(a) + df_getexp(b) - DF_BIAS - 20; + xf_debug("formed: ", x); + if (!isnormal(a_in) || !isnormal(b_in)) { + /* crush to inexact zero */ + x.sticky = 1; + x.exp = -4096; + xf_debug("crushing: ", x); + } + x.sign = a.x.sign ^ b.x.sign; + xf_debug("with sign: ", x); + return xf_round_df_t(x).f; +} + +float conv_df_to_sf(double in_f) +{ + xf_t x; + df_t in; + if (isz(in_f) || isnan(in_f) || isinf(in_f)) { + return in_f; + } + xf_init(&x); + in.f = in_f; + x.mant = int128_mul_6464(df_getmant(in), 1); + x.exp = df_getexp(in) - DF_BIAS + SF_BIAS - 52 + 23; + x.sign = in.x.sign; + xf_debug("conv to sf: x: ", x); + return xf_round_sf_t(x).f; +} +target/hexagon/fma_emu.h new file +30
-0@@ -0,0 +1,30 @@ +/* +* Copyright (c) 2019 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/>. +*/ + +#ifndef FMA_EMU_H +#define FMA_EMU_H + +extern float internal_fmafx (float a_in,float b_in,float c_in,int scale); +extern float internal_fmaf (float a_in,float b_in,float c_in); +extern double internal_fma (double a_in,double b_in,double c_in); +extern double internal_fmax (double a_in,double b_in,double c_in,int scale); +extern float internal_mpyf (float a_in,float b_in); +extern double internal_mpy (double a_in,double b_in); +extern double internal_mpyhh (double a_in,double b_in, +unsigned long long int accumulated); + +#endif
RFC PATCH 20/66 Hexagon generator phase 1 - C preprocessor for semantics
In reply to Taylor SimpsonRun the C preprocessor across the instruction definition files and macro definitoin file to expand macros and prepare the semantics_generated.pyinc file. The resulting file contains one entry with the semantics for each instruction and
one line with the instruction attributes associated with each macro.
--- target/hexagon/gen_semantics.c | 92 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 target/hexagon/gen_semantics.c
target/hexagon/gen_semantics.c new file +92 -0
@@ -0,0 +1,92 @@ +/* +* Copyright (c) 2019 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/>. +*/ + +/* +* This program generates the semantics file that is processed by +* the do_qemu.py script. We use the C preporcessor to manipulate the +* files imported from the Hexagon architecture library. +*/ + +#include <stdio.h> +#define STRINGIZE (X ) #X + +int main (int argc,char *argv[]) +{ +FILE *outfile; + +if (argc !=2 ) { +fprintf (stderr,"Usage: gen_semantics ouptputfile\n" ); +return -1 ; + } + outfile =fopen (argv[1 ],"w" ); +if (outfile ==NULL ) { +fprintf (stderr,"Cannot open %s for writing\n" , argv[1 ]); +return -1 ; + } + +/* +* Process the instruction definitions +* Scalar core instructions have the following form +* Q6INSN(A2_add,"Rd32=add(Rs32,Rt32)",ATTRIBS(), +* "Add 32-bit registers", +* { RdV=RsV+RtV;}) +* HVX instructions have the following form +* EXTINSN(V6_vinsertwr, "Vx32.w=vinsert(Rt32)", +* ATTRIBS(A_EXTENSION,A_CVI,A_CVI_VX,A_CVI_LATE,A_NOTE_MPY_RESOURCE), +* "Insert Word Scalar into Vector", +* VxV.uw[0] = RtV;) +*/ +#define Q6INSN (TAG ,BEH ,ATTRIBS ,DESCR ,SEM ) \ + do { \ + fprintf(outfile, "SEMANTICS(\"%s\",%s,\"\"\"%s\"\"\")\n", \ + #TAG, STRINGIZE(BEH), STRINGIZE(SEM)); \ + fprintf(outfile, "ATTRIBUTES(\"%s\",\"%s\")\n", \ + #TAG, STRINGIZE(ATTRIBS)); \ + } while (0); +#define EXTINSN (TAG ,BEH ,ATTRIBS ,DESCR ,SEM ) \ + do { \ + fprintf(outfile, "EXT_SEMANTICS(\"%s\",\"%s\",%s,\"\"\"%s\"\"\")\n", \ + EXTSTR, #TAG, STRINGIZE(BEH), STRINGIZE(SEM)); \ + fprintf(outfile, "ATTRIBUTES(\"%s\",\"%s\")\n", \ + #TAG, STRINGIZE(ATTRIBS)); \ + } while (0); +#include "imported/allidefs.def" +#undef Q6INSN +#undef EXTINSN + +/* +* Process the macro definitions +* Macros definitions have the following form +* DEF_MACRO( +* fLSBNEW0,, +* "P0.new[0]", +* "Least significant bit of new P0", +* predlog_read(thread,0), +* (A_DOTNEW,A_IMPLICIT_READS_P0) +* ) +* The important part here is the attributes. Whenever an instruction +* invokes a macro, we add the macro's attributes to the instruction. +*/ +#define DEF_MACRO (MNAME ,PARAMS ,SDESC ,LDESC ,BEH ,ATTRS ) \ + fprintf(outfile, "MACROATTRIB(\"%s\",\"\"\"%s\"\"\",\"%s\")\n", \ + #MNAME, STRINGIZE(BEH), STRINGIZE(ATTRS)); +#include "imported/macros.def" +#undef DEF_MACRO + +fclose (outfile); +return 0 ; +}
Signature · 1 line
2.7.4
Re: [RFC PATCH 20/66] Hexagon generator phase 1 - C preprocessor for semantics
Quoted 99 lines · Taylor Simpson
Run the C preprocessor across the instruction definition files and macro definitoin file to expand macros and prepare the semantics_generated.pyinc file. The resulting file contains one entry with the semantics for each instruction and
one line with the instruction attributes associated with each macro.Signed-off-by Taylor Simpson <[email protected]>--- target/hexagon/gen_semantics.c | 92 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+)create mode 100644
target/hexagon/gen_semantics.ctarget/hexagon/gen_semantics.c new file +82
-0@@ -0,0 +1,92 @@ +/* +* Copyright (c) 2019 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/>. +*/ + +/* +* This program generates the semantics file that is processed by +* the do_qemu.py script. We use the C preporcessor to manipulate the +* files imported from the Hexagon architecture library. +*/ + +#include <stdio.h> +#define STRINGIZE (X ) #X + +int main (int argc,char *argv[]) +{ +FILE *outfile; + +if (argc !=2 ) { +fprintf (stderr,"Usage: gen_semantics ouptputfile\n" ); +return -1 ; + } + outfile =fopen (argv[1 ],"w" ); +if (outfile ==NULL ) { +fprintf (stderr,"Cannot open %s for writing\n" , argv[1 ]); +return -1 ; + } + +/* +* Process the instruction definitions +* Scalar core instructions have the following form +* Q6INSN(A2_add,"Rd32=add(Rs32,Rt32)",ATTRIBS(), +* "Add 32-bit registers", +* { RdV=RsV+RtV;}) +* HVX instructions have the following form +* EXTINSN(V6_vinsertwr, "Vx32.w=vinsert(Rt32)", +* ATTRIBS(A_EXTENSION,A_CVI,A_CVI_VX,A_CVI_LATE,A_NOTE_MPY_RESOURCE), +* "Insert Word Scalar into Vector", +* VxV.uw[0] = RtV;) +*/ +#define Q6INSN (TAG ,BEH ,ATTRIBS ,DESCR ,SEM ) \ + do { \ + fprintf(outfile, "SEMANTICS(\"%s\",%s,\"\"\"%s\"\"\")\n", \ + #TAG, STRINGIZE(BEH), STRINGIZE(SEM)); \ + fprintf(outfile, "ATTRIBUTES(\"%s\",\"%s\")\n", \ + #TAG, STRINGIZE(ATTRIBS)); \ + } while (0); +#define EXTINSN (TAG ,BEH ,ATTRIBS ,DESCR ,SEM ) \ + do { \ + fprintf(outfile, "EXT_SEMANTICS(\"%s\",\"%s\",%s,\"\"\"%s\"\"\")\n", \ + EXTSTR, #TAG, STRINGIZE(BEH), STRINGIZE(SEM)); \ + fprintf(outfile, "ATTRIBUTES(\"%s\",\"%s\")\n", \ + #TAG, STRINGIZE(ATTRIBS)); \ + } while (0); +#include "imported/allidefs.def" +#undef Q6INSN +#undef EXTINSN + +/* +* Process the macro definitions +* Macros definitions have the following form +* DEF_MACRO( +* fLSBNEW0,, +* "P0.new[0]", +* "Least significant bit of new P0", +* predlog_read(thread,0), +* (A_DOTNEW,A_IMPLICIT_READS_P0) +* ) +* The important part here is the attributes. Whenever an instruction +* invokes a macro, we add the macro's attributes to the instruction.
target/hexagon/gen_semantics.c line 92
Quoted 10 lines
target/hexagon/gen_semantics.c new file +10
-0+*/ +#define DEF_MACRO (MNAME ,PARAMS ,SDESC ,LDESC ,BEH ,ATTRS ) \ + fprintf(outfile, "MACROATTRIB(\"%s\",\"\"\"%s\"\"\",\"%s\")\n", \ + #MNAME, STRINGIZE(BEH), STRINGIZE(ATTRS)); +#include "imported/macros.def" +#undef DEF_MACRO + +fclose (outfile); +return 0 ; +}
RFC PATCH 21/66 Hexagon generator phase 2 - qemu_def_generated.h
In reply to Taylor SimpsonFor each instruction we create
DEF_HELPER function prototype
TCG code to generate call to helper
Helper definition
--- target/hexagon/do_qemu.py | 773 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 773 insertions(+) create mode 100755 target/hexagon/do_qemu.py
target/hexagon/do_qemu.py new file +773 -0
@@ -0,0 +1,773 @@ +#!/usr/bin/env python + +from __future__ import print_function +## +## Copyright (c) 2019 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/>. +## + +import sys +import re +import string +try: + from StringIO import StringIO +except ImportError: + from io import StringIO + + +import operator +from itertools import chain + + + +behdict = {} # tag ->behavior +semdict = {} # tag -> semantics +extdict = {} # tag -> What extension an instruction belongs to (or "") +extnames = {} # ext name -> True +attribdict = {} # tag -> attributes +macros = {} # macro -> macro information... +attribinfo = {} # Register information and misc +tags = [] # list of all tags + +def get_macro(macname,ext=""): + mackey = macname + ":" + ext + if ext and mackey not in macros: + return get_macro(macname,"") + return macros[mackey] + +# We should do this as a hash for performance, +# but to keep order let's keep it as a list. +def uniquify(seq): + seen = set() + seen_add = seen.add + return [x for x in seq if x not in seen and not seen_add(x)] + +regre = re.compile( + r"((?<!DUP)[MNORCPQXSGVZA])([stuvwxyzdefg]+)([.]?[LlHh]?)(\d+S?)") +immre = re.compile(r"[#]([rRsSuUm])(\d+)(?:[:](\d+))?") +reg_or_immre = \ + re.compile(r"(((?<!DUP)[MNRCOPQXSGVZA])([stuvwxyzdefg]+)" + \ + "([.]?[LlHh]?)(\d+S?))|([#]([rRsSuUm])(\d+)[:]?(\d+)?)") +relimmre = re.compile(r"[#]([rR])(\d+)(?:[:](\d+))?") +absimmre = re.compile(r"[#]([sSuUm])(\d+)(?:[:](\d+))?") + +finished_macros = set() + +def expand_macro_attribs(macro,allmac_re): + if macro.key not in finished_macros: + # Get a list of all things that might be macros + l = allmac_re.findall(macro.beh) + for submacro in l: + if not submacro: continue + if not get_macro(submacro,macro.ext): + raise Exception("Couldn't find macro: <%s>" % l) + macro.attribs |= expand_macro_attribs( + get_macro(submacro,macro.ext), allmac_re) + finished_macros.add(macro.key) + return macro.attribs + +immextre = re.compile(r'f(MUST_)?IMMEXT[(]([UuSsRr])') +def calculate_attribs(): + # Recurse down macros, find attributes from sub-macros + macroValues = list(macros.values()) + allmacros_restr = "|".join(set([ m.re.pattern for m in macroValues ])) + allmacros_re = re.compile(allmacros_restr) + for macro in macroValues: + expand_macro_attribs(macro,allmacros_re) + # Append attributes to all instructions + for tag in tags: + for macname in allmacros_re.findall(semdict[tag]): + if not macname: continue + macro = get_macro(macname,extdict[tag]) + attribdict[tag] |= set(macro.attribs) + m = immextre.search(semdict[tag]) + if m: + if m.group(2).isupper(): + attrib = 'A_EXT_UPPER_IMMED' + elif m.group(2).islower(): + attrib = 'A_EXT_LOWER_IMMED' + else: + raise "Not a letter: %s (%s)" % (m.group(1),tag) + if not attrib in attribdict[tag]: + attribdict[tag].add(attrib) + +def SEMANTICS(tag, beh, sem): + #print tag,beh,sem + extdict[tag] = "" + behdict[tag] = beh + semdict[tag] = sem + attribdict[tag] = set() + tags.append(tag) # dicts have no order, this is for order + +def ATTRIBUTES(tag, attribstring): + attribstring = \ + attribstring.replace("ATTRIBS","").replace("(","").replace(")","") + if not attribstring: + return + attribs = attribstring.split(",") + for attrib in attribs: + attribdict[tag].add(attrib.strip()) + +class Macro(object): + __slots__ = ['key','name', 'beh', 'attribs', 're','ext'] + def __init__(self,key, name, beh, attribs,ext): + self.key = key + self.name = name + self.beh = beh + self.attribs = set(attribs) + self.ext = ext + self.re = re.compile("\\b" + name + "\\b") + +def MACROATTRIB(macname,beh,attribstring,ext=""): + attribstring = attribstring.replace("(","").replace(")","") + mackey = macname + ":" + ext + if attribstring: + attribs = attribstring.split(",") + else: + attribs = [] + macros[mackey] = Macro(mackey,macname,beh,attribs,ext) + +# read in file. Evaluate each line: each line calls a function above + +for line in open(sys.argv[1], 'rt').readlines(): + if not line.startswith("#"): + eval(line.strip()) + + +calculate_attribs() + + +attribre = re.compile(r'DEF_ATTRIB\(([A-Za-z0-9_]+), ([^,]*), ' + + r'"([A-Za-z0-9_\.]*)", "([A-Za-z0-9_\.]*)"\)') +for line in open(sys.argv[2], 'rt').readlines(): + if not attribre.match(line): + continue + (attrib_base,descr,rreg,wreg) = attribre.findall(line)[0] + attrib_base = 'A_' + attrib_base + attribinfo[attrib_base] = {'rreg':rreg, 'wreg':wreg, 'descr':descr} + +def compute_tag_regs(tag): + return uniquify(regre.findall(behdict[tag])) + +def compute_tag_immediates(tag): + return uniquify(immre.findall(behdict[tag])) + +## +## tagregs is the main data structure we'll use +## tagregs[tag] will contain the registers used by an instruction +## Within each entry, we'll use the regtype and regid fields +## regtype can be one of the following +## C control register +## N new register value +## P predicate register +## R GPR register +## M modifier register +## regid can be one of the following +## d, e destination register +## dd destination register pair +## s, t, u, v, w source register +## ss, tt, uu, vv source register pair +## x, y read-write register +## xx, yy read-write register pair +## +tagregs = dict(zip(tags, list(map(compute_tag_regs, tags)))) + +def is_pair(regid): + return len(regid) == 2 + +def is_single(regid): + return len(regid) == 1 + +def is_written(regid): + return regid[0] in "dexy" + +def is_writeonly(regid): + return regid[0] in "de" + +def is_read(regid): + return regid[0] in "stuvwxy" + +def is_readwrite(regid): + return regid[0] in "xy" + +def is_scalar_reg(regtype): + return regtype in "RPC" + +def is_old_val(regtype, regid, tag): + return regtype+regid+'V' in semdict[tag] + +def is_new_val(regtype, regid, tag): + return regtype+regid+'N' in semdict[tag] + +tagimms = dict(zip(tags, list(map(compute_tag_immediates, tags)))) + +def need_slot(tag): + if ('A_CONDEXEC' in attribdict[tag] or + 'A_STORE' in attribdict[tag]): + return 1 + else: + return 0 + +def need_part1(tag): + return re.compile(r"fPART1").search(semdict[tag]) + +def need_ea(tag): + return re.compile(r"\bEA\b").search(semdict[tag]) + +def imm_name(immlett): + return "%siV" % immlett + +## +## Helpers for gen_helper_prototype +## +def_helper_types = { + 'N' : 's32', + 'O' : 's32', + 'P' : 's32', + 'M' : 's32', + 'C' : 's32', + 'R' : 's32', + 'V' : 'ptr', + 'Q' : 'ptr' +} + +def_helper_types_pair = { + 'R' : 's64', + 'C' : 's64', + 'S' : 's64', + 'G' : 's64', + 'V' : 'ptr', + 'Q' : 'ptr' +} + +def gen_def_helper_opn(f, tag, regtype, regid, toss, numregs, i): + if (is_pair(regid)): + f.write(", %s" % (def_helper_types_pair[regtype])) + elif (is_single(regid)): + f.write(", %s" % (def_helper_types[regtype])) + else: + print("Bad register parse: ",regtype,regid,toss,numregs) + +## +## Generate the DEF_HELPER prototype for an instruction +## For A2_add: Rd32=add(Rs32,Rt32) +## We produce: +## #ifndef fWRAP_A2_add +## DEF_HELPER_3(A2_add, s32, env, s32, s32) +## #endif +## +def gen_helper_prototype(f, tag, regs, imms): + f.write('#ifndef fWRAP_%s\n' % tag) + numresults = 0 + numscalarresults = 0 + numscalarreadwrite = 0 + for regtype,regid,toss,numregs in regs: + if (is_written(regid)): + numresults += 1 + if (is_scalar_reg(regtype)): + numscalarresults += 1 + if (is_readwrite(regid)): + if (is_scalar_reg(regtype)): + numscalarreadwrite += 1 + + if (numscalarresults > 1): + ## The helper is bogus when there is more than one result + f.write('DEF_HELPER_1(%s, void, env)\n' % tag) + else: + ## Figure out how many arguments the helper will take + if (numscalarresults == 0): + def_helper_size = len(regs)+len(imms)+numscalarreadwrite+1 + if need_part1(tag): def_helper_size += 1 + if need_slot(tag): def_helper_size += 1 + f.write('DEF_HELPER_%s(%s' % (def_helper_size, tag)) + ## The return type is void + f.write(', void' ) + else: + def_helper_size = len(regs)+len(imms)+numscalarreadwrite + if need_part1(tag): def_helper_size += 1 + if need_slot(tag): def_helper_size += 1 + f.write('DEF_HELPER_%s(%s' % (def_helper_size, tag)) + + ## Generate the qemu DEF_HELPER type for each result + i=0 + for regtype,regid,toss,numregs in regs: + if (is_written(regid)): + gen_def_helper_opn(f, tag, regtype, regid, toss, numregs, i) + i += 1 + + ## Put the env between the outputs and inputs + f.write(', env' ) + i += 1 + + ## Generate the qemu type for each input operand (regs and immediates) + for regtype,regid,toss,numregs in regs: + if (is_read(regid)): + gen_def_helper_opn(f, tag, regtype, regid, toss, numregs, i) + i += 1 + for immlett,bits,immshift in imms: + f.write(", s32") + + ## Add the arguments for the instruction slot and part1 (if needed) + if need_slot(tag): f.write(', i32' ) + if need_part1(tag): f.write(' , i32' ) + f.write(')\n') + f.write('#endif\n') + +## +## Helpers for gen_tcg_func +## +def gen_decl_ea_tcg(f): + f.write("DECL_EA;\n") + +def gen_free_ea_tcg(f): + f.write("FREE_EA;\n") + +def genptr_decl(f,regtype,regid,regno): + regN="%s%sN" % (regtype,regid) + macro = "DECL_%sREG_%s" % (regtype, regid) + f.write("%s(%s%sV, %s, %d, 0);\n" % \ + (macro, regtype, regid, regN, regno)) + +def genptr_decl_new(f,regtype,regid,regno): + regN="%s%sX" % (regtype,regid) + macro = "DECL_NEW_%sREG_%s" % (regtype, regid) + f.write("%s(%s%sN, %s, %d, 0);\n" % \ + (macro, regtype, regid, regN, regno)) + +def genptr_decl_opn(f, tag, regtype, regid, toss, numregs, i): + if (is_pair(regid)): + genptr_decl(f,regtype,regid,i) + elif (is_single(regid)): + if is_old_val(regtype, regid, tag): + genptr_decl(f,regtype,regid,i) + elif is_new_val(regtype, regid, tag): + genptr_decl_new(f,regtype,regid,i) + else: + print("Bad register parse: ",regtype,regid,toss,numregs) + else: + print("Bad register parse: ",regtype,regid,toss,numregs) + +def genptr_decl_imm(f,immlett): + if (immlett.isupper()): + i = 1 + else: + i = 0 + f.write("DECL_IMM(%s,%d);\n" % (imm_name(immlett),i)) + +def genptr_free(f,regtype,regid,regno): + macro = "FREE_%sREG_%s" % (regtype, regid) + f.write("%s(%s%sV);\n" % (macro, regtype, regid)) + +def genptr_free_new(f,regtype,regid,regno): + macro = "FREE_NEW_%sREG_%s" % (regtype, regid) + f.write("%s(%s%sN);\n" % (macro, regtype, regid)) + +def genptr_free_opn(f,regtype,regid,i): + if (is_pair(regid)): + genptr_free(f,regtype,regid,i) + elif (is_single(regid)): + if is_old_val(regtype, regid, tag): + genptr_free(f,regtype,regid,i) + elif is_new_val(regtype, regid, tag): + genptr_free_new(f,regtype,regid,i) + else: + print("Bad register parse: ",regtype,regid,toss,numregs) + else: + print("Bad register parse: ",regtype,regid,toss,numregs) + +def genptr_free_imm(f,immlett): + f.write("FREE_IMM(%s);\n" % (imm_name(immlett))) + +def genptr_src_read(f,regtype,regid): + macro = "READ_%sREG_%s" % (regtype, regid) + f.write("%s(%s%sV, %s%sN);\n" % \ + (macro,regtype,regid,regtype,regid)) + +def genptr_src_read_new(f,regtype,regid): + macro = "READ_NEW_%sREG_%s" % (regtype, regid) + f.write("%s(%s%sN, %s%sX);\n" % \ + (macro,regtype,regid,regtype,regid)) + +def genptr_src_read_opn(f,regtype,regid): + if (is_pair(regid)): + genptr_src_read(f,regtype,regid) + elif (is_single(regid)): + if is_old_val(regtype, regid, tag): + genptr_src_read(f,regtype,regid) + elif is_new_val(regtype, regid, tag): + genptr_src_read_new(f,regtype,regid) + else: + print("Bad register parse: ",regtype,regid,toss,numregs) + else: + print("Bad register parse: ",regtype,regid,toss,numregs) + +def gen_helper_call_opn(f, tag, regtype, regid, toss, numregs, i): + if (i > 0): f.write(", ") + if (is_pair(regid)): + f.write("%s%sV" % (regtype,regid)) + elif (is_single(regid)): + if is_old_val(regtype, regid, tag): + f.write("%s%sV" % (regtype,regid)) + elif is_new_val(regtype, regid, tag): + f.write("%s%sN" % (regtype,regid)) + else: + print("Bad register parse: ",regtype,regid,toss,numregs) + else: + print("Bad register parse: ",regtype,regid,toss,numregs) + +def gen_helper_decl_imm(f,immlett): + f.write("DECL_TCG_IMM(tcgv_%s, %s);\n" % \ + (imm_name(immlett), imm_name(immlett))) + +def gen_helper_call_imm(f,immlett): + f.write(", tcgv_%s" % imm_name(immlett)) + +def gen_helper_free_imm(f,immlett): + f.write("FREE_TCG_IMM(tcgv_%s);\n" % imm_name(immlett)) + +def genptr_dst_write(f,regtype, regid): + macro = "WRITE_%sREG_%s" % (regtype, regid) + f.write("%s(%s%sN, %s%sV);\n" % (macro, regtype, regid, regtype, regid)) + +def genptr_dst_write_opn(f,regtype, regid, tag): + if (is_pair(regid)): + genptr_dst_write(f, regtype, regid) + elif (is_single(regid)): + genptr_dst_write(f, regtype, regid) + else: + print("Bad register parse: ",regtype,regid,toss,numregs) + +## +## Generate the TCG code to call the helper +## For A2_add: Rd32=add(Rs32,Rt32), { RdV=RsV+RtV;} +## We produce: +## { +## /* A2_add */ +## DECL_RREG_d(RdV, RdN, 0, 0); +## DECL_RREG_s(RsV, RsN, 1, 0); +## DECL_RREG_t(RtV, RtN, 2, 0); +## READ_RREG_s(RsV, RsN); +## READ_RREG_t(RtV, RtN); +## fWRAP_A2_add( +## do { +## gen_helper_A2_add(RdV, cpu_env, RsV, RtV); +## while (0), +## { RdV=RsV+RtV;}); +## WRITE_RREG_d(RdN, RdV); +## FREE_RREG_d(RdV); +## FREE_RREG_s(RsV); +## FREE_RREG_t(RtV); +## /* A2_add */ +## } +## +def gen_tcg_func(f, tag, regs, imms): + f.write('{\n') + f.write('/* %s */\n' % tag) + if need_ea(tag): gen_decl_ea_tcg(f) + i=0 + ## Declare all the operands (regs and immediates) + for regtype,regid,toss,numregs in regs: + genptr_decl_opn(f, tag, regtype, regid, toss, numregs, i) + i += 1 + for immlett,bits,immshift in imms: + genptr_decl_imm(f,immlett) + + if 'A_PRIV' in attribdict[tag]: + f.write('fCHECKFORPRIV();\n') + if 'A_GUEST' in attribdict[tag]: + f.write('fCHECKFORGUEST();\n') + if 'A_FPOP' in attribdict[tag]: + f.write('fFPOP_START();\n'); + + ## Read all the inputs + for regtype,regid,toss,numregs in regs: + if (is_read(regid)): + genptr_src_read_opn(f,regtype,regid) + + ## Generate the call to the helper + f.write("fWRAP_%s(\n" % tag) + f.write("do {\n") + for immlett,bits,immshift in imms: + gen_helper_decl_imm(f,immlett) + if need_part1(tag): f.write("PART1_WRAP(") + if need_slot(tag): f.write("SLOT_WRAP(") + f.write("gen_helper_%s(" % (tag)) + i=0 + ## If there is a scalar result, it is the return type + for regtype,regid,toss,numregs in regs: + if (is_written(regid)): + gen_helper_call_opn(f, tag, regtype, regid, toss, numregs, i) + i += 1 + if (i > 0): f.write(", ") + f.write("cpu_env") + i=1 + for regtype,regid,toss,numregs in regs: + if (is_read(regid)): + gen_helper_call_opn(f, tag, regtype, regid, toss, numregs, i) + i += 1 + for immlett,bits,immshift in imms: + gen_helper_call_imm(f,immlett) + + if need_slot(tag): f.write(", slot") + if need_part1(tag): f.write(", part1" ) + f.write(")") + if need_slot(tag): f.write(")") + if need_part1(tag): f.write(")") + f.write(";\n") + for immlett,bits,immshift in imms: + gen_helper_free_imm(f,immlett) + f.write("} while (0)") + f.write(",\n%s);\n" % semdict[tag] ) + + ## Write all the outputs + for regtype,regid,toss,numregs in regs: + if (is_written(regid)): + genptr_dst_write_opn(f,regtype, regid, tag) + + if 'A_FPOP' in attribdict[tag]: + f.write('fFPOP_END();\n'); + + + ## Free all the operands (regs and immediates) + if need_ea(tag): gen_free_ea_tcg(f) + for regtype,regid,toss,numregs in regs: + genptr_free_opn(f,regtype,regid,i) + i += 1 + for immlett,bits,immshift in imms: + genptr_free_imm(f,immlett) + + f.write("/* %s */\n" % tag) + f.write("}") + +## +## Helpers for gen_helper_definition +## +def gen_decl_ea(f): + f.write("size4u_t EA;\n") + +def gen_helper_return_type(f,regtype,regid,regno): + if regno > 1 : f.write(", ") + f.write("int32_t") + +def gen_helper_return_type_pair(f,regtype,regid,regno): + if regno > 1 : f.write(", ") + f.write("int64_t") + +def gen_helper_arg(f,regtype,regid,regno): + if regno > 0 : f.write(", " ) + f.write("int32_t %s%sV" % (regtype,regid)) + +def gen_helper_arg_new(f,regtype,regid,regno): + if regno >= 0 : f.write(", " ) + f.write("int32_t %s%sN" % (regtype,regid)) + +def gen_helper_arg_pair(f,regtype,regid,regno): + if regno >= 0 : f.write(", ") + f.write("int64_t %s%sV" % (regtype,regid)) + +def gen_helper_arg_opn(f,regtype,regid,i): + if (is_pair(regid)): + gen_helper_arg_pair(f,regtype,regid,i) + elif (is_single(regid)): + if is_old_val(regtype, regid, tag): + gen_helper_arg(f,regtype,regid,i) + elif is_new_val(regtype, regid, tag): + gen_helper_arg_new(f,regtype,regid,i) + else: + print("Bad register parse: ",regtype,regid,toss,numregs) + else: + print("Bad register parse: ",regtype,regid,toss,numregs) + +def gen_helper_arg_imm(f,immlett): + f.write(", int32_t %s" % (imm_name(immlett))) + +def gen_helper_dest_decl(f,regtype,regid,regno,subfield=""): + f.write("int32_t %s%sV%s = 0;\n" % \ + (regtype,regid,subfield)) + +def gen_helper_dest_decl_pair(f,regtype,regid,regno,subfield=""): + f.write("int64_t %s%sV%s = 0;\n" % \ + (regtype,regid,subfield)) + +def gen_helper_dest_decl_opn(f,regtype,regid,i): + if (is_pair(regid)): + gen_helper_dest_decl_pair(f,regtype,regid,i) + elif (is_single(regid)): + gen_helper_dest_decl(f,regtype,regid,i) + else: + print("Bad register parse: ",regtype,regid,toss,numregs) + +def gen_helper_return(f,regtype,regid,regno): + f.write("return %s%sV;\n" % (regtype,regid)) + +def gen_helper_return_pair(f,regtype,regid,regno): + f.write("return %s%sV;\n" % (regtype,regid)) + +def gen_helper_return_opn(f, regtype, regid, i): + if (is_pair(regid)): + gen_helper_return_pair(f,regtype,regid,i) + elif (is_single(regid)): + gen_helper_return(f,regtype,regid,i) + else: + print("Bad register parse: ",regtype,regid,toss,numregs) + +## +## Generate the TCG code to call the helper +## For A2_add: Rd32=add(Rs32,Rt32), { RdV=RsV+RtV;} +## We produce: +## #ifndef fWRAP_A2_add +## int32_t HELPER(A2_add)(CPUHexagonState *env, int32_t RsV, int32_t RtV) +## { +## uint32_t slot = 4; slot = slot; +## int32_t RdV = 0; +## { RdV=RsV+RtV;} +## COUNT_HELPER(A2_add); +## return RdV; +## } +## #endif +## +def gen_helper_definition(f, tag, regs, imms): + f.write('#ifndef fWRAP_%s\n' % tag) + numresults = 0 + numscalarresults = 0 + numscalarreadwrite = 0 + for regtype,regid,toss,numregs in regs: + if (is_written(regid)): + numresults += 1 + if (is_scalar_reg(regtype)): + numscalarresults += 1 + if (is_readwrite(regid)): + if (is_scalar_reg(regtype)): + numscalarreadwrite += 1 + + if (numscalarresults > 1): + ## The helper is bogus when there is more than one result + f.write("void HELPER(%s)(CPUHexagonState *env) { BOGUS_HELPER(%s); }\n" + % (tag, tag)) + else: + ## The return type of the function is the type of the destination + ## register + i=0 + for regtype,regid,toss,numregs in regs: + if (is_written(regid)): + if (is_pair(regid)): + gen_helper_return_type_pair(f,regtype,regid,i) + elif (is_single(regid)): + gen_helper_return_type(f,regtype,regid,i) + else: + print("Bad register parse: ",regtype,regid,toss,numregs) + i += 1 + + if (numscalarresults == 0): + f.write("void") + f.write(" HELPER(%s)(CPUHexagonState *env" % tag) + + i = 1 + ## Arguments to the helper function are the source regs and immediates + for regtype,regid,toss,numregs in regs: + if (is_read(regid)): + gen_helper_arg_opn(f,regtype,regid,i) + i += 1 + for immlett,bits,immshift in imms: + gen_helper_arg_imm(f,immlett) + i += 1 + if need_slot(tag): + if i > 0: f.write(", ") + f.write("uint32_t slot") + i += 1 + if need_part1(tag): + if i > 0: f.write(", ") + f.write("uint32_t part1") + f.write(")\n{\n") + if (not need_slot(tag)): f.write("uint32_t slot = 4; slot = slot;\n" ) + if need_ea(tag): gen_decl_ea(f) + ## Declare the return variable + i=0 + for regtype,regid,toss,numregs in regs: + if (is_writeonly(regid)): + gen_helper_dest_decl_opn(f,regtype,regid,i) + i += 1 + + if 'A_FPOP' in attribdict[tag]: + f.write('fFPOP_START();\n'); + + f.write(semdict[tag]) + f.write("\n") + f.write("COUNT_HELPER(%s);\n" % tag ) + + if 'A_FPOP' in attribdict[tag]: + f.write('fFPOP_END();\n'); + + ## Save/return the return variable + for regtype,regid,toss,numregs in regs: + if (is_written(regid)): + gen_helper_return_opn(f, regtype, regid, i) + f.write("}\n") + ## End of the helper definition + f.write('#endif\n') + +## +## Bring it all together in the DEF_QEMU macro +## +def gen_qemu(f, tag): + regs = tagregs[tag] + imms = tagimms[tag] + + f.write('DEF_QEMU(%s,%s,\n' % (tag,semdict[tag])) + gen_helper_prototype(f, tag, regs, imms) + f.write(",\n" ) + gen_tcg_func(f, tag, regs, imms) + f.write(",\n" ) + gen_helper_definition(f, tag, regs, imms) + f.write(")\n") + +## +## Generate the qemu_def_generated.h file +## +f = StringIO() + +f.write("#ifndef DEF_QEMU\n") +f.write("#define DEF_QEMU(TAG,SHORTCODE,HELPER,GENFN,HELPFN) /* Nothing */\n") +f.write("#endif\n\n") + + +for tag in tags: + ## Skip assembler mapped instructions + if "A_MAPPING" in attribdict[tag]: + continue + ## Skip the fake instructions + if ( "A_FAKEINSN" in attribdict[tag] ) : + continue + ## Skip the priv instructions + if ( "A_PRIV" in attribdict[tag] ) : + continue + ## Skip the guest instructions + if ( "A_GUEST" in attribdict[tag] ) : + continue + ## Skip the diag instructions + if ( tag == "Y6_diag" ) : + continue + if ( tag == "Y6_diag0" ) : + continue + if ( tag == "Y6_diag1" ) : + continue + + gen_qemu(f, tag) + +realf = open('qemu_def_generated.h','w') +realf.write(f.getvalue()) +realf.close() +f.close() +
Signature · 1 line
2.7.4
Re: [RFC PATCH 21/66] Hexagon generator phase 2 - qemu_def_generated.h
Quoted 17 lines · Taylor Simpson
For each instruction we create
DEF_HELPERfunction prototype
TCG code to generate call to helper
Helper definitionSigned-off-by Taylor Simpson <[email protected]>--- target/hexagon/do_qemu.py | 773 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 773 insertions(+)create mode 100755
target/hexagon/do_qemu.pytarget/hexagon/do_qemu.py new file +0
-0
target/hexagon/do_qemu.py line 1
Quoted 1 line
target/hexagon/do_qemu.py new file +1
-0@@ -0,0 +1,773 @@ +#!/usr/bin/env python
python3 ;)
target/hexagon/do_qemu.py line 3
Quoted 2 lines
target/hexagon/do_qemu.py new file +2
-0+ +from __future__ import print_function
Not needed anymore.
Quoted 14 lines
target/hexagon/do_qemu.py new file +14
-0+## +## Copyright (c) 2019 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
target/hexagon/do_qemu.py line 27
Quoted 10 lines
target/hexagon/do_qemu.py new file +10
-0+## along with this program; if not, see <http://www.gnu.org/licenses/>. +## + +import sys +import re +import string +try: + from StringIO import StringIO +except ImportError: + from io import StringIO
Directly "from io import StringIO".
Quoted 39 lines
target/hexagon/do_qemu.py new file +39
-0+ + +import operator +from itertools import chain + + + +behdict = {} # tag ->behavior +semdict = {} # tag -> semantics +extdict = {} # tag -> What extension an instruction belongs to (or "") +extnames = {} # ext name -> True +attribdict = {} # tag -> attributes +macros = {} # macro -> macro information... +attribinfo = {} # Register information and misc +tags = [] # list of all tags + +def get_macro(macname,ext=""): + mackey = macname + ":" + ext + if ext and mackey not in macros: + return get_macro(macname,"") + return macros[mackey] + +# We should do this as a hash for performance, +# but to keep order let's keep it as a list. +def uniquify(seq): + seen = set() + seen_add = seen.add + return [x for x in seq if x not in seen and not seen_add(x)] + +regre = re.compile( + r"((?<!DUP)[MNORCPQXSGVZA])([stuvwxyzdefg]+)([.]?[LlHh]?)(\d+S?)") +immre = re.compile(r"[#]([rRsSuUm])(\d+)(?:[:](\d+))?") +reg_or_immre = \ + re.compile(r"(((?<!DUP)[MNRCOPQXSGVZA])([stuvwxyzdefg]+)" + \ + "([.]?[LlHh]?)(\d+S?))|([#]([rRsSuUm])(\d+)[:]?(\d+)?)") +relimmre = re.compile(r"[#]([rR])(\d+)(?:[:](\d+))?") +absimmre = re.compile(r"[#]([sSuUm])(\d+)(?:[:](\d+))?") + +finished_macros = set()
[...]
RFC PATCH 22/66 Hexagon generator phase 2 - qemu_wrap_generated.h
In reply to Taylor SimpsonGives a default definition of fWRAP_<tag> for each instruction
--- target/hexagon/do_qemu.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
target/hexagon/do_qemu.py +14 -0
@@ -771,3 +771,17 @@ realf.write(f.getvalue()) realf.close() f.close() +## +## Generate the qemu_wrap_generated.h file +## Gives a default definition of fWRAP_<tag> for each instruction +## +f = StringIO() +for tag in tags: + f.write( "#ifndef fWRAP_%s\n" % tag ) + f.write( "#define fWRAP_%s(GENHLPR, SHORTCODE) GENHLPR\n" % tag ) + f.write( "#endif\n\n" ) +realf = open('qemu_wrap_generated.h', 'wt') +realf.write(f.getvalue()) +realf.close() +f.close() +
Signature · 1 line
2.7.4
RFC PATCH 23/66 Hexagon generator phase 2 - opcodes_def_generated.h
In reply to Taylor SimpsonGives a list of all the opcodes
--- target/hexagon/do_qemu.py | 12 ++++++++++++ 1 file changed, 12 insertions(+)
target/hexagon/do_qemu.py +12 -0
@@ -785,3 +785,15 @@ realf.write(f.getvalue()) realf.close() f.close() +## +## Generate the opcodes_def_generated.h file +## Gives a list of all the opcodes +## +f = StringIO() +for tag in tags: + f.write ( "OPCODE(%s),\n" % (tag) ) +realf = open('opcodes_def_generated.h', 'wt') +realf.write(f.getvalue()) +realf.close() +f.close() +
Signature · 1 line
2.7.4
RFC PATCH 24/66 Hexagon generator phase 2 - op_attribs_generated.h
In reply to Taylor SimpsonLists all the attributes associated with each instruction
--- target/hexagon/do_qemu.py | 13 +++++++++++++ 1 file changed, 13 insertions(+)
target/hexagon/do_qemu.py +13 -0
@@ -797,3 +797,16 @@ realf.write(f.getvalue()) realf.close() f.close() +## +## Generate the op_attribs_generated.h file +## Lists all the attributes associated with each instruction +## +f = StringIO() +for tag in tags: + f.write('OP_ATTRIB(%s,ATTRIBS(%s))\n' % \ + (tag,string.join(sorted(attribdict[tag]),","))) +realf = open('op_attribs_generated.h', 'wt') +realf.write(f.getvalue()) +realf.close() +f.close() +
Signature · 1 line
2.7.4
Re: [RFC PATCH 24/66] Hexagon generator phase 2 - op_attribs_generated.h
Quoted 19 lines · Taylor Simpson
Lists all the attributes associated with each instruction
Signed-off-by Taylor Simpson <[email protected]>--- target/hexagon/do_qemu.py | 13 +++++++++++++ 1 file changed, 13 insertions(+)target/hexagon/do_qemu.py +3
-0@@ -797,3 +797,16 @@ realf.write(f.getvalue()) realf.close() f.close() +## +## Generate the op_attribs_generated.h file +## Lists all the attributes associated with each instruction
target/hexagon/do_qemu.py realf.write(f.getvalue()) · line 812
Quoted 10 lines
target/hexagon/do_qemu.py +10
-0+## +f = StringIO() +for tag in tags: + f.write('OP_ATTRIB(%s,ATTRIBS(%s))\n' % \ + (tag,string.join(sorted(attribdict[tag]),","))) +realf = open('op_attribs_generated.h', 'wt') +realf.write(f.getvalue()) +realf.close() +f.close() +
This fails with Python 3:
GEN Hexagon generated files
Traceback (most recent call last):
File "target/hexagon/do_qemu.py", line 952, in <module>
(tag,string.join(sorted(attribdict[tag]),",")))
AttributeError: module 'string' has no attribute 'join'
RFC PATCH 25/66 Hexagon generator phase 2 - op_regs_generated.h
In reply to Taylor SimpsonLists the register and immediate operands for each instruction
--- target/hexagon/do_qemu.py | 86 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+)
target/hexagon/do_qemu.py +86 -0
@@ -810,3 +810,89 @@ realf.write(f.getvalue()) realf.close() f.close() +## +## Generate the op_regs_generated.h file +## Lists the register and immediate operands for each instruction +## +def calculate_regid_reg(tag): + def letter_inc(x): return chr(ord(x)+1) + ordered_implregs = [ 'SP','FP','LR' ] + srcdst_lett = 'X' + src_lett = 'S' + dst_lett = 'D' + retstr = "" + mapdict = {} + for reg in ordered_implregs: + reg_rd = 0 + reg_wr = 0 + if ('A_IMPLICIT_READS_'+reg) in attribdict[tag]: reg_rd = 1 + if ('A_IMPLICIT_WRITES_'+reg) in attribdict[tag]: reg_wr = 1 + if reg_rd and reg_wr: + retstr += srcdst_lett + mapdict[srcdst_lett] = reg + srcdst_lett = letter_inc(srcdst_lett) + elif reg_rd: + retstr += src_lett + mapdict[src_lett] = reg + src_lett = letter_inc(src_lett) + elif reg_wr: + retstr += dst_lett + mapdict[dst_lett] = reg + dst_lett = letter_inc(dst_lett) + return retstr,mapdict + +def calculate_regid_letters(tag): + retstr,mapdict = calculate_regid_reg(tag) + return retstr + +def strip_verif_info_in_regs(x): + y=x.replace('UREG.','') + y=y.replace('MREG.','') + return y.replace('GREG.','') + +f = StringIO() + +for tag in tags: + regs = tagregs[tag] + rregs = [] + wregs = [] + regids = "" + for regtype,regid,toss,numregs in regs: + if is_read(regid): + if regid[0] not in regids: regids += regid[0] + rregs.append(regtype+regid+numregs) + if is_written(regid): + wregs.append(regtype+regid+numregs) + if regid[0] not in regids: regids += regid[0] + for attrib in attribdict[tag]: + if attribinfo[attrib]['rreg']: + rregs.append(strip_verif_info_in_regs(attribinfo[attrib]['rreg'])) + if attribinfo[attrib]['wreg']: + wregs.append(strip_verif_info_in_regs(attribinfo[attrib]['wreg'])) + regids += calculate_regid_letters(tag) + f.write('REGINFO(%s,"%s",\t/*RD:*/\t"%s",\t/*WR:*/\t"%s")\n' % \ + (tag,regids,",".join(rregs),",".join(wregs))) + +for tag in tags: + imms = tagimms[tag] + f.write( 'IMMINFO(%s' % tag) + if not imms: + f.write(''','u',0,0,'U',0,0''') + for sign,size,shamt in imms: + if sign == 'r': sign = 's' + if not shamt: + shamt = "0" + f.write(''','%s',%s,%s''' % (sign,size,shamt)) + if len(imms) == 1: + if sign.isupper(): + myu = 'u' + else: + myu = 'U' + f.write(''','%s',0,0''' % myu) + f.write(')\n') + +realf = open('op_regs_generated.h','w') +realf.write(f.getvalue()) +realf.close() +f.close() +
Signature · 1 line
2.7.4
RFC PATCH 26/66 Hexagon generator phase 2 - printinsn-generated.h
In reply to Taylor SimpsonData for printing (disassembling) each instruction (format string + operands)
--- target/hexagon/do_qemu.py | 151 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+)
target/hexagon/do_qemu.py +151 -0
@@ -896,3 +896,154 @@ realf.write(f.getvalue()) realf.close() f.close() +## +## Generate the printinsn_generated.h file +## Data for printing each instruction (format string + operands) +## +def regprinter(m): + str = m.group(1) + str += ":".join(["%d"]*len(m.group(2))) + str += m.group(3) + if ('S' in m.group(1)) and (len(m.group(2)) == 1): + str += "/%s" + elif ('C' in m.group(1)) and (len(m.group(2)) == 1): + str += "/%s" + return str + +# Regular expression that matches any operator that contains '=' character: +opswithequal_re = '[-+^&|!<>=]?=' +# Regular expression that matches any assignment operator. +assignment_re = '[-+^&|]?=' + +# Out of the operators that contain the = sign, if the operator is also an +# assignment, spaces will be added around it, unless it's enclosed within +# parentheses, or spaces are already present. + +equals = re.compile(opswithequal_re) +assign = re.compile(assignment_re) + +def spacify(s): + slen = len(s) + paren_count = {} + i = 0 + pc = 0 + while i < slen: + c = s[i] + if c == '(': + pc += 1 + elif c == ')': + pc -= 1 + paren_count[i] = pc + i += 1 + + # Iterate over all operators that contain the equal sign. If any + # match is also an assignment operator, add spaces around it if + # the parenthesis count is 0. + pos = 0 + out = [] + for m in equals.finditer(s): + ms = m.start() + me = m.end() + # t is the string that matched opswithequal_re. + t = m.string[ms:me] + out += s[pos:ms] + pos = me + if paren_count[ms] == 0: + # Check if the entire string t is an assignment. + am = assign.match(t) + if am and len(am.group(0)) == me-ms: + # Don't add spaces if they are already there. + if ms > 0 and s[ms-1] != ' ': + out.append(' ') + out += t + if me < slen and s[me] != ' ': + out.append(' ') + continue + # If this is not an assignment, just append it to the output + # string. + out += t + + # Append the remaining part of the string. + out += s[pos:len(s)] + return ''.join(out) + +immext_casere = re.compile(r'IMMEXT\(([A-Za-z])') + +f = StringIO() + +for tag in tags: + if not behdict[tag]: continue + extendable_upper_imm = False + extendable_lower_imm = False + m = immext_casere.search(semdict[tag]) + if m: + if m.group(1).isupper(): + extendable_upper_imm = True + else: + extendable_lower_imm = True + beh = behdict[tag] + beh = regre.sub(regprinter,beh) + beh = absimmre.sub(r"#%s0x%x",beh) + beh = relimmre.sub(r"PC+%s%d",beh) + beh = spacify(beh) + # Print out a literal "%s" at the end, used to match empty string + # so C won't complain at us + if ("A_VECX" in attribdict[tag]): macname = "DEF_VECX_PRINTINFO" + else: macname = "DEF_PRINTINFO" + f.write('%s(%s,"%s%%s"' % (macname,tag,beh)) + regs_or_imms = reg_or_immre.findall(behdict[tag]) + ri = 0 + seenregs = {} + for allregs,a,b,c,d,allimm,immlett,bits,immshift in regs_or_imms: + if a: + #register + if b in seenregs: + regno = seenregs[b] + else: + regno = ri + if len(b) == 1: + f.write(',REGNO(%d)' % regno) + if 'S' in a: + f.write(',sreg2str(REGNO(%d))' % regno) + elif 'C' in a: + f.write(',creg2str(REGNO(%d))' % regno) + elif len(b) == 2: + f.write(',REGNO(%d)+1,REGNO(%d)' % (regno,regno)) + elif len(b) == 4: + f.write(',REGNO(%d)^3,REGNO(%d)^2,REGNO(%d)^1,REGNO(%d)' % \ + (regno,regno,regno,regno)) + else: + print("Put some stuff to handle quads here") + if b not in seenregs: + seenregs[b] = ri + ri += 1 + else: + #immediate + if (immlett.isupper()): + if extendable_upper_imm: + if immlett in 'rR': + f.write(',insn->extension_valid?"##":""') + else: + f.write(',insn->extension_valid?"#":""') + else: + f.write(',""') + ii = 1 + else: + if extendable_lower_imm: + if immlett in 'rR': + f.write(',insn->extension_valid?"##":""') + else: + f.write(',insn->extension_valid?"#":""') + else: + f.write(',""') + ii = 0 + f.write(',IMMNO(%d)' % ii) + # append empty string so there is at least one more arg + f.write(',"")\n') + +realf = open('printinsn_generated.h','w') +realf.write(f.getvalue()) +realf.close() +f.close() + +
Signature · 1 line
2.7.4
RFC PATCH 27/66 Hexagon generator phase 3 - C preprocessor for decode tree
In reply to Taylor SimpsonRun the C preprocessor across the instruction definition and encoding files to expand macros and prepare the iset.py file. The resulting fill contains python data structures used to build the decode tree.
--- target/hexagon/gen_dectree_import.c | 205 ++++++++++++++++++++++++++++++++++++ 1 file changed, 205 insertions(+) create mode 100644 target/hexagon/gen_dectree_import.c
target/hexagon/gen_dectree_import.c new file +205 -0
@@ -0,0 +1,205 @@ +/* +* Copyright (c) 2019 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/>. +*/ + +/* +* This program generates the encodings file that is processed by +* the dectree.py script to produce the decoding tree. We use the C +* preprocessor to manipulate the files imported from the Hexagon +* architecture library. +*/ +#include <stdio.h> +#include <string.h> +#include "opcodes.h" + +#define STRINGIZE (X ) #X + +const char *opcode_names[] = { +#define OPCODE(IID) STRINGIZE(IID) +#include "opcodes_def_generated.h" +NULL +#undef OPCODE +}; + +char *opcode_syntax[XX_LAST_OPCODE ]; + +/* +* Process the instruction definitions +* Scalar core instructions have the following form +* Q6INSN(A2_add,"Rd32=add(Rs32,Rt32)",ATTRIBS(), +* "Add 32-bit registers", +* { RdV=RsV+RtV;}) +* HVX instructions have the following form +* EXTINSN(V6_vinsertwr, "Vx32.w=vinsert(Rt32)", +* ATTRIBS(A_EXTENSION,A_CVI,A_CVI_VX,A_CVI_LATE,A_NOTE_MPY_RESOURCE), +* "Insert Word Scalar into Vector", +* VxV.uw[0] = RtV;) +*/ +void opcode_init () +{ +#define Q6INSN (TAG ,BEH ,ATTRIBS ,DESCR ,SEM ) \ + opcode_syntax[TAG] = BEH; +#define EXTINSN (TAG ,BEH ,ATTRIBS ,DESCR ,SEM ) \ + opcode_syntax[TAG] = BEH; +#include "imported/allidefs.def" +#undef Q6INSN +#undef EXTINSN +} + +const char *opcode_rregs[] = { +#define REGINFO(TAG, REGINFO, RREGS, WREGS) RREGS, +#define IMMINFO(TAG, SIGN, SIZE, SHAMT, SIGN2, SIZE2, SHAMT2) /* nothing */ +#include "op_regs_generated.h" +NULL +#undef REGINFO +#undef IMMINFO +}; + +const char *opcode_wregs[] = { +#define REGINFO(TAG, REGINFO, RREGS, WREGS) WREGS, +#define IMMINFO(TAG, SIGN, SIZE, SHAMT, SIGN2, SIZE2, SHAMT2) /* nothing */ +#include "op_regs_generated.h" +NULL +#undef REGINFO +#undef IMMINFO +}; + +opcode_encoding_t opcode_encodings[] = { +#define DEF_ENC32(TAG, ENCSTR) \ + [TAG] = { .encoding = ENCSTR }, +#define DEF_ENC_SUBINSN(TAG, CLASS, ENCSTR) \ + [TAG] = { .encoding = ENCSTR, .enc_class = CLASS }, +#define DEF_EXT_ENC(TAG, CLASS, ENCSTR) \ + [TAG] = { .encoding = ENCSTR, .enc_class = CLASS }, +#include "imported/encode.def" +#undef DEF_ENC32 +#undef DEF_ENC_SUBINSN +#undef DEF_EXT_ENC +}; + +static const char *const opcode_enc_class_names[XX_LAST_ENC_CLASS ] = { +"NORMAL" , +"16BIT" , +"SUBINSN_A" , +"SUBINSN_L1" , +"SUBINSN_L2" , +"SUBINSN_S1" , +"SUBINSN_S2" , +"EXT_noext" , +"EXT_mmvec" , +}; + +static const char *get_opcode_enc (int opcode) +{ +const char *tmp = opcode_encodings[opcode].encoding; +if (tmp ==NULL ) { + tmp ="MISSING ENCODING" ; + } +return tmp; +} + +static const char *get_opcode_enc_class (int opcode) +{ +const char *tmp = opcode_encodings[opcode].encoding; +if (tmp ==NULL ) { +char *test ="V6_" ;/* HVX */ +char *name = (char *)opcode_names[opcode]; +if (strncmp (name, test,strlen (test)) ==0 ) { +return "EXT_mmvec" ; + } + } +return opcode_enc_class_names[opcode_encodings[opcode].enc_class]; +} + +static void gen_iset_table (FILE *out) +{ +int i; + +fprintf (out,"iset = {\n" ); +for (i =0 ; i <XX_LAST_OPCODE ; i++) { +fprintf (out,"\t\'%s\' : {\n" , opcode_names[i]); +fprintf (out,"\t\t\'tag\' : \'%s\',\n" , opcode_names[i]); +fprintf (out,"\t\t\'syntax\' : \'%s\',\n" , opcode_syntax[i]); +fprintf (out,"\t\t\'rregs\' : \'%s\',\n" , opcode_rregs[i]); +fprintf (out,"\t\t\'wregs\' : \'%s\',\n" , opcode_wregs[i]); +fprintf (out,"\t\t\'enc\' : \'%s\',\n" ,get_opcode_enc (i)); +fprintf (out,"\t\t\'enc_class\' : \'%s\',\n" ,get_opcode_enc_class (i)); +fprintf (out,"\t},\n" ); + } +fprintf (out,"};\n\n" ); +} + +static void gen_tags_list (FILE *out) +{ +int i; + +fprintf (out,"tags = [\n" ); +for (i =0 ; i <XX_LAST_OPCODE ; i++) { +fprintf (out,"\t\'%s\',\n" , opcode_names[i]); + } +fprintf (out,"];\n\n" ); +} + +static void gen_enc_ext_spaces_table (FILE *out) +{ +fprintf (out,"enc_ext_spaces = {\n" ); +#define DEF_EXT_SPACE (SPACEID ,ENCSTR ) \ + fprintf(out, "\t\'%s\' : \'%s\',\n", #SPACEID, ENCSTR); +#include "imported/encode.def" +#undef DEF_EXT_SPACE +fprintf (out,"};\n\n" ); +} + +static void gen_subinsn_groupings_table (FILE *out) +{ +fprintf (out,"subinsn_groupings = {\n" ); +#define DEF_PACKED32 (TAG ,TYPEA ,TYPEB ,ENCSTR ) \ + do { \ + fprintf(out, "\t\'%s\' : {\n", #TAG); \ + fprintf(out, "\t\t\'name\' : \'%s\',\n", #TAG); \ + fprintf(out, "\t\t\'class_a\' : \'%s\',\n", #TYPEA); \ + fprintf(out, "\t\t\'class_b\' : \'%s\',\n", #TYPEB); \ + fprintf(out, "\t\t\'enc\' : \'%s\',\n", ENCSTR); \ + fprintf(out, "\t},\n"); \ + } while (0); +#include "imported/encode.def" +#undef DEF_PACKED32 +fprintf (out,"};\n\n" ); +} + +int main (int argc,char *argv[]) +{ +FILE *outfile; + +if (argc !=2 ) { +fprintf (stderr,"Usage: gen_dectree_import ouptputfile\n" ); +return -1 ; + } + outfile =fopen (argv[1 ],"w" ); +if (outfile ==NULL ) { +fprintf (stderr,"Cannot open %s for writing\n" , argv[1 ]); +return -1 ; + } + +opcode_init (); +gen_iset_table (outfile); +gen_tags_list (outfile); +gen_enc_ext_spaces_table (outfile); +gen_subinsn_groupings_table (outfile); + +fclose (outfile); +return 0 ; +}
Signature · 1 line
2.7.4
Re: [RFC PATCH 27/66] Hexagon generator phase 3 - C preprocessor for decode tree
Quoted 212 lines · Taylor Simpson
Run the C preprocessor across the instruction definition and encoding files to expand macros and prepare the
iset.pyfile. The resulting fill contains python data structures used to build the decode tree.Signed-off-by Taylor Simpson <[email protected]>--- target/hexagon/gen_dectree_import.c | 205 ++++++++++++++++++++++++++++++++++++ 1 file changed, 205 insertions(+)create mode 100644
target/hexagon/gen_dectree_import.ctarget/hexagon/gen_dectree_import.c new file +195
-0@@ -0,0 +1,205 @@ +/* +* Copyright (c) 2019 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/>. +*/ + +/* +* This program generates the encodings file that is processed by +* the dectree.py script to produce the decoding tree. We use the C +* preprocessor to manipulate the files imported from the Hexagon +* architecture library. +*/ +#include <stdio.h> +#include <string.h> +#include "opcodes.h" + +#define STRINGIZE (X ) #X + +const char *opcode_names[] = { +#define OPCODE(IID) STRINGIZE(IID) +#include "opcodes_def_generated.h" +NULL +#undef OPCODE +}; + +char *opcode_syntax[XX_LAST_OPCODE ]; + +/* +* Process the instruction definitions +* Scalar core instructions have the following form +* Q6INSN(A2_add,"Rd32=add(Rs32,Rt32)",ATTRIBS(), +* "Add 32-bit registers", +* { RdV=RsV+RtV;}) +* HVX instructions have the following form +* EXTINSN(V6_vinsertwr, "Vx32.w=vinsert(Rt32)", +* ATTRIBS(A_EXTENSION,A_CVI,A_CVI_VX,A_CVI_LATE,A_NOTE_MPY_RESOURCE), +* "Insert Word Scalar into Vector", +* VxV.uw[0] = RtV;) +*/ +void opcode_init () +{ +#define Q6INSN (TAG ,BEH ,ATTRIBS ,DESCR ,SEM ) \ + opcode_syntax[TAG] = BEH; +#define EXTINSN (TAG ,BEH ,ATTRIBS ,DESCR ,SEM ) \ + opcode_syntax[TAG] = BEH; +#include "imported/allidefs.def" +#undef Q6INSN +#undef EXTINSN +} + +const char *opcode_rregs[] = { +#define REGINFO(TAG, REGINFO, RREGS, WREGS) RREGS, +#define IMMINFO(TAG, SIGN, SIZE, SHAMT, SIGN2, SIZE2, SHAMT2) /* nothing */ +#include "op_regs_generated.h" +NULL +#undef REGINFO +#undef IMMINFO +}; + +const char *opcode_wregs[] = { +#define REGINFO(TAG, REGINFO, RREGS, WREGS) WREGS, +#define IMMINFO(TAG, SIGN, SIZE, SHAMT, SIGN2, SIZE2, SHAMT2) /* nothing */ +#include "op_regs_generated.h" +NULL +#undef REGINFO +#undef IMMINFO +}; + +opcode_encoding_t opcode_encodings[] = { +#define DEF_ENC32(TAG, ENCSTR) \ + [TAG] = { .encoding = ENCSTR }, +#define DEF_ENC_SUBINSN(TAG, CLASS, ENCSTR) \ + [TAG] = { .encoding = ENCSTR, .enc_class = CLASS }, +#define DEF_EXT_ENC(TAG, CLASS, ENCSTR) \ + [TAG] = { .encoding = ENCSTR, .enc_class = CLASS }, +#include "imported/encode.def" +#undef DEF_ENC32 +#undef DEF_ENC_SUBINSN +#undef DEF_EXT_ENC +}; + +static const char *const opcode_enc_class_names[XX_LAST_ENC_CLASS ] = { +"NORMAL" , +"16BIT" , +"SUBINSN_A" , +"SUBINSN_L1" , +"SUBINSN_L2" , +"SUBINSN_S1" , +"SUBINSN_S2" , +"EXT_noext" , +"EXT_mmvec" , +}; + +static const char *get_opcode_enc (int opcode) +{ +const char *tmp = opcode_encodings[opcode].encoding; +if (tmp ==NULL ) { + tmp ="MISSING ENCODING" ; + } +return tmp; +} + +static const char *get_opcode_enc_class (int opcode) +{ +const char *tmp = opcode_encodings[opcode].encoding; +if (tmp ==NULL ) { +char *test ="V6_" ;/* HVX */ +char *name = (char *)opcode_names[opcode]; +if (strncmp (name, test,strlen (test)) ==0 ) { +return "EXT_mmvec" ; + } + } +return opcode_enc_class_names[opcode_encodings[opcode].enc_class]; +} + +static void gen_iset_table (FILE *out) +{ +int i; + +fprintf (out,"iset = {\n" ); +for (i =0 ; i <XX_LAST_OPCODE ; i++) { +fprintf (out,"\t\'%s\' : {\n" , opcode_names[i]); +fprintf (out,"\t\t\'tag\' : \'%s\',\n" , opcode_names[i]); +fprintf (out,"\t\t\'syntax\' : \'%s\',\n" , opcode_syntax[i]); +fprintf (out,"\t\t\'rregs\' : \'%s\',\n" , opcode_rregs[i]); +fprintf (out,"\t\t\'wregs\' : \'%s\',\n" , opcode_wregs[i]); +fprintf (out,"\t\t\'enc\' : \'%s\',\n" ,get_opcode_enc (i)); +fprintf (out,"\t\t\'enc_class\' : \'%s\',\n" ,get_opcode_enc_class (i)); +fprintf (out,"\t},\n" ); + } +fprintf (out,"};\n\n" ); +} + +static void gen_tags_list (FILE *out) +{ +int i; + +fprintf (out,"tags = [\n" ); +for (i =0 ; i <XX_LAST_OPCODE ; i++) { +fprintf (out,"\t\'%s\',\n" , opcode_names[i]); + } +fprintf (out,"];\n\n" ); +} + +static void gen_enc_ext_spaces_table (FILE *out) +{ +fprintf (out,"enc_ext_spaces = {\n" ); +#define DEF_EXT_SPACE (SPACEID ,ENCSTR ) \ + fprintf(out, "\t\'%s\' : \'%s\',\n", #SPACEID, ENCSTR); +#include "imported/encode.def" +#undef DEF_EXT_SPACE +fprintf (out,"};\n\n" ); +} + +static void gen_subinsn_groupings_table (FILE *out) +{ +fprintf (out,"subinsn_groupings = {\n" ); +#define DEF_PACKED32 (TAG ,TYPEA ,TYPEB ,ENCSTR ) \ + do { \ + fprintf(out, "\t\'%s\' : {\n", #TAG); \ + fprintf(out, "\t\t\'name\' : \'%s\',\n", #TAG); \ + fprintf(out, "\t\t\'class_a\' : \'%s\',\n", #TYPEA); \ + fprintf(out, "\t\t\'class_b\' : \'%s\',\n", #TYPEB); \ + fprintf(out, "\t\t\'enc\' : \'%s\',\n", ENCSTR); \ + fprintf(out, "\t},\n"); \ + } while (0); +#include "imported/encode.def" +#undef DEF_PACKED32 +fprintf (out,"};\n\n" ); +} + +int main (int argc,char *argv[]) +{ +FILE *outfile; + +if (argc !=2 ) { +fprintf (stderr,"Usage: gen_dectree_import ouptputfile\n" ); +return -1 ; + } + outfile =fopen (argv[1 ],"w" ); +if (outfile ==NULL ) { +fprintf (stderr,"Cannot open %s for writing\n" , argv[1 ]); +return -1 ; + }
target/hexagon/gen_dectree_import.c line 205
Quoted 10 lines
target/hexagon/gen_dectree_import.c new file +10
-0+ +opcode_init (); +gen_iset_table (outfile); +gen_tags_list (outfile); +gen_enc_ext_spaces_table (outfile); +gen_subinsn_groupings_table (outfile); + +fclose (outfile); +return 0 ; +}
RFC PATCH 28/66 Hexagon generater phase 4 - Decode tree
In reply to Taylor SimpsonPython script that emits the decode tree in dectree_generated.h.
--- target/hexagon/dectree.py | 354 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 354 insertions(+) create mode 100755 target/hexagon/dectree.py
target/hexagon/dectree.py new file +354 -0
@@ -0,0 +1,354 @@ +#!/usr/bin/env python + +from __future__ import print_function +## +## Copyright (c) 2019 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/>. +## + +import cStringIO +import re + +import sys +sys.path.insert(0, sys.argv[1]) +import iset + +encs = {tag : ''.join(reversed(iset.iset[tag]['enc'].replace(' ', ''))) + for tag in iset.tags if iset.iset[tag]['enc'] != 'MISSING ENCODING'} + +enc_classes = set([iset.iset[tag]['enc_class'] for tag in encs.keys()]) +subinsn_enc_classes = \ + set([enc_class for enc_class in enc_classes \ + if enc_class.startswith('SUBINSN_')]) +ext_enc_classes = \ + set([enc_class for enc_class in enc_classes \ + if enc_class not in ('NORMAL', '16BIT') and \ + not enc_class.startswith('SUBINSN_')]) + +try: + subinsn_groupings = iset.subinsn_groupings +except AttributeError: + subinsn_groupings = {} + +for (tag, subinsn_grouping) in subinsn_groupings.items(): + encs[tag] = ''.join(reversed(subinsn_grouping['enc'].replace(' ', ''))) + +dectree_normal = {'leaves' : set()} +dectree_16bit = {'leaves' : set()} +dectree_subinsn_groupings = {'leaves' : set()} +dectree_subinsns = {name : {'leaves' : set()} for name in subinsn_enc_classes} +dectree_extensions = {name : {'leaves' : set()} for name in ext_enc_classes} + +for tag in encs.keys(): + if tag in subinsn_groupings: + dectree_subinsn_groupings['leaves'].add(tag) + continue + enc_class = iset.iset[tag]['enc_class'] + if enc_class.startswith('SUBINSN_'): + if len(encs[tag]) != 32: + encs[tag] = encs[tag] + '0' * (32 - len(encs[tag])) + dectree_subinsns[enc_class]['leaves'].add(tag) + elif enc_class == '16BIT': + if len(encs[tag]) != 16: + raise Exception('Tag "{}" has enc_class "{}" and not an encoding ' + + 'width of 16 bits!'.format(tag, enc_class)) + dectree_16bit['leaves'].add(tag) + else: + if len(encs[tag]) != 32: + raise Exception('Tag "{}" has enc_class "{}" and not an encoding ' + + 'width of 32 bits!'.format(tag, enc_class)) + if enc_class == 'NORMAL': + dectree_normal['leaves'].add(tag) + else: + dectree_extensions[enc_class]['leaves'].add(tag) + +faketags = set() +for (tag, enc) in iset.enc_ext_spaces.items(): + faketags.add(tag) + encs[tag] = ''.join(reversed(enc.replace(' ', ''))) + dectree_normal['leaves'].add(tag) + +faketags |= set(subinsn_groupings.keys()) + +def every_bit_counts(bitset): + for i in range(1, len(next(iter(bitset)))): + if len(set([bits[:i] + bits[i+1:] for bits in bitset])) == len(bitset): + return False + return True + +def auto_separate(node): + tags = node['leaves'] + if len(tags) <= 1: + return + enc_width = len(encs[next(iter(tags))]) + opcode_bit_for_all = \ + [all([encs[tag][i] in '01' \ + for tag in tags]) for i in range(enc_width)] + opcode_bit_is_0_for_all = \ + [opcode_bit_for_all[i] and all([encs[tag][i] == '0' \ + for tag in tags]) for i in range(enc_width)] + opcode_bit_is_1_for_all = \ + [opcode_bit_for_all[i] and all([encs[tag][i] == '1' \ + for tag in tags]) for i in range(enc_width)] + differentiator_opcode_bit = \ + [opcode_bit_for_all[i] and \ + not (opcode_bit_is_0_for_all[i] or \ + opcode_bit_is_1_for_all[i]) \ + for i in range(enc_width)] + best_width = 0 + for width in range(4, 0, -1): + for lsb in range(enc_width - width, -1, -1): + bitset = set([encs[tag][lsb:lsb+width] for tag in tags]) + if all(differentiator_opcode_bit[lsb:lsb+width]) and \ + (len(bitset) == len(tags) or every_bit_counts(bitset)): + best_width = width + best_lsb = lsb + caught_all_tags = len(bitset) == len(tags) + break + if best_width != 0: + break + if best_width == 0: + raise Exception('Could not find a way to differentiate the encodings ' + + 'of the following tags:\n{}'.format('\n'.join(tags))) + if caught_all_tags: + for width in range(1, best_width): + for lsb in range(enc_width - width, -1, -1): + bitset = set([encs[tag][lsb:lsb+width] for tag in tags]) + if all(differentiator_opcode_bit[lsb:lsb+width]) and \ + len(bitset) == len(tags): + best_width = width + best_lsb = lsb + break + else: + continue + break + node['separator_lsb'] = best_lsb + node['separator_width'] = best_width + node['children'] = [] + for value in range(2 ** best_width): + child = {} + bits = ''.join(reversed('{:0{}b}'.format(value, best_width))) + child['leaves'] = \ + set([tag for tag in tags \ + if encs[tag][best_lsb:best_lsb+best_width] == bits]) + node['children'].append(child) + for child in node['children']: + auto_separate(child) + +auto_separate(dectree_normal) +auto_separate(dectree_16bit) +if subinsn_groupings: + auto_separate(dectree_subinsn_groupings) +for dectree_subinsn in dectree_subinsns.values(): + auto_separate(dectree_subinsn) +for dectree_ext in dectree_extensions.values(): + auto_separate(dectree_ext) + +for tag in faketags: + del encs[tag] + +def table_name(parents, node): + path = parents + [node] + root = path[0] + tag = next(iter(node['leaves'])) + if tag in subinsn_groupings: + enc_width = len(subinsn_groupings[tag]['enc'].replace(' ', '')) + else: + tag = next(iter(node['leaves'] - faketags)) + enc_width = len(encs[tag]) + determining_bits = ['_'] * enc_width + for (parent, child) in zip(path[:-1], path[1:]): + lsb = parent['separator_lsb'] + width = parent['separator_width'] + value = parent['children'].index(child) + determining_bits[lsb:lsb+width] = \ + list(reversed('{:0{}b}'.format(value, width))) + if tag in subinsn_groupings: + name = 'DECODE_ROOT_EE' + else: + enc_class = iset.iset[tag]['enc_class'] + if enc_class in ext_enc_classes: + name = 'DECODE_EXT_{}'.format(enc_class) + elif enc_class in subinsn_enc_classes: + name = 'DECODE_SUBINSN_{}'.format(enc_class) + else: + name = 'DECODE_ROOT_{}'.format(enc_width) + if node != root: + name += '_' + ''.join(reversed(determining_bits)) + return name + +def print_node(f, node, parents): + if len(node['leaves']) <= 1: + return + name = table_name(parents, node) + lsb = node['separator_lsb'] + width = node['separator_width'] + print('DECODE_NEW_TABLE({},{},DECODE_SEPARATOR_BITS({},{}))'.\ + format(name, 2 ** width, lsb, width), file=f) + for child in node['children']: + if len(child['leaves']) == 0: + print('INVALID()', file=f) + elif len(child['leaves']) == 1: + (tag,) = child['leaves'] + if tag in subinsn_groupings: + class_a = subinsn_groupings[tag]['class_a'] + class_b = subinsn_groupings[tag]['class_b'] + enc = subinsn_groupings[tag]['enc'].replace(' ', '') + if 'RESERVED' in tag: + print('INVALID()', file=f) + else: + print('SUBINSNS({},{},{},"{}")'.\ + format(tag, class_a, class_b, enc), file=f) + elif tag in iset.enc_ext_spaces: + enc = iset.enc_ext_spaces[tag].replace(' ', '') + print('EXTSPACE({},"{}")'.format(tag, enc), file=f) + else: + enc = ''.join(reversed(encs[tag])) + print('TERMINAL({},"{}")'.format(tag, enc), file=f) + else: + print('TABLE_LINK({})'.format(table_name(parents + [node], child)), + file=f) + print('DECODE_END_TABLE({},{},DECODE_SEPARATOR_BITS({},{}))'.\ + format(name, 2 ** width, lsb, width), file=f) + print(file=f) + parents.append(node) + for child in node['children']: + print_node(f, child, parents) + parents.pop() + +def print_tree(f, tree): + print_node(f, tree, []) + +def print_match_info(f): + for tag in sorted(encs.keys(), key=iset.tags.index): + enc = ''.join(reversed(encs[tag])) + mask = int(re.sub(r'[^1]', r'0', enc.replace('0', '1')), 2) + match = int(re.sub(r'[^01]', r'0', enc), 2) + suffix = '' + print('DECODE{}_MATCH_INFO({},0x{:x}U,0x{:x}U)'.\ + format(suffix, tag, mask, match), file=f) + +regre = re.compile( + r'((?<!DUP)[MNORCPQXSGVZA])([stuvwxyzdefg]+)([.]?[LlHh]?)(\d+S?)') +immre = re.compile(r'[#]([rRsSuUm])(\d+)(?:[:](\d+))?') + +def ordered_unique(l): + return sorted(set(l), key=l.index) + +implicit_registers = { + 'SP' : 29, + 'FP' : 30, + 'LR' : 31 +} + +num_registers = { + 'R' : 32, + 'V' : 32 +} + +def print_op_info(f): + for tag in sorted(encs.keys(), key=iset.tags.index): + enc = encs[tag] + print(file=f) + print('DECODE_OPINFO({},'.format(tag), file=f) + regs = ordered_unique(regre.findall(iset.iset[tag]['syntax'])) + imms = ordered_unique(immre.findall(iset.iset[tag]['syntax'])) + regno = 0 + for reg in regs: + reg_type = reg[0] + reg_letter = reg[1][0] + reg_num_choices = int(reg[3].rstrip('S')) + reg_mapping = reg[0] + ''.join(['_' for letter in reg[1]]) + reg[3] + reg_enc_fields = re.findall(reg_letter + '+', enc) + if len(reg_enc_fields) == 0: + raise Exception('Tag "{}" missing register field!'.format(tag)) + if len(reg_enc_fields) > 1: + raise Exception('Tag "{}" has split register field!'.\ + format(tag)) + reg_enc_field = reg_enc_fields[0] + if 2 ** len(reg_enc_field) != reg_num_choices: + raise Exception('Tag "{}" has incorrect register field width!'.\ + format(tag)) + print(' DECODE_REG({},{},{})'.\ + format(regno, len(reg_enc_field), enc.index(reg_enc_field)), + file=f) + if reg_type in num_registers and \ + reg_num_choices != num_registers[reg_type]: + print(' DECODE_MAPPED_REG({},{})'.\ + format(regno, reg_mapping), file=f) + regno += 1 + def implicit_register_key(reg): + return implicit_registers[reg] + for reg in sorted( + set([r for r in (iset.iset[tag]['rregs'].split(',') + \ + iset.iset[tag]['wregs'].split(',')) \ + if r in implicit_registers]), key=implicit_register_key): + print(' DECODE_IMPL_REG({},{})'.\ + format(regno, implicit_registers[reg]), file=f) + regno += 1 + if imms and imms[0][0].isupper(): + imms = reversed(imms) + for imm in imms: + if imm[0].isupper(): + immno = 1 + else: + immno = 0 + imm_type = imm[0] + imm_width = int(imm[1]) + imm_shift = imm[2] + if imm_shift: + imm_shift = int(imm_shift) + else: + imm_shift = 0 + if imm_type.islower(): + imm_letter = 'i' + else: + imm_letter = 'I' + remainder = imm_width + for m in reversed(list(re.finditer(imm_letter + '+', enc))): + remainder -= m.end() - m.start() + print(' DECODE_IMM({},{},{},{})'.\ + format(immno, m.end() - m.start(), m.start(), remainder), + file=f) + if remainder != 0: + if imm[2]: + imm[2] = ':' + imm[2] + raise Exception('Tag "{}" has an incorrect number of ' + \ + 'encoding bits for immediate "{}"'.\ + format(tag, ''.join(imm))) + if imm_type.lower() in 'sr': + print(' DECODE_IMM_SXT({},{})'.\ + format(immno, imm_width), file=f) + if imm_type.lower() == 'n': + print(' DECODE_IMM_NEG({},{})'.\ + format(immno, imm_width), file=f) + if imm_shift: + print(' DECODE_IMM_SHIFT({},{})'.\ + format(immno, imm_shift), file=f) + print(')', file=f) + +if __name__ == '__main__': + f = cStringIO.StringIO() + print_tree(f, dectree_normal) + print_tree(f, dectree_16bit) + if subinsn_groupings: + print_tree(f, dectree_subinsn_groupings) + for (name, dectree_subinsn) in sorted(dectree_subinsns.items()): + print_tree(f, dectree_subinsn) + for (name, dectree_ext) in sorted(dectree_extensions.items()): + print_tree(f, dectree_ext) + print_match_info(f) + print_op_info(f) + open('dectree_generated.h', 'w').write(f.getvalue())
Signature · 1 line
2.7.4
Re: [RFC PATCH 28/66] Hexagon generater phase 4 - Decode tree
Quoted 14 lines · Taylor Simpson
Python script that emits the decode tree in
dectree_generated.h.Signed-off-by Taylor Simpson <[email protected]>--- target/hexagon/dectree.py | 354 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 354 insertions(+)create mode 100755
target/hexagon/dectree.pytarget/hexagon/dectree.py new file +0
-0
target/hexagon/dectree.py line 1
Quoted 1 line
target/hexagon/dectree.py new file +1
-0@@ -0,0 +1,354 @@ +#!/usr/bin/env python
python3
target/hexagon/dectree.py line 3
Quoted 2 lines
target/hexagon/dectree.py new file +2
-0+ +from __future__ import print_function
Not needed anymore.
Quoted 342 lines
target/hexagon/dectree.py new file +341
-0+## +## Copyright (c) 2019 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/>. +## + +import cStringIO +import re + +import sys +sys.path.insert(0, sys.argv[1]) +import iset + +encs = {tag : ''.join(reversed(iset.iset[tag]['enc'].replace(' ', ''))) + for tag in iset.tags if iset.iset[tag]['enc'] != 'MISSING ENCODING'} + +enc_classes = set([iset.iset[tag]['enc_class'] for tag in encs.keys()]) +subinsn_enc_classes = \ + set([enc_class for enc_class in enc_classes \ + if enc_class.startswith('SUBINSN_')]) +ext_enc_classes = \ + set([enc_class for enc_class in enc_classes \ + if enc_class not in ('NORMAL', '16BIT') and \ + not enc_class.startswith('SUBINSN_')]) + +try: + subinsn_groupings = iset.subinsn_groupings +except AttributeError: + subinsn_groupings = {} + +for (tag, subinsn_grouping) in subinsn_groupings.items(): + encs[tag] = ''.join(reversed(subinsn_grouping['enc'].replace(' ', ''))) + +dectree_normal = {'leaves' : set()} +dectree_16bit = {'leaves' : set()} +dectree_subinsn_groupings = {'leaves' : set()} +dectree_subinsns = {name : {'leaves' : set()} for name in subinsn_enc_classes} +dectree_extensions = {name : {'leaves' : set()} for name in ext_enc_classes} + +for tag in encs.keys(): + if tag in subinsn_groupings: + dectree_subinsn_groupings['leaves'].add(tag) + continue + enc_class = iset.iset[tag]['enc_class'] + if enc_class.startswith('SUBINSN_'): + if len(encs[tag]) != 32: + encs[tag] = encs[tag] + '0' * (32 - len(encs[tag])) + dectree_subinsns[enc_class]['leaves'].add(tag) + elif enc_class == '16BIT': + if len(encs[tag]) != 16: + raise Exception('Tag "{}" has enc_class "{}" and not an encoding ' + + 'width of 16 bits!'.format(tag, enc_class)) + dectree_16bit['leaves'].add(tag) + else: + if len(encs[tag]) != 32: + raise Exception('Tag "{}" has enc_class "{}" and not an encoding ' + + 'width of 32 bits!'.format(tag, enc_class)) + if enc_class == 'NORMAL': + dectree_normal['leaves'].add(tag) + else: + dectree_extensions[enc_class]['leaves'].add(tag) + +faketags = set() +for (tag, enc) in iset.enc_ext_spaces.items(): + faketags.add(tag) + encs[tag] = ''.join(reversed(enc.replace(' ', ''))) + dectree_normal['leaves'].add(tag) + +faketags |= set(subinsn_groupings.keys()) + +def every_bit_counts(bitset): + for i in range(1, len(next(iter(bitset)))): + if len(set([bits[:i] + bits[i+1:] for bits in bitset])) == len(bitset): + return False + return True + +def auto_separate(node): + tags = node['leaves'] + if len(tags) <= 1: + return + enc_width = len(encs[next(iter(tags))]) + opcode_bit_for_all = \ + [all([encs[tag][i] in '01' \ + for tag in tags]) for i in range(enc_width)] + opcode_bit_is_0_for_all = \ + [opcode_bit_for_all[i] and all([encs[tag][i] == '0' \ + for tag in tags]) for i in range(enc_width)] + opcode_bit_is_1_for_all = \ + [opcode_bit_for_all[i] and all([encs[tag][i] == '1' \ + for tag in tags]) for i in range(enc_width)] + differentiator_opcode_bit = \ + [opcode_bit_for_all[i] and \ + not (opcode_bit_is_0_for_all[i] or \ + opcode_bit_is_1_for_all[i]) \ + for i in range(enc_width)] + best_width = 0 + for width in range(4, 0, -1): + for lsb in range(enc_width - width, -1, -1): + bitset = set([encs[tag][lsb:lsb+width] for tag in tags]) + if all(differentiator_opcode_bit[lsb:lsb+width]) and \ + (len(bitset) == len(tags) or every_bit_counts(bitset)): + best_width = width + best_lsb = lsb + caught_all_tags = len(bitset) == len(tags) + break + if best_width != 0: + break + if best_width == 0: + raise Exception('Could not find a way to differentiate the encodings ' + + 'of the following tags:\n{}'.format('\n'.join(tags))) + if caught_all_tags: + for width in range(1, best_width): + for lsb in range(enc_width - width, -1, -1): + bitset = set([encs[tag][lsb:lsb+width] for tag in tags]) + if all(differentiator_opcode_bit[lsb:lsb+width]) and \ + len(bitset) == len(tags): + best_width = width + best_lsb = lsb + break + else: + continue + break + node['separator_lsb'] = best_lsb + node['separator_width'] = best_width + node['children'] = [] + for value in range(2 ** best_width): + child = {} + bits = ''.join(reversed('{:0{}b}'.format(value, best_width))) + child['leaves'] = \ + set([tag for tag in tags \ + if encs[tag][best_lsb:best_lsb+best_width] == bits]) + node['children'].append(child) + for child in node['children']: + auto_separate(child) + +auto_separate(dectree_normal) +auto_separate(dectree_16bit) +if subinsn_groupings: + auto_separate(dectree_subinsn_groupings) +for dectree_subinsn in dectree_subinsns.values(): + auto_separate(dectree_subinsn) +for dectree_ext in dectree_extensions.values(): + auto_separate(dectree_ext) + +for tag in faketags: + del encs[tag] + +def table_name(parents, node): + path = parents + [node] + root = path[0] + tag = next(iter(node['leaves'])) + if tag in subinsn_groupings: + enc_width = len(subinsn_groupings[tag]['enc'].replace(' ', '')) + else: + tag = next(iter(node['leaves'] - faketags)) + enc_width = len(encs[tag]) + determining_bits = ['_'] * enc_width + for (parent, child) in zip(path[:-1], path[1:]): + lsb = parent['separator_lsb'] + width = parent['separator_width'] + value = parent['children'].index(child) + determining_bits[lsb:lsb+width] = \ + list(reversed('{:0{}b}'.format(value, width))) + if tag in subinsn_groupings: + name = 'DECODE_ROOT_EE' + else: + enc_class = iset.iset[tag]['enc_class'] + if enc_class in ext_enc_classes: + name = 'DECODE_EXT_{}'.format(enc_class) + elif enc_class in subinsn_enc_classes: + name = 'DECODE_SUBINSN_{}'.format(enc_class) + else: + name = 'DECODE_ROOT_{}'.format(enc_width) + if node != root: + name += '_' + ''.join(reversed(determining_bits)) + return name + +def print_node(f, node, parents): + if len(node['leaves']) <= 1: + return + name = table_name(parents, node) + lsb = node['separator_lsb'] + width = node['separator_width'] + print('DECODE_NEW_TABLE({},{},DECODE_SEPARATOR_BITS({},{}))'.\ + format(name, 2 ** width, lsb, width), file=f) + for child in node['children']: + if len(child['leaves']) == 0: + print('INVALID()', file=f) + elif len(child['leaves']) == 1: + (tag,) = child['leaves'] + if tag in subinsn_groupings: + class_a = subinsn_groupings[tag]['class_a'] + class_b = subinsn_groupings[tag]['class_b'] + enc = subinsn_groupings[tag]['enc'].replace(' ', '') + if 'RESERVED' in tag: + print('INVALID()', file=f) + else: + print('SUBINSNS({},{},{},"{}")'.\ + format(tag, class_a, class_b, enc), file=f) + elif tag in iset.enc_ext_spaces: + enc = iset.enc_ext_spaces[tag].replace(' ', '') + print('EXTSPACE({},"{}")'.format(tag, enc), file=f) + else: + enc = ''.join(reversed(encs[tag])) + print('TERMINAL({},"{}")'.format(tag, enc), file=f) + else: + print('TABLE_LINK({})'.format(table_name(parents + [node], child)), + file=f) + print('DECODE_END_TABLE({},{},DECODE_SEPARATOR_BITS({},{}))'.\ + format(name, 2 ** width, lsb, width), file=f) + print(file=f) + parents.append(node) + for child in node['children']: + print_node(f, child, parents) + parents.pop() + +def print_tree(f, tree): + print_node(f, tree, []) + +def print_match_info(f): + for tag in sorted(encs.keys(), key=iset.tags.index): + enc = ''.join(reversed(encs[tag])) + mask = int(re.sub(r'[^1]', r'0', enc.replace('0', '1')), 2) + match = int(re.sub(r'[^01]', r'0', enc), 2) + suffix = '' + print('DECODE{}_MATCH_INFO({},0x{:x}U,0x{:x}U)'.\ + format(suffix, tag, mask, match), file=f) + +regre = re.compile( + r'((?<!DUP)[MNORCPQXSGVZA])([stuvwxyzdefg]+)([.]?[LlHh]?)(\d+S?)') +immre = re.compile(r'[#]([rRsSuUm])(\d+)(?:[:](\d+))?') + +def ordered_unique(l): + return sorted(set(l), key=l.index) + +implicit_registers = { + 'SP' : 29, + 'FP' : 30, + 'LR' : 31 +} + +num_registers = { + 'R' : 32, + 'V' : 32 +} + +def print_op_info(f): + for tag in sorted(encs.keys(), key=iset.tags.index): + enc = encs[tag] + print(file=f) + print('DECODE_OPINFO({},'.format(tag), file=f) + regs = ordered_unique(regre.findall(iset.iset[tag]['syntax'])) + imms = ordered_unique(immre.findall(iset.iset[tag]['syntax'])) + regno = 0 + for reg in regs: + reg_type = reg[0] + reg_letter = reg[1][0] + reg_num_choices = int(reg[3].rstrip('S')) + reg_mapping = reg[0] + ''.join(['_' for letter in reg[1]]) + reg[3] + reg_enc_fields = re.findall(reg_letter + '+', enc) + if len(reg_enc_fields) == 0: + raise Exception('Tag "{}" missing register field!'.format(tag)) + if len(reg_enc_fields) > 1: + raise Exception('Tag "{}" has split register field!'.\ + format(tag)) + reg_enc_field = reg_enc_fields[0] + if 2 ** len(reg_enc_field) != reg_num_choices: + raise Exception('Tag "{}" has incorrect register field width!'.\ + format(tag)) + print(' DECODE_REG({},{},{})'.\ + format(regno, len(reg_enc_field), enc.index(reg_enc_field)), + file=f) + if reg_type in num_registers and \ + reg_num_choices != num_registers[reg_type]: + print(' DECODE_MAPPED_REG({},{})'.\ + format(regno, reg_mapping), file=f) + regno += 1 + def implicit_register_key(reg): + return implicit_registers[reg] + for reg in sorted( + set([r for r in (iset.iset[tag]['rregs'].split(',') + \ + iset.iset[tag]['wregs'].split(',')) \ + if r in implicit_registers]), key=implicit_register_key): + print(' DECODE_IMPL_REG({},{})'.\ + format(regno, implicit_registers[reg]), file=f) + regno += 1 + if imms and imms[0][0].isupper(): + imms = reversed(imms) + for imm in imms: + if imm[0].isupper(): + immno = 1 + else: + immno = 0 + imm_type = imm[0] + imm_width = int(imm[1]) + imm_shift = imm[2] + if imm_shift: + imm_shift = int(imm_shift) + else: + imm_shift = 0 + if imm_type.islower(): + imm_letter = 'i' + else: + imm_letter = 'I' + remainder = imm_width + for m in reversed(list(re.finditer(imm_letter + '+', enc))): + remainder -= m.end() - m.start() + print(' DECODE_IMM({},{},{},{})'.\ + format(immno, m.end() - m.start(), m.start(), remainder), + file=f) + if remainder != 0: + if imm[2]: + imm[2] = ':' + imm[2] + raise Exception('Tag "{}" has an incorrect number of ' + \ + 'encoding bits for immediate "{}"'.\ + format(tag, ''.join(imm))) + if imm_type.lower() in 'sr': + print(' DECODE_IMM_SXT({},{})'.\ + format(immno, imm_width), file=f) + if imm_type.lower() == 'n': + print(' DECODE_IMM_NEG({},{})'.\ + format(immno, imm_width), file=f) + if imm_shift: + print(' DECODE_IMM_SHIFT({},{})'.\ + format(immno, imm_shift), file=f) + print(')', file=f) + +if __name__ == '__main__': + f = cStringIO.StringIO() + print_tree(f, dectree_normal)
target/hexagon/dectree.py line 354
Quoted 10 lines
target/hexagon/dectree.py new file +10
-0+ print_tree(f, dectree_16bit) + if subinsn_groupings: + print_tree(f, dectree_subinsn_groupings) + for (name, dectree_subinsn) in sorted(dectree_subinsns.items()): + print_tree(f, dectree_subinsn) + for (name, dectree_ext) in sorted(dectree_extensions.items()): + print_tree(f, dectree_ext) + print_match_info(f) + print_op_info(f) + open('dectree_generated.h', 'w').write(f.getvalue())
Re: [RFC PATCH 28/66] Hexagon generater phase 4 - Decode tree
Quoted 36 lines · Philippe Mathieu-Daudé
Quoted 15 lines · Taylor Simpson
Python script that emits the decode tree in
dectree_generated.h.Signed-off-by Taylor Simpson <[email protected]>---
target/hexagon/dectree.py| 354
++++++++++++++++++++++++++++++++++++++++++++++1 file changed, 354 insertions(+)create mode 100755
target/hexagon/dectree.pytarget/hexagon/dectree.py new file +0
-0target/hexagon/dectree.py line 1
Quoted 1 line
target/hexagon/dectree.py new file +1
-0@@ -0,0 +1,354 @@ +#!/usr/bin/env pythonpython3
target/hexagon/dectree.py line 3
Quoted 2 lines
target/hexagon/dectree.py new file +2
-0+ +from __future__ import print_functionNot needed anymore.
Quoted 11 lines
target/hexagon/dectree.py new file +2
-0+## +## Copyright (c) 2019 Qualcomm Innovation Center, Inc. All RightsReserved.
target/hexagon/dectree.py new file +8
-0+## +## 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
Quoted 8 lines
target/hexagon/dectree.py line 21
Quoted 8 lines
target/hexagon/dectree.py new file +8
-0+## 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/>. +## + +import cStringIO
Another Python 3 failure:
GEN Hexagon decode tree
Traceback (most recent call last):
File "target/hexagon/dectree.py", line 20, in <module>
import cStringIO
ModuleNotFoundError: No module named 'cStringIO'
Quoted 352 lines
Quoted 340 lines
target/hexagon/dectree.py new file +25
-0+import re + +import sys +sys.path.insert(0, sys.argv[1]) +import iset + +encs = {tag : ''.join(reversed(iset.iset[tag]['enc'].replace(' ', ''))) + for tag in iset.tags if iset.iset[tag]['enc'] != 'MISSING ENCODING'} + +enc_classes = set([iset.iset[tag]['enc_class'] for tag in encs.keys()]) +subinsn_enc_classes = \ + set([enc_class for enc_class in enc_classes \ + if enc_class.startswith('SUBINSN_')]) +ext_enc_classes = \ + set([enc_class for enc_class in enc_classes \ + if enc_class not in ('NORMAL', '16BIT') and \ + not enc_class.startswith('SUBINSN_')]) + +try: + subinsn_groupings = iset.subinsn_groupings +except AttributeError: + subinsn_groupings = {} + +for (tag, subinsn_grouping) in subinsn_groupings.items(): + encs[tag] = ''.join(reversed(subinsn_grouping['enc'].replace(' ','')))
target/hexagon/dectree.py new file +5
-0+ +dectree_normal = {'leaves' : set()} +dectree_16bit = {'leaves' : set()} +dectree_subinsn_groupings = {'leaves' : set()} +dectree_subinsns = {name : {'leaves' : set()} for name in
subinsn_enc_classes}
+dectree_extensions = {name : {'leaves' :set()} for name inext_enc_classes}target/hexagon/dectree.py new file +13
-0+ +for tag in encs.keys(): + if tag in subinsn_groupings: + dectree_subinsn_groupings['leaves'].add(tag) + continue + enc_class = iset.iset[tag]['enc_class'] + if enc_class.startswith('SUBINSN_'): + if len(encs[tag]) != 32: + encs[tag] = encs[tag] + '0' * (32 - len(encs[tag])) + dectree_subinsns[enc_class]['leaves'].add(tag) + elif enc_class == '16BIT': + if len(encs[tag]) != 16: + raise Exception('Tag "{}" has enc_class "{}" and not anencoding ' +
+ 'width of 16 bits!'.format(tag,enc_class)) + dectree_16bit['leaves'].add(tag)
+ else:
+ iflen(encs[tag])!= 32:
+ raise Exception('Tag "{}" hasenc_class"{}" and not an encoding ' +
+ 'width of 32 bits!'.format(tag,enc_class)) + ifenc_class== 'NORMAL':
+ dectree_normal['leaves'].add(tag)
+ else:
+ dectree_extensions[enc_class]['leaves'].add(tag)target/hexagon/dectree.py new file +12
-0+ +faketags = set() +for (tag, enc) in iset.enc_ext_spaces.items(): + faketags.add(tag) + encs[tag] = ''.join(reversed(enc.replace(' ', ''))) + dectree_normal['leaves'].add(tag) + +faketags |= set(subinsn_groupings.keys()) + +def every_bit_counts(bitset): + for i in range(1, len(next(iter(bitset)))): + if len(set([bits[:i] + bits[i+1:] for bits in bitset])) ==len(bitset):
+ return False
+ return Truetarget/hexagon/dectree.py new file +34
-0+ +def auto_separate(node): + tags = node['leaves'] + if len(tags) <= 1: + return + enc_width = len(encs[next(iter(tags))]) + opcode_bit_for_all = \ + [all([encs[tag][i] in '01' \ + for tag in tags]) for i in range(enc_width)] + opcode_bit_is_0_for_all = \ + [opcode_bit_for_all[i] and all([encs[tag][i] == '0' \ + for tag in tags]) for i in range(enc_width)] + opcode_bit_is_1_for_all = \ + [opcode_bit_for_all[i] and all([encs[tag][i] == '1' \ + for tag in tags]) for i in range(enc_width)] + differentiator_opcode_bit = \ + [opcode_bit_for_all[i] and \ + not (opcode_bit_is_0_for_all[i] or \ + opcode_bit_is_1_for_all[i]) \ + for i in range(enc_width)] + best_width = 0 + for width in range(4, 0, -1): + for lsb in range(enc_width - width, -1, -1): + bitset = set([encs[tag][lsb:lsb+width] for tag in tags]) + if all(differentiator_opcode_bit[lsb:lsb+width]) and \ + (len(bitset) == len(tags) or every_bit_counts(bitset)): + best_width = width + best_lsb = lsb + caught_all_tags = len(bitset) == len(tags) + break + if best_width != 0: + break + if best_width == 0: + raise Exception('Could not find a way to differentiate theencodings ' +
+ 'of the following tags:\n{}'.format('\n'.join(tags)))
+ ifcaught_all_tags:
+ for width inrange(1, best_width):
+ for lsb inrange(enc_width - width, -1, -1):
+ bitset =set([encs[tag][lsb:lsb+width] for tag in tags])+ ifall(differentiator_opcode_bit[lsb:lsb+width])and \
+ len(bitset) == len(tags):
+best_width= width
+best_lsb= lsb
+ break
+ else:
+ continue
+ break
+ node['separator_lsb'] =best_lsb
+ node['separator_width'] =best_width
+ node['children'] = []
+ for value inrange(2 ** best_width):
+ child = {}
+ bits = ''.join(reversed('{:0{}b}'.format(value,best_width))) + child['leaves'] = \
+ set([tag for tag in tags \
+ if encs[tag][best_lsb:best_lsb+best_width] == bits]) + node['children'].append(child)
+ for child in node['children']:
+auto_separate(child)target/hexagon/dectree.py new file +73
-0+ +auto_separate(dectree_normal) +auto_separate(dectree_16bit) +if subinsn_groupings: + auto_separate(dectree_subinsn_groupings) +for dectree_subinsn in dectree_subinsns.values(): + auto_separate(dectree_subinsn) +for dectree_ext in dectree_extensions.values(): + auto_separate(dectree_ext) + +for tag in faketags: + del encs[tag] + +def table_name(parents, node): + path = parents + [node] + root = path[0] + tag = next(iter(node['leaves'])) + if tag in subinsn_groupings: + enc_width = len(subinsn_groupings[tag]['enc'].replace(' ', '')) + else: + tag = next(iter(node['leaves'] - faketags)) + enc_width = len(encs[tag]) + determining_bits = ['_'] * enc_width + for (parent, child) in zip(path[:-1], path[1:]): + lsb = parent['separator_lsb'] + width = parent['separator_width'] + value = parent['children'].index(child) + determining_bits[lsb:lsb+width] = \ + list(reversed('{:0{}b}'.format(value, width))) + if tag in subinsn_groupings: + name = 'DECODE_ROOT_EE' + else: + enc_class = iset.iset[tag]['enc_class'] + if enc_class in ext_enc_classes: + name = 'DECODE_EXT_{}'.format(enc_class) + elif enc_class in subinsn_enc_classes: + name = 'DECODE_SUBINSN_{}'.format(enc_class) + else: + name = 'DECODE_ROOT_{}'.format(enc_width) + if node != root: + name += '_' + ''.join(reversed(determining_bits)) + return name + +def print_node(f, node, parents): + if len(node['leaves']) <= 1: + return + name = table_name(parents, node) + lsb = node['separator_lsb'] + width = node['separator_width'] + print('DECODE_NEW_TABLE({},{},DECODE_SEPARATOR_BITS({},{}))'.\ + format(name, 2 ** width, lsb, width), file=f) + for child in node['children']: + if len(child['leaves']) == 0: + print('INVALID()', file=f) + elif len(child['leaves']) == 1: + (tag,) = child['leaves'] + if tag in subinsn_groupings: + class_a = subinsn_groupings[tag]['class_a'] + class_b = subinsn_groupings[tag]['class_b'] + enc = subinsn_groupings[tag]['enc'].replace(' ', '') + if 'RESERVED' in tag: + print('INVALID()', file=f) + else: + print('SUBINSNS({},{},{},"{}")'.\ + format(tag, class_a, class_b, enc), file=f) + elif tag in iset.enc_ext_spaces: + enc = iset.enc_ext_spaces[tag].replace(' ', '') + print('EXTSPACE({},"{}")'.format(tag, enc), file=f) + else: + enc = ''.join(reversed(encs[tag])) + print('TERMINAL({},"{}")'.format(tag, enc), file=f) + else: + print('TABLE_LINK({})'.format(table_name(parents +[node], child)),
+ file=f)
+ print('DECODE_END_TABLE({},{},DECODE_SEPARATOR_BITS({},{}))'.\
+format(name, 2 ** width, lsb, width), file=f)
+ print(file=f)
+parents.append(node)
+ for child in node['children']:
+print_node(f, child, parents)
+parents.pop()target/hexagon/dectree.py new file +44
-0+ +def print_tree(f, tree): + print_node(f, tree, []) + +def print_match_info(f): + for tag in sorted(encs.keys(), key=iset.tags.index): + enc = ''.join(reversed(encs[tag])) + mask = int(re.sub(r'[^1]', r'0', enc.replace('0', '1')), 2) + match = int(re.sub(r'[^01]', r'0', enc), 2) + suffix = '' + print('DECODE{}_MATCH_INFO({},0x{:x}U,0x{:x}U)'.\ + format(suffix, tag, mask, match), file=f) + +regre = re.compile( + r'((?<!DUP)[MNORCPQXSGVZA])([stuvwxyzdefg]+)([.]?[LlHh]?)(\d+S?)') +immre = re.compile(r'[#]([rRsSuUm])(\d+)(?:[:](\d+))?') + +def ordered_unique(l): + return sorted(set(l), key=l.index) + +implicit_registers = { + 'SP' : 29, + 'FP' : 30, + 'LR' : 31 +} + +num_registers = { + 'R' : 32, + 'V' : 32 +} + +def print_op_info(f): + for tag in sorted(encs.keys(), key=iset.tags.index): + enc = encs[tag] + print(file=f) + print('DECODE_OPINFO({},'.format(tag), file=f) + regs = ordered_unique(regre.findall(iset.iset[tag]['syntax'])) + imms = ordered_unique(immre.findall(iset.iset[tag]['syntax'])) + regno = 0 + for reg in regs: + reg_type = reg[0] + reg_letter = reg[1][0] + reg_num_choices = int(reg[3].rstrip('S')) + reg_mapping = reg[0] + ''.join(['_' for letter inreg[1]]) + reg[3]
+reg_enc_fields=re.findall(reg_letter + '+', enc)+ iflen(reg_enc_fields)== 0:
+ raiseException('Tag "{}" missing register field!'.format(tag))
+ iflen(reg_enc_fields)> 1:
+ raise Exception('Tag "{}" has split register field!'.\
+ format(tag))
+reg_enc_field= reg_enc_fields[0]
+ if 2 **len(reg_enc_field)!=reg_num_choices:
+ raise Exception('Tag "{}" has incorrect register field width!'.\
+ format(tag))
+ print(' DECODE_REG({},{},{})'.\
+format(regno, len(reg_enc_field), enc.index(reg_enc_field)),
+ file=f)
+ ifreg_typeinnum_registersand \
+reg_num_choices!= num_registers[reg_type]:
+ print(' DECODE_MAPPED_REG({},{})'.\
+format(regno, reg_mapping), file=f)
+ regno += 1
+ defimplicit_register_key(reg):
+ return implicit_registers[reg]
+ for reg in sorted(
+ set([r for r in (iset.iset[tag]['rregs'].split(',') + \
+ iset.iset[tag]['wregs'].split(',')) \
+ if r inimplicit_registers]), key=implicit_register_key):
+ print(' DECODE_IMPL_REG({},{})'.\
+format(regno, implicit_registers[reg]), file=f) + regno += 1
+ if imms and imms[0][0].isupper():
+ imms = reversed(imms)
+ for imm in imms:
+ if imm[0].isupper():
+ immno = 1
+ else:
+ immno = 0
+imm_type= imm[0]
+imm_width=int(imm[1])
+imm_shift= imm[2]
+ ifimm_shift:
+imm_shift=int(imm_shift)
+ else:
+imm_shift= 0
+ ifimm_type.islower():
+imm_letter= 'i'
+ else:
+imm_letter= 'I'
+ remainder =imm_width
+ for m inreversed(list(re.finditer(imm_letter + '+', enc))):
+ remainder -=m.end()-m.start()
+ print(' DECODE_IMM({},{},{},{})'.\
+format(immno, m.end() - m.start(), m.start(), remainder),
+ file=f)
+ if remainder != 0:
+ if imm[2]:
+ imm[2] = ':' + imm[2]
+ raise Exception('Tag "{}" has an incorrect number of ' + \
+ 'encoding bits for immediate "{}"'.\
+format(tag, ''.join(imm)))
+ ifimm_type.lower()in 'sr':
+ print(' DECODE_IMM_SXT({},{})'.\
+format(immno, imm_width), file=f)
+ ifimm_type.lower()== 'n':
+ print(' DECODE_IMM_NEG({},{})'.\
+format(immno, imm_width), file=f)
+ ifimm_shift:
+ print(' DECODE_IMM_SHIFT({},{})'.\
+format(immno, imm_shift), file=f)
+ print(')', file=f)target/hexagon/dectree.py new file +4
-0+ +if __name__ == '__main__': + f = cStringIO.StringIO() + print_tree(f, dectree_normal)target/hexagon/dectree.py line 354
Quoted 10 lines
target/hexagon/dectree.py new file +10
-0+ print_tree(f, dectree_16bit) + if subinsn_groupings: + print_tree(f, dectree_subinsn_groupings) + for (name, dectree_subinsn) in sorted(dectree_subinsns.items()): + print_tree(f, dectree_subinsn) + for (name, dectree_ext) in sorted(dectree_extensions.items()): + print_tree(f, dectree_ext) + print_match_info(f) + print_op_info(f) + open('dectree_generated.h', 'w').write(f.getvalue())
RFC PATCH 29/66 Hexagon opcode data structures
In reply to Taylor Simpson--- target/hexagon/opcodes.c | 223 +++++++++++++++++++++++++++++++++++++++++++++++ target/hexagon/opcodes.h | 67 ++++++++++++++ 2 files changed, 290 insertions(+) create mode 100644 target/hexagon/opcodes.c create mode 100644 target/hexagon/opcodes.h
target/hexagon/opcodes.c new file +223 -0
@@ -0,0 +1,223 @@ +/* +* Copyright (c) 2019 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/>. +*/ + +/* +* opcodes.c +* +* data tables generated automatically +* Maybe some functions too +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <strings.h> +#include <string.h> +#include <stdarg.h> +#include <ctype.h> +#include "qemu/osdep.h" +#include "opcodes.h" +#include "decode.h" + +#define VEC_DESCR (A ,B ,C ) DESCR(A, B, C) +#define DONAME (X ) #X + +const char *opcode_names[] = { +#define OPCODE(IID) DONAME(IID) +#include "opcodes_def_generated.h" +NULL +#undef OPCODE +}; + +const char *opcode_reginfo[] = { +#define IMMINFO(TAG, SIGN, SIZE, SHAMT, SIGN2, SIZE2, SHAMT2) /* nothing */ +#define REGINFO(TAG, REGINFO, RREGS, WREGS) REGINFO, +#include "op_regs_generated.h" +NULL +#undef REGINFO +#undef IMMINFO +}; + + +const char *opcode_rregs[] = { +#define IMMINFO(TAG, SIGN, SIZE, SHAMT, SIGN2, SIZE2, SHAMT2) /* nothing */ +#define REGINFO(TAG, REGINFO, RREGS, WREGS) RREGS, +#include "op_regs_generated.h" +NULL +#undef REGINFO +#undef IMMINFO +}; + + +const char *opcode_wregs[] = { +#define IMMINFO(TAG, SIGN, SIZE, SHAMT, SIGN2, SIZE2, SHAMT2) /* nothing */ +#define REGINFO(TAG, REGINFO, RREGS, WREGS) WREGS, +#include "op_regs_generated.h" +NULL +#undef REGINFO +#undef IMMINFO +}; + +const char *opcode_short_semantics[] = { +#define OPCODE(X) NULL +#include "opcodes_def_generated.h" +#undef OPCODE +NULL +}; + + +size4u_t + opcode_attribs[XX_LAST_OPCODE ][(A_ZZ_LASTATTRIB /ATTRIB_WIDTH ) +1 ] = {0 }; + +static void init_attribs (int tag, ...) +{ +va_list ap; +int attr; +va_start (ap, tag); +while ((attr =va_arg (ap, int)) !=0 ) { + opcode_attribs[tag][attr /ATTRIB_WIDTH ] |=1 << (attr %ATTRIB_WIDTH ); + } +} + +static size4u_t str2val (const char *str) +{ +size4u_t ret =0 ; +for ( ; *str; str++) { +switch (*str) { +case ' ' : +case '\t' : +break ; +case 's' : +case 't' : +case 'u' : +case 'v' : +case 'w' : +case 'd' : +case 'e' : +case 'x' : +case 'y' : +case 'i' : +case 'I' : +case 'P' : +case 'E' : +case 'o' : +case '-' : +case '0' : + ret = (ret <<1 ) |0 ; +break ; +case '1' : + ret = (ret <<1 ) |1 ; +break ; +default : +break ; + } + } +return ret; +} + +static size1u_t has_ee (const char *str) +{ +return (strchr (str,'E' ) !=NULL ); +} + +opcode_encoding_t opcode_encodings[] = { +#define DEF_ENC32(OPCODE, ENCSTR) \ + [OPCODE] = { .encoding = ENCSTR }, + +#define DEF_ENC_SUBINSN(OPCODE, CLASS, ENCSTR) \ + [OPCODE] = { .encoding = ENCSTR, .enc_class = CLASS }, + +#define DEF_EXT_ENC(OPCODE, CLASS, ENCSTR) \ + [OPCODE] = { .encoding = ENCSTR, .enc_class = CLASS }, + +#include "imported/encode.def" + +#undef DEF_ENC32 +#undef DEF_ENC_SUBINSN +#undef DEF_EXT_ENC +}; + +void opcode_init (void ) +{ +init_attribs (0 ,0 ); + +#define DEF_ENC32 (OPCODE ,ENCSTR ) \ + opcode_encodings[OPCODE].vals = str2val(ENCSTR); \ + opcode_encodings[OPCODE].is_ee = has_ee(ENCSTR); + +#define DEF_ENC_SUBINSN (OPCODE ,CLASS ,ENCSTR ) \ + opcode_encodings[OPCODE].vals = str2val(ENCSTR); + +#define LEGACY_DEF_ENC32 (OPCODE ,ENCSTR ) \ + opcode_encodings[OPCODE].dep_vals = str2val(ENCSTR); + +#define DEF_EXT_ENC (OPCODE ,CLASS ,ENCSTR ) \ + opcode_encodings[OPCODE].vals = str2val(ENCSTR); + +#include "imported/encode.def" + +#undef LEGACY_DEF_ENC32 +#undef DEF_ENC32 +#undef DEF_ENC_SUBINSN +#undef DEF_EXT_ENC + +#define ATTRIBS (...) , ## __VA_ARGS__, 0 +#define OP_ATTRIB (TAG ,ARGS ) init_attribs(TAG ARGS); +#include "op_attribs_generated.h" +#undef OP_ATTRIB +#undef ATTRIBS + +decode_init (); + +#define DEF_QEMU (TAG ,SHORTCODE ,HELPER ,GENFN ,HELPFN ) \ + opcode_short_semantics[TAG] = #SHORTCODE; +#include "qemu_def_generated.h" +#undef DEF_QEMU +} + + +#define NEEDLE "IMMEXT(" + +int opcode_which_immediate_is_extended (opcode_t opcode) +{ +const char *p; +if (opcode >=XX_LAST_OPCODE ) { +g_assert_not_reached (); +return 0 ; + } +if (!GET_ATTRIB (opcode,A_EXTENDABLE )) { +g_assert_not_reached (); +return 0 ; + } + p = opcode_short_semantics[opcode]; + p =strstr (p,NEEDLE ); +if (p ==NULL ) { +g_assert_not_reached (); +return 0 ; + } + p +=strlen (NEEDLE ); +while (isspace (*p)) { + p++; + } +/* lower is always imm 0, upper always imm 1. */ +if (islower (*p)) { +return 0 ; + }else if (isupper (*p)) { +return 1 ; + }else { +g_assert_not_reached (); + } +}
target/hexagon/opcodes.h new file +67 -0
67 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [RFC PATCH 29/66] Hexagon opcode data structures
Quoted 34 lines · Taylor Simpson
Signed-off-by Taylor Simpson <[email protected]>--- target/hexagon/opcodes.c | 223 +++++++++++++++++++++++++++++++++++++++++++++++ target/hexagon/opcodes.h | 67 ++++++++++++++ 2 files changed, 290 insertions(+)create mode 100644
target/hexagon/opcodes.c
create mode 100644target/hexagon/opcodes.htarget/hexagon/opcodes.c new file +20
-0@@ -0,0 +1,223 @@ +/* +* Copyright (c) 2019 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/>. +*/ + +/* +* opcodes.c +*
target/hexagon/opcodes.c line 30
Quoted 10 lines
target/hexagon/opcodes.c new file +10
-0+* data tables generated automatically +* Maybe some functions too +*/ + +#include <stdio.h> +#include <stdlib.h> +#include <strings.h> +#include <string.h> +#include <stdarg.h> +#include <ctype.h>
Previous includes not needed ("qemu/osdep.h" includes them for you).
Quoted 207 lines
target/hexagon/opcodes.c new file +193
-0+#include "qemu/osdep.h" +#include "opcodes.h" +#include "decode.h" + +#define VEC_DESCR (A ,B ,C ) DESCR(A, B, C) +#define DONAME (X ) #X + +const char *opcode_names[] = { +#define OPCODE(IID) DONAME(IID) +#include "opcodes_def_generated.h" +NULL +#undef OPCODE +}; + +const char *opcode_reginfo[] = { +#define IMMINFO(TAG, SIGN, SIZE, SHAMT, SIGN2, SIZE2, SHAMT2) /* nothing */ +#define REGINFO(TAG, REGINFO, RREGS, WREGS) REGINFO, +#include "op_regs_generated.h" +NULL +#undef REGINFO +#undef IMMINFO +}; + + +const char *opcode_rregs[] = { +#define IMMINFO(TAG, SIGN, SIZE, SHAMT, SIGN2, SIZE2, SHAMT2) /* nothing */ +#define REGINFO(TAG, REGINFO, RREGS, WREGS) RREGS, +#include "op_regs_generated.h" +NULL +#undef REGINFO +#undef IMMINFO +}; + + +const char *opcode_wregs[] = { +#define IMMINFO(TAG, SIGN, SIZE, SHAMT, SIGN2, SIZE2, SHAMT2) /* nothing */ +#define REGINFO(TAG, REGINFO, RREGS, WREGS) WREGS, +#include "op_regs_generated.h" +NULL +#undef REGINFO +#undef IMMINFO +}; + +const char *opcode_short_semantics[] = { +#define OPCODE(X) NULL +#include "opcodes_def_generated.h" +#undef OPCODE +NULL +}; + + +size4u_t + opcode_attribs[XX_LAST_OPCODE ][(A_ZZ_LASTATTRIB /ATTRIB_WIDTH ) +1 ] = {0 }; + +static void init_attribs (int tag, ...) +{ +va_list ap; +int attr; +va_start (ap, tag); +while ((attr =va_arg (ap, int)) !=0 ) { + opcode_attribs[tag][attr /ATTRIB_WIDTH ] |=1 << (attr %ATTRIB_WIDTH ); + } +} + +static size4u_t str2val (const char *str) +{ +size4u_t ret =0 ; +for ( ; *str; str++) { +switch (*str) { +case ' ' : +case '\t' : +break ; +case 's' : +case 't' : +case 'u' : +case 'v' : +case 'w' : +case 'd' : +case 'e' : +case 'x' : +case 'y' : +case 'i' : +case 'I' : +case 'P' : +case 'E' : +case 'o' : +case '-' : +case '0' : + ret = (ret <<1 ) |0 ; +break ; +case '1' : + ret = (ret <<1 ) |1 ; +break ; +default : +break ; + } + } +return ret; +} + +static size1u_t has_ee (const char *str) +{ +return (strchr (str,'E' ) !=NULL ); +} + +opcode_encoding_t opcode_encodings[] = { +#define DEF_ENC32(OPCODE, ENCSTR) \ + [OPCODE] = { .encoding = ENCSTR }, + +#define DEF_ENC_SUBINSN(OPCODE, CLASS, ENCSTR) \ + [OPCODE] = { .encoding = ENCSTR, .enc_class = CLASS }, + +#define DEF_EXT_ENC(OPCODE, CLASS, ENCSTR) \ + [OPCODE] = { .encoding = ENCSTR, .enc_class = CLASS }, + +#include "imported/encode.def" + +#undef DEF_ENC32 +#undef DEF_ENC_SUBINSN +#undef DEF_EXT_ENC +}; + +void opcode_init (void ) +{ +init_attribs (0 ,0 ); + +#define DEF_ENC32 (OPCODE ,ENCSTR ) \ + opcode_encodings[OPCODE].vals = str2val(ENCSTR); \ + opcode_encodings[OPCODE].is_ee = has_ee(ENCSTR); + +#define DEF_ENC_SUBINSN (OPCODE ,CLASS ,ENCSTR ) \ + opcode_encodings[OPCODE].vals = str2val(ENCSTR); + +#define LEGACY_DEF_ENC32 (OPCODE ,ENCSTR ) \ + opcode_encodings[OPCODE].dep_vals = str2val(ENCSTR); + +#define DEF_EXT_ENC (OPCODE ,CLASS ,ENCSTR ) \ + opcode_encodings[OPCODE].vals = str2val(ENCSTR); + +#include "imported/encode.def" + +#undef LEGACY_DEF_ENC32 +#undef DEF_ENC32 +#undef DEF_ENC_SUBINSN +#undef DEF_EXT_ENC + +#define ATTRIBS (...) , ## __VA_ARGS__, 0 +#define OP_ATTRIB (TAG ,ARGS ) init_attribs(TAG ARGS); +#include "op_attribs_generated.h" +#undef OP_ATTRIB +#undef ATTRIBS + +decode_init (); + +#define DEF_QEMU (TAG ,SHORTCODE ,HELPER ,GENFN ,HELPFN ) \ + opcode_short_semantics[TAG] = #SHORTCODE; +#include "qemu_def_generated.h" +#undef DEF_QEMU +} + + +#define NEEDLE "IMMEXT(" + +int opcode_which_immediate_is_extended (opcode_t opcode) +{ +const char *p; +if (opcode >=XX_LAST_OPCODE ) { +g_assert_not_reached (); +return 0 ; + } +if (!GET_ATTRIB (opcode,A_EXTENDABLE )) { +g_assert_not_reached (); +return 0 ; + } + p = opcode_short_semantics[opcode]; + p =strstr (p,NEEDLE ); +if (p ==NULL ) { +g_assert_not_reached (); +return 0 ; + } + p +=strlen (NEEDLE ); +while (isspace (*p)) { + p++; + } +/* lower is always imm 0, upper always imm 1. */ +if (islower (*p)) { +return 0 ; + }else if (isupper (*p)) { +return 1 ; + }else { +g_assert_not_reached (); + } +}target/hexagon/opcodes.h new file +8
-0@@ -0,0 +1,67 @@ +/* +* Copyright (c) 2019 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. +*
target/hexagon/opcodes.h line 18
Quoted 10 lines
target/hexagon/opcodes.h new file +10
-0+* 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/>. +*/ + +#ifndef OPCODES_H
HEXAGON_OPCODES_H
I wonder if it would ease review to split this patch in 2, keep the C here, but provide opcodes.h in an earlier patch.
Quoted 50 lines
target/hexagon/opcodes.h new file +49
-0+#define OPCODES_H + +#include "hex_arch_types.h" +#include "attribs.h" + +typedef enum { +#define OPCODE(IID) IID +#include "opcodes_def_generated.h" + XX_LAST_OPCODE +#undef OPCODE +} opcode_t; + +typedef enum { +NORMAL , +HALF , +SUBINSN_A , +SUBINSN_L1 , +SUBINSN_L2 , +SUBINSN_S1 , +SUBINSN_S2 , + EXT_noext, + EXT_mmvec, +XX_LAST_ENC_CLASS +}enc_class_t ; + +extern const char *opcode_names[]; + +extern const char *opcode_reginfo[]; +extern const char *opcode_rregs[]; +extern const char *opcode_wregs[]; + +typedef struct { +const char *const encoding; +size4u_t vals; +size4u_t dep_vals; +const enc_class_t enc_class; +size1u_t is_ee:1 ; +}opcode_encoding_t ; + +extern opcode_encoding_t opcode_encodings[XX_LAST_OPCODE ]; + +extern size4u_t + opcode_attribs[XX_LAST_OPCODE ][(A_ZZ_LASTATTRIB /ATTRIB_WIDTH ) +1 ]; + +extern void opcode_init (void ); + +extern int opcode_which_immediate_is_extended (opcode_t opcode); + +#endif
RE: [RFC PATCH 29/66] Hexagon opcode data structures
Quoted 8 lines
-----Original Message-----
From: Philippe Mathieu-Daudé <[email protected]>
Sent: Tuesday, February 11, 2020 1:41 AM
To: Taylor Simpson <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [RFC PATCH 29/66] Hexagon opcode data structures
Quoted 6 lines
Quoted 1 line
+#ifndef
OPCODES_H
HEXAGON_OPCODES_HI wonder if it would ease review to split this patch in 2, keep the C here, but provide
opcodes.hin an earlier patch.
Wouldn't using scripts/git.orderfile solve this just as well? It will put opcodes.h ahead of opcodes.c in this patch.
Quoted 3 lines
Quoted 3 lines
target/hexagon/opcodes.h new file +2
-0+#define OPCODES_H +
RFC PATCH 30/66 Hexagon macros to interface with the generator
In reply to Taylor SimpsonVarious forms of declare, read, write, free
--- target/hexagon/macros.h | 388 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 388 insertions(+) create mode 100644 target/hexagon/macros.h
target/hexagon/macros.h new file +388 -0
@@ -0,0 +1,388 @@ +/* +* Copyright (c) 2019 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/>. +*/ + +#ifndef MACROS_H +#define MACROS_H + +#include "cpu.h" +#include "hex_regs.h" +#include "reg_fields.h" + +#ifdef QEMU_GENERATE +#define DECL_REG (NAME ,NUM ,X ,OFF ) \ + TCGv NAME = tcg_temp_local_new(); \ + int NUM = REGNO(X) + OFF + +#define DECL_REG_WRITABLE (NAME ,NUM ,X ,OFF ) \ + TCGv NAME = tcg_temp_local_new(); \ + int NUM = REGNO(X) + OFF; \ + do { \ + int is_predicated = GET_ATTRIB(insn->opcode, A_CONDEXEC); \ + if (is_predicated && !is_preloaded(ctx, NUM)) { \ + tcg_gen_mov_tl(hex_new_value[NUM], hex_gpr[NUM]); \ + } \ + } while (0) +/* +* For read-only temps, avoid allocating and freeing +*/ +#define DECL_REG_READONLY (NAME ,NUM ,X ,OFF ) \ + TCGv NAME; \ + int NUM = REGNO(X) + OFF + +#define DECL_RREG_d (NAME ,NUM ,X ,OFF ) \ + DECL_REG_WRITABLE(NAME, NUM, X, OFF) +#define DECL_RREG_e (NAME ,NUM ,X ,OFF ) \ + DECL_REG(NAME, NUM, X, OFF) +#define DECL_RREG_s (NAME ,NUM ,X ,OFF ) \ + DECL_REG_READONLY(NAME, NUM, X, OFF) +#define DECL_RREG_t (NAME ,NUM ,X ,OFF ) \ + DECL_REG_READONLY(NAME, NUM, X, OFF) +#define DECL_RREG_u (NAME ,NUM ,X ,OFF ) \ + DECL_REG_READONLY(NAME, NUM, X, OFF) +#define DECL_RREG_v (NAME ,NUM ,X ,OFF ) \ + DECL_REG_READONLY(NAME, NUM, X, OFF) +#define DECL_RREG_x (NAME ,NUM ,X ,OFF ) \ + DECL_REG_WRITABLE(NAME, NUM, X, OFF) +#define DECL_RREG_y (NAME ,NUM ,X ,OFF ) \ + DECL_REG_WRITABLE(NAME, NUM, X, OFF) + +#define DECL_PREG_d (NAME ,NUM ,X ,OFF ) \ + DECL_REG(NAME, NUM, X, OFF) +#define DECL_PREG_e (NAME ,NUM ,X ,OFF ) \ + DECL_REG(NAME, NUM, X, OFF) +#define DECL_PREG_s (NAME ,NUM ,X ,OFF ) \ + DECL_REG_READONLY(NAME, NUM, X, OFF) +#define DECL_PREG_t (NAME ,NUM ,X ,OFF ) \ + DECL_REG_READONLY(NAME, NUM, X, OFF) +#define DECL_PREG_u (NAME ,NUM ,X ,OFF ) \ + DECL_REG_READONLY(NAME, NUM, X, OFF) +#define DECL_PREG_v (NAME ,NUM ,X ,OFF ) \ + DECL_REG_READONLY(NAME, NUM, X, OFF) +#define DECL_PREG_x (NAME ,NUM ,X ,OFF ) \ + DECL_REG(NAME, NUM, X, OFF) +#define DECL_PREG_y (NAME ,NUM ,X ,OFF ) \ + DECL_REG(NAME, NUM, X, OFF) + +#define DECL_CREG_d (NAME ,NUM ,X ,OFF ) \ + DECL_REG(NAME, NUM, X, OFF) +#define DECL_CREG_s (NAME ,NUM ,X ,OFF ) \ + DECL_REG(NAME, NUM, X, OFF) + +#define DECL_MREG_u (NAME ,NUM ,X ,OFF ) \ + DECL_REG(NAME, NUM, X, OFF) + +#define DECL_NEW_NREG_s (NAME ,NUM ,X ,OFF ) \ + DECL_REG_READONLY(NAME, NUM, X, OFF) +#define DECL_NEW_NREG_t (NAME ,NUM ,X ,OFF ) \ + DECL_REG_READONLY(NAME, NUM, X, OFF) + +#define DECL_NEW_PREG_t (NAME ,NUM ,X ,OFF ) \ + DECL_REG_READONLY(NAME, NUM, X, OFF) +#define DECL_NEW_PREG_u (NAME ,NUM ,X ,OFF ) \ + DECL_REG_READONLY(NAME, NUM, X, OFF) +#define DECL_NEW_PREG_v (NAME ,NUM ,X ,OFF ) \ + DECL_REG_READONLY(NAME, NUM, X, OFF) + +#define DECL_NEW_OREG_s (NAME ,NUM ,X ,OFF ) \ + DECL_REG_READONLY(NAME, NUM, X, OFF) + +#define DECL_PAIR (NAME ,NUM ,X ,OFF ) \ + TCGv_i64 NAME = tcg_temp_local_new_i64(); \ + size1u_t NUM = REGNO(X) + OFF + +#define DECL_PAIR_WRITABLE (NAME ,NUM ,X ,OFF ) \ + TCGv_i64 NAME = tcg_temp_local_new_i64(); \ + size1u_t NUM = REGNO(X) + OFF; \ + do { \ + int is_predicated = GET_ATTRIB(insn->opcode, A_CONDEXEC); \ + if (is_predicated) { \ + if (!is_preloaded(ctx, NUM)) { \ + tcg_gen_mov_tl(hex_new_value[NUM], hex_gpr[NUM]); \ + } \ + if (!is_preloaded(ctx, NUM + 1)) { \ + tcg_gen_mov_tl(hex_new_value[NUM + 1], hex_gpr[NUM + 1]); \ + } \ + } \ + } while (0) + +#define DECL_RREG_dd (NAME ,NUM ,X ,OFF ) \ + DECL_PAIR_WRITABLE(NAME, NUM, X, OFF) +#define DECL_RREG_ss (NAME ,NUM ,X ,OFF ) \ + DECL_PAIR(NAME, NUM, X, OFF) +#define DECL_RREG_tt (NAME ,NUM ,X ,OFF ) \ + DECL_PAIR(NAME, NUM, X, OFF) +#define DECL_RREG_xx (NAME ,NUM ,X ,OFF ) \ + DECL_PAIR_WRITABLE(NAME, NUM, X, OFF) +#define DECL_RREG_yy (NAME ,NUM ,X ,OFF ) \ + DECL_PAIR_WRITABLE(NAME, NUM, X, OFF) + +#define DECL_CREG_dd (NAME ,NUM ,X ,OFF ) \ + DECL_PAIR_WRITABLE(NAME, NUM, X, OFF) +#define DECL_CREG_ss (NAME ,NUM ,X ,OFF ) \ + DECL_PAIR(NAME, NUM, X, OFF) + +#define DECL_IMM (NAME ,X ) \ + int NAME = IMMNO(X); \ + do { \ + NAME = NAME; \ + } while (0) +#define DECL_TCG_IMM (TCG_NAME ,VAL ) \ + TCGv TCG_NAME = tcg_const_tl(VAL) + +#define DECL_EA \ + TCGv EA; \ + do { \ + if (GET_ATTRIB(insn->opcode, A_CONDEXEC)) { \ + EA = tcg_temp_local_new(); \ + } else { \ + EA = tcg_temp_new(); \ + } \ + } while (0) + +#define LOG_REG_WRITE (RNUM ,VAL )\ + do { \ + int is_predicated = GET_ATTRIB(insn->opcode, A_CONDEXEC); \ + gen_log_reg_write(RNUM, VAL, insn->slot, is_predicated); \ + ctx_log_reg_write(ctx, (RNUM)); \ + } while (0) + +#define LOG_PRED_WRITE (PNUM ,VAL ) \ + do { \ + gen_log_pred_write(PNUM, VAL); \ + ctx_log_pred_write(ctx, (PNUM)); \ + } while (0) + +#define FREE_REG (NAME ) \ + tcg_temp_free(NAME) +#define FREE_REG_READONLY (NAME ) \ +/* Nothing */ + +#define FREE_RREG_d (NAME ) FREE_REG(NAME) +#define FREE_RREG_e (NAME ) FREE_REG(NAME) +#define FREE_RREG_s (NAME ) FREE_REG_READONLY(NAME) +#define FREE_RREG_t (NAME ) FREE_REG_READONLY(NAME) +#define FREE_RREG_u (NAME ) FREE_REG_READONLY(NAME) +#define FREE_RREG_v (NAME ) FREE_REG_READONLY(NAME) +#define FREE_RREG_x (NAME ) FREE_REG(NAME) +#define FREE_RREG_y (NAME ) FREE_REG(NAME) + +#define FREE_PREG_d (NAME ) FREE_REG(NAME) +#define FREE_PREG_e (NAME ) FREE_REG(NAME) +#define FREE_PREG_s (NAME ) FREE_REG_READONLY(NAME) +#define FREE_PREG_t (NAME ) FREE_REG_READONLY(NAME) +#define FREE_PREG_u (NAME ) FREE_REG_READONLY(NAME) +#define FREE_PREG_v (NAME ) FREE_REG_READONLY(NAME) +#define FREE_PREG_x (NAME ) FREE_REG(NAME) + +#define FREE_CREG_d (NAME ) FREE_REG(NAME) +#define FREE_CREG_s (NAME ) FREE_REG_READONLY(NAME) + +#define FREE_MREG_u (NAME ) FREE_REG_READONLY(NAME) + +#define FREE_NEW_NREG_s (NAME ) FREE_REG(NAME) +#define FREE_NEW_NREG_t (NAME ) FREE_REG(NAME) + +#define FREE_NEW_PREG_t (NAME ) FREE_REG_READONLY(NAME) +#define FREE_NEW_PREG_u (NAME ) FREE_REG_READONLY(NAME) +#define FREE_NEW_PREG_v (NAME ) FREE_REG_READONLY(NAME) + +#define FREE_NEW_OREG_s (NAME ) FREE_REG(NAME) + +#define FREE_REG_PAIR (NAME ) \ + tcg_temp_free_i64(NAME) + +#define FREE_RREG_dd (NAME ) FREE_REG_PAIR(NAME) +#define FREE_RREG_ss (NAME ) FREE_REG_PAIR(NAME) +#define FREE_RREG_tt (NAME ) FREE_REG_PAIR(NAME) +#define FREE_RREG_xx (NAME ) FREE_REG_PAIR(NAME) +#define FREE_RREG_yy (NAME ) FREE_REG_PAIR(NAME) + +#define FREE_CREG_dd (NAME ) FREE_REG_PAIR(NAME) +#define FREE_CREG_ss (NAME ) FREE_REG_PAIR(NAME) + +#define FREE_IMM (NAME )/* nothing */ +#define FREE_TCG_IMM (NAME ) tcg_temp_free(NAME) + +#define FREE_EA \ + tcg_temp_free(EA) +#else +#define LOG_REG_WRITE (RNUM ,VAL )\ + log_reg_write(env, RNUM, VAL, slot) +#define LOG_PRED_WRITE (RNUM ,VAL )\ + log_pred_write(env, RNUM, VAL) +#endif + +#define SLOT_WRAP (CODE ) \ + do { \ + TCGv slot = tcg_const_tl(insn->slot); \ + CODE; \ + tcg_temp_free(slot); \ + } while (0) + +#define PART1_WRAP (CODE ) \ + do { \ + TCGv part1 = tcg_const_tl(insn->part1); \ + CODE; \ + tcg_temp_free(part1); \ + } while (0) + +#define MARK_LATE_PRED_WRITE (RNUM )/* Not modelled in qemu */ + +#define REGNO (NUM ) (insn->regno[NUM]) +#define IMMNO (NUM ) (insn->immed[NUM]) + +#ifdef QEMU_GENERATE +#define READ_REG (dest,NUM ) \ + gen_read_reg(dest, NUM) +#define READ_REG_READONLY (dest,NUM ) \ + do { dest = hex_gpr[NUM]; } while (0) + +#define READ_RREG_s (dest,NUM ) \ + READ_REG_READONLY(dest, NUM) +#define READ_RREG_t (dest,NUM ) \ + READ_REG_READONLY(dest, NUM) +#define READ_RREG_u (dest,NUM ) \ + READ_REG_READONLY(dest, NUM) +#define READ_RREG_x (dest,NUM ) \ + READ_REG(dest, NUM) +#define READ_RREG_y (dest,NUM ) \ + READ_REG(dest, NUM) + +#define READ_OREG_s (dest,NUM ) \ + READ_REG_READONLY(dest, NUM) + +#ifdef QEMU_GENERATE +#define READ_CREG_s (dest,NUM ) \ + do { \ + if ((NUM) + HEX_REG_SA0 == HEX_REG_P3_0) { \ + gen_read_p3_0(dest); \ + } else { \ + READ_REG_READONLY(dest, ((NUM) + HEX_REG_SA0)); \ + } \ + } while (0) +#else +static inline int32_t read_p3_0 (CPUHexagonState *env) +{ +int32_t control_reg =0 ; +int i; +for (i =NUM_PREGS -1 ; i >=0 ; i--) { + control_reg <<=8 ; + control_reg |= env->pred[i] &0xff ; + } +return control_reg; +} + +#define READ_CREG_s (dest,NUM ) \ + do { \ + if (NUM == HEX_REG_P3_0) { \ + dest = read_p3_0(env); \ + } else { \ + READ_REG_READONLY(dest, ((NUM) + HEX_REG_SA0)); \ + } \ + } while (0) +#endif +#define READ_MREG_u (dest,NUM ) \ + do { \ + READ_REG_READONLY(dest, ((NUM) + HEX_REG_M0)); \ + dest = dest; \ + } while (0) +#else +#define READ_REG (NUM ) \ + (env->gpr[(NUM)]) +#define READ_MREG (NUM ) \ + (env->gpr[NUM + REG_M]) +#define READ_CSREG (NUM ) \ + (env->gpr[NUM + HEX_REG_CS0]) +#endif + +#ifdef QEMU_GENERATE +#define READ_REG_PAIR (tmp,NUM ) \ + tcg_gen_concat_i32_i64(tmp, hex_gpr[NUM], hex_gpr[(NUM) + 1]) +#define READ_RREG_ss (tmp,NUM ) READ_REG_PAIR(tmp, NUM) +#define READ_RREG_tt (tmp,NUM ) READ_REG_PAIR(tmp, NUM) +#define READ_RREG_xx (tmp,NUM ) READ_REG_PAIR(tmp, NUM) +#define READ_RREG_yy (tmp,NUM ) READ_REG_PAIR(tmp, NUM) + +#define READ_CREG_PAIR (tmp, i) \ + READ_REG_PAIR(tmp, ((i) + HEX_REG_SA0)) +#define READ_CREG_ss (tmp, i) READ_CREG_PAIR(tmp, i) +#endif + +#ifdef QEMU_GENERATE +#define READ_PREG (dest,NUM ) gen_read_preg(dest, (NUM)) +#define READ_PREG_READONLY (dest,NUM ) do { dest = hex_pred[NUM]; } while (0) + +#define READ_PREG_s (dest,NUM ) READ_PREG_READONLY(dest, NUM) +#define READ_PREG_t (dest,NUM ) READ_PREG_READONLY(dest, NUM) +#define READ_PREG_u (dest,NUM ) READ_PREG_READONLY(dest, NUM) +#define READ_PREG_v (dest,NUM ) READ_PREG_READONLY(dest, NUM) +#define READ_PREG_x (dest,NUM ) READ_PREG(dest, NUM) + +#define READ_NEW_PREG (pred,PNUM ) \ + do { pred = hex_new_pred_value[PNUM]; } while (0) +#define READ_NEW_PREG_t (pred,PNUM ) READ_NEW_PREG(pred, PNUM) +#define READ_NEW_PREG_u (pred,PNUM ) READ_NEW_PREG(pred, PNUM) +#define READ_NEW_PREG_v (pred,PNUM ) READ_NEW_PREG(pred, PNUM) + +#define READ_NEW_REG (tmp, i) \ + do { tmp = tcg_const_tl(i); } while (0) +#define READ_NEW_NREG_s (tmp, i) READ_NEW_REG(tmp, i) +#define READ_NEW_NREG_t (tmp, i) READ_NEW_REG(tmp, i) +#define READ_NEW_OREG_s (tmp, i) READ_NEW_REG(tmp, i) +#else +#define READ_PREG (NUM ) (env->pred[NUM]) +#endif + + +#define WRITE_RREG (NUM ,VAL ) LOG_REG_WRITE(NUM, VAL) +#define WRITE_RREG_d (NUM ,VAL ) LOG_REG_WRITE(NUM, VAL) +#define WRITE_RREG_e (NUM ,VAL ) LOG_REG_WRITE(NUM, VAL) +#define WRITE_RREG_x (NUM ,VAL ) LOG_REG_WRITE(NUM, VAL) +#define WRITE_RREG_y (NUM ,VAL ) LOG_REG_WRITE(NUM, VAL) + +#define WRITE_PREG (NUM ,VAL ) LOG_PRED_WRITE(NUM, VAL) +#define WRITE_PREG_d (NUM ,VAL ) LOG_PRED_WRITE(NUM, VAL) +#define WRITE_PREG_e (NUM ,VAL ) LOG_PRED_WRITE(NUM, VAL) +#define WRITE_PREG_x (NUM ,VAL ) LOG_PRED_WRITE(NUM, VAL) + +#ifdef QEMU_GENERATE +#define WRITE_CREG (i, tmp) \ + do { \ + if (i + HEX_REG_SA0 == HEX_REG_P3_0) { \ + gen_write_p3_0(tmp); \ + } else { \ + WRITE_RREG((i) + HEX_REG_SA0, tmp); \ + } \ + } while (0) +#define WRITE_CREG_d (NUM ,VAL ) WRITE_CREG(NUM, VAL) + +#define WRITE_CREG_PAIR (i, tmp) WRITE_REG_PAIR((i) + HEX_REG_SA0, tmp) +#define WRITE_CREG_dd (NUM ,VAL ) WRITE_CREG_PAIR(NUM, VAL) + +#define WRITE_REG_PAIR (NUM ,VAL ) \ + do { \ + int is_predicated = GET_ATTRIB(insn->opcode, A_CONDEXEC); \ + gen_log_reg_write_pair(NUM, VAL, insn->slot, is_predicated); \ + ctx_log_reg_write(ctx, (NUM)); \ + ctx_log_reg_write(ctx, (NUM) + 1); \ + } while (0) + +#define WRITE_RREG_dd (NUM ,VAL ) WRITE_REG_PAIR(NUM, VAL) +#define WRITE_RREG_xx (NUM ,VAL ) WRITE_REG_PAIR(NUM, VAL) +#define WRITE_RREG_yy (NUM ,VAL ) WRITE_REG_PAIR(NUM, VAL) +#endif +
Signature · 1 line
2.7.4
RFC PATCH 31/66 Hexagon macros referenced in instruction semantics
In reply to Taylor Simpson--- target/hexagon/macros.h | 1111 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 1111 insertions(+)
target/hexagon/macros.h +1111 -0
@@ -386,3 +386,1114 @@ static inline int32_t read_p3_0(CPUHexagonState *env)#define WRITE_RREG_yy (NUM ,VAL ) WRITE_REG_PAIR(NUM, VAL)#endif +#define PCALIGN 4 +#define PCALIGN_MASK (PCALIGN - 1) + +#define GET_FIELD (FIELD ,REGIN ) \ + fEXTRACTU_BITS(REGIN, reg_field_info[FIELD].width, \ + reg_field_info[FIELD].offset) + +#ifdef QEMU_GENERATE +#define GET_USR_FIELD (FIELD ,DST ) \ + tcg_gen_extract_tl(DST, hex_gpr[HEX_REG_USR], \ + reg_field_info[FIELD].offset, \ + reg_field_info[FIELD].width) + +#define SET_USR_FIELD_FUNC (X ) \ + _Generic((X), int : gen_set_usr_fieldi, TCGv : gen_set_usr_field) +#define SET_USR_FIELD (FIELD ,VAL ) \ + SET_USR_FIELD_FUNC(VAL)(FIELD, VAL) +#else +#define GET_USR_FIELD (FIELD ) \ + fEXTRACTU_BITS(env->gpr[HEX_REG_USR], reg_field_info[FIELD].width, \ + reg_field_info[FIELD].offset) + +#define SET_USR_FIELD (FIELD ,VAL ) \ + fINSERT_BITS(env->gpr[HEX_REG_USR], reg_field_info[FIELD].width, \ + reg_field_info[FIELD].offset, (VAL)) +#endif + +#ifdef QEMU_GENERATE +#define MEM_LOAD1s (DST ,VA ) tcg_gen_qemu_ld8s(DST, VA, ctx->mem_idx) +#define MEM_LOAD1u (DST ,VA ) tcg_gen_qemu_ld8u(DST, VA, ctx->mem_idx) +#define MEM_LOAD2s (DST ,VA ) tcg_gen_qemu_ld16s(DST, VA, ctx->mem_idx) +#define MEM_LOAD2u (DST ,VA ) tcg_gen_qemu_ld16u(DST, VA, ctx->mem_idx) +#define MEM_LOAD4s (DST ,VA ) tcg_gen_qemu_ld32s(DST, VA, ctx->mem_idx) +#define MEM_LOAD4u (DST ,VA ) tcg_gen_qemu_ld32s(DST, VA, ctx->mem_idx) +#define MEM_LOAD8s (DST ,VA ) tcg_gen_qemu_ld64(DST, VA, ctx->mem_idx) +#define MEM_LOAD8u (DST ,VA ) tcg_gen_qemu_ld64(DST, VA, ctx->mem_idx) + +#define MEM_STORE1_FUNC (X ) \ + _Generic((X), int : gen_store1i, TCGv_i32 : gen_store1) +#define MEM_STORE1 (VA ,DATA ,SLOT ) \ + MEM_STORE1_FUNC(DATA)(cpu_env, VA, DATA, ctx, SLOT) + +#define MEM_STORE2_FUNC (X ) \ + _Generic((X), int : gen_store2i, TCGv_i32 : gen_store2) +#define MEM_STORE2 (VA ,DATA ,SLOT ) \ + MEM_STORE2_FUNC(DATA)(cpu_env, VA, DATA, ctx, SLOT) + +#define MEM_STORE4_FUNC (X ) \ + _Generic((X), int : gen_store4i, TCGv_i32 : gen_store4) +#define MEM_STORE4 (VA ,DATA ,SLOT ) \ + MEM_STORE4_FUNC(DATA)(cpu_env, VA, DATA, ctx, SLOT) + +#define MEM_STORE8_FUNC (X ) \ + _Generic((X), int64_t : gen_store8i, TCGv_i64 : gen_store8) +#define MEM_STORE8 (VA ,DATA ,SLOT ) \ + MEM_STORE8_FUNC(DATA)(cpu_env, VA, DATA, ctx, SLOT) + +#else +/* +* These should never be executed, but they are needed so the helpers will +* compile. All the instructions with loads must be implemented under +* QEMU_GENERATE. +*/ +static inline uint8_t mem_load1 (CPUHexagonState *env,target_ulong vaddr) +{ +printf ("ERROR: mem_load1\n" ); +g_assert_not_reached (); +} + +static inline uint16_t mem_load2 (CPUHexagonState *env,target_ulong vadd) +{ +printf ("ERROR: mem_load2\n" ); +g_assert_not_reached (); +} + +static inline uint32_t mem_load4 (CPUHexagonState *env,target_ulong vaddr) +{ +printf ("ERROR: mem_load4\n" ); +g_assert_not_reached (); +} + +static inline uint64_t mem_load8 (CPUHexagonState *env,target_ulong vaddr) +{ +printf ("ERROR: mem_load8\n" ); +g_assert_not_reached (); +} + +static inline +uint32_t mem_load_locked4 (CPUHexagonState *env,target_ulong vaddr) +{ +printf ("ERROR: load_locked4\n" ); +g_assert_not_reached (); +return 0 ; +} + +static inline +uint64_t mem_load_locked8 (CPUHexagonState *env,target_ulong vaddr) +{ +printf ("ERROR: load_locked8\n" ); +g_assert_not_reached (); +return 0 ; +} + +static inline +uint8_t mem_store_conditional (CPUHexagonState *env, +target_ulong vaddr,uint32_t src,int size) +{ +printf ("ERROR: store conditional\n" ); +g_assert_not_reached (); +return 0 ; +} + +#define MEM_LOAD1s (VA ) ((size1s_t)mem_load1(env, VA)) +#define MEM_LOAD1u (VA ) ((size1u_t)mem_load1(env, VA)) +#define MEM_LOAD2s (VA ) ((size2s_t)mem_load2(env, VA)) +#define MEM_LOAD2u (VA ) ((size2u_t)mem_load2(env, VA)) +#define MEM_LOAD4s (VA ) ((size4s_t)mem_load4(env, VA)) +#define MEM_LOAD4u (VA ) ((size4u_t)mem_load4(env, VA)) +#define MEM_LOAD8s (VA ) ((size8s_t)mem_load8(env, VA)) +#define MEM_LOAD8u (VA ) ((size8u_t)mem_load8(env, VA)) + +#define MEM_STORE1 (VA ,DATA ,SLOT ) log_store32(env, VA, DATA, 1, SLOT) +#define MEM_STORE2 (VA ,DATA ,SLOT ) log_store32(env, VA, DATA, 2, SLOT) +#define MEM_STORE4 (VA ,DATA ,SLOT ) log_store32(env, VA, DATA, 4, SLOT) +#define MEM_STORE8 (VA ,DATA ,SLOT ) log_store64(env, VA, DATA, 8, SLOT) +#endif + + +#ifdef QEMU_GENERATE +static inline void gen_slot_cancelled_check (TCGv check,int slot_num) +{ +TCGv mask =tcg_const_tl (1 << slot_num); +TCGv one =tcg_const_tl (1 ); +TCGv zero =tcg_const_tl (0 ); + +tcg_gen_and_tl (mask, hex_slot_cancelled, mask); +tcg_gen_movcond_tl (TCG_COND_NE , check, mask, zero, one, zero); + +tcg_temp_free (one); +tcg_temp_free (zero); +tcg_temp_free (mask); +} + +static inline void gen_cancel (TCGv slot) +{ +TCGv one =tcg_const_tl (1 ); +TCGv mask =tcg_temp_new (); +tcg_gen_shl_tl (mask, one, slot); +tcg_gen_or_tl (hex_slot_cancelled, hex_slot_cancelled, mask); +tcg_temp_free (one); +tcg_temp_free (mask); +} + +#define CANCEL gen_cancel(slot); +#else +#define CANCEL cancel_slot(env, slot) +#endif + +#define STORE_ZERO +#define LOAD_CANCEL (EA ) do { CANCEL; } while (0) + +#ifdef QEMU_GENERATE +static inline void gen_pred_cancel (TCGv pred,int slot_num) + { +TCGv slot_mask =tcg_const_tl (1 << slot_num); +TCGv tmp =tcg_temp_new (); +TCGv zero =tcg_const_tl (0 ); +TCGv one =tcg_const_tl (1 ); +tcg_gen_or_tl (slot_mask, hex_slot_cancelled, slot_mask); +tcg_gen_andi_tl (tmp, pred,1 ); +tcg_gen_movcond_tl (TCG_COND_EQ , hex_slot_cancelled, tmp, zero, + slot_mask, hex_slot_cancelled); +tcg_temp_free (slot_mask); +tcg_temp_free (tmp); +tcg_temp_free (zero); +tcg_temp_free (one); +} +#define PRED_LOAD_CANCEL (PRED ,EA ) \ + gen_pred_cancel(PRED, insn->is_endloop ? 4 : insn->slot) + +#define PRED_STORE_CANCEL (PRED ,EA ) \ + gen_pred_cancel(PRED, insn->is_endloop ? 4 : insn->slot) +#else +#define STORE_CANCEL (EA ) { env->slot_cancelled |= (1 << slot); } +#endif + +#define IS_CANCELLED (SLOT ) +#define fMAX (A ,B ) (((A) > (B)) ? (A) : (B)) + +#ifdef QEMU_GENERATE +#define fMIN (DST ,A ,B ) tcg_gen_movcond_i32(TCG_COND_GT, DST, A, B, A, B) +#else +#define fMIN (A ,B ) (((A) < (B)) ? (A) : (B)) +#endif + +#define fABS (A ) (((A) < 0) ? (-(A)) : (A)) +#define fINSERT_BITS (REG ,WIDTH ,OFFSET ,INVAL ) \ + do { \ + REG = ((REG) & ~(((fCONSTLL(1) << (WIDTH)) - 1) << (OFFSET))) | \ + (((INVAL) & ((fCONSTLL(1) << (WIDTH)) - 1)) << (OFFSET)); \ + } while (0) +#define fEXTRACTU_BITS (INREG ,WIDTH ,OFFSET ) \ + (fZXTN(WIDTH, 32, (INREG >> OFFSET))) +#define fEXTRACTU_BIDIR (INREG ,WIDTH ,OFFSET ) \ + (fZXTN(WIDTH, 32, fBIDIR_LSHIFTR((INREG), (OFFSET), 4_8))) +#define fEXTRACTU_RANGE (INREG ,HIBIT ,LOWBIT ) \ + (fZXTN((HIBIT - LOWBIT + 1), 32, (INREG >> LOWBIT))) +#define fINSERT_RANGE (INREG ,HIBIT ,LOWBIT ,INVAL ) \ + do { \ + int offset = LOWBIT; \ + int width = HIBIT - LOWBIT + 1; \ + INREG &= ~(((fCONSTLL(1) << width) - 1) << offset); \ + INREG |= ((INVAL & ((fCONSTLL(1) << width) - 1)) << offset); \ + } while (0) + +#ifdef QEMU_GENERATE +#define f8BITSOF (RES ,VAL ) gen_8bitsof(RES, VAL) +#define fLSBOLD (VAL ) tcg_gen_andi_tl(LSB, (VAL), 1) +#else +#define f8BITSOF (VAL ) ((VAL) ? 0xff : 0x00) +#define fLSBOLD (VAL ) ((VAL) & 1) +#endif + +#ifdef QEMU_GENERATE +#define fLSBNEW (PVAL ) tcg_gen_mov_tl(LSB, (PVAL)) +#define fLSBNEW0 fLSBNEW(0) +#define fLSBNEW1 fLSBNEW(1) +#else +#define fLSBNEW (PVAL ) (PVAL) +#define fLSBNEW0 new_pred_value(env, 0) +#define fLSBNEW1 new_pred_value(env, 1) +#endif + +#ifdef QEMU_GENERATE +static inline void gen_logical_not (TCGv dest,TCGv src) +{ +TCGv one =tcg_const_tl (1 ); +TCGv zero =tcg_const_tl (0 ); + +tcg_gen_movcond_tl (TCG_COND_NE , dest, src, zero, zero, one); + +tcg_temp_free (one); +tcg_temp_free (zero); +} +#define fLSBOLDNOT (VAL ) \ + do { \ + tcg_gen_andi_tl(LSB, (VAL), 1); \ + tcg_gen_xori_tl(LSB, LSB, 1); \ + } while (0) +#define fLSBNEWNOT (PNUM ) \ + gen_logical_not(LSB, (PNUM)) +#define fLSBNEW0NOT \ + do { \ + tcg_gen_mov_tl(LSB, hex_new_pred_value[0]); \ + gen_logical_not(LSB, LSB); \ + } while (0) +#define fLSBNEW1NOT \ + do { \ + tcg_gen_mov_tl(LSB, hex_new_pred_value[1]); \ + gen_logical_not(LSB, LSB); \ + } while (0) +#else +#define fLSBNEWNOT (PNUM ) (!fLSBNEW(PNUM)) +#define fLSBOLDNOT (VAL ) (!fLSBOLD(VAL)) +#define fLSBNEW0NOT (!fLSBNEW0) +#define fLSBNEW1NOT (!fLSBNEW1) +#endif + +#define fNEWREG (RNUM ) HELPER(new_value)(env, RNUM) + +#ifdef QEMU_GENERATE +#define fNEWREG_ST (RNUM ) gen_newreg_st(NEWREG_ST, cpu_env, RNUM) +#else +#define fNEWREG_ST (RNUM ) HELPER(new_value)(env, RNUM) +#endif + +#define fMEMZNEW (RNUM ) (RNUM == 0) +#define fMEMNZNEW (RNUM ) (RNUM != 0) +#define fVSATUVALN (N ,VAL ) \ + ({ \ + (((int)(VAL)) < 0) ? 0 : ((1LL << (N)) - 1); \ + }) +#define fSATUVALN (N ,VAL ) \ + ({ \ + fSET_OVERFLOW(); \ + ((VAL) < 0) ? 0 : ((1LL << (N)) - 1); \ + }) +#define fSATVALN (N ,VAL ) \ + ({ \ + fSET_OVERFLOW(); \ + ((VAL) < 0) ? (-(1LL << ((N) - 1))) : ((1LL << ((N) - 1)) - 1); \ + }) +#define fVSATVALN (N ,VAL ) \ + ({ \ + ((VAL) < 0) ? (-(1LL << ((N) - 1))) : ((1LL << ((N) - 1)) - 1); \ + }) +#define fZXTN (N ,M ,VAL ) ((VAL) & ((1LL << (N)) - 1)) +#define fSXTN (N ,M ,VAL ) \ + ((fZXTN(N, M, VAL) ^ (1LL << ((N) - 1))) - (1LL << ((N) - 1))) +#define fSATN (N ,VAL ) \ + ((fSXTN(N, 64, VAL) == (VAL)) ? (VAL) : fSATVALN(N, VAL)) +#define fVSATN (N ,VAL ) \ + ((fSXTN(N, 64, VAL) == (VAL)) ? (VAL) : fVSATVALN(N, VAL)) +#define fADDSAT64 (DST ,A ,B ) \ + do { \ + size8u_t __a = fCAST8u(A); \ + size8u_t __b = fCAST8u(B); \ + size8u_t __sum = __a + __b; \ + size8u_t __xor = __a ^ __b; \ + const size8u_t __mask = 0x8000000000000000ULL; \ + if (__xor & __mask) { \ + DST = __sum; \ + } \ + else if ((__a ^ __sum) & __mask) { \ + if (__sum & __mask) { \ + DST = 0x7FFFFFFFFFFFFFFFLL; \ + fSET_OVERFLOW(); \ + } else { \ + DST = 0x8000000000000000LL; \ + fSET_OVERFLOW(); \ + } \ + } else { \ + DST = __sum; \ + } \ + } while (0) +#define fVSATUN (N ,VAL ) \ + ((fZXTN(N, 64, VAL) == (VAL)) ? (VAL) : fVSATUVALN(N, VAL)) +#define fSATUN (N ,VAL ) \ + ((fZXTN(N, 64, VAL) == (VAL)) ? (VAL) : fSATUVALN(N, VAL)) +#define fSATH (VAL ) (fSATN(16, VAL)) +#define fSATUH (VAL ) (fSATUN(16, VAL)) +#define fVSATH (VAL ) (fVSATN(16, VAL)) +#define fVSATUH (VAL ) (fVSATUN(16, VAL)) +#define fSATUB (VAL ) (fSATUN(8, VAL)) +#define fSATB (VAL ) (fSATN(8, VAL)) +#define fVSATUB (VAL ) (fVSATUN(8, VAL)) +#define fVSATB (VAL ) (fVSATN(8, VAL)) +#define fIMMEXT (IMM ) (IMM = IMM) +#define fMUST_IMMEXT (IMM ) fIMMEXT(IMM) + +#define fPCALIGN (IMM ) IMM = (IMM & ~PCALIGN_MASK) + +#define fGET_EXTENSION (insn->extension) + +#ifdef QEMU_GENERATE +static inline TCGv gen_read_ireg (TCGv tmp,TCGv val,int shift) +{ +/* +* #define fREAD_IREG(VAL) \ +* (fSXTN(11, 64, (((VAL) & 0xf0000000)>>21) | ((VAL >> 17) & 0x7f))) +*/ +tcg_gen_sari_tl (tmp, val,17 ); +tcg_gen_andi_tl (tmp, tmp,0x7f ); +tcg_gen_shli_tl (tmp, tmp, shift); +return tmp; +} +#define fREAD_IREG (VAL ,SHIFT ) gen_read_ireg(ireg, (VAL), (SHIFT)) +#define fREAD_R0 () (READ_REG(tmp, 0)) +#define fREAD_LR () (READ_REG(tmp, HEX_REG_LR)) +#define fREAD_SSR () (READ_REG(tmp, HEX_REG_SSR)) +#else +#define fREAD_IREG (VAL ) \ + (fSXTN(11, 64, (((VAL) & 0xf0000000) >> 21) | ((VAL >> 17) & 0x7f))) +#define fREAD_R0 () (READ_REG(0)) +#define fREAD_LR () (READ_REG(HEX_REG_LR)) +#define fREAD_SSR () (READ_REG(HEX_REG_SSR)) +#endif + +#define fWRITE_R0 (A ) WRITE_RREG(0, A) +#define fWRITE_LR (A ) WRITE_RREG(HEX_REG_LR, A) +#define fWRITE_FP (A ) WRITE_RREG(HEX_REG_FP, A) +#define fWRITE_SP (A ) WRITE_RREG(HEX_REG_SP, A) +#define fWRITE_GOSP (A ) WRITE_RREG(HEX_REG_GOSP, A) +#define fWRITE_GP (A ) WRITE_RREG(HEX_REG_GP, A) + +#ifdef QEMU_GENERATE +#define fREAD_SP () (READ_REG(tmp, HEX_REG_SP)) +#define fREAD_GOSP () (READ_REG(tmp, HEX_REG_GOSP)) +#define fREAD_GELR () (READ_REG(tmp, HEX_REG_GELR)) +#define fREAD_GEVB () (READ_REG(tmp, HEX_REG_GEVB)) +#define fREAD_CSREG (N ) (READ_REG(tmp, HEX_REG_CS0 + N)) +#define fREAD_LC0 (READ_REG(tmp, HEX_REG_LC0)) +#define fREAD_LC1 (READ_REG(tmp, HEX_REG_LC1)) +#define fREAD_SA0 (READ_REG(tmp, HEX_REG_SA0)) +#define fREAD_SA1 (READ_REG(tmp, HEX_REG_SA1)) +#define fREAD_FP () (READ_REG(tmp, HEX_REG_FP)) +#define fREAD_GP () (READ_REG(tmp, HEX_REG_GP)) +#define fREAD_PC () (READ_REG(tmp, HEX_REG_PC)) +#else +#define fREAD_SP () (READ_REG(HEX_REG_SP)) +#define fREAD_GOSP () (READ_REG(HEX_REG_GOSP)) +#define fREAD_GELR () (READ_REG(HEX_REG_GELR)) +#define fREAD_GEVB () (READ_REG(HEX_REG_GEVB)) +#define fREAD_CSREG (N ) (READ_REG(HEX_REG_CS0 + N)) +#define fREAD_LC0 (READ_REG(HEX_REG_LC0)) +#define fREAD_LC1 (READ_REG(HEX_REG_LC1)) +#define fREAD_SA0 (READ_REG(HEX_REG_SA0)) +#define fREAD_SA1 (READ_REG(HEX_REG_SA1)) +#define fREAD_FP () (READ_REG(HEX_REG_FP)) +#define fREAD_GP () (READ_REG(HEX_REG_GP)) +#define fREAD_PC () (READ_REG(HEX_REG_PC)) +#endif + +#define fREAD_NPC () (env->next_PC & (0xfffffffe)) + +#ifdef QEMU_GENERATE +#define fREAD_P0 () (READ_PREG(tmp, 0)) +#define fREAD_P3 () (READ_PREG(tmp, 3)) +#define fNOATTRIB_READ_P3 () (READ_PREG(tmp, 3)) +#else +#define fREAD_P0 () (READ_PREG(0)) +#define fREAD_P3 () (READ_PREG(3)) +#define fNOATTRIB_READ_P3 () (READ_PREG(3)) +#endif + +#define fCHECK_PCALIGN (A ) +#define fCUREXT () GET_SSR_FIELD(SSR_XA) +#define fCUREXT_WRAP (EXT_NO ) + +#ifdef QEMU_GENERATE +#define fWRITE_NPC (A ) gen_write_new_pc(A) +#else +#define fWRITE_NPC (A ) write_new_pc(env, A) +#endif + +#define fLOOPSTATS (A ) +#define fCOF_CALLBACK (LOC ,TYPE ) +#define fBRANCH (LOC ,TYPE ) \ + do { \ + fWRITE_NPC(LOC); \ + fCOF_CALLBACK(LOC, TYPE); \ + } while (0) +#define fJUMPR (REGNO ,TARGET ,TYPE ) fBRANCH(TARGET, COF_TYPE_JUMPR) +#define fHINTJR (TARGET ) { } +#define fBP_RAS_CALL (A ) +#define fCALL (A ) \ + do { \ + fWRITE_LR(fREAD_NPC()); \ + fBRANCH(A, COF_TYPE_CALL); \ + } while (0) +#define fCALLR (A ) \ + do { \ + fWRITE_LR(fREAD_NPC()); \ + fBRANCH(A, COF_TYPE_CALLR); \ + } while (0) +#define fWRITE_LOOP_REGS0 (START ,COUNT ) \ + do { \ + WRITE_RREG(HEX_REG_LC0, COUNT); \ + WRITE_RREG(HEX_REG_SA0, START); \ + } while (0) +#define fWRITE_LOOP_REGS1 (START ,COUNT ) \ + do { \ + WRITE_RREG(HEX_REG_LC1, COUNT); \ + WRITE_RREG(HEX_REG_SA1, START);\ + } while (0) +#define fWRITE_LC0 (VAL ) WRITE_RREG(HEX_REG_LC0, VAL) +#define fWRITE_LC1 (VAL ) WRITE_RREG(HEX_REG_LC1, VAL) + +#ifdef QEMU_GENERATE +#define fCARRY_FROM_ADD (A ,B ,C ) gen_carry_from_add64(tmp_i64, A, B, C) +#else +#define fCARRY_FROM_ADD (A ,B ,C ) carry_from_add64(A, B, C) +#endif + +#define fSETCV_ADD (A ,B ,CARRY ) \ + do { \ + SET_USR_FIELD(USR_C, gen_carry_add((A), (B), ((A) + (B)))); \ + SET_USR_FIELD(USR_V, gen_overflow_add((A), (B), ((A) + (B)))); \ + } while (0) +#define fSETCV_SUB (A ,B ,CARRY ) \ + do { \ + SET_USR_FIELD(USR_C, gen_carry_add((A), (B), ((A) - (B)))); \ + SET_USR_FIELD(USR_V, gen_overflow_add((A), (B), ((A) - (B)))); \ + } while (0) +#define fSET_OVERFLOW () SET_USR_FIELD(USR_OVF, 1) +#define fSET_LPCFG (VAL ) SET_USR_FIELD(USR_LPCFG, (VAL)) +#define fGET_LPCFG (GET_USR_FIELD(USR_LPCFG)) +#define fWRITE_P0 (VAL ) WRITE_PREG(0, VAL) +#define fWRITE_P1 (VAL ) WRITE_PREG(1, VAL) +#define fWRITE_P2 (VAL ) WRITE_PREG(2, VAL) +#define fWRITE_P3 (VAL ) WRITE_PREG(3, VAL) +#define fWRITE_P3_LATE (VAL ) WRITE_PREG(3, VAL) +#define fPART1 (WORK ) if (part1) { WORK; return; } +#define fCAST4u (A ) ((size4u_t)(A)) +#define fCAST4s (A ) ((size4s_t)(A)) +#define fCAST8u (A ) ((size8u_t)(A)) +#define fCAST8s (A ) ((size8s_t)(A)) +#define fCAST2_2s (A ) ((size2s_t)(A)) +#define fCAST2_2u (A ) ((size2u_t)(A)) +#define fCAST4_4s (A ) ((size4s_t)(A)) +#define fCAST4_4u (A ) ((size4u_t)(A)) +#define fCAST4_8s (A ) ((size8s_t)((size4s_t)(A))) +#define fCAST4_8u (A ) ((size8u_t)((size4u_t)(A))) +#define fCAST8_8s (A ) ((size8s_t)(A)) +#define fCAST8_8u (A ) ((size8u_t)(A)) +#define fCAST2_8s (A ) ((size8s_t)((size2s_t)(A))) +#define fCAST2_8u (A ) ((size8u_t)((size2u_t)(A))) +#define fZE8_16 (A ) ((size2s_t)((size1u_t)(A))) +#define fSE8_16 (A ) ((size2s_t)((size1s_t)(A))) +#define fSE16_32 (A ) ((size4s_t)((size2s_t)(A))) +#define fZE16_32 (A ) ((size4u_t)((size2u_t)(A))) +#define fSE32_64 (A ) ((size8s_t)((size4s_t)(A))) +#define fZE32_64 (A ) ((size8u_t)((size4u_t)(A))) +#define fSE8_32 (A ) ((size4s_t)((size1s_t)(A))) +#define fZE8_32 (A ) ((size4s_t)((size1u_t)(A))) +#define fMPY8UU (A ,B ) (int)(fZE8_16(A) * fZE8_16(B)) +#define fMPY8US (A ,B ) (int)(fZE8_16(A) * fSE8_16(B)) +#define fMPY8SU (A ,B ) (int)(fSE8_16(A) * fZE8_16(B)) +#define fMPY8SS (A ,B ) (int)((short)(A) * (short)(B)) +#define fMPY16SS (A ,B ) fSE32_64(fSE16_32(A) * fSE16_32(B)) +#define fMPY16UU (A ,B ) fZE32_64(fZE16_32(A) * fZE16_32(B)) +#define fMPY16SU (A ,B ) fSE32_64(fSE16_32(A) * fZE16_32(B)) +#define fMPY16US (A ,B ) fMPY16SU(B, A) +#define fMPY32SS (A ,B ) (fSE32_64(A) * fSE32_64(B)) +#define fMPY32UU (A ,B ) (fZE32_64(A) * fZE32_64(B)) +#define fMPY32SU (A ,B ) (fSE32_64(A) * fZE32_64(B)) +#define fMPY3216SS (A ,B ) (fSE32_64(A) * fSXTN(16, 64, B)) +#define fMPY3216SU (A ,B ) (fSE32_64(A) * fZXTN(16, 64, B)) +#define fROUND (A ) (A + 0x8000) +#define fCLIP (DST ,SRC ,U ) \ + do { \ + size4s_t maxv = (1 << U) - 1; \ + size4s_t minv = -(1 << U); \ + DST = fMIN(maxv, fMAX(SRC, minv)); \ + } while (0) +#define fCRND (A ) ((((A) & 0x3) == 0x3) ? ((A) + 1) : ((A))) +#define fRNDN (A ,N ) ((((N) == 0) ? (A) : (((fSE32_64(A)) + (1 << ((N) - 1)))))) +#define fCRNDN (A ,N ) (conv_round(A, N)) +#define fCRNDN64 (A ,N ) (conv_round64(A, N)) +#define fADD128 (A ,B ) (add128(A, B)) +#define fSUB128 (A ,B ) (sub128(A, B)) +#define fSHIFTR128 (A ,B ) (shiftr128(A, B)) +#define fSHIFTL128 (A ,B ) (shiftl128(A, B)) +#define fAND128 (A ,B ) (and128(A, B)) +#define fCAST8S_16S (A ) (cast8s_to_16s(A)) +#define fCAST16S_8S (A ) (cast16s_to_8s(A)) +#define fCAST16S_4S (A ) (cast16s_to_4s(A)) + +#ifdef QEMU_GENERATE +#define fEA_RI (REG ,IMM ) tcg_gen_addi_tl(EA, REG, IMM) +#define fEA_RRs (REG ,REG2 ,SCALE ) \ + do { \ + TCGv tmp = tcg_temp_new(); \ + tcg_gen_shli_tl(tmp, REG2, SCALE); \ + tcg_gen_add_tl(EA, REG, tmp); \ + tcg_temp_free(tmp); \ + } while (0) +#define fEA_IRs (IMM ,REG ,SCALE ) \ + do { \ + tcg_gen_shli_tl(EA, REG, SCALE); \ + tcg_gen_addi_tl(EA, EA, IMM); \ + } while (0) +#else +#define fEA_RI (REG ,IMM ) \ + do { \ + EA = REG + IMM; \ + fDOCHKPAGECROSS(REG, EA); \ + } while (0) +#define fEA_RRs (REG ,REG2 ,SCALE ) \ + do { \ + EA = REG + (REG2 << SCALE); \ + fDOCHKPAGECROSS(REG, EA); \ + } while (0) +#define fEA_IRs (IMM ,REG ,SCALE ) \ + do { \ + EA = IMM + (REG << SCALE); \ + fDOCHKPAGECROSS(IMM, EA); \ + } while (0) +#endif + +#ifdef QEMU_GENERATE +#define fEA_IMM (IMM ) tcg_gen_movi_tl(EA, IMM) +#define fEA_REG (REG ) tcg_gen_mov_tl(EA, REG) +static inline void gen_fbrev (TCGv result,TCGv src) +{ +TCGv result_hi =tcg_temp_new (); +TCGv result_lo =tcg_temp_new (); +TCGv tmp1 =tcg_temp_new (); +TCGv tmp2 =tcg_temp_new (); +int i; + +/* +* Bit reverse the low 16 bits of the address +*/ +tcg_gen_andi_tl (result_hi, src,0xffff0000 ); +tcg_gen_movi_tl (result_lo,0 ); +tcg_gen_mov_tl (tmp1, src); +for (i =0 ; i <16 ; i++) { +/* +* result_lo = (result_lo << 1) | (tmp1 & 1); +* tmp1 >>= 1; +*/ +tcg_gen_shli_tl (result_lo, result_lo,1 ); +tcg_gen_andi_tl (tmp2, tmp1,1 ); +tcg_gen_or_tl (result_lo, result_lo, tmp2); +tcg_gen_sari_tl (tmp1, tmp1,1 ); + } +tcg_gen_or_tl (result, result_hi, result_lo); + +tcg_temp_free (result_hi); +tcg_temp_free (result_lo); +tcg_temp_free (tmp1); +tcg_temp_free (tmp2); +} +static inline void gen_fcircadd (TCGv reg,TCGv incr,TCGv M ,TCGv start_addr) +{ +TCGv length =tcg_temp_new (); +TCGv new_ptr =tcg_temp_new (); +TCGv end_addr =tcg_temp_new (); +TCGv tmp =tcg_temp_new (); + +tcg_gen_andi_tl (length,M ,0x1ffff ); +tcg_gen_add_tl (new_ptr, reg, incr); +tcg_gen_add_tl (end_addr, start_addr, length); + +tcg_gen_sub_tl (tmp, new_ptr, length); +tcg_gen_movcond_tl (TCG_COND_GE , new_ptr, new_ptr, end_addr, tmp, new_ptr); +tcg_gen_add_tl (tmp, new_ptr, length); +tcg_gen_movcond_tl (TCG_COND_LT , new_ptr, new_ptr, start_addr, tmp, new_ptr); + +tcg_gen_mov_tl (reg, new_ptr); + +tcg_temp_free (length); +tcg_temp_free (new_ptr); +tcg_temp_free (end_addr); +tcg_temp_free (tmp); +} + +#define fEA_BREVR (REG ) gen_fbrev(EA, REG) +#define fEA_GPI (IMM ) tcg_gen_addi_tl(EA, fREAD_GP(), IMM) +#define fPM_I (REG ,IMM ) tcg_gen_addi_tl(REG, REG, IMM) +#define fPM_M (REG ,MVAL ) tcg_gen_add_tl(REG, REG, MVAL) +#else +#define fEA_IMM (IMM ) EA = IMM +#define fEA_REG (REG ) EA = REG +#define fEA_GPI (IMM ) \ + do { \ + EA = fREAD_GP() + IMM; \ + fGP_DOCHKPAGECROSS(fREAD_GP(), EA); \ + } while (0) +#define fPM_I (REG ,IMM ) \ + do { \ + REG = REG + IMM; \ + } while (0) +#define fPM_M (REG ,MVAL ) \ + do { \ + REG = REG + MVAL; \ + } while (0) +#define fEA_BREVR (REG ) \ + do { \ + EA = fbrev(REG); \ + } while (0) +#endif +#define fPM_CIRI (REG ,IMM ,MVAL ) \ + do { \ + TCGv tmp = tcg_const_tl(siV); \ + fcirc_add(REG, tmp, MuV); \ + tcg_temp_free(tmp); \ + } while (0) +#define fPM_CIRR (REG ,VAL ,MVAL ) \ + do { \ + fcirc_add(REG, VAL, MuV); \ + } while (0) +#define fMODCIRCU (N ,P ) ((N) & ((1 << (P)) - 1)) +#define fSCALE (N ,A ) (((size8s_t)(A)) << N) +#define fVSATW (A ) fVSATN(32, ((long long)A)) +#define fSATW (A ) fSATN(32, ((long long)A)) +#define fVSAT (A ) fVSATN(32, (A)) +#define fSAT (A ) fSATN(32, (A)) +#define fSAT_ORIG_SHL (A ,ORIG_REG ) \ + ((((size4s_t)((fSAT(A)) ^ ((size4s_t)(ORIG_REG)))) < 0) \ + ? fSATVALN(32, ((size4s_t)(ORIG_REG))) \ + : ((((ORIG_REG) > 0) && ((A) == 0)) ? fSATVALN(32, (ORIG_REG)) \ + : fSAT(A))) +#define fPASS (A ) A +#define fRND (A ) (((A) + 1) >> 1) +#define fBIDIR_SHIFTL (SRC ,SHAMT ,REGSTYPE ) \ + (((SHAMT) < 0) ? ((fCAST##REGSTYPE(SRC) >> ((-(SHAMT)) - 1)) >> 1) \ + : (fCAST##REGSTYPE(SRC) << (SHAMT))) +#define fBIDIR_ASHIFTL (SRC ,SHAMT ,REGSTYPE ) \ + fBIDIR_SHIFTL(SRC, SHAMT, REGSTYPE##s) +#define fBIDIR_LSHIFTL (SRC ,SHAMT ,REGSTYPE ) \ + fBIDIR_SHIFTL(SRC, SHAMT, REGSTYPE##u) +#define fBIDIR_ASHIFTL_SAT (SRC ,SHAMT ,REGSTYPE ) \ + (((SHAMT) < 0) ? ((fCAST##REGSTYPE##s(SRC) >> ((-(SHAMT)) - 1)) >> 1) \ + : fSAT_ORIG_SHL(fCAST##REGSTYPE##s(SRC) << (SHAMT), (SRC))) +#define fBIDIR_SHIFTR (SRC ,SHAMT ,REGSTYPE ) \ + (((SHAMT) < 0) ? ((fCAST##REGSTYPE(SRC) << ((-(SHAMT)) - 1)) << 1) \ + : (fCAST##REGSTYPE(SRC) >> (SHAMT))) +#define fBIDIR_ASHIFTR (SRC ,SHAMT ,REGSTYPE ) \ + fBIDIR_SHIFTR(SRC, SHAMT, REGSTYPE##s) +#define fBIDIR_LSHIFTR (SRC ,SHAMT ,REGSTYPE ) \ + fBIDIR_SHIFTR(SRC, SHAMT, REGSTYPE##u) +#define fBIDIR_ASHIFTR_SAT (SRC ,SHAMT ,REGSTYPE ) \ + (((SHAMT) < 0) ? fSAT_ORIG_SHL((fCAST##REGSTYPE##s(SRC) \ + << ((-(SHAMT)) - 1)) << 1, (SRC)) \ + : (fCAST##REGSTYPE##s(SRC) >> (SHAMT))) +#ifdef QEMU_GENERATE +#define fASHIFTR (DST ,SRC ,SHAMT ,REGSTYPE ) \ + gen_ashiftr_##REGSTYPE##s(DST, SRC, SHAMT) +#define fLSHIFTR (DST ,SRC ,SHAMT ,REGSTYPE ) \ + gen_lshiftr_##REGSTYPE##u(DST, SRC, SHAMT) +#else +#define fASHIFTR (SRC ,SHAMT ,REGSTYPE ) (fCAST##REGSTYPE##s(SRC) >> (SHAMT)) +#define fLSHIFTR (SRC ,SHAMT ,REGSTYPE ) \ + (((SHAMT) >= 64) ? 0 : (fCAST##REGSTYPE##u(SRC) >> (SHAMT))) +#endif +#define fROTL (SRC ,SHAMT ,REGSTYPE ) \ + (((SHAMT) == 0) ? (SRC) : ((fCAST##REGSTYPE##u(SRC) << (SHAMT)) | \ + ((fCAST##REGSTYPE##u(SRC) >> \ + ((sizeof(SRC) * 8) - (SHAMT)))))) +#define fROTR (SRC ,SHAMT ,REGSTYPE ) \ + (((SHAMT) == 0) ? (SRC) : ((fCAST##REGSTYPE##u(SRC) >> (SHAMT)) | \ + ((fCAST##REGSTYPE##u(SRC) << \ + ((sizeof(SRC) * 8) - (SHAMT)))))) +#ifdef QEMU_GENERATE +#define fASHIFTL (DST ,SRC ,SHAMT ,REGSTYPE ) \ + gen_ashiftl_##REGSTYPE##s(DST, SRC, SHAMT) +#else +#define fASHIFTL (SRC ,SHAMT ,REGSTYPE ) \ + (((SHAMT) >= 64) ? 0 : (fCAST##REGSTYPE##s(SRC) << (SHAMT))) +#endif +#define fFLOAT (A ) \ + ({ union { float f; size4u_t i; } _fipun; _fipun.i = (A); _fipun.f; }) +#define fUNFLOAT (A ) \ + ({ union { float f; size4u_t i; } _fipun; \ + _fipun.f = (A); isnan(_fipun.f) ? 0xFFFFFFFFU : _fipun.i; }) +#define fSFNANVAL () 0xffffffff +#define fSFINFVAL (A ) (((A) & 0x80000000) | 0x7f800000) +#define fSFONEVAL (A ) (((A) & 0x80000000) | fUNFLOAT(1.0)) +#define fCHECKSFNAN (DST ,A ) \ + do { \ + if (isnan(fFLOAT(A))) { \ + if ((fGETBIT(22, A)) == 0) { \ + fRAISEFLAGS(FE_INVALID); \ + } \ + DST = fSFNANVAL(); \ + } \ + } while (0) +#define fCHECKSFNAN3 (DST ,A ,B ,C ) \ + do { \ + fCHECKSFNAN(DST, A); \ + fCHECKSFNAN(DST, B); \ + fCHECKSFNAN(DST, C); \ + } while (0) +#define fSF_BIAS () 127 +#define fSF_MANTBITS () 23 +#define fSF_RECIP_LOOKUP (IDX ) arch_recip_lookup(IDX) +#define fSF_INVSQRT_LOOKUP (IDX ) arch_invsqrt_lookup(IDX) +#define fSF_MUL_POW2 (A ,B ) \ + (fUNFLOAT(fFLOAT(A) * fFLOAT((fSF_BIAS() + (B)) << fSF_MANTBITS()))) +#define fSF_GETEXP (A ) (((A) >> fSF_MANTBITS()) & 0xff) +#define fSF_MAXEXP () (254) +#define fSF_RECIP_COMMON (N ,D ,O ,A ) arch_sf_recip_common(&N, &D, &O, &A) +#define fSF_INVSQRT_COMMON (N ,O ,A ) arch_sf_invsqrt_common(&N, &O, &A) +#define fFMAFX (A ,B ,C ,ADJ ) internal_fmafx(A, B, C, fSXTN(8, 64, ADJ)) +#define fFMAF (A ,B ,C ) internal_fmafx(A, B, C, 0) +#define fSFMPY (A ,B ) internal_mpyf(A, B) +#define fMAKESF (SIGN ,EXP ,MANT ) \ + ((((SIGN) & 1) << 31) | \ + (((EXP) & 0xff) << fSF_MANTBITS()) | \ + ((MANT) & ((1 << fSF_MANTBITS()) - 1))) +#define fDOUBLE (A ) \ + ({ union { double f; size8u_t i; } _fipun; _fipun.i = (A); _fipun.f; }) +#define fUNDOUBLE (A ) \ + ({ union { double f; size8u_t i; } _fipun; \ + _fipun.f = (A); \ + isnan(_fipun.f) ? 0xFFFFFFFFFFFFFFFFULL : _fipun.i; }) +#define fDFNANVAL () 0xffffffffffffffffULL +#define fDFINFVAL (A ) (((A) & 0x8000000000000000ULL) | 0x7ff0000000000000ULL) +#define fDFONEVAL (A ) (((A) & 0x8000000000000000ULL) | fUNDOUBLE(1.0)) +#define fCHECKDFNAN (DST ,A ) \ + do { \ + if (isnan(fDOUBLE(A))) { \ + if ((fGETBIT(51, A)) == 0) { \ + fRAISEFLAGS(FE_INVALID); \ + } \ + DST = fDFNANVAL(); \ + } \ + } while (0) +#define fCHECKDFNAN3 (DST ,A ,B ,C ) \ + do { \ + fCHECKDFNAN(DST, A); \ + fCHECKDFNAN(DST, B); \ + fCHECKDFNAN(DST, C); \ + } while (0) +#define fDF_BIAS () 1023 +#define fDF_ISNORMAL (X ) (fpclassify(fDOUBLE(X)) == FP_NORMAL) +#define fDF_ISDENORM (X ) (fpclassify(fDOUBLE(X)) == FP_SUBNORMAL) +#define fDF_ISBIG (X ) (fDF_GETEXP(X) >= 512) +#define fDF_MANTBITS () 52 +#define fDF_RECIP_LOOKUP (IDX ) (size8u_t)(arch_recip_lookup(IDX)) +#define fDF_INVSQRT_LOOKUP (IDX ) (size8u_t)(arch_invsqrt_lookup(IDX)) +#define fDF_MUL_POW2 (A ,B ) \ + (fUNDOUBLE(fDOUBLE(A) * fDOUBLE((0ULL + fDF_BIAS() + (B)) << \ + fDF_MANTBITS()))) +#define fDF_GETEXP (A ) (((A) >> fDF_MANTBITS()) & 0x7ff) +#define fDF_MAXEXP () (2046) +#define fDF_RECIP_COMMON (N ,D ,O ,A ) arch_df_recip_common(&N, &D, &O, &A) +#define fDF_INVSQRT_COMMON (N ,O ,A ) arch_df_invsqrt_common(&N, &O, &A) +#define fFMA (A ,B ,C ) internal_fma(A, B, C) +#define fDFMPY (A ,B ) internal_mpy(A, B) +#define fDF_MPY_HH (A ,B ,ACC ) internal_mpyhh(A, B, ACC) +#define fFMAX (A ,B ,C ,ADJ ) internal_fmax(A, B, C, fSXTN(8, 64, ADJ) * 2) +#define fMAKEDF (SIGN ,EXP ,MANT ) \ + ((((SIGN) & 1ULL) << 63) | \ + (((EXP) & 0x7ffULL) << fDF_MANTBITS()) | \ + ((MANT) & ((1ULL << fDF_MANTBITS()) - 1))) + +#ifdef QEMU_GENERATE +/* These will be needed if we write any FP instructions with TCG */ +#define fFPOP_START ()/* nothing */ +#define fFPOP_END ()/* nothing */ +#else +#define fFPOP_START () arch_fpop_start(env) +#define fFPOP_END () arch_fpop_end(env) +#endif + +#define fFPSETROUND_NEAREST () fesetround(FE_TONEAREST) +#define fFPSETROUND_CHOP () fesetround(FE_TOWARDZERO) +#define fFPCANCELFLAGS () feclearexcept(FE_ALL_EXCEPT) +#define fISINFPROD (A ,B ) \ + ((isinf(A) && isinf(B)) || \ + (isinf(A) && isfinite(B) && ((B) != 0.0)) || \ + (isinf(B) && isfinite(A) && ((A) != 0.0))) +#define fISZEROPROD (A ,B ) \ + ((((A) == 0.0) && isfinite(B)) || (((B) == 0.0) && isfinite(A))) +#define fRAISEFLAGS (A ) arch_raise_fpflag(A) +#define fDF_MAX (A ,B ) \ + (((A) == (B)) ? fDOUBLE(fUNDOUBLE(A) & fUNDOUBLE(B)) : fmax(A, B)) +#define fDF_MIN (A ,B ) \ + (((A) == (B)) ? fDOUBLE(fUNDOUBLE(A) | fUNDOUBLE(B)) : fmin(A, B)) +#define fSF_MAX (A ,B ) \ + (((A) == (B)) ? fFLOAT(fUNFLOAT(A) & fUNFLOAT(B)) : fmaxf(A, B)) +#define fSF_MIN (A ,B ) \ + (((A) == (B)) ? fFLOAT(fUNFLOAT(A) | fUNFLOAT(B)) : fminf(A, B)) +#define fMMU (ADDR ) ADDR + +#ifdef QEMU_GENERATE +#define fcirc_add (REG ,INCR ,MV ) \ + gen_fcircadd(REG, INCR, MV, fREAD_CSREG(MuN)) +#else +#define fcirc_add (REG ,INCR ,IMMED )/* Not possible in helpers */ +#endif + +#define fbrev (REG ) (fbrevaddr(REG)) + +#ifdef QEMU_GENERATE +#define fLOAD (NUM ,SIZE ,SIGN ,EA ,DST ) MEM_LOAD##SIZE##SIGN(DST, EA) +#else +#define fLOAD (NUM ,SIZE ,SIGN ,EA ,DST ) \ + DST = (size##SIZE##SIGN##_t)MEM_LOAD##SIZE##SIGN(EA) +#endif + +#define fMEMOP (NUM ,SIZE ,SIGN ,EA ,FNTYPE ,VALUE ) + +#ifdef QEMU_GENERATE +#define fGET_FRAMEKEY () READ_REG(tmp, HEX_REG_FRAMEKEY) +static inline TCGv_i64 gen_frame_scramble (TCGv_i64 result) +{ +/* ((LR << 32) | FP) ^ (FRAMEKEY << 32)) */ +TCGv_i64 LR_i64 =tcg_temp_new_i64 (); +TCGv_i64 FP_i64 =tcg_temp_new_i64 (); +TCGv_i64 FRAMEKEY_i64 =tcg_temp_new_i64 (); + +tcg_gen_extu_i32_i64 (LR_i64, hex_gpr[HEX_REG_LR ]); +tcg_gen_extu_i32_i64 (FP_i64, hex_gpr[HEX_REG_FP ]); +tcg_gen_extu_i32_i64 (FRAMEKEY_i64, hex_gpr[HEX_REG_FRAMEKEY ]); + +tcg_gen_shli_i64 (LR_i64, LR_i64,32 ); +tcg_gen_shli_i64 (FRAMEKEY_i64, FRAMEKEY_i64,32 ); +tcg_gen_or_i64 (result, LR_i64, FP_i64); +tcg_gen_xor_i64 (result, result, FRAMEKEY_i64); + +tcg_temp_free_i64 (LR_i64); +tcg_temp_free_i64 (FP_i64); +tcg_temp_free_i64 (FRAMEKEY_i64); +return result; +} +#define fFRAME_SCRAMBLE (VAL ) gen_frame_scramble(scramble_tmp) +static inline TCGv_i64 gen_frame_unscramble (TCGv_i64 frame) +{ +TCGv_i64 FRAMEKEY_i64 =tcg_temp_new_i64 (); +tcg_gen_extu_i32_i64 (FRAMEKEY_i64, hex_gpr[HEX_REG_FRAMEKEY ]); +tcg_gen_shli_i64 (FRAMEKEY_i64, FRAMEKEY_i64,32 ); +tcg_gen_xor_i64 (frame, frame, FRAMEKEY_i64); +tcg_temp_free_i64 (FRAMEKEY_i64); +return frame; +} + +#define fFRAME_UNSCRAMBLE (VAL ) gen_frame_unscramble(VAL) +#else +#define fGET_FRAMEKEY () READ_REG(HEX_REG_FRAMEKEY) +#define fFRAME_SCRAMBLE (VAL ) ((VAL) ^ (fCAST8u(fGET_FRAMEKEY()) << 32)) +#define fFRAME_UNSCRAMBLE (VAL ) fFRAME_SCRAMBLE(VAL) +#endif + +#ifdef CONFIG_USER_ONLY +#define fFRAMECHECK (ADDR ,EA ) do { } while (0)/* Not modelled in linux-user */ +#else +/* System mode not implemented yet */ +#define fFRAMECHECK (ADDR ,EA ) g_assert_not_reached(); +#endif + +#ifdef QEMU_GENERATE +#define fLOAD_LOCKED (NUM ,SIZE ,SIGN ,EA ,DST ) \ + gen_load_locked##SIZE##SIGN(DST, EA, ctx->mem_idx); +#else +#define fLOAD_LOCKED (NUM ,SIZE ,SIGN ,EA ,DST ) \ + DST = (size##SIZE##SIGN##_t)mem_load_locked##SIZE(env, EA); +#endif + +#define fLOAD_PHYS (NUM ,SIZE ,SIGN ,SRC1 ,SRC2 ,DST ) + +#ifdef QEMU_GENERATE +#define fSTORE (NUM ,SIZE ,EA ,SRC ) MEM_STORE##SIZE(EA, SRC, insn->slot) +#else +#define fSTORE (NUM ,SIZE ,EA ,SRC ) MEM_STORE##SIZE(EA, SRC, slot) +#endif + +#ifdef QEMU_GENERATE +#define fSTORE_LOCKED (NUM ,SIZE ,EA ,SRC ,PRED ) \ + gen_store_conditional##SIZE(env, ctx, PdN, PRED, EA, SRC); +#else +#define fSTORE_LOCKED (NUM ,SIZE ,EA ,SRC ,PRED ) \ + PRED = (mem_store_conditional(env, EA, SRC, SIZE) ? 0xff : 0); +#endif + +#define fVTCM_MEMCPY (DST ,SRC ,SIZE ) +#define fPERMUTEH (SRC0 ,SRC1 ,CTRL ) fpermuteh((SRC0), (SRC1), CTRL) +#define fPERMUTEB (SRC0 ,SRC1 ,CTRL ) fpermuteb((SRC0), (SRC1), CTRL) + +#ifdef QEMU_GENERATE +#define GETBYTE_FUNC (X ) \ + _Generic((X), TCGv_i32 : gen_get_byte, TCGv_i64 : gen_get_byte_i64) +#define fGETBYTE (N ,SRC ) GETBYTE_FUNC(SRC)(BYTE, N, SRC, true) +#define fGETUBYTE (N ,SRC ) GETBYTE_FUNC(SRC)(BYTE, N, SRC, false) +#else +#define fGETBYTE (N ,SRC ) ((size1s_t)((SRC >> ((N) * 8)) & 0xff)) +#define fGETUBYTE (N ,SRC ) ((size1u_t)((SRC >> ((N) * 8)) & 0xff)) +#endif + +#ifdef QEMU_GENERATE +#define SETBYTE_FUNC (X ) \ + _Generic((X), TCGv_i32 : gen_set_byte, TCGv_i64 : gen_set_byte_i64) +#define fSETBYTE (N ,DST ,VAL ) SETBYTE_FUNC(DST)(N, DST, VAL) + +#define fGETHALF (N ,SRC ) gen_get_half(HALF, N, SRC, true) +#define fGETUHALF (N ,SRC ) gen_get_half(HALF, N, SRC, false) + +#define SETHALF_FUNC (X ) \ + _Generic((X), TCGv_i32 : gen_set_half, TCGv_i64 : gen_set_half_i64) +#define fSETHALF (N ,DST ,VAL ) SETHALF_FUNC(DST)(N, DST, VAL) +#define fSETHALFw (N ,DST ,VAL ) gen_set_half(N, DST, VAL) +#define fSETHALFd (N ,DST ,VAL ) gen_set_half_i64(N, DST, VAL) +#else +#define fSETBYTE (N ,DST ,VAL ) \ + do { \ + DST = (DST & ~(0x0ffLL << ((N) * 8))) | \ + (((size8u_t)((VAL) & 0x0ffLL)) << ((N) * 8)); \ + } while (0) +#define fGETHALF (N ,SRC ) ((size2s_t)((SRC >> ((N) * 16)) & 0xffff)) +#define fGETUHALF (N ,SRC ) ((size2u_t)((SRC >> ((N) * 16)) & 0xffff)) +#define fSETHALF (N ,DST ,VAL ) \ + do { \ + DST = (DST & ~(0x0ffffLL << ((N) * 16))) | \ + (((size8u_t)((VAL) & 0x0ffff)) << ((N) * 16)); \ + } while (0) +#define fSETHALFw fSETHALF +#define fSETHALFd fSETHALF +#endif + +#ifdef QEMU_GENERATE +#define GETWORD_FUNC (X ) \ + _Generic((X), TCGv_i32 : gen_get_word, TCGv_i64 : gen_get_word_i64) +#define fGETWORD (N ,SRC ) GETWORD_FUNC(WORD)(WORD, N, SRC, true) +#define fGETUWORD (N ,SRC ) GETWORD_FUNC(WORD)(WORD, N, SRC, false) +#else +#define fGETWORD (N ,SRC ) \ + ((size8s_t)((size4s_t)((SRC >> ((N) * 32)) & 0x0ffffffffLL))) +#define fGETUWORD (N ,SRC ) \ + ((size8u_t)((size4u_t)((SRC >> ((N) * 32)) & 0x0ffffffffLL))) +#endif + +#define fSETWORD (N ,DST ,VAL ) \ + do { \ + DST = (DST & ~(0x0ffffffffLL << ((N) * 32))) | \ + (((VAL) & 0x0ffffffffLL) << ((N) * 32)); \ + } while (0) +#define fACC () +#define fEXTENSION_AUDIO (A ) A + +#ifdef QEMU_GENERATE +#define fSETBIT (N ,DST ,VAL ) gen_set_bit((N), (DST), (VAL)); +#else +#define fSETBIT (N ,DST ,VAL ) \ + do { \ + DST = (DST & ~(1ULL << (N))) | (((size8u_t)(VAL)) << (N)); \ + } while (0) +#endif + +#define fGETBIT (N ,SRC ) (((SRC) >> N) & 1) +#define fSETBITS (HI ,LO ,DST ,VAL ) \ + do { \ + int j; \ + for (j = LO; j <= HI; j++) { \ + fSETBIT(j, DST, VAL); \ + } \ + } while (0) +#define fCOUNTONES_2 (VAL ) count_ones_2(VAL) +#define fCOUNTONES_4 (VAL ) count_ones_4(VAL) +#define fCOUNTONES_8 (VAL ) count_ones_8(VAL) +#define fBREV_8 (VAL ) reverse_bits_8(VAL) +#define fBREV_4 (VAL ) reverse_bits_4(VAL) +#define fBREV_2 (VAL ) reverse_bits_2(VAL) +#define fBREV_1 (VAL ) reverse_bits_1(VAL) +#define fCL1_8 (VAL ) count_leading_ones_8(VAL) +#define fCL1_4 (VAL ) count_leading_ones_4(VAL) +#define fCL1_2 (VAL ) count_leading_ones_2(VAL) +#define fCL1_1 (VAL ) count_leading_ones_1(VAL) +#define fINTERLEAVE (ODD ,EVEN ) interleave(ODD, EVEN) +#define fDEINTERLEAVE (MIXED ) deinterleave(MIXED) +#define fNORM16 (VAL ) \ + ((VAL == 0) ? (31) : (fMAX(fCL1_2(VAL), fCL1_2(~VAL)) - 1)) +#define fHIDE (A ) A +#define fCONSTLL (A ) A##LL +#define fCONSTULL (A ) A##ULL +#define fECHO (A ) (A) + +#define fDO_TRACE (SREG ) +#define fBREAK () +#define fGP_DOCHKPAGECROSS (BASE ,SUM ) +#define fDOCHKPAGECROSS (BASE ,SUM ) +#define fPAUSE (IMM ) +#define fTRAP (TRAPTYPE ,IMM ) helper_raise_exception(env, HEX_EXCP_TRAP0) + +#define fALIGN_REG_FIELD_VALUE (FIELD ,VAL ) \ + ((VAL) << reg_field_info[FIELD].offset) +#define fGET_REG_FIELD_MASK (FIELD ) \ + (((1 << reg_field_info[FIELD].width) - 1) << reg_field_info[FIELD].offset) +#define fLOG_REG_FIELD (REG ,FIELD ,VAL ) +#define fWRITE_GLOBAL_REG_FIELD (REG ,FIELD ,VAL ) +#define fLOG_GLOBAL_REG_FIELD (REG ,FIELD ,VAL ) +#define fREAD_REG_FIELD (REG ,FIELD ) \ + fEXTRACTU_BITS(env->gpr[HEX_REG_##REG], \ + reg_field_info[FIELD].width, \ + reg_field_info[FIELD].offset) +#define fREAD_GLOBAL_REG_FIELD (REG ,FIELD ) +#define fGET_FIELD (VAL ,FIELD ) +#define fSET_FIELD (VAL ,FIELD ,NEWVAL ) +#define fPOW2_HELP_ROUNDUP (VAL ) \ + ((VAL) | \ + ((VAL) >> 1) | \ + ((VAL) >> 2) | \ + ((VAL) >> 4) | \ + ((VAL) >> 8) | \ + ((VAL) >> 16)) +#define fPOW2_ROUNDUP (VAL ) (fPOW2_HELP_ROUNDUP((VAL) - 1) + 1) +#define fBARRIER () +#define fSYNCH () +#define fISYNC () +#define fICFETCH (REG ) +#define fDCFETCH (REG ) do { REG = REG; } while (0)/* Nothing to do in qemu */ +#define fICINVIDX (REG ) +#define fICINVA (REG ) do { REG = REG; } while (0)/* Nothing to do in qemu */ +#define fICKILL () +#define fDCKILL () +#define fL2KILL () +#define fL2UNLOCK () +#define fL2CLEAN () +#define fL2CLEANINV () +#define fL2CLEANPA (REG ) +#define fL2CLEANINVPA (REG ) +#define fL2CLEANINVIDX (REG ) +#define fL2CLEANIDX (REG ) +#define fL2INVIDX (REG ) +#define fL2FETCH (ADDR ,HEIGHT ,WIDTH ,STRIDE ,FLAGS ) +#define fL2TAGR (INDEX ,DST ,DSTREG ) +#define fL2LOCKA (VA ,DST ,PREGDST ) +#define fL2UNLOCKA (VA ) +#define fL2TAGW (INDEX ,PART2 ) +#define fDCCLEANIDX (REG ) +#define fDCCLEANA (REG ) do { REG = REG; } while (0)/* Nothing to do in qemu */ +#define fDCCLEANINVIDX (REG ) +#define fDCCLEANINVA (REG ) \ + do { REG = REG; } while (0)/* Nothing to do in qemu */ + +#ifdef QEMU_GENERATE +#define fDCZEROA (REG ) tcg_gen_mov_tl(hex_dczero_addr, (REG)) +#else +#define fDCZEROA (REG ) do { REG = REG; g_assert_not_reached(); } while (0) +#endif + +#define fDCINVIDX (REG ) +#define fDCINVA (REG ) do { REG = REG; } while (0)/* Nothing to do in qemu */ +#define fBRANCH_SPECULATED_RIGHT (JC ,SD ,DOTNEWVAL ) \ + (((JC) ^ (SD) ^ (DOTNEWVAL & 1)) & 0x1) +#define fBRANCH_SPECULATE_STALL (DOTNEWVAL ,JUMP_COND ,SPEC_DIR ,HINTBITNUM , \ +STRBITNUM )/* Nothing */ + +#define IV1DEAD () +#define fVIRTINSN_SPSWAP (IMM ,REG ) +#define fVIRTINSN_GETIE (IMM ,REG ) { REG = 0xdeafbeef; } +#define fVIRTINSN_SETIE (IMM ,REG ) +#define fVIRTINSN_RTE (IMM ,REG ) +#define fTRAP1_VIRTINSN (IMM ) \ + (((IMM) == 1) || ((IMM) == 3) || ((IMM) == 4) || ((IMM) == 6)) +#define fNOP_EXECUTED +#define fPREDUSE_TIMING () + +#endif
Signature · 1 line
2.7.4
RFC PATCH 32/66 Hexagon instruction classes
In reply to Taylor SimpsonUsed to determine legal VLIW slots for each instruction
--- target/hexagon/iclass.c | 109 ++++++++++++++++++++++++++++++++++++++++++++++++ target/hexagon/iclass.h | 46 ++++++++++++++++++++ 2 files changed, 155 insertions(+) create mode 100644 target/hexagon/iclass.c create mode 100644 target/hexagon/iclass.h
target/hexagon/iclass.c new file +109 -0
@@ -0,0 +1,109 @@ +/* +* Copyright (c) 2019 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 <stddef.h> +#include <stdio.h> +#include "qemu/osdep.h" +#include "iclass.h" + +typedef struct { +const char *const slots; +}iclass_info_t ; + +static const iclass_info_t iclass_info[] = { + +#define DEF_EE_ICLASS32(TYPE, SLOTS, UNITS) /* nothing */ +#define DEF_PP_ICLASS32(TYPE, SLOTS, UNITS) \ + [ICLASS_FROM_TYPE(TYPE)] = { .slots = #SLOTS }, + +#include "imported/iclass.def" +#undef DEF_PP_ICLASS32 +#undef DEF_EE_ICLASS32 + +#define DEF_PP_ICLASS32(TYPE, SLOTS, UNITS) /* nothing */ +#define DEF_EE_ICLASS32(TYPE, SLOTS, UNITS) \ + [ICLASS_FROM_TYPE(TYPE)] = { .slots = #SLOTS }, + +#include "imported/iclass.def" +#undef DEF_PP_ICLASS32 +#undef DEF_EE_ICLASS32 + + {0 } +}; + +const char *find_iclass_slots(opcode_t opcode, int itype) +{ +/* There are some exceptions to what the iclass dictates */ + if (GET_ATTRIB(opcode, A_ICOP)) { + return "2"; + } else if (GET_ATTRIB(opcode, A_RESTRICT_SLOT0ONLY)) { + return "0"; + } else if (GET_ATTRIB(opcode, A_RESTRICT_SLOT1ONLY)) { + return "1"; + } else if (GET_ATTRIB(opcode, A_RESTRICT_SLOT2ONLY)) { + return "2"; + } else if (GET_ATTRIB(opcode, A_RESTRICT_SLOT3ONLY)) { + return "3"; + } else if (GET_ATTRIB(opcode, A_COF) && + GET_ATTRIB(opcode, A_INDIRECT) && + !GET_ATTRIB(opcode, A_MEMLIKE) && + !GET_ATTRIB(opcode, A_MEMLIKE_PACKET_RULES)) { + return "2"; + } else if (GET_ATTRIB(opcode, A_RESTRICT_NOSLOT1)) { + return "0"; + } else if ((opcode == J2_trap0) || (opcode == J2_trap1) || + (opcode == Y2_isync) || (opcode == J2_rte) || + (opcode == J2_pause) || (opcode == J4_hintjumpr)) { + return "2"; + } else if ((itype == ICLASS_V2LDST) && (GET_ATTRIB(opcode, A_STORE))) { + return "01"; + } else if ((itype == ICLASS_V2LDST) && (!GET_ATTRIB(opcode, A_STORE))) { + return "01"; + } else if (GET_ATTRIB(opcode, A_CRSLOT23)) { + return "23"; + } else if (GET_ATTRIB(opcode, A_RESTRICT_PREFERSLOT0)) { + return "0"; + } else if (GET_ATTRIB(opcode, A_SUBINSN)) { + return "01"; + } else if (GET_ATTRIB(opcode, A_CALL)) { + return "23"; + } else if ((opcode == J4_jumpseti) || (opcode == J4_jumpsetr)) { + return "23"; + } else if (GET_ATTRIB(opcode, A_EXTENSION) && GET_ATTRIB(opcode, A_CVI)) { +/* CVI EXTENSIONS */ + if (GET_ATTRIB(opcode, A_CVI_VM)) { + return "01"; + } else if (GET_ATTRIB(opcode, A_RESTRICT_SLOT2ONLY)) { + return "2"; + } else if (GET_ATTRIB(opcode, A_CVI_SLOT23)) { + return "23"; + } else if (GET_ATTRIB(opcode, A_CVI_VX)) { + return "23"; + } else if (GET_ATTRIB(opcode, A_CVI_VX_DV)) { + return "23"; + } else if (GET_ATTRIB(opcode, A_CVI_VS_VX)) { + return "23"; + } else if (GET_ATTRIB(opcode, A_MEMLIKE)) { + return "01"; + } else { + return "0123"; + } + } else { + return iclass_info[itype].slots; + } +} +
target/hexagon/iclass.h new file +46 -0
46 lines not on this page · raw message
Signature · 1 line
2.7.4
RFC PATCH 33/66 Hexagon TCG generation helpers - step 1
In reply to Taylor SimpsonHelpers for reading and writing registers
Helpers for getting and setting parts of values (e.g., set bit)
--- target/hexagon/genptr_helpers.h | 323 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 323 insertions(+) create mode 100644 target/hexagon/genptr_helpers.h
target/hexagon/genptr_helpers.h new file +323 -0
@@ -0,0 +1,323 @@ +/* +* Copyright (c) 2019 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/>. +*/ + +#ifndef GENPTR_HELPERS_H +#define GENPTR_HELPERS_H + +static inline TCGv gen_read_reg (TCGv result,int num) +{ +tcg_gen_mov_tl (result, hex_gpr[num]); +return result; +} + +static inline TCGv gen_read_preg (TCGv pred,uint8_t num) +{ +tcg_gen_mov_tl (pred, hex_pred[num]); +return pred; +} + +static inline TCGv gen_newreg_st (TCGv result,TCGv_env cpu_env,TCGv rnum) +{ +gen_helper_new_value (result, cpu_env, rnum); +return result; +} + +static inline bool is_preloaded (DisasContext *ctx,int num) +{ +int i; +for (i =0 ; i < ctx->ctx_reg_log_idx; i++) { +if (ctx->ctx_reg_log[i] == num) { +return true; + } + } +return false; +} + +static inline void gen_log_reg_write (int rnum,TCGv val,int slot, +int is_predicated) +{ +if (is_predicated) { +TCGv one =tcg_const_tl (1 ); +TCGv zero =tcg_const_tl (0 ); +TCGv slot_mask =tcg_temp_new (); + +tcg_gen_andi_tl (slot_mask, hex_slot_cancelled,1 << slot); +tcg_gen_movcond_tl (TCG_COND_EQ , hex_new_value[rnum], slot_mask, zero, + val, hex_new_value[rnum]); + +tcg_temp_free (one); +tcg_temp_free (zero); +tcg_temp_free (slot_mask); + }else { +tcg_gen_mov_tl (hex_new_value[rnum], val); + } +} + +static inline void gen_log_reg_write_pair (int rnum,TCGv_i64 val,int slot, +int is_predicated) +{ +TCGv val32 =tcg_temp_new (); + +if (is_predicated) { +TCGv one =tcg_const_tl (1 ); +TCGv zero =tcg_const_tl (0 ); +TCGv slot_mask =tcg_temp_new (); + +tcg_gen_andi_tl (slot_mask, hex_slot_cancelled,1 << slot); +/* Low word */ +tcg_gen_extrl_i64_i32 (val32, val); +tcg_gen_movcond_tl (TCG_COND_EQ , hex_new_value[rnum], slot_mask, zero, + val32, hex_new_value[rnum]); +/* High word */ +tcg_gen_extrh_i64_i32 (val32, val); +tcg_gen_movcond_tl (TCG_COND_EQ , hex_new_value[rnum +1 ], + slot_mask, zero, + val32, hex_new_value[rnum +1 ]); + +tcg_temp_free (one); +tcg_temp_free (zero); +tcg_temp_free (slot_mask); + }else { +/* Low word */ +tcg_gen_extrl_i64_i32 (val32, val); +tcg_gen_mov_tl (hex_new_value[rnum], val32); +/* High word */ +tcg_gen_extrh_i64_i32 (val32, val); +tcg_gen_mov_tl (hex_new_value[rnum +1 ], val32); + } + +tcg_temp_free (val32); +} + +static inline void gen_log_pred_write (int pnum,TCGv val) +{ +TCGv zero =tcg_const_tl (0 ); +TCGv base_val =tcg_temp_local_new (); +TCGv and_val =tcg_temp_local_new (); + +/* Multiple writes to the same preg are and'ed together */ +tcg_gen_andi_tl (base_val, val,0xff ); +tcg_gen_and_tl (and_val, base_val, hex_new_pred_value[pnum]); +tcg_gen_movcond_tl (TCG_COND_NE , hex_new_pred_value[pnum], + hex_pred_written[pnum], zero, + and_val, base_val); +tcg_gen_movi_tl (hex_pred_written[pnum],1 ); + +tcg_temp_free (zero); +tcg_temp_free (base_val); +tcg_temp_free (and_val); +} + +static inline void gen_read_p3_0 (TCGv control_reg) +{ +TCGv pval =tcg_temp_new (); +int i; +tcg_gen_movi_tl (control_reg,0 ); +for (i =NUM_PREGS -1 ; i >=0 ; i--) { +tcg_gen_shli_tl (control_reg, control_reg,8 ); +tcg_gen_andi_tl (pval, hex_pred[i],0xff ); +tcg_gen_or_tl (control_reg, control_reg, pval); + } +tcg_temp_free (pval); +} + +static inline void gen_write_p3_0 (TCGv tmp) +{ +TCGv control_reg =tcg_temp_new (); +TCGv pred_val =tcg_temp_new (); +int i; + +tcg_gen_mov_tl (control_reg, tmp); +for (i =0 ; i <NUM_PREGS ; i++) { +tcg_gen_andi_tl (pred_val, control_reg,0xff ); +tcg_gen_mov_tl (hex_pred[i], pred_val); +tcg_gen_shri_tl (control_reg, control_reg,8 ); + } +tcg_temp_free (control_reg); +tcg_temp_free (pred_val); +} + +static inline TCGv gen_get_byte (TCGv result,int N ,TCGv src,bool sign) +{ +TCGv shift =tcg_const_tl (8 *N ); +TCGv mask =tcg_const_tl (0xff ); + +tcg_gen_shr_tl (result, src, shift); +tcg_gen_and_tl (result, result, mask); +if (sign) { +tcg_gen_ext8s_tl (result, result); + }else { +tcg_gen_ext8u_tl (result, result); + } +tcg_temp_free (mask); +tcg_temp_free (shift); + +return result; +} + +static inline TCGv gen_get_byte_i64 (TCGv result,int N ,TCGv_i64 src,bool sign) +{ +TCGv_i64 result_i64 =tcg_temp_new_i64 (); +TCGv_i64 shift =tcg_const_i64 (8 *N ); +TCGv_i64 mask =tcg_const_i64 (0xff ); +tcg_gen_shr_i64 (result_i64, src, shift); +tcg_gen_and_i64 (result_i64, result_i64, mask); +tcg_gen_extrl_i64_i32 (result, result_i64); +if (sign) { +tcg_gen_ext8s_tl (result, result); + }else { +tcg_gen_ext8u_tl (result, result); + } +tcg_temp_free_i64 (result_i64); +tcg_temp_free_i64 (shift); +tcg_temp_free_i64 (mask); + +return result; + +} +static inline TCGv gen_get_half (TCGv result,int N ,TCGv src,bool sign) +{ +TCGv shift =tcg_const_tl (16 *N ); +TCGv mask =tcg_const_tl (0xffff ); + +tcg_gen_shr_tl (result, src, shift); +tcg_gen_and_tl (result, result, mask); +if (sign) { +tcg_gen_ext16s_tl (result, result); + }else { +tcg_gen_ext16u_tl (result, result); + } +tcg_temp_free (mask); +tcg_temp_free (shift); + +return result; +} + +static inline void gen_set_half (int N ,TCGv result,TCGv src) +{ +TCGv mask1 =tcg_const_tl (~(0xffff << (N *16 ))); +TCGv mask2 =tcg_const_tl (0xffff ); +TCGv shift =tcg_const_tl (N *16 ); +TCGv tmp =tcg_temp_new (); + +tcg_gen_and_tl (result, result, mask1); +tcg_gen_and_tl (tmp, src, mask2); +tcg_gen_shli_tl (tmp, tmp,N *16 ); +tcg_gen_or_tl (result, result, tmp); + +tcg_temp_free (mask1); +tcg_temp_free (mask2); +tcg_temp_free (shift); +tcg_temp_free (tmp); +} + +static inline void gen_set_half_i64 (int N ,TCGv_i64 result,TCGv src) +{ +TCGv_i64 mask1 =tcg_const_i64 (~(0xffffLL << (N *16 ))); +TCGv_i64 mask2 =tcg_const_i64 (0xffffLL ); +TCGv_i64 shift =tcg_const_i64 (N *16 ); +TCGv_i64 tmp =tcg_temp_new_i64 (); + +tcg_gen_and_i64 (result, result, mask1); +tcg_gen_concat_i32_i64 (tmp, src, src); +tcg_gen_and_i64 (tmp, tmp, mask2); +tcg_gen_shli_i64 (tmp, tmp,N *16 ); +tcg_gen_or_i64 (result, result, tmp); + +tcg_temp_free_i64 (mask1); +tcg_temp_free_i64 (mask2); +tcg_temp_free_i64 (shift); +tcg_temp_free_i64 (tmp); +} + +static inline void gen_set_byte (int N ,TCGv result,TCGv src) +{ +TCGv mask1 =tcg_const_tl (~(0xff << (N *8 ))); +TCGv mask2 =tcg_const_tl (0xff ); +TCGv shift =tcg_const_tl (N *8 ); +TCGv tmp =tcg_temp_new (); + +tcg_gen_and_tl (result, result, mask1); +tcg_gen_and_tl (tmp, src, mask2); +tcg_gen_shli_tl (tmp, tmp,N *8 ); +tcg_gen_or_tl (result, result, tmp); + +tcg_temp_free (mask1); +tcg_temp_free (mask2); +tcg_temp_free (shift); +tcg_temp_free (tmp); +} + +static inline void gen_set_byte_i64 (int N ,TCGv_i64 result,TCGv src) +{ +TCGv_i64 mask1 =tcg_const_i64 (~(0xffLL << (N *8 ))); +TCGv_i64 mask2 =tcg_const_i64 (0xffLL ); +TCGv_i64 shift =tcg_const_i64 (N *8 ); +TCGv_i64 tmp =tcg_temp_new_i64 (); + +tcg_gen_and_i64 (result, result, mask1); +tcg_gen_concat_i32_i64 (tmp, src, src); +tcg_gen_and_i64 (tmp, tmp, mask2); +tcg_gen_shli_i64 (tmp, tmp,N *8 ); +tcg_gen_or_i64 (result, result, tmp); + +tcg_temp_free_i64 (mask1); +tcg_temp_free_i64 (mask2); +tcg_temp_free_i64 (shift); +tcg_temp_free_i64 (tmp); +} + +static inline TCGv gen_get_word (TCGv result,int N ,TCGv_i64 src,bool sign) +{ +if (N ==0 ) { +tcg_gen_extrl_i64_i32 (result, src); + }else if (N ==1 ) { +tcg_gen_extrh_i64_i32 (result, src); + }else { +g_assert_not_reached (); + } +return result; +} + +static inline TCGv_i64 gen_get_word_i64 (TCGv_i64 result,int N ,TCGv_i64 src, +bool sign) +{ +TCGv word =tcg_temp_new (); +gen_get_word (word,N , src, sign); +if (sign) { +tcg_gen_ext_i32_i64 (result, word); + }else { +tcg_gen_extu_i32_i64 (result, word); + } +tcg_temp_free (word); +return result; +} + +static inline TCGv gen_set_bit (int i,TCGv result,TCGv src) +{ +TCGv mask =tcg_const_tl (~(1 << i)); +TCGv bit =tcg_temp_new (); +tcg_gen_shli_tl (bit, src, i); +tcg_gen_and_tl (result, result, mask); +tcg_gen_or_tl (result, result, bit); +tcg_temp_free (mask); +tcg_temp_free (bit); + +return result; +} + +#endif
Signature · 1 line
2.7.4
Re: [RFC PATCH 33/66] Hexagon TCG generation helpers - step 1
Quoted 25 lines · Taylor Simpson
Helpers for reading and writing registers
Helpers for getting and setting parts of values (e.g., set bit)Signed-off-by Taylor Simpson <[email protected]>--- target/hexagon/genptr_helpers.h | 323 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 323 insertions(+)create mode 100644
target/hexagon/genptr_helpers.htarget/hexagon/genptr_helpers.h new file +10
-0@@ -0,0 +1,323 @@ +/* +* Copyright (c) 2019 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
target/hexagon/genptr_helpers.h line 20
Quoted 10 lines
target/hexagon/genptr_helpers.h new file +10
-0+* 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/>. +*/ + +#ifndef GENPTR_HELPERS_H +#define GENPTR_HELPERS_H +
#include "tcg/tcg.h"?
Quoted 48 lines
target/hexagon/genptr_helpers.h new file +48
-0+static inline TCGv gen_read_reg (TCGv result,int num) +{ +tcg_gen_mov_tl (result, hex_gpr[num]); +return result; +} + +static inline TCGv gen_read_preg (TCGv pred,uint8_t num) +{ +tcg_gen_mov_tl (pred, hex_pred[num]); +return pred; +} + +static inline TCGv gen_newreg_st (TCGv result,TCGv_env cpu_env,TCGv rnum) +{ +gen_helper_new_value (result, cpu_env, rnum); +return result; +} + +static inline bool is_preloaded (DisasContext *ctx,int num) +{ +int i; +for (i =0 ; i < ctx->ctx_reg_log_idx; i++) { +if (ctx->ctx_reg_log[i] == num) { +return true; + } + } +return false; +} + +static inline void gen_log_reg_write (int rnum,TCGv val,int slot, +int is_predicated) +{ +if (is_predicated) { +TCGv one =tcg_const_tl (1 ); +TCGv zero =tcg_const_tl (0 ); +TCGv slot_mask =tcg_temp_new (); + +tcg_gen_andi_tl (slot_mask, hex_slot_cancelled,1 << slot); +tcg_gen_movcond_tl (TCG_COND_EQ , hex_new_value[rnum], slot_mask, zero, + val, hex_new_value[rnum]); + +tcg_temp_free (one); +tcg_temp_free (zero); +tcg_temp_free (slot_mask); + }else { +tcg_gen_mov_tl (hex_new_value[rnum], val); + } +}
[...]
RFC PATCH 34/66 Hexagon TCG generation helpers - step 2
In reply to Taylor SimpsonHelpers for load-locked/store-conditional
--- target/hexagon/genptr_helpers.h | 52 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+)
target/hexagon/genptr_helpers.h +52 -0
@@ -320,4 +320,56 @@ static inline TCGv gen_set_bit(int i, TCGv result, TCGv src)return result; } +static inline void gen_load_locked4u (TCGv dest,TCGv vaddr,int mem_index) +{ +tcg_gen_qemu_ld32u (dest, vaddr, mem_index); +tcg_gen_mov_tl (llsc_addr, vaddr); +tcg_gen_mov_tl (llsc_val, dest); +} + +static inline void gen_load_locked8u (TCGv_i64 dest,TCGv vaddr,int mem_index) +{ +tcg_gen_qemu_ld64 (dest, vaddr, mem_index); +tcg_gen_mov_tl (llsc_addr, vaddr); +tcg_gen_mov_i64 (llsc_val_i64, dest); +} + +static inline void gen_store_conditional4 (CPUHexagonState *env, +DisasContext *ctx,int prednum, +TCGv pred,TCGv vaddr,TCGv src) +{ +TCGv tmp =tcg_temp_new (); +TCGLabel *fail =gen_new_label (); + +tcg_gen_ld_tl (tmp, cpu_env, offsetof(CPUHexagonState , llsc_addr)); +tcg_gen_brcond_tl (TCG_COND_NE , vaddr, tmp, fail); +tcg_gen_movi_tl (tmp, prednum); +tcg_gen_st_tl (tmp, cpu_env, offsetof(CPUHexagonState , llsc_reg)); +tcg_gen_st_tl (src, cpu_env, offsetof(CPUHexagonState , llsc_newval)); +gen_exception (HEX_EXCP_SC4 ); + +gen_set_label (fail); +tcg_gen_movi_tl (pred,0 ); +tcg_temp_free (tmp); +} + +static inline void gen_store_conditional8 (CPUHexagonState *env, +DisasContext *ctx,int prednum, +TCGv pred,TCGv vaddr,TCGv_i64 src) +{ +TCGv tmp =tcg_temp_new (); +TCGLabel *fail =gen_new_label (); + +tcg_gen_ld_tl (tmp, cpu_env, offsetof(CPUHexagonState , llsc_addr)); +tcg_gen_brcond_tl (TCG_COND_NE , vaddr, tmp, fail); +tcg_gen_movi_tl (tmp, prednum); +tcg_gen_st_tl (tmp, cpu_env, offsetof(CPUHexagonState , llsc_reg)); +tcg_gen_st_i64 (src, cpu_env, offsetof(CPUHexagonState , llsc_newval_i64)); +gen_exception (HEX_EXCP_SC8 ); + +gen_set_label (fail); +tcg_gen_movi_tl (pred,0 ); +tcg_temp_free (tmp); +} +#endif
Signature · 1 line
2.7.4
RFC PATCH 35/66 Hexagon TCG generation helpers - step 3
In reply to Taylor SimpsonHelpers for store instructions
--- target/hexagon/genptr_helpers.h | 77 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+)
target/hexagon/genptr_helpers.h +77 -0
@@ -372,4 +372,81 @@ static inline void gen_store_conditional8(CPUHexagonState *env,tcg_temp_free (tmp); } +static inline void gen_store32 (TCGv vaddr,TCGv src,int width,int slot) +{ +tcg_gen_mov_tl (hex_store_addr[slot], vaddr); +tcg_gen_movi_tl (hex_store_width[slot], width); +tcg_gen_mov_tl (hex_store_val32[slot], src); +} + +static inline void gen_store1 (TCGv_env cpu_env,TCGv vaddr,TCGv src, +DisasContext *ctx,int slot) +{ +TCGv tmp =tcg_const_tl (slot); +gen_store32 (vaddr, src,1 , slot); +tcg_temp_free (tmp); + ctx->ctx_store_width[slot] =1 ; +} + +static inline void gen_store1i (TCGv_env cpu_env,TCGv vaddr,int32_t src, +DisasContext *ctx,int slot) +{ +TCGv tmp =tcg_const_tl (src); +gen_store1 (cpu_env, vaddr, tmp, ctx, slot); +tcg_temp_free (tmp); +} + +static inline void gen_store2 (TCGv_env cpu_env,TCGv vaddr,TCGv src, +DisasContext *ctx,int slot) +{ +TCGv tmp =tcg_const_tl (slot); +gen_store32 (vaddr, src,2 , slot); +tcg_temp_free (tmp); + ctx->ctx_store_width[slot] =2 ; +} + +static inline void gen_store2i (TCGv_env cpu_env,TCGv vaddr,int32_t src, +DisasContext *ctx,int slot) +{ +TCGv tmp =tcg_const_tl (src); +gen_store2 (cpu_env, vaddr, tmp, ctx, slot); +tcg_temp_free (tmp); +} + +static inline void gen_store4 (TCGv_env cpu_env,TCGv vaddr,TCGv src, +DisasContext *ctx,int slot) +{ +TCGv tmp =tcg_const_tl (slot); +gen_store32 (vaddr, src,4 , slot); +tcg_temp_free (tmp); + ctx->ctx_store_width[slot] =4 ; +} + +static inline void gen_store4i (TCGv_env cpu_env,TCGv vaddr,int32_t src, +DisasContext *ctx,int slot) +{ +TCGv tmp =tcg_const_tl (src); +gen_store4 (cpu_env, vaddr, tmp, ctx, slot); +tcg_temp_free (tmp); +} + +static inline void gen_store8 (TCGv_env cpu_env,TCGv vaddr,TCGv_i64 src, +DisasContext *ctx,int slot) +{ +TCGv tmp =tcg_const_tl (slot); +tcg_gen_mov_tl (hex_store_addr[slot], vaddr); +tcg_gen_movi_tl (hex_store_width[slot],8 ); +tcg_gen_mov_i64 (hex_store_val64[slot], src); +tcg_temp_free (tmp); + ctx->ctx_store_width[slot] =8 ; +} + +static inline void gen_store8i (TCGv_env cpu_env,TCGv vaddr,int64_t src, +DisasContext *ctx,int slot) +{ +TCGv_i64 tmp =tcg_const_i64 (src); +gen_store8 (cpu_env, vaddr, tmp, ctx, slot); +tcg_temp_free_i64 (tmp); +} +#endif
Signature · 1 line
2.7.4