OSDN Git Service

downgrade some fixmes -> ???
[pf3gnuchains/sourceware.git] / cgen / rtx-funcs.scm
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.
5
6 ; THIS FILE CONTAINS ONE BIG FUNCTION: def-rtx-funcs.
7 ;
8 ; It is ok for this file to use procs "internal" to rtl.scm.
9 ;
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.
17
18 (define (def-rtx-funcs)
19
20 ; Do not change the indentation here.
21 (let
22 (
23  ; These are defined in rtl.scm.
24  (drn define-rtx-node)
25  (drsn define-rtx-syntax-node)
26  (dron define-rtx-operand-node)
27  (drmn define-rtx-macro-node)
28 )
29
30 ; The reason for the odd indenting above is so that emacs begins indenting the
31 ; following code at column 1.
32 \f
33 ; Error reporting.
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.
37
38 (drn (error &options &mode message)
39      #f
40      (OPTIONS VOIDORNUMMODE STRING) (NA NA NA)
41      MISC
42      (estate-error *estate* "error in rtl" message)
43 )
44
45 ; Enums
46 ; Default mode is INT.
47
48 (drn (enum &options &mode enum-name)
49      #f
50      (OPTIONS ANYINTMODE SYMBOL) (NA NA NA) ;; ??? s/SYMBOL/ENUM-NAME/ ?
51      ARG
52      ; When computing a value, return the enum's value.
53      (enum-lookup-val enum-name)
54 )
55
56 ; Instruction fields
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
60 ; in this.
61
62 (dron (ifield &options &mode ifld-name)
63       #f
64       (OPTIONS ANYNUMMODE SYMBOL) (NA NA NA) ;; ??? s/SYMBOL/IFIELD-NAME/ ?
65       ARG
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)
70                            (obj-atlist f))
71               (obj:name (ifld-hw-type f))
72               (obj:name (ifld-mode f))
73               (make <hw-index> 'anonymous 'ifield (ifld-mode f) f)
74               nil #f #f))
75 )
76
77 ; Specify an operand.
78 ; Operands are normally specified by name, but they are subsequently wrapped
79 ; in this.
80
81 (dron (operand &options &mode op-name)
82       #f
83       (OPTIONS ANYNUMMODE SYMBOL) (NA NA NA) ;; ??? s/SYMBOL/OPERAND-NAME/ ?
84       ARG
85       (current-op-lookup op-name)
86 )
87
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
92 ; sometimes it is.
93 ;
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.
97 ; (define-insn ...
98 ;   (inputs (in-gr1 src1) (in-gr2 src2))
99 ;   (outputs (out-pc pc) (out-gr dr) (reg-14 (reg WI h-gr 14)))
100 ;   ...)
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.
103 ;
104 ; In instructions, operand numbers are recorded as well, to implement
105 ; profiling and result writeback of parallel insns.
106
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.
111
112 (drsn (name &options &mode new-name value)
113       #f
114       (OPTIONS ANYNUMMODE SYMBOL RTX) (NA NA NA ANY)
115       ARG
116       ;; FIXME: s/DFLT/&mode/ ?
117       (let ((result (object-copy (rtx-get 'DFLT value))))
118         (op:set-sem-name! result new-name)
119         result)
120 )
121
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.
127
128 (dron (xop &options &mode object)
129       #f
130       (OPTIONS ANYNUMMODE OBJECT) (NA NA NA) ;; ??? s/OBJECT/OPERAND/ ?
131       ARG
132       object
133 )
134
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)
137 ;      ARG
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
142 ;       ; operands.
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))
147 ;         operand))
148 ;)
149
150 ; Specify a reference to a local variable.
151 ; Local variables are normally specified by name, but they are subsequently
152 ; wrapped in this.
153
154 (dron (local &options &mode local-name)
155       #f
156       (OPTIONS ANYNUMMODE SYMBOL) (NA NA NA) ;; ??? s/SYMBOL/LOCAL-NAME/ ?
157       ARG
158       (rtx-temp-lookup (tstate-env *tstate*) local-name)
159 )
160
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))
167 ;)
168 ;
169 ; ??? Since operands are given names and not numbers this isn't currently used.
170 ;
171 ;(drsn (dup &options &mode op-name)
172 ;     #f
173 ;     (OPTIONS ANYNUMMODE SYMBOL) (NA NA NA)
174 ;     ;(s-dup *estate* op-name)
175 ;     (begin
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)))
180 ;     #f
181 ;)
182
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.
186
187 (drsn (ref &options &mode name)
188       BI
189       (OPTIONS BIMODE SYMBOL) (NA NA NA) ;; ??? s/SYMBOL/OPERAND-NAME/ ?
190       ARG
191       #f
192 )
193
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.
198
199 (dron (index-of &options &mode op-rtx)
200       INT
201       (OPTIONS INTMODE RTX) (NA NA ANY)
202       ARG
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)
208               f-name f-name
209               (atlist-cons (bool-attr-make 'SEM-ONLY #t)
210                            (obj-atlist f))
211               (obj:name (ifld-hw-type f))
212               (obj:name (ifld-mode f))
213               (make <hw-index> 'anonymous
214                     'ifield
215                     (ifld-mode f)
216                     ; (send (op:type op) 'get-index-mode)
217                     f)
218               nil #f #f))
219 )
220
221 ; Same as index-of, but improves readability for registers.
222
223 (drmn (regno reg)
224       (list 'index-of reg)
225 )
226 \f
227 ; Hardware elements.
228
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'
235 ; unevaluated.
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)
239 ;      ARG
240 ;      (let ((indx (if (pair? indx-sel) (car indx-sel) 0))
241 ;            (selector (if (and (pair? indx-sel) (pair? (cdr indx-sel)))
242 ;                          (cadr indx-sel)
243 ;                          hw-selector-default))))
244 ;      (s-hw *estate* mode hw-elm indx selector)
245 ;)
246
247 ; Register accesses.
248 ; INDX-SEL is an optional index and possible selector.
249 (dron (reg &options &mode hw-elm . indx-sel)
250       #f
251       (OPTIONS ANYNUMMODE SYMBOL . RTX) (NA NA NA . INT) ;; ??? s/SYMBOL/HW-NAME/ ?
252       ARG
253       (let ((indx (if (pair? indx-sel) (car indx-sel) 0))
254             (selector (if (and (pair? indx-sel) (pair? (cdr indx-sel)))
255                           (cadr indx-sel)
256                           hw-selector-default)))
257         (s-hw *estate* mode hw-elm indx selector))          
258 )
259
260 ; A raw-reg bypasses the getter/setter stuff.  It's usually used in
261 ; getter/setter definitions.
262
263 (dron (raw-reg &options &mode hw-elm . indx-sel)
264       #f
265       (OPTIONS ANYNUMMODE SYMBOL . RTX) (NA NA NA . INT) ;; ??? s/SYMBOL/HW-NAME/ ?
266       ARG
267       (let ((indx (if (pair? indx-sel) (car indx-sel) 0))
268             (selector (if (and (pair? indx-sel) (pair? (cdr indx-sel)))
269                           (cadr 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))
273           result))
274 )
275
276 ; Memory accesses.
277 (dron (mem &options &mode addr . sel)
278       #f
279       (OPTIONS EXPLNUMMODE RTX . RTX) (NA NA AI . INT)
280       ARG
281       (s-hw *estate* mode 'h-memory addr
282             (if (pair? sel) (car sel) hw-selector-default))
283 )
284 \f
285 ; Instruction execution support.
286 ; There are no jumps, per se.  A jump is a set of `pc'.
287
288 ; The program counter.
289 ; ??? Hmmm... needed?  The pc is usually specified as `pc' which is shorthand
290 ; for (operand pc).
291 ;(dron (pc) () () ARG s-pc)
292
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.
296 ; ??? wip!
297
298 (drmn (ifetch mode pc)
299       (list 'mem mode pc) ; hw-selector-ispace
300 )
301
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].
305 ; ??? wip!
306
307 (drmn (decode mode pc insn num)
308       (list 'c-call mode 'EXTRACT pc insn num)
309 )
310
311 ; NUM is the same number passed to `decode'.
312 ; ??? wip!
313
314 (drmn (execute mode num)
315       (list 'c-call mode 'EXECUTE num)
316 )
317 \f
318 ; Control Transfer Instructions
319
320 ; Sets of pc are handled like other sets so there are no branch rtx's.
321
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.
325 ; ??? wip!
326
327 (drn (delay &options &mode n rtx)
328      #f
329      (OPTIONS VOIDORNUMMODE RTX RTX) (NA NA INT MATCHEXPR)
330      MISC
331      #f ; (s-sequence *estate* VOID '() rtx) ; wip!
332 )
333
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.
337 ; ??? wip!
338
339 (drmn (annul yes?)
340       ; The pc reference here is hidden in c-code to not generate a spurious
341       ; pc input operand.
342       (list 'c-call 'VOID "SEM_ANNUL_INSN" (list 'c-code 'IAI "pc") yes?)
343 )
344
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.
348 ; ??? wip!
349
350 (drn (skip &options &mode yes?)
351      VOID
352      (OPTIONS VOIDMODE RTX) (NA NA INT)
353      MISC
354      #f
355 )
356 \f
357 ; Attribute support.
358
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.
366 ; FIXME: wip
367 ;
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.
371
372 (drn (eq-attr &options &mode owner attr value)
373      BI
374       (OPTIONS BIMODE RTX SYMBOL SYMORNUM) (NA NA ANY NA NA)
375       MISC
376       (let ((atval (if owner
377                        (obj-attr-value owner attr)
378                        (attr-lookup-default attr #f))))
379         (if (list? value)
380             (->bool (memq atval value))
381             (eq? atval value)))
382 )
383
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).
388 ; FIXME:wip
389 ; This uses INTMODE because we can't otherwise determine the
390 ; mode of the result (if elided).
391
392 (drn (int-attr &options &mode obj attr-name)
393      #f
394      (OPTIONS INTMODE RTX SYMBOL) (NA NA ANY NA)
395      MISC
396      #f
397 )
398
399 ;; Deprecated alias for int-attr.
400
401 (drmn (attr arg1 . rest)
402       (cons 'int-attr (cons arg1 rest))
403 )
404
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?]
407
408 (drsn (symbol &options &mode name)
409       SYM
410       (OPTIONS SYMMODE SYMBOL) (NA NA NA)
411       ARG
412       name
413 )
414
415 ; Return the current instruction.
416
417 (drn (current-insn &options &mode)
418      INSN
419      (OPTIONS INSNMODE) (NA NA)
420      MISC
421      (let ((obj (estate-owner *estate*)))
422        (if (not (insn? obj))
423            (error "current context not an insn"))
424        obj)
425 )
426
427 ; Return the currently selected machine.
428 ; This can either be a compile-time or run-time value.
429
430 (drn (current-mach &options &mode)
431      MACH
432      (OPTIONS MACHMODE) (NA NA)
433      MISC
434      -rtx-current-mach
435 )
436 \f
437 ; Constants.
438
439 ; FIXME: Need to consider 64 bit hosts.
440 (drn (const &options &mode c)
441      #f
442      (OPTIONS ANYNUMMODE NUMBER) (NA NA NA)
443      ARG
444      ; When computing a value, just return the constant unchanged.
445      c
446 )
447 \f
448 ; Large mode support.
449
450 ; Combine smaller modes into a larger one.
451 ; Arguments are specified most significant to least significant.
452 ; ??? Not all of the combinations are supported in the simulator.
453 ; They'll get added as necessary.
454 (drn (join &options &out-mode in-mode arg1 . arg-rest)
455      #f
456      (OPTIONS ANYNUMMODE ANYNUMMODE RTX . RTX) (NA NA NA ANY . ANY)
457      MISC
458      ; FIXME: Ensure correct number of args for in/out modes.
459      ; FIXME: Ensure compatible modes.
460      #f
461 )
462
463 ; GCC's subreg.
464 ; Called subword 'cus it's not exactly subreg.
465 ; Word numbering is word-order dependent.
466 ; Word number 0 is the most significant word if big-endian-words.
467 ; Word number 0 is the least significant word if little-endian-words.
468 ; ??? GCC plans to switch to SUBREG_BYTE.  Keep an eye out for the switch
469 ; (which is extensive so probably won't happen anytime soon).
470 ; MODE is the mode of the result, not operand0.
471 ;
472 ; The mode spec of operand0 use to be MATCHEXPR, but subword is not a normal rtx.
473 ; The mode of operand0 is not necessarily the same as the mode of the result,
474 ; and code which analyzes it would otherwise use the result mode (specified by
475 ; `&mode') for the mode of operand0.
476
477 (drn (subword &options &mode value word-num)
478      #f
479      (OPTIONS ANYNUMMODE RTX RTX) (NA NA ANY INT)
480      ARG
481      #f
482 )
483
484 ; ??? The split and concat stuff is just an experiment and should not be used.
485 ; What's there now is just "thoughts put down on paper."
486
487 (drmn (split split-mode in-mode di)
488       ; FIXME: Ensure compatible modes
489       ;(list 'c-raw-call 'BLK (string-append "SPLIT" in-mode split-mode) di)
490       '(const 0)
491 )
492
493 (drmn (concat modes arg1 . arg-rest)
494       ; FIXME: Here might be the place to ensure
495       ; (= (length modes) (length (cons arg1 arg-rest))).
496       ;(cons 'c-raw-call (cons modes (cons "CONCAT" (cons arg1 arg-rest))))
497       '(const 0)
498 )
499 \f
500 ; Support for explicit C code.
501 ; ??? GCC RTL calls this "unspec" which is arguably a more application
502 ; independent name.
503
504 (drn (c-code &options &mode text)
505      #f
506      (OPTIONS ANYEXPRMODE STRING) (NA NA NA)
507      UNSPEC
508      #f
509 )
510
511 ; Invoke C functions passing them arguments from the semantic code.
512 ; The arguments are passed as is, no conversion is done here.
513 ; Usage is:
514 ;           (c-call mode name arg1 arg2 ...)
515 ; which is converted into a C function call:
516 ;           name (current_cpu, arg1, arg2, ...)
517 ; MODE is the mode of the result.
518 ; If it is VOID this call is a statement and ';' is appended.
519 ; Otherwise it is part of an expression.
520
521 (drn (c-call &options &mode name . args)
522      #f
523      (OPTIONS ANYEXPRMODE STRING . RTX) (NA NA NA . ANY)
524      UNSPEC
525      #f
526 )
527
528 ; Same as c-call but without implicit first arg of `current_cpu'.
529
530 (drn (c-raw-call &options &mode name . args)
531      #f
532      (OPTIONS ANYEXPRMODE STRING . RTX) (NA NA NA . ANY)
533      UNSPEC
534      #f
535 )
536 \f
537 ; Set/get/miscellaneous
538
539 (drn (nop &options &mode)
540      VOID
541      (OPTIONS VOIDMODE) (NA NA)
542      MISC
543      #f
544 )
545
546 ; Clobber - mark an object as modified without explaining why or how.
547
548 (drn (clobber &options &mode object)
549      VOID
550      (OPTIONS VOIDORNUMMODE RTX) (NA NA MATCHEXPR)
551      MISC
552      #f
553 )
554
555 ; The `set' rtx.
556 ; MODE is the mode of DST.  If DFLT, use DST's default mode.
557 ; The mode of the result is always VOID.
558 ;
559 ; ??? It might be more consistent to rename set -> set-trace, but that's
560 ; too wordy.  The `set' rtx is the normal one and we want the normal one to
561 ; be the verbose one (prints result tracing messages).  `set-quiet' is the
562 ; atypical one, it doesn't print tracing messages.  It may also turn out that
563 ; a different mechanism (rather than the name "set-quiet") is used some day.
564 ; One way would be to record the "quietness" state with the traversal state and
565 ; use something like (with-quiet (set foo bar)) akin to with-output-to-string
566 ; in Guile.
567 ;
568 ; i.e. set -> gen-set-trace
569 ;      set-quiet -> gen-set-quiet
570 ;
571 ; ??? One might want a `!' suffix as in `set!', but methinks that's following
572 ; Scheme too closely.
573
574 (drn (set &options &mode dst src)
575      VOID
576      (OPTIONS ANYNUMMODE SETRTX RTX) (NA NA MATCHEXPR MATCH2)
577      SET
578      #f
579 )
580
581 (drn (set-quiet &options &mode dst src)
582      VOID
583      (OPTIONS ANYNUMMODE SETRTX RTX) (NA NA MATCHEXPR MATCH2)
584      SET
585      #f
586 )
587 \f
588 ; Standard arithmetic operations.
589
590 ; It's nice emitting macro calls to the actual C operation in that the RTX
591 ; expression is preserved, albeit in C.  On the one hand it's one extra thing
592 ; the programmer has to know when looking at the code.  But on the other it's
593 ; trivial stuff, and having a layer between RTX and C allows the
594 ; macros/functions to be modified to handle unexpected situations.
595
596 ; We do emit C directly for cases other than cpu semantics
597 ; (e.g. the assembler).
598 ;
599 ; The language is defined such that we assume ANSI C semantics while avoiding
600 ; implementation defined areas, with as few exceptions as possible.
601 ;
602 ; Current exceptions:
603 ; - signed shift right assumes the sign bit is replicated.
604 ;
605 ; Additional notes [perhaps repeating what's in ANSI C for emphasis]:
606 ; - callers of division and modulus fns must test for 0 beforehand
607 ;   if necessary
608 ; - division and modulus fns have unspecified behavior for negative args
609 ;   [yes I know the C standard says implementation defined, here its
610 ;   unspecified]
611 ; - later add versions of div/mod that have an explicit behaviour for -ve args
612 ; - signedness is part of the rtx operation name, and is not determined
613 ;   from the arguments [elsewhere is a description of the tradeoffs]
614 ; - ???
615
616 (drn (neg &options &mode s1)
617      #f
618      (OPTIONS ANYNUMMODE RTX) (NA NA MATCHEXPR)
619      UNARY
620      #f
621 )
622
623 (drn (abs &options &mode s1)
624      #f
625      (OPTIONS ANYNUMMODE RTX) (NA NA MATCHEXPR)
626      UNARY
627      #f
628 )
629
630 ; For integer values this is a bitwise operation (each bit inverted).
631 ; For floating point values this produces 1/x.
632 ; ??? Might want different names.
633 (drn (inv &options &mode s1)
634      #f
635      (OPTIONS ANYINTMODE RTX) (NA NA MATCHEXPR)
636      UNARY
637      #f
638 )
639
640 ; This is a boolean operation.
641 ; MODE is the mode of S1.  The result always has mode BI.
642 ; ??? Perhaps `mode' shouldn't be here.
643 (drn (not &options &mode s1)
644      BI
645      (OPTIONS ANYINTMODE RTX) (NA NA MATCHEXPR)
646      UNARY
647      #f
648 )
649
650 (drn (add &options &mode s1 s2)
651      #f
652      (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
653      BINARY
654      #f
655 )
656 (drn (sub &options &mode s1 s2)
657      #f
658      (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
659      BINARY
660      #f
661 )
662
663 ; "OF" for "overflow flag", "CF" for "carry flag",
664 ; "s3" here must have type BI.
665 ; For the *flag rtx's, MODE is the mode of S1,S2; the result always has
666 ; mode BI.
667 (drn (addc &options &mode s1 s2 s3)
668      #f
669      (OPTIONS ANYINTMODE RTX RTX RTX) (NA NA MATCHEXPR MATCH2 BI)
670      TRINARY
671      #f
672 )
673 (drn (addc-cflag &options &mode s1 s2 s3)
674      BI
675      (OPTIONS ANYINTMODE RTX RTX RTX) (NA NA MATCHEXPR MATCH2 BI)
676      TRINARY
677      #f
678 )
679 (drn (addc-oflag &options &mode s1 s2 s3)
680      BI
681      (OPTIONS ANYINTMODE RTX RTX RTX) (NA NA MATCHEXPR MATCH2 BI)
682      TRINARY
683      #f
684 )
685 (drn (subc &options &mode s1 s2 s3)
686      #f
687      (OPTIONS ANYINTMODE RTX RTX RTX) (NA NA MATCHEXPR MATCH2 BI)
688      TRINARY
689      #f
690 )
691 (drn (subc-cflag &options &mode s1 s2 s3)
692      BI
693      (OPTIONS ANYINTMODE RTX RTX RTX) (NA NA MATCHEXPR MATCH2 BI)
694      TRINARY
695      #f
696 )
697 (drn (subc-oflag &options &mode s1 s2 s3)
698      BI
699      (OPTIONS ANYINTMODE RTX RTX RTX) (NA NA MATCHEXPR MATCH2 BI)
700      TRINARY
701      #f
702 )
703
704 ;; ??? These are deprecated.  Delete in time.
705 (drn (add-cflag &options &mode s1 s2 s3)
706      BI
707      (OPTIONS ANYINTMODE RTX RTX RTX) (NA NA MATCHEXPR MATCH2 BI)
708      TRINARY
709      #f
710 )
711 (drn (add-oflag &options &mode s1 s2 s3)
712      BI
713      (OPTIONS ANYINTMODE RTX RTX RTX) (NA NA MATCHEXPR MATCH2 BI)
714      TRINARY
715      #f
716 )
717 (drn (sub-cflag &options &mode s1 s2 s3)
718      BI
719      (OPTIONS ANYINTMODE RTX RTX RTX) (NA NA MATCHEXPR MATCH2 BI)
720      TRINARY
721      #f
722 )
723 (drn (sub-oflag &options &mode s1 s2 s3)
724      BI
725      (OPTIONS ANYINTMODE RTX RTX RTX) (NA NA MATCHEXPR MATCH2 BI)
726      TRINARY
727      #f
728 )
729
730 ; Usurp these names so that we have consistent rtl should a program generator
731 ; ever want to infer more about what the semantics are doing.
732 ; For now these are just macros that expand to real rtl to perform the
733 ; operation.
734
735 ; Return bit indicating if VALUE is zero/non-zero.
736 (drmn (zflag arg1 . rest) ; mode value)
737       (if (null? rest) ; mode missing?
738           (list 'eq 'DFLT arg1 0)
739           (list 'eq arg1 (car rest) 0))
740 )
741
742 ; Return bit indicating if VALUE is negative/non-negative.
743 (drmn (nflag arg1 . rest) ; mode value)
744       (if (null? rest) ; mode missing?
745           (list 'lt 'DFLT arg1 0)
746           (list 'lt arg1 (car rest) 0))
747 )
748
749 ; Multiply/divide.
750
751 (drn (mul &options &mode s1 s2)
752      #f
753      (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
754      BINARY
755      #f
756 )
757 ; ??? In non-sim case, ensure s1,s2 is in right C type for right result.
758 ; ??? Need two variants, one that avoids implementation defined situations
759 ; [both host and target], and one that specifies implementation defined
760 ; situations [target].
761 (drn (div &options &mode s1 s2)
762      #f
763      (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
764      BINARY
765      #f
766 )
767 (drn (udiv &options &mode s1 s2)
768      #f
769      (OPTIONS ANYINTMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
770      BINARY
771      #f
772 )
773 (drn (mod &options &mode s1 s2)
774      #f
775      (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
776      BINARY
777      #f
778 )
779 (drn (umod &options &mode s1 s2)
780      #f
781      (OPTIONS ANYINTMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
782      BINARY
783      #f
784 )
785
786 ; wip: mixed mode mul/div
787
788 ; various floating point routines
789
790 (drn (sqrt &options &mode s1)
791      #f
792      (OPTIONS ANYFLOATMODE RTX) (NA NA MATCHEXPR)
793      UNARY
794      #f
795 )
796
797 (drn (cos &options &mode s1)
798      #f
799      (OPTIONS ANYFLOATMODE RTX) (NA NA MATCHEXPR)
800      UNARY
801      #f
802 )
803
804 (drn (sin &options &mode s1)
805      #f
806      (OPTIONS ANYFLOATMODE RTX) (NA NA MATCHEXPR)
807      UNARY
808      #f
809 )
810
811 ; min/max
812
813 (drn (min &options &mode s1 s2)
814      #f
815      (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
816      BINARY
817      #f
818 )
819
820 (drn (max &options &mode s1 s2)
821      #f
822      (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
823      BINARY
824      #f
825 )
826
827 (drn (umin &options &mode s1 s2)
828      #f
829      (OPTIONS ANYINTMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
830      BINARY
831      #f
832 )
833
834 (drn (umax &options &mode s1 s2)
835      #f
836      (OPTIONS ANYINTMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
837      BINARY
838      #f
839 )
840
841 ; These are bitwise operations.
842 (drn (and &options &mode s1 s2)
843      #f
844      (OPTIONS ANYINTMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
845      BINARY
846      #f
847 )
848 (drn (or &options &mode s1 s2)
849      #f
850      (OPTIONS ANYINTMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
851      BINARY
852      #f
853 )
854 (drn (xor &options &mode s1 s2)
855      #f
856      (OPTIONS ANYINTMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
857      BINARY
858      #f
859 )
860
861 ; Shift operations.
862
863 (drn (sll &options &mode s1 s2)
864      #f
865      (OPTIONS ANYINTMODE RTX RTX) (NA NA MATCHEXPR INT)
866      BINARY
867      #f
868 )
869 (drn (srl &options &mode s1 s2)
870      #f
871      (OPTIONS ANYINTMODE RTX RTX) (NA NA MATCHEXPR INT)
872      BINARY
873      #f
874 )
875 ; ??? In non-sim case, ensure s1 is in right C type for right result.
876 (drn (sra &options &mode s1 s2)
877      #f
878      (OPTIONS ANYINTMODE RTX RTX) (NA NA MATCHEXPR INT)
879      BINARY
880      #f
881 )
882 ; Rotates don't really have a sign, so doesn't matter what we say.
883 (drn (ror &options &mode s1 s2)
884      #f
885      (OPTIONS ANYINTMODE RTX RTX) (NA NA MATCHEXPR INT)
886      BINARY
887      #f
888 )
889 (drn (rol &options &mode s1 s2)
890      #f
891      (OPTIONS ANYINTMODE RTX RTX) (NA NA MATCHEXPR INT)
892      BINARY
893      #f
894 )
895 ; ??? Will also need rotate-with-carry [duh...].
896
897 ; These are boolean operations (e.g. C &&, ||).
898 ; The result always has mode BI.
899 ; ??? 'twould be more Schemey to take a variable number of args.
900 ; ??? 'twould also simplify several .cpu description entries.
901 ; On the other hand, handling an arbitrary number of args isn't supported by
902 ; ISA's, which the main goal of what we're trying to represent.
903 (drn (andif &options &mode s1 s2)
904      BI
905      (OPTIONS BIMODE RTX RTX) (NA NA ANYINT ANYINT)
906      BINARY ; IF?
907      #f
908 )
909 (drn (orif &options &mode s1 s2)
910      BI
911      (OPTIONS BIMODE RTX RTX) (NA NA ANYINT ANYINT)
912      BINARY ; IF?
913      #f
914 )
915 \f
916 ; `bitfield' is an experimental operation.
917 ; It's not really needed but it might help simplify some things.
918 ;
919 ;(drn (bitfield mode src start length)
920 ;     ...
921 ;     ...
922 ;)
923 \f
924 ; Conversions.
925
926 (drn (ext &options &mode s1)
927      #f
928      (OPTIONS ANYINTMODE RTX) (NA NA ANY)
929      UNARY
930      #f
931 )
932 (drn (zext &options &mode s1)
933      #f
934      (OPTIONS ANYINTMODE RTX) (NA NA ANY)
935      UNARY
936      #f
937 )
938 (drn (trunc &options &mode s1)
939      #f
940      (OPTIONS ANYINTMODE RTX) (NA NA ANY)
941      UNARY
942      #f
943 )
944 (drn (fext &options &mode s1)
945      #f
946      (OPTIONS ANYFLOATMODE RTX) (NA NA ANY)
947      UNARY
948      #f
949 )
950 (drn (ftrunc &options &mode s1)
951      #f
952      (OPTIONS ANYFLOATMODE RTX) (NA NA ANY)
953      UNARY
954      #f
955 )
956 (drn (float &options &mode s1)
957      #f
958      (OPTIONS ANYFLOATMODE RTX) (NA NA ANY)
959      UNARY
960      #f
961 )
962 (drn (ufloat &options &mode s1)
963      #f
964      (OPTIONS ANYFLOATMODE RTX) (NA NA ANY)
965      UNARY
966      #f
967 )
968 (drn (fix &options &mode s1)
969      #f
970      (OPTIONS ANYINTMODE RTX) (NA NA ANY)
971      UNARY
972      #f
973 )
974 (drn (ufix &options &mode s1)
975      #f
976      (OPTIONS ANYINTMODE RTX) (NA NA ANY)
977      UNARY
978      #f
979 )
980 \f
981 ; Comparisons.
982 ; MODE is the mode of S1,S2.  The result always has mode BI.
983
984 (drn (eq &options &mode s1 s2)
985      BI
986      (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
987      COMPARE
988      #f
989 )
990 (drn (ne &options &mode s1 s2)
991      BI
992      (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
993      COMPARE
994      #f
995 )
996 ; ??? In non-sim case, ensure s1,s2 is in right C type for right result.
997 (drn (lt &options &mode s1 s2)
998      BI
999      (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
1000      COMPARE
1001      #f
1002 )
1003 (drn (le &options &mode s1 s2)
1004      BI
1005      (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
1006      COMPARE
1007      #f
1008 )
1009 (drn (gt &options &mode s1 s2)
1010      BI
1011      (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
1012      COMPARE
1013      #f
1014 )
1015 (drn (ge &options &mode s1 s2)
1016      BI
1017      (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
1018      COMPARE
1019      #f
1020 )
1021 ; ??? In non-sim case, ensure s1,s2 is in right C type for right result.
1022 (drn (ltu &options &mode s1 s2)
1023      BI
1024      (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
1025      COMPARE
1026      #f
1027 )
1028 (drn (leu &options &mode s1 s2)
1029      BI
1030      (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
1031      COMPARE
1032      #f
1033 )
1034 (drn (gtu &options &mode s1 s2)
1035      BI
1036      (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
1037      COMPARE
1038      #f
1039 )
1040 (drn (geu &options &mode s1 s2)
1041      BI
1042      (OPTIONS ANYNUMMODE RTX RTX) (NA NA MATCHEXPR MATCH2)
1043      COMPARE
1044      #f
1045 )
1046 \f
1047 ; Set membership.
1048 ; Useful in ifield assertions.
1049
1050 ; Return a boolean (BI mode) indicating if VALUE is in SET.
1051 ; VALUE is any constant rtx.  SET is a `number-list' rtx.
1052
1053 (drn (member &options &mode value set)
1054      #f
1055      (OPTIONS BIMODE RTX RTX) (NA NA INT INT)
1056      MISC
1057      (begin
1058        (if (not (rtx-constant? value))
1059            (estate-error *estate* "`member rtx'"
1060                          "value is not a constant" value))
1061        (if (not (rtx-kind? 'number-list set))
1062            (estate-error *estate* "`member' rtx"
1063                          "set is not a `number-list' rtx" set))
1064        (if (memq (rtx-constant-value value) (rtx-number-list-values set))
1065            (rtx-true)
1066            (rtx-false)))
1067 )
1068
1069 ;; FIXME: "number" in "number-list" implies floats are ok.
1070 ;; Rename to integer-list, int-list, or some such.
1071
1072 (drn (number-list &options &mode value-list)
1073      #f
1074      (OPTIONS INTMODE NUMBER . NUMBER) (NA NA NA . NA)
1075      MISC
1076      #f
1077 )
1078 \f
1079 ; Conditional execution.
1080
1081 ; FIXME: make syntax node?
1082 (drn (if &options &mode cond then . else)
1083      #f
1084      ;; ??? It would be cleaner if TESTRTX had to have BI mode.
1085      (OPTIONS VOIDORNUMMODE TESTRTX RTX . RTX) (NA NA ANYINT MATCHEXPR . MATCH3)
1086      IF
1087      (apply e-if (append! (list *estate* mode cond then) else))
1088 )
1089
1090 ; ??? The syntax here isn't quite that of Scheme.  A condition must be
1091 ; followed by a result expression.
1092 ; ??? The syntax here isn't quite right, there must be at least one cond rtx.
1093 ; ??? Intermediate expressions (the ones before the last one) needn't have
1094 ; the same mode as the result.
1095 (drsn (cond &options &mode . cond-code-list)
1096      #f
1097       (OPTIONS VOIDORNUMMODE . CONDRTX) (NA NA . MATCHEXPR)
1098       COND
1099       #f
1100 )
1101
1102 ; ??? The syntax here isn't quite right, there must be at least one case.
1103 ; ??? Intermediate expressions (the ones before the last one) needn't have
1104 ; the same mode as the result.
1105 (drn (case &options &mode test . case-list)
1106      #f
1107      (OPTIONS VOIDORNUMMODE RTX . CASERTX) (NA NA ANY . MATCHEXPR)
1108      COND
1109      #f
1110 )
1111 \f
1112 ; parallel, sequence, do-count, closure
1113
1114 ; This has to be a syntax node as we don't want EXPRS to be pre-evaluated.
1115 ; All semantic ops must have a mode, though here it must be VOID.
1116 ; IGNORE is for consistency with sequence.  ??? Delete some day.
1117 ; ??? There's no real need for mode either, but convention requires it.
1118
1119 (drsn (parallel &options &mode ignore expr . exprs)
1120      #f
1121       (OPTIONS VOIDMODE LOCALS RTX . RTX) (NA NA NA VOID . VOID)
1122       SEQUENCE
1123       #f
1124 )
1125
1126 ; This has to be a syntax node to handle locals properly: they're not defined
1127 ; yet and thus pre-evaluating the expressions doesn't work.
1128
1129 (drsn (sequence &options &mode locals expr . exprs)
1130      #f
1131       (OPTIONS VOIDORNUMMODE LOCALS RTX . RTX) (NA NA NA MATCHSEQ . MATCHSEQ)
1132       SEQUENCE
1133       #f
1134 )
1135
1136 ; This has to be a syntax node to handle iter-var properly: it's not defined
1137 ; yet and thus pre-evaluating the expressions doesn't work.
1138
1139 (drsn (do-count &options &mode iter-var nr-times expr . exprs)
1140      #f
1141       (OPTIONS VOIDMODE ITERATION RTX RTX . RTX) (NA NA NA INT VOID . VOID)
1142       SEQUENCE
1143       #f
1144 )
1145
1146 ; Internal rtx to create a closure.
1147 ; Internal, so it does not appear in rtl.texi (at least not yet).
1148 ; ??? Maybe closures shouldn't be separate from sequences,
1149 ; but I'm less convinced these days.
1150
1151 (drsn (closure &options &mode isa-name-list env-stack expr)
1152      #f
1153       (OPTIONS VOIDORNUMMODE SYMBOLLIST ENVSTACK RTX) (NA NA NA NA MATCHEXPR)
1154       MISC
1155       #f
1156 )
1157 \f
1158 )) ; End of def-rtx-funcs