URL
https://opencores.org/ocsvn/scarts/scarts/trunk
Subversion Repositories scarts
[/] [scarts/] [trunk/] [toolchain/] [scarts-binutils/] [binutils-2.19.1/] [cgen/] [insn.scm] - Rev 6
Compare with Previous | Blame | View Log
; Instruction definitions. ; Copyright (C) 2000, 2009 Red Hat, Inc. ; This file is part of CGEN. ; See file COPYING.CGEN for details. ; Class to hold an insn. ; Used to explicitly specify mnemonic, now it's computed from ; syntax string. ??? Might be useful as an override someday. ;mnemonic ; Instruction syntax string. ; The insn fields as specified in the .cpu file. ; Also contains values for constant fields. ; Lazily computed cache ; RTL source of assertions of ifield values or #f if none. ; This is used, for example, by the decoder to help ; distinguish what would otherwise be an ambiguity in the ; specification. It is also used by decode-split support. ; ??? It could also be used the the assembler/disassembler ; some day. ; The <fmt-desc> of the insn. ; This is used to help calculate the ifmt,sfmt members. ; The <iformat> of the insn. ; The <sformat> of the insn. ; Temp slot for use by applications. ; Instruction semantics. ; This is the rtl in source form or #f if there is none. ; ; There are a few issues (ick, I hate that word) to consider ; here: ; - some apps don't need the trap checks (e.g. SIGSEGV) ; - some apps treat the pieces in different ways ; - the simulator tries to merge common fragments among insns ; to reduce code size in a pbb simulator ; ; Some insns don't have any semantics at all, they are defined ; in another insn [akin to anonymous patterns in gcc]. wip. ; ; ??? GCC-like apps will need a new field to allow specifying ; the semantics if a different value is needed. wip. ; ??? May wish to put this and the compiled forms in a ; separate class. ; ??? Contents of trap expressions is wip. It will probably ; be a sequence with an #:errchk modifier or some such. ; The processed form of the above. ; This remains #f for virtual insns (FIXME: keep?). ; The mapping of the semantics onto the host. ; FIXME: Not sure what its value will be. ; Another thing that will be needed is [in some cases] a more ; simplified version of the RTL for use by apps like compilers. ; Perhaps that's what this will become. ; The function unit usage of the instruction. ; Accessor fns ; Return a boolean indicating if X is an <insn>. ; Return a list of the machs that support INSN. ; ??? wip ; Return the length of INSN in bits. ; Return the length of INSN in bytes. ; Return instruction mnemonic. ; This is computed from the syntax string. ; The mnemonic, as we define it, is everything up to, but not including, the ; first space or '$'. ; FIXME: Rename to syntax-mnemonic, and take a syntax string argument. ; FIXME: Doesn't handle \$ to indicate a $ is actually in the mnemonic. ; Return enum cgen_insn_types value for INSN. "@ARCH@_INSN_"; Return enum for insn named INSN-NAME. ; This is needed for the `invalid' insn, there is no object for it. ; [Though obviously having such an object seems like a good idea.] "@ARCH@_INSN_"; Insns with derived operands (see define-derived-operand). ; ??? These are [currently] recorded separately to minimize impact on existing ; code while the design is worked out. ; ; The class is called <multi-insn> because the insn has multiple variants, ; one for each combination of "anyof" alternatives. ; Internally we create one <insn> per alternative. The theory is that this ; will remain an internal implementation issue. When appropriate applications ; will collapse the number of insns in a way that is appropriate for them. ; ; ??? Another way to do this is with insn templates. One problem the current ; way has is that it requires each operand's assembler syntax to be self ; contained (one way to fix this is to use "fake" operands like before). ; Insn templates needn't have this problem. On the other hand insn templates ; [seem to] require more description file entries. ; ; ??? This doesn't use all of the members of <insn>. ; The <multi-insn> class is wip, but should eventually reorganize <insn>. ; This reorganization might also take into account real, virtual, etc. insns. ; An <insn> is created for each combination of "anyof" ; alternatives. They are recorded with other insns, but a ; list of them is recorded here as well. ; This is #f if the sub-insns haven't been instantiated yet. ; Return a boolean indicating if X is a <multi-insn>. ; Subroutine of -sub-insn-make! to create the ifield list. ; Return encoding of {insn} with each element of {anyof-operands} replaced ; with {new-values}. ; {value-names} is a list of names of {anyof-operands}. ; (debug-repl-env insn anyof-operands value-names new-values) ; Delete ifields of {anyof-operands} and add those for {new-values}. ; Delete ifields in {anyof-operands}. ; Add ifields for {new-values}. ; Return the last ifield of OWNER in IFLD-LIST. ; OWNER is the object that owns the <ifield> we want. ; For ifields, the owner is the ifield itself. ; For operands, the owner is the operand. ; For derived operands, the owner is the "anyof" parent. ; IFLD-LIST is an unsorted list of <ifield> elements. ;(debug-repl-env ifld-list owner) ; This is the interesting case. The instantiated choice of ; {owner} is in {ifld-list}. We have to find it. ;(debug-repl-env ifld-list owner) ; derived operands are handled here too "`owner' not <ifield>, <operand>, or <derived-operand>"; Resolve any `follows' specs. ; Bad worst case performance but ifield lists aren't usually that long. ; FIXME: Doesn't handle A following B following C. ; Subroutine of multi-insn-instantiate! to instantiate one insn. ; INSN is the parent insn. ; ANYOF-OPERANDS is a list of the <anyof-operand>'s of INSN. ; NEW-VALUES is a list of the value to use for each corresponding element in ; ANYOF-OPERANDS. Each element is a <derived-operand>. ;(debug-repl-env insn anyof-operands new-values) "Instantiating "":"" ""="" ...\n"; (if (eq? '@sib+disp8-QI-disp32-8 ; (obj:name (car new-values))) ; (debug-repl-env insn anyof-operands new-values)) ; Don't create insn if ifield assertions fail. ; FIXME " instantiated.\n";; FIXME: Hack to remove differences in generated code when we ;; switched to recording insns in hash tables. ;; See similar comment in arch-analyze-insns!. ;; Make the ordinals count backwards. ;; Subtract 2 because mach.scm:-get-next-ordinal! adds 1. " failed ifield assertions.\n"; Instantiate all sub-insns of MULTI-INSN. ; ??? Might be better to return the list of insns, rather than add them to ; the global list, and leave it to the caller to add them. ; We shouldn't get called more than once. ; What we want to create here is the set of all "anyof" alternatives. ; From that we create one <insn> per alternative. " anyof: ""\n"" choices: ""\n"; Iterate over all combinations. ; TODO is a list with one element for each <anyof-operand>. ; Each element is in turn a list of all choices (<derived-operands>'s) ; for the <anyof-operand>. Note that some of these values may be ; derived from nested <anyof-operand>'s. ; ??? anyof-all-choices should cache the results. [Still useful?] ; ??? Need to cache results of assertion processing in addition or ; instead of anyof-all-choices. [Still useful?] "Instantiating "" multi-insns for "" ...\n"; ??? One might prefer a `do' loop here, but every time I see one I ; have to spend too long remembering its syntax. "Derived: ""\n"; Parse an instruction description. ; This is the main routine for building an insn object from a ; description in the .cpu file. ; All arguments are in raw (non-evaluated) form. ; The result is the parsed object or #f if insn isn't for selected mach(s). "Processing insn "" ...\n";; Pick out name first to augment the error context. "cgen_insn"" format"; If there are no semantics, mark this as an alias. ; ??? Not sure this makes sense for multi-insns. "Ignoring "".\n"; Read an instruction description. ; This is the main routine for analyzing instructions in the .cpu file. ; This is also used to create virtual insns by apps like simulators. ; CONTEXT is a <context> object for error messages. ; ARG-LIST is an associative list of field name and field value. ; -insn-parse is invoked to create the <insn> object. ""; Loop over each element in ARG-LIST, recording what's found. "invalid insn arg"; Now that we've identified the elements, build the object. ; Define an instruction object, name/value pair list version. "define-insn"; Define an instruction object, all arguments specified. "define-full-insn"; Parsing support. ; Parse an insn syntax field. ; SYNTAX is either a string or a list of strings, each element of which may ; in turn be a list of strings. ; ??? Not sure this extra flexibility is worth it yet. "improper syntax"; Subroutine of -parse-insn-format to parse a symbol ifield spec. ;(debug-repl-env sym) ; There is a one-to-one relationship b/w derived operands and ; the associated derived ifield. ; An insn-enum? "bad format element, expecting symbol to be operand or insn enum"; Subroutine of -parse-insn-format to parse an (ifield-name value) ifield spec. ; ; The last element is the ifield's value. It must be an integer. ; ??? Whether it can be negative is still unspecified. ; ??? While there might be a case where allowing floating point values is ; desirable, supporting them would require precise conversion routines. ; They should be rare enough that we instead punt. ; ; ??? May wish to support something like "(% startbit bitsize value)". ; ; ??? Error messages need improvement, but that's generally true of cgen. "bad ifield format, should be (ifield-name value)"; ??? This use to allow (ifield-name operand-name). That's how ; `operand-name' elements are handled, but there's no current need ; to handle (ifield-name operand-name). "symbolic ifield value not an enum""ifield value not an integer or enum"; Subroutine of -parse-insn-format to parse an ; (ifield-name value) ifield spec. ; ??? There is room for growth in the specification syntax here. ; Possibilities are (ifield-name|operand-name [options] [value]). "unknown ifield"; Given an insn format field from a .cpu file, replace it with a list of ; ifield objects with the values assigned. ; ; An insn format field is a list of ifields that make up the instruction. ; All bits must be specified, including reserved bits ; [at present no checking is made of this, but the rule still holds]. ; ; A normal entry begins with `+' and then consist of the following: ; - operand name ; - (ifield-name [options] value) ; - (operand-name [options] [value]) ; - insn ifield enum ; ; Example: (+ OP1_ADD (f-res2 0) dr src1 (f-src2 1) (f-res1 #xea)) ; ; where OP1_ADD is an enum, dr and src1 are operands, and f-src2 and f-res1 ; are ifield's. The `+' allows for future extension. ; ; The other form of entry begins with `=' and is followed by an instruction ; name that has the same format. The specified instruction must already be ; defined. Instructions with this form typically also include an ; `ifield-assertion' spec to keep them separate. ; ; An empty field list is ok. This means it's unspecified. ; VIRTUAL insns have this. ; ; This is one of the more important routines to be efficient. ; It's called for each instruction, and is one of the more expensive routines ; in insn parsing. ; field list unspecified ; ??? This use to allow <ifield> objects ; in the `car' position. Checked for below. "FIXME: <ifield> object in format spec""bad format element, neither symbol nor ifield spec""bad `=' format spec, should be `(= insn-name)'""unknown insn""format must begin with `+' or `='"; Return a boolean indicating if IFLD-LIST contains anyof operands. ; Insn utilities. ; ??? multi-insn support wip, may require changes here. ; Return a boolean indicating if INSN is an alias insn. ; Return a list of instructions that are not aliases in INSN-LIST. ; Return a boolean indicating if INSN is a "real" INSN ; (not ALIAS and not VIRTUAL and not a <multi-insn>). ; Return a list of real instructions in INSN-LIST. ; Return a boolean indicating if INSN is a virtual insn. ; Return a list of virtual instructions in INSN-LIST. ; Return a list of non-alias/non-pbb insns in INSN-LIST. ; Return a list of multi-insns in INSN-LIST. ; And the opposite: ; Filter out instructions whose ifield patterns are strict supersets of ; another, keeping the less general cousin. Used to resolve ambiguity ; when there are no more bits to consider. "Filtering "" instructions for non specializations.\n"; insn2: possible submatch (more mask bits) "Instruction "" specialization-filtered by ""\n"; Filter out instructions whose ifield patterns are identical. "Filtering "" instructions for identical variants.\n"; Helper function for above: does (m1,v1) match a STRICT superset of (m2,v2) ? ; ; eg> mask-superset? #b1100 #b1000 #b1110 #b1010 -> #t ; eg> mask-superset? #b1100 #b1000 #b1010 #b1010 -> #f ; eg> mask-superset? #b1100 #b1000 #b1110 #b1100 -> #f ; eg> mask-superset? #b1100 #b1000 #b1100 #b1000 -> #f ; "("","")"" contains ""("","")""\n"; Return a boolean indicating if INSN is a cti [control transfer insn]. ; This includes SKIP-CTI insns even though they don't terminate a basic block. ; ??? SKIP-CTI insns are wip, waiting for more examples of how they're used. ; Return a boolean indicating if INSN can be executed in parallel. ; Such insns are required to have enum attribute PARALLEL != NO. ; This is worded specifically to allow the PARALLEL attribute to have more ; than just NO/YES values (should a target want to do so). ; This specification may not be sufficient, but the intent is explicit. ; Return a list of the insns that support parallel execution in INSN-LIST. ; Instruction field utilities. ; Return a boolean indicating if INSN has ifield named F-NAME. ; Insn opcode value utilities. ; Given INSN, return the length in bits of the base mask (insn-base-mask). ; Given INSN, return the bitmask of constant values (the opcode field) ; in the base part. ; Given INSN, return the sum of the constant values in the insn ; (i.e. the opcode field). ; ; See also (compute-insn-base-mask). ; ; Insn operand utilities. ; Lookup operand SEM-NAME in INSN. ; Insn syntax utilities. ; Create a list of syntax strings broken up into a list of characters and ; operand objects. ; ??? The style of the following could be more Scheme-like. Later. ; Handle escaped syntax metacharacters. "syntax-break-out: missing char after '\\' in "; Handle operand reference. ; Extract the symbol from the string, get the operand. ; FIXME: Will crash if $ is last char in string. ; Handle everything else. ; Given a list of syntax elements (e.g. the result of syntax-break-out), ; create a syntax string. "\\""${""}"; Called before a .cpu file is read in. "\ Define an instruction, name/value pair list version. ""\ Define an instruction, all arguments specified. "; Called before a .cpu file is read in to install any builtins. ; Standard insn attributes. ; ??? Some of these can be combined into one. "unconditional cti""conditional cti"; SKIP-CTI: one or more immediately following instructions are conditionally ; executed (or skipped) "skip cti"; DELAY-SLOT: insn has one or more delay slots (wip) "insn has a delay slot"; RELAXABLE: Insn has one or more identical but larger variants. ; The assembler tries this one first and then the relaxation phase ; switches to the larger ones as necessary. ; All insns of identical behaviour have a RELAX_FOO attribute that groups ; them together. ; FIXME: This is a case where we need one attribute with several values. ; Presently each RELAX_FOO will use up a bit. "insn is relaxable"; RELAXED: Large relaxable variant. Avoided by assembler in first pass. "relaxed form of insn"; NO-DIS: For macro insns, do not use during disassembly. "don't use for disassembly"; PBB: Virtual insn used for PBB support. "virtual insn used for PBB support"; DECODE-SPLIT: insn resulted from decode-split processing "insn split from another insn for decoding purposes"; Also (defined elsewhere): ; VIRTUAL: Helper insn used by the simulator. ; Called after the .cpu file has been read in.