1 ; Standard RTL functions.
2 ; Copyright (C) 2000, 2009 Red Hat, Inc.
3 ; This file is part of CGEN.
4 ; See file COPYING.CGEN for details.
6 ; THIS FILE CONTAINS ONE BIG FUNCTION: def-rtx-funcs.
8 ; It is ok for this file to use procs "internal" to rtl.scm.
10 ; Each rtx functions has two leading operands: &options, &mode;
11 ; though `&mode' may be spelled differently.
12 ; The "&" prefix is to indicate that the parsing of these operands is handled
13 ; differently. They are optional and are written with leading colons
14 ; (e.g. :SI). The leading ":" is to help the parser - all leading optional
15 ; operands begin with ":". The order of the arguments is &options then &mode
16 ; though there is no imposed order in written RTL.
18 (define (def-rtx-funcs)
20 ; Do not change the indentation here.
23 ; These are defined in rtl.scm.
25 (drsn define-rtx-syntax-node)
26 (dron define-rtx-operand-node)
27 (drmn define-rtx-macro-node)
30 ; The reason for the odd indenting above is so that emacs begins indenting the
31 ; following code at column 1.
34 ; MODE is present for use in situations like non-VOID mode cond's.
35 ; The code will expect the mode to be compatible even though `error'
36 ; "doesn't return". A small concession for simpler code.
38 (drn (error &options &mode message)
40 (OPTIONS VOIDORNUMMODE STRING) (NA NA NA)
42 (estate-error *estate* "error in rtl" message)
46 ; Default mode is INT.
48 (drn (enum &options &mode enum-name)
50 (OPTIONS ANYINTMODE SYMBOL) (NA NA NA) ;; FIXME: s/SYMBOL/ENUM-NAME/ ?
52 ; When computing a value, return the enum's value.
53 (enum-lookup-val enum-name)
57 ; These are used in the encode/decode specs of other ifields as well as in
58 ; instruction semantics.
59 ; Ifields are normally specified by name, but they are subsequently wrapped
62 (dron (ifield &options &mode ifld-name)
64 (OPTIONS ANYNUMMODE SYMBOL) (NA NA NA) ;; FIXME: s/SYMBOL/IFIELD-NAME/ ?
66 (let ((f (current-ifld-lookup ifld-name)))
67 (make <operand> (obj-location f)
68 ifld-name (string-append ifld-name " used as operand")
69 (atlist-cons (bool-attr-make 'SEM-ONLY #t)
71 (obj:name (ifld-hw-type f))
72 (obj:name (ifld-mode f))
73 (make <hw-index> 'anonymous 'ifield (ifld-mode f) f)
78 ; Operands are normally specified by name, but they are subsequently wrapped
81 (dron (operand &options &mode op-name)
83 (OPTIONS ANYNUMMODE SYMBOL) (NA NA NA) ;; FIXME: s/SYMBOL/OPERAND-NAME/ ?
85 (current-op-lookup op-name)
88 ; Operand naming/numbering.
89 ; Operands are given names so that the operands as used in the semantics can
90 ; be matched with arguments of function units. With good name choices of
91 ; operands and function unit arguments, this is rarely necessary, but
94 ; ??? This obfuscates the semantic code a fair bit. Another way to do this
95 ; would be to add new elements to <insn> to specify operands outside of
96 ; the semantic code. E.g.
98 ; (inputs (in-gr1 src1) (in-gr2 src2))
99 ; (outputs (out-pc pc) (out-gr dr) (reg-14 (reg WI h-gr 14)))
101 ; The intent here is to continue to allow the semantic code to use names
102 ; of operands, and not overly complicate the input/output description.
104 ; In instructions, operand numbers are recorded as well, to implement
105 ; profiling and result writeback of parallel insns.
107 ; Rename operand VALUE to NEW-NAME.
108 ; VALUE is an expression whose result is an object of type <operand>.
109 ; It can be the name of an existing operand.
110 ; ??? Might also support numbering by allowing NEW-NAME to be a number.
112 (drsn (name &options &mode new-name value)
114 (OPTIONS ANYNUMMODE SYMBOL RTX) (NA NA NA ANY)
116 ;; FIXME: s/DFLT/&mode/ ?
117 (let ((result (object-copy (rtx-get 'DFLT value))))
118 (op:set-sem-name! result new-name)
122 ; Operands are generally compiled to an internal form first.
123 ; There is a fair bit of state associated with them, and it's easier to
124 ; work with an object than source [which might get fairly complicated if
125 ; it expresses all the state].
126 ; Compiled operands are wrapped in this so that they still look like rtx.
128 (dron (xop &options &mode object)
130 (OPTIONS ANYNUMMODE OBJECT) (NA NA NA) ;; FIXME: s/OBJECT/OPERAND/ ?
135 ;(dron (opspec: &options &mode op-name op-num hw-ref attrs)
136 ; (OPTIONS ANYNUMMODE SYMBOL NUMBER RTX ATTRS) (NA NA NA NA ANY NA)
138 ; (let ((opval (rtx-eval-with-estate hw-ref (mode:lookup &mode) *estate*)))
139 ; (assert (operand? opval))
140 ; ; Set the specified mode, ensuring it's ok.
141 ; ; This also makes a copy as we don't want to modify predefined
143 ; (let ((operand (op:new-mode opval mode)))
144 ; (op:set-sem-name! operand op-name)
145 ; (op:set-num! operand op-num)
146 ; (op:set-cond?! operand (attr-value attrs 'COND-REF #f))
150 ; Specify a reference to a local variable.
151 ; Local variables are normally specified by name, but they are subsequently
154 (dron (local &options &mode local-name)
156 (OPTIONS ANYNUMMODE SYMBOL) (NA NA NA) ;; FIXME: s/SYMBOL/LOCAL-NAME/ ?
158 (rtx-temp-lookup (tstate-env *tstate*) local-name)
161 ; FIXME: This doesn't work. See s-operand.
162 ;(define (s-dup estate op-name)
163 ; (if (not (insn? (estate-owner estate)))
164 ; (error "dup: not processing an insn"))
165 ; (vector-ref (insn:operands (current-current-context))
166 ; (op:lookup-num (insn:operands (estate-owner estate)) op-name))
169 ; ??? Since operands are given names and not numbers this isn't currently used.
171 ;(drsn (dup &options &mode op-name)
173 ; (OPTIONS ANYNUMMODE SYMBOL) (NA NA NA)
174 ; ;(s-dup *estate* op-name)
176 ; (if (not (insn? (estate-owner *estate*)))
177 ; (error "dup: not processing an insn"))
178 ; (vector-ref (insn:operands (estate-owner *estate*))
179 ; (op:lookup-num (insn:operands (estate-owner *estate*)) op-name)))
183 ; Returns non-zero if operand NAME was referenced (read if input operand
184 ; and written if output operand).
185 ; ??? What about input/output operands.
187 (drsn (ref &options &mode name)
189 (OPTIONS BIMODE SYMBOL) (NA NA NA) ;; FIXME: s/SYMBOL/OPERAND-NAME/ ?
194 ; Return the index of an operand.
195 ; For registers this is the register number.
196 ; ??? Mode handling incomplete, this doesn't handle mem, which it could.
197 ; Until then we fix the mode of the result to INT.
199 (dron (index-of &options &mode op-rtx)
201 (OPTIONS INTMODE RTX) (NA NA ANY)
203 ;; FIXME: s/DFLT/&mode/ ?
204 (let* ((operand (rtx-eval-with-estate op-rtx DFLT *estate*))
205 (f (hw-index:value (op:index operand)))
206 (f-name (obj:name f)))
207 (make <operand> (if (source-ident? f) (obj-location f) #f)
209 (atlist-cons (bool-attr-make 'SEM-ONLY #t)
211 (obj:name (ifld-hw-type f))
212 (obj:name (ifld-mode f))
213 (make <hw-index> 'anonymous
216 ; (send (op:type op) 'get-index-mode)
221 ; Same as index-of, but improves readability for registers.
229 ; Describe a random hardware object.
230 ; If INDX is missing, assume the element is a scalar. We pass 0 so s-hw
231 ; doesn't have to unpack the list that would be passed if it were defined as
232 ; (hw mode hw-name . indx). This is an internal implementation detail
233 ; and thus harmless to the description language.
234 ; These are implemented as syntax nodes as we must pass INDX to `s-hw'
236 ; ??? Not currently supported. Not sure whether it should be.
237 ;(drsn (hw &options &mode hw-elm . indx-sel)
238 ; (OPTIONS ANYNUMMODE SYMBOL . RTX) (NA NA NA . INT)
240 ; (let ((indx (if (pair? indx-sel) (car indx-sel) 0))
241 ; (selector (if (and (pair? indx-sel) (pair? (cdr indx-sel)))
243 ; hw-selector-default))))
244 ; (s-hw *estate* mode hw-elm indx selector)
248 ; INDX-SEL is an optional index and possible selector.
249 (dron (reg &options &mode hw-elm . indx-sel)
251 (OPTIONS ANYNUMMODE SYMBOL . RTX) (NA NA NA . INT) ;; FIXME: s/SYMBOL/HW-NAME/ ?
253 (let ((indx (if (pair? indx-sel) (car indx-sel) 0))
254 (selector (if (and (pair? indx-sel) (pair? (cdr indx-sel)))
256 hw-selector-default)))
257 (s-hw *estate* mode hw-elm indx selector))
260 ; A raw-reg bypasses the getter/setter stuff. It's usually used in
261 ; getter/setter definitions.
263 (dron (raw-reg &options &mode hw-elm . indx-sel)
265 (OPTIONS ANYNUMMODE SYMBOL . RTX) (NA NA NA . INT) ;; FIXME: s/SYMBOL/HW-NAME/ ?
267 (let ((indx (if (pair? indx-sel) (car indx-sel) 0))
268 (selector (if (and (pair? indx-sel) (pair? (cdr indx-sel)))
270 hw-selector-default)))
271 (let ((result (s-hw *estate* mode hw-elm indx selector)))
272 (obj-cons-attr! result (bool-attr-make 'RAW #t))
277 (dron (mem &options &mode addr . sel)
279 (OPTIONS EXPLNUMMODE RTX . RTX) (NA NA AI . INT)
281 (s-hw *estate* mode 'h-memory addr
282 (if (pair? sel) (car sel) hw-selector-default))
285 ; Instruction execution support.
286 ; There are no jumps, per se. A jump is a set of `pc'.
288 ; The program counter.
289 ; ??? Hmmm... needed? The pc is usually specified as `pc' which is shorthand
291 ;(dron (pc) () () ARG s-pc)
293 ; Fetch bytes from the instruction stream of size MODE.
294 ; FIXME: Later need to augment this by passing an indicator to the mem-fetch
295 ; routines that we're doing an ifetch.
298 (drmn (ifetch mode pc)
299 (list 'mem mode pc) ; hw-selector-ispace
302 ; NUM is the instruction number. Generally it is zero but if more than one
303 ; insn is decoded at a time, it is non-zero. This is used, for example, to
304 ; index into the scache [as an offset from the first insn].
307 (drmn (decode mode pc insn num)
308 (list 'c-call mode 'EXTRACT pc insn num)
311 ; NUM is the same number passed to `decode'.
314 (drmn (execute mode num)
315 (list 'c-call mode 'EXECUTE num)
318 ; Control Transfer Instructions
320 ; Sets of pc are handled like other sets so there are no branch rtx's.
322 ; Indicate there are N delay slots in the processing of RTX.
323 ; N is a `const' node.
324 ; The mode of the result is the mode of RTX.
327 (drn (delay &options &mode n rtx)
329 (OPTIONS VOIDORNUMMODE RTX RTX) (NA NA INT MATCHEXPR)
331 #f ; (s-sequence *estate* VOID '() rtx) ; wip!
334 ; Annul the following insn if YES? is non-zero.
335 ; PC is the address of the annuling insn.
336 ; The target is required to define SEM_ANNUL_INSN.
340 ; The pc reference here is hidden in c-code to not generate a spurious
342 (list 'c-call 'VOID "SEM_ANNUL_INSN" (list 'c-code 'IAI "pc") yes?)
345 ; Skip the following insn if YES? is non-zero.
346 ; The target is required to define SEM_SKIP_INSN.
347 ; ??? This is similar to annul. Deletion of one of them defered.
350 (drn (skip &options &mode yes?)
352 (OPTIONS VOIDMODE RTX) (NA NA INT)
359 ; Return a boolean indicating if attribute named ATTR is VALUE in OWNER.
360 ; If VALUE is a list, return "true" if ATTR is any of the listed values.
361 ; ??? Don't yet support !VALUE.
362 ; OWNER is the result of either (current-insn) or (current-mach)
363 ; [note that canonicalization will turn them into
364 ; (current-{insn,mach} () DFLT)].
365 ; The result is always of mode BI.
368 ; This is a syntax node so the args are not pre-evaluated.
369 ; We just want the symbols.
370 ; FIXME: Hmmm... it currently isn't a syntax node.
372 (drn (eq-attr &options &mode owner attr value)
374 (OPTIONS BIMODE RTX SYMBOL SYMORNUM) (NA NA ANY NA NA)
376 (let ((atval (if owner
377 (obj-attr-value owner attr)
378 (attr-lookup-default attr #f))))
380 (->bool (memq atval value))
384 ; Get the value of attribute ATTR-NAME, expressable as an integer.
385 ; OBJ is the result of either (current-insn) or (current-mach).
386 ; Note that canonicalization will turn them into
387 ; (current-{insn,mach} () {INSN,MACH}MODE).
389 ; This uses INTMODE because we can't otherwise determine the
390 ; mode of the result (if elided).
392 (drn (int-attr &options &mode obj attr-name)
394 (OPTIONS INTMODE RTX SYMBOL) (NA NA ANY NA)
399 ;; Deprecated alias for int-attr.
401 (drmn (attr arg1 . rest)
402 (cons 'int-attr (cons arg1 rest))
405 ; Same as `quote', for use in attributes cus "quote" sounds too jargonish.
406 ; [Ok, not a strong argument for using "symbol", but so what?]
408 (drsn (symbol &options &mode name)
410 (OPTIONS SYMMODE SYMBOL) (NA NA NA)
415 ; Return the current instruction.
417 (drn (current-insn &options &mode)
419 (OPTIONS INSNMODE) (NA NA)
421 (let ((obj (estate-owner *estate*)))
422 (if (not (insn? obj))
423 (error "current context not an insn"))
427 ; Return the currently selected machine.
428 ; This can either be a compile-time or run-time value.
430 (drn (current-mach &options &mode)
432 (OPTIONS MACHMODE) (NA NA)
439 ; FIXME: Need to consider 64 bit hosts.
440 (drn (const &options &mode c)
442 (OPTIONS ANYNUMMODE NUMBER) (NA NA NA)
444 ; When computing a value, just return the constant unchanged.
448 ; Large mode support.
450 ; Combine smaller modes into a larger one.
451 ; Arguments are specified most significant to least significant.
452 ; ??? May also want an endian dependent argument order. That can be
453 ; implemented on top of or beside this.
454 ; ??? Not all of the combinations are supported in the simulator.
455 ; They'll get added as necessary.
456 (drn (join &options &out-mode in-mode arg1 . arg-rest)
458 (OPTIONS ANYNUMMODE ANYNUMMODE RTX . RTX) (NA NA NA ANY . ANY)
460 ; FIXME: Ensure correct number of args for in/out modes.
461 ; FIXME: Ensure compatible modes.
466 ; Called subword 'cus it's not exactly subreg.
467 ; Word numbering is from most significant (word 0) to least (word N-1).
468 ; ??? May also want an endian dependent word ordering. That can be
469 ; implemented on top of or beside this.
470 ; ??? GCC plans to switch to SUBREG_BYTE. Keep an eye out for the switch
471 ; (which is extensive so probably won't happen anytime soon).
473 ; The mode spec of operand0 use to be MATCHEXPR, but subword is not a normal rtx.
474 ; The mode of operand0 is not necessarily the same as the mode of the result,
475 ; and code which analyzes it would otherwise use the result mode (specified by
476 ; `&mode') for the mode of operand0.
478 (drn (subword &options &mode value word-num)
480 (OPTIONS ANYNUMMODE RTX RTX) (NA NA ANY INT)
485 ; ??? The split and concat stuff is just an experiment and should not be used.
486 ; What's there now is just "thoughts put down on paper."
488 (drmn (split split-mode in-mode di)
489 ; FIXME: Ensure compatible modes
490 ;(list 'c-raw-call 'BLK (string-append "SPLIT" in-mode split-mode) di)
494 (drmn (concat modes arg1 . arg-rest)
495 ; FIXME: Here might be the place to ensure
496 ; (= (length modes) (length (cons arg1 arg-rest))).
497 ;(cons 'c-raw-call (cons modes (cons "CONCAT" (cons arg1 arg-rest))))
501 ; Support for explicit C code.
502 ; ??? GCC RTL calls this "unspec" which is arguably a more application
505 (drn (c-code &options &mode text)
507 (OPTIONS ANYEXPRMODE STRING) (NA NA NA)
512 ; Invoke C functions passing them arguments from the semantic code.
513 ; The arguments are passed as is, no conversion is done here.
515 ; (c-call mode name arg1 arg2 ...)
516 ; which is converted into a C function call:
517 ; name (current_cpu, arg1, arg2, ...)
518 ; Mode is the mode of the result.
519 ; If it is VOID this call is a statement and ';' is appended.
520 ; Otherwise it is part of an expression.
522 (drn (c-call &options &mode name . args)
524 (OPTIONS ANYEXPRMODE STRING . RTX) (NA NA NA . ANY)
529 ; Same as c-call but without implicit first arg of `current_cpu'.
531 (drn (c-raw-call &options &mode name . args)
533 (OPTIONS ANYEXPRMODE STRING . RTX) (NA NA NA . ANY)
538 ; Set/get/miscellaneous
540 (drn (nop &options &mode)
542 (OPTIONS VOIDMODE) (NA NA)
547 ; Clobber - mark an object as modified without explaining why or how.
549 (drn (clobber &options &mode object)
551 (OPTIONS VOIDORNUMMODE RTX) (NA NA MATCHEXPR)
557 ; MODE is the mode of DST. If DFLT, use DST's default mode.
558 ; The mode of the result is always VOID.
560 ; ??? It might be more consistent to rename set -> set-trace, but that's
561 ; too wordy. The `set' rtx is the normal one and we want the normal one to
562 ; be the verbose one (prints result tracing messages). `set-quiet' is the
563 ; atypical one, it doesn't print tracing messages. It may also turn out that
564 ; a different mechanism (rather than the name "set-quiet") is used some day.
565 ; One way would be to record the "quietness" state with the traversal state and
566 ; use something like (with-quiet (set foo bar)) akin to with-output-to-string
569 ; i.e. set -> gen-set-trace
570 ; set-quiet -> gen-set-quiet
572 ; ??? One might want a `!' suffix as in `set!', but methinks that's following
573 ; Scheme too closely.
575 (drn (set &options &mode dst src)
577 (OPTIONS ANYNUMMODE SETRTX RTX) (NA NA MATCHEXPR MATCH2)
582 (drn (set-quiet &options &mode dst src)
584 (OPTIONS ANYNUMMODE SETRTX RTX) (NA NA MATCHEXPR MATCH2)
589 ; Standard arithmetic operations.
591 ; It's nice emitting macro calls to the actual C operation in that the RTX
592 ; expression is preserved, albeit in C. On the one hand it's one extra thing
593 ; the programmer has to know when looking at the code. But on the other it's
594 ; trivial stuff, and having a layer between RTX and C allows the
595 ; macros/functions to be modified to handle unexpected situations.
597 ; We do emit C directly for cases other than cpu semantics
598 ; (e.g. the assembler).
600 ; The language is defined such that we assume ANSI C semantics while avoiding
601 ; implementation defined areas, with as few exceptions as possible.
603 ; Current exceptions:
604 ; - signed shift right assumes the sign bit is replicated.
606 ; Additional notes [perhaps repeating what's in ANSI C for emphasis]:
607 ; - callers of division and modulus fns must test for 0 beforehand
609 ; - division and modulus fns have unspecified behavior for negative args
610 ; [yes I know the C standard says implementation defined, here its
612 ; - later add versions of div/mod that have an explicit behaviour for -ve args
613 ; - signedness is part of the rtx operation name, and is not determined
614 ; from the arguments [elsewhere is a description of the tradeoffs]
617 (drn (neg &options &mode s1)
619 (OPTIONS ANYNUMMODE RTX) (NA NA MATCHEXPR)
624 (drn (abs &options &mode s1)
626 (OPTIONS ANYNUMMODE RTX) (NA NA MATCHEXPR)
631 ; For integer values this is a bitwise operation (each bit inverted).
632 ; For floating point values this produces 1/x.
633 ; ??? Might want different names.
634 (drn (inv &options &mode s1)
636 (OPTIONS ANYINTMODE RTX) (NA NA MATCHEXPR)
641 ; This is a boolean operation.
642 ; MODE is the mode of S1. The result always has mode BI.
643 ; ??? Perhaps `mode' shouldn't be here.
644 (drn (not &options &mode s1)
646 (OPTIONS ANYINTMODE RTX) (NA NA MATCHEXPR)
651 (drn (add &options &mode s1 s2)
653 (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
657 (drn (sub &options &mode s1 s2)
659 (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
664 ; "OF" for "overflow flag", "CF" for "carry flag",
665 ; "s3" here must have type BI.
666 ; For the *flag rtx's, MODE is the mode of S1,S2; the result always has
668 (drn (addc &options &mode s1 s2 s3)
670 (OPTIONS ANYINTMODE RTX RTX RTX) (NA NA MATCHEXPR MATCH2 BI)
674 (drn (addc-cflag &options &mode s1 s2 s3)
676 (OPTIONS ANYINTMODE RTX RTX RTX) (NA NA MATCHEXPR MATCH2 BI)
680 (drn (addc-oflag &options &mode s1 s2 s3)
682 (OPTIONS ANYINTMODE RTX RTX RTX) (NA NA MATCHEXPR MATCH2 BI)
686 (drn (subc &options &mode s1 s2 s3)
688 (OPTIONS ANYINTMODE RTX RTX RTX) (NA NA MATCHEXPR MATCH2 BI)
692 (drn (subc-cflag &options &mode s1 s2 s3)
694 (OPTIONS ANYINTMODE RTX RTX RTX) (NA NA MATCHEXPR MATCH2 BI)
698 (drn (subc-oflag &options &mode s1 s2 s3)
700 (OPTIONS ANYINTMODE RTX RTX RTX) (NA NA MATCHEXPR MATCH2 BI)
705 ;; ??? These are deprecated. Delete in time.
706 (drn (add-cflag &options &mode s1 s2 s3)
708 (OPTIONS ANYINTMODE RTX RTX RTX) (NA NA MATCHEXPR MATCH2 BI)
712 (drn (add-oflag &options &mode s1 s2 s3)
714 (OPTIONS ANYINTMODE RTX RTX RTX) (NA NA MATCHEXPR MATCH2 BI)
718 (drn (sub-cflag &options &mode s1 s2 s3)
720 (OPTIONS ANYINTMODE RTX RTX RTX) (NA NA MATCHEXPR MATCH2 BI)
724 (drn (sub-oflag &options &mode s1 s2 s3)
726 (OPTIONS ANYINTMODE RTX RTX RTX) (NA NA MATCHEXPR MATCH2 BI)
731 ; Usurp these names so that we have consistent rtl should a program generator
732 ; ever want to infer more about what the semantics are doing.
733 ; For now these are just macros that expand to real rtl to perform the
736 ; Return bit indicating if VALUE is zero/non-zero.
737 (drmn (zflag arg1 . rest) ; mode value)
738 (if (null? rest) ; mode missing?
739 (list 'eq 'DFLT arg1 0)
740 (list 'eq arg1 (car rest) 0))
743 ; Return bit indicating if VALUE is negative/non-negative.
744 (drmn (nflag arg1 . rest) ; mode value)
745 (if (null? rest) ; mode missing?
746 (list 'lt 'DFLT arg1 0)
747 (list 'lt arg1 (car rest) 0))
752 (drn (mul &options &mode s1 s2)
754 (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
758 ; ??? In non-sim case, ensure s1,s2 is in right C type for right result.
759 ; ??? Need two variants, one that avoids implementation defined situations
760 ; [both host and target], and one that specifies implementation defined
761 ; situations [target].
762 (drn (div &options &mode s1 s2)
764 (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
768 (drn (udiv &options &mode s1 s2)
770 (OPTIONS ANYINTMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
774 (drn (mod &options &mode s1 s2)
776 (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
780 (drn (umod &options &mode s1 s2)
782 (OPTIONS ANYINTMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
787 ; wip: mixed mode mul/div
789 ; various floating point routines
791 (drn (sqrt &options &mode s1)
793 (OPTIONS ANYFLOATMODE RTX) (NA NA MATCHEXPR)
798 (drn (cos &options &mode s1)
800 (OPTIONS ANYFLOATMODE RTX) (NA NA MATCHEXPR)
805 (drn (sin &options &mode s1)
807 (OPTIONS ANYFLOATMODE RTX) (NA NA MATCHEXPR)
814 (drn (min &options &mode s1 s2)
816 (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
821 (drn (max &options &mode s1 s2)
823 (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
828 (drn (umin &options &mode s1 s2)
830 (OPTIONS ANYINTMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
835 (drn (umax &options &mode s1 s2)
837 (OPTIONS ANYINTMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
842 ; These are bitwise operations.
843 (drn (and &options &mode s1 s2)
845 (OPTIONS ANYINTMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
849 (drn (or &options &mode s1 s2)
851 (OPTIONS ANYINTMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
855 (drn (xor &options &mode s1 s2)
857 (OPTIONS ANYINTMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
864 (drn (sll &options &mode s1 s2)
866 (OPTIONS ANYINTMODE RTX RTX) (NA NA MATCHEXPR INT)
870 (drn (srl &options &mode s1 s2)
872 (OPTIONS ANYINTMODE RTX RTX) (NA NA MATCHEXPR INT)
876 ; ??? In non-sim case, ensure s1 is in right C type for right result.
877 (drn (sra &options &mode s1 s2)
879 (OPTIONS ANYINTMODE RTX RTX) (NA NA MATCHEXPR INT)
883 ; Rotates don't really have a sign, so doesn't matter what we say.
884 (drn (ror &options &mode s1 s2)
886 (OPTIONS ANYINTMODE RTX RTX) (NA NA MATCHEXPR INT)
890 (drn (rol &options &mode s1 s2)
892 (OPTIONS ANYINTMODE RTX RTX) (NA NA MATCHEXPR INT)
896 ; ??? Will also need rotate-with-carry [duh...].
898 ; These are boolean operations (e.g. C &&, ||).
899 ; The result always has mode BI.
900 ; ??? 'twould be more Schemey to take a variable number of args.
901 ; ??? 'twould also simplify several .cpu description entries.
902 ; On the other hand, handling an arbitrary number of args isn't supported by
903 ; ISA's, which the main goal of what we're trying to represent.
904 (drn (andif &options &mode s1 s2)
906 (OPTIONS BIMODE RTX RTX) (NA NA ANYINT ANYINT)
910 (drn (orif &options &mode s1 s2)
912 (OPTIONS BIMODE RTX RTX) (NA NA ANYINT ANYINT)
917 ; `bitfield' is an experimental operation.
918 ; It's not really needed but it might help simplify some things.
920 ;(drn (bitfield mode src start length)
927 (drn (ext &options &mode s1)
929 (OPTIONS ANYINTMODE RTX) (NA NA ANY)
933 (drn (zext &options &mode s1)
935 (OPTIONS ANYINTMODE RTX) (NA NA ANY)
939 (drn (trunc &options &mode s1)
941 (OPTIONS ANYINTMODE RTX) (NA NA ANY)
945 (drn (fext &options &mode s1)
947 (OPTIONS ANYFLOATMODE RTX) (NA NA ANY)
951 (drn (ftrunc &options &mode s1)
953 (OPTIONS ANYFLOATMODE RTX) (NA NA ANY)
957 (drn (float &options &mode s1)
959 (OPTIONS ANYFLOATMODE RTX) (NA NA ANY)
963 (drn (ufloat &options &mode s1)
965 (OPTIONS ANYFLOATMODE RTX) (NA NA ANY)
969 (drn (fix &options &mode s1)
971 (OPTIONS ANYINTMODE RTX) (NA NA ANY)
975 (drn (ufix &options &mode s1)
977 (OPTIONS ANYINTMODE RTX) (NA NA ANY)
983 ; MODE is the mode of S1,S2. The result always has mode BI.
985 (drn (eq &options &mode s1 s2)
987 (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
991 (drn (ne &options &mode s1 s2)
993 (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
997 ; ??? In non-sim case, ensure s1,s2 is in right C type for right result.
998 (drn (lt &options &mode s1 s2)
1000 (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
1004 (drn (le &options &mode s1 s2)
1006 (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
1010 (drn (gt &options &mode s1 s2)
1012 (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
1016 (drn (ge &options &mode s1 s2)
1018 (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
1022 ; ??? In non-sim case, ensure s1,s2 is in right C type for right result.
1023 (drn (ltu &options &mode s1 s2)
1025 (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
1029 (drn (leu &options &mode s1 s2)
1031 (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
1035 (drn (gtu &options &mode s1 s2)
1037 (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
1041 (drn (geu &options &mode s1 s2)
1043 (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
1049 ; Useful in ifield assertions.
1051 ; Return a boolean (BI mode) indicating if VALUE is in SET.
1052 ; VALUE is any constant rtx. SET is a `number-list' rtx.
1054 (drn (member &options &mode value set)
1056 (OPTIONS BIMODE RTX RTX) (NA NA INT INT)
1059 (if (not (rtx-constant? value))
1060 (estate-error *estate* "`member rtx'"
1061 "value is not a constant" value))
1062 (if (not (rtx-kind? 'number-list set))
1063 (estate-error *estate* "`member' rtx"
1064 "set is not a `number-list' rtx" set))
1065 (if (memq (rtx-constant-value value) (rtx-number-list-values set))
1070 ;; FIXME: "number" in "number-list" implies floats are ok.
1071 ;; Rename to integer-list, int-list, or some such.
1073 (drn (number-list &options &mode value-list)
1075 (OPTIONS INTMODE NUMBER . NUMBER) (NA NA NA . NA)
1080 ; Conditional execution.
1082 ; FIXME: make syntax node?
1083 (drn (if &options &mode cond then . else)
1085 ;; ??? It would be cleaner if TESTRTX had to have BI mode.
1086 (OPTIONS VOIDORNUMMODE TESTRTX RTX . RTX) (NA NA ANYINT MATCHEXPR . MATCH3)
1088 (apply e-if (append! (list *estate* mode cond then) else))
1091 ; ??? The syntax here isn't quite that of Scheme. A condition must be
1092 ; followed by a result expression.
1093 ; ??? The syntax here isn't quite right, there must be at least one cond rtx.
1094 ; ??? Intermediate expressions (the ones before the last one) needn't have
1095 ; the same mode as the result.
1096 (drsn (cond &options &mode . cond-code-list)
1098 (OPTIONS VOIDORNUMMODE . CONDRTX) (NA NA . MATCHEXPR)
1103 ; ??? The syntax here isn't quite right, there must be at least one case.
1104 ; ??? Intermediate expressions (the ones before the last one) needn't have
1105 ; the same mode as the result.
1106 (drn (case &options &mode test . case-list)
1108 (OPTIONS VOIDORNUMMODE RTX . CASERTX) (NA NA ANY . MATCHEXPR)
1113 ; parallel, sequence, do-count, closure
1115 ; This has to be a syntax node as we don't want EXPRS to be pre-evaluated.
1116 ; All semantic ops must have a mode, though here it must be VOID.
1117 ; IGNORE is for consistency with sequence. ??? Delete some day.
1118 ; ??? There's no real need for mode either, but convention requires it.
1120 (drsn (parallel &options &mode ignore expr . exprs)
1122 (OPTIONS VOIDMODE LOCALS RTX . RTX) (NA NA NA VOID . VOID)
1127 ; This has to be a syntax node to handle locals properly: they're not defined
1128 ; yet and thus pre-evaluating the expressions doesn't work.
1129 ; ??? This should create a closure.
1131 (drsn (sequence &options &mode locals expr . exprs)
1133 (OPTIONS VOIDORNUMMODE LOCALS RTX . RTX) (NA NA NA MATCHSEQ . MATCHSEQ)
1138 ; This has to be a syntax node to handle iter-var properly: it's not defined
1139 ; yet and thus pre-evaluating the expressions doesn't work.
1141 (drsn (do-count &options &mode iter-var nr-times expr . exprs)
1143 (OPTIONS VOIDMODE ITERATION RTX RTX . RTX) (NA NA NA INT VOID . VOID)
1148 ; Internal rtx to create a closure.
1149 ; Internal, so it does not appear in rtl.texi.
1151 (drsn (closure &options &mode expr env)
1153 (OPTIONS VOIDORNUMMODE RTX ENV) (NA NA MATCHEXPR NA)
1158 )) ; End of def-rtx-funcs