OSDN Git Service

* All *.scm files: Update copyright year.
[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
36 (drn (error &options &mode message)
37      (OPTIONS ANYMODE STRING) (NA NA NA)
38      MISC
39      (context-error (estate-context *estate*) message)
40 )
41
42 ; Enums
43 ; Default mode is INT.
44
45 (drn (enum &options &mode enum-name)
46      (OPTIONS NUMMODE SYMBOL) (NA NA NA)
47      ARG
48      ; When computing a value, return the enum's value.
49      (enum-lookup-val enum-name)
50 )
51
52 ; Instruction fields
53 ; These are used in the encode/decode specs of other ifields as well as in
54 ; instruction semantics.
55 ; Ifields are normally specified by name, but they are subsequently wrapped
56 ; in this.
57
58 (dron (ifield &options &mode ifld-name)
59       (OPTIONS DFLTMODE SYMBOL) (NA NA NA)
60       ARG
61       (let ((f (current-ifld-lookup ifld-name)))
62         (make <operand> ifld-name (string-append ifld-name " used as operand")
63               (atlist-cons (bool-attr-make 'SEM-ONLY #t)
64                            (obj-atlist f))
65               (obj:name (ifld-hw-type f))
66               (obj:name (ifld-mode f))
67               (make <hw-index> 'anonymous 'ifield (ifld-mode f) f)
68               nil #f #f))
69 )
70
71 ; Specify an operand.
72 ; Operands are normally specified by name, but they are subsequently wrapped
73 ; in this.
74
75 (dron (operand &options &mode op-name)
76       (OPTIONS DFLTMODE SYMBOL) (NA NA NA)
77       ARG
78       (current-op-lookup op-name)
79 )
80
81 ; Operand naming/numbering.
82 ; Operands are given names so that the operands as used in the semantics can
83 ; be matched with arguments of function units.  With good name choices of
84 ; operands and function unit arguments, this is rarely necessary, but
85 ; sometimes it is.
86 ;
87 ; ??? This obfuscates the semantic code a fair bit.  Another way to do this
88 ; would be to add new elements to <insn> to specify operands outside of
89 ; the semantic code.  E.g.
90 ; (define-insn ...
91 ;   (inputs (in-gr1 src1) (in-gr2 src2))
92 ;   (outputs (out-pc pc) (out-gr dr) (reg-14 (reg WI h-gr 14)))
93 ;   ...)
94 ; The intent here is to continue to allow the semantic code to use names
95 ; of operands, and not overly complicate the input/output description.
96 ;
97 ; In instructions, operand numbers are recorded as well, to implement
98 ; profiling and result writeback of parallel insns.
99
100 ; Rename operand VALUE to NEW-NAME.
101 ; VALUE is an expression whose result is an object of type <operand>.
102 ; It can be the name of an existing operand.
103 ; ??? Might also support numbering by allowing NEW-NAME to be a number.
104
105 (drsn (name &options &mode new-name value)
106       (OPTIONS DFLTMODE SYMBOL RTX) (NA NA NA ANY)
107       ARG
108       (let ((result (object-copy (rtx-get 'DFLT value))))
109         (op:set-sem-name! result new-name)
110         result)
111 )
112
113 ; Operands are generally compiled to an internal form first.
114 ; There is a fair bit of state associated with them, and it's easier to
115 ; work with an object than source [which might get fairly complicated if
116 ; it expresses all the state].
117 ; Compiled operands are wrapped in this so that they still look like rtx.
118
119 (dron (xop &options &mode object)
120       (OPTIONS DFLTMODE OBJECT) (NA NA NA)
121       ARG
122       object
123 )
124
125 ;(dron (opspec: &options &mode op-name op-num hw-ref attrs)
126 ;      (OPTIONS ANYMODE SYMBOL NUMBER RTX ATTRS) (NA NA NA NA ANY NA)
127 ;      ARG
128 ;      (let ((opval (rtx-eval-with-estate hw-ref mode *estate*)))
129 ;       (assert (operand? opval))
130 ;       ; Set the specified mode, ensuring it's ok.
131 ;       ; This also makes a copy as we don't want to modify predefined
132 ;       ; operands.
133 ;       (let ((operand (op:new-mode opval mode)))
134 ;         (op:set-sem-name! operand op-name)
135 ;         (op:set-num! operand op-num)
136 ;         (op:set-cond?! operand (attr-value attrs 'COND-REF #f))
137 ;         operand))
138 ;)
139
140 ; Specify a reference to a local variable.
141 ; Local variables are normally specified by name, but they are subsequently
142 ; wrapped in this.
143
144 (dron (local &options &mode local-name)
145       (OPTIONS DFLTMODE SYMBOL) (NA NA NA)
146       ARG
147       (rtx-temp-lookup (tstate-env *tstate*) local-name)
148 )
149
150 ; FIXME: This doesn't work.  See s-operand.
151 ;(define (s-dup estate op-name)
152 ;  (if (not (insn? (estate-owner estate)))
153 ;      (error "dup: not processing an insn"))
154 ;  (vector-ref (insn:operands (current-current-context))
155 ;              (op:lookup-num (insn:operands (estate-owner estate)) op-name))
156 ;)
157 ;
158 ; ??? Since operands are given names and not numbers this isn't currently used.
159 ;
160 ;(drsn (dup &options &mode op-name)
161 ;     (OPTIONS DFLTMODE SYMBOL) (NA NA NA)
162 ;     ;(s-dup *estate* op-name)
163 ;     (begin
164 ;       (if (not (insn? (estate-owner *estate*)))
165 ;          (error "dup: not processing an insn"))
166 ;       (vector-ref (insn:operands (estate-owner *estate*))
167 ;                  (op:lookup-num (insn:operands (estate-owner *estate*)) op-name)))
168 ;     #f
169 ;)
170
171 ; Returns non-zero if operand NAME was referenced (read if input operand
172 ; and written if output operand).
173 ; ??? What about input/output operands.
174
175 (drsn (ref &options &mode name)
176       (OPTIONS DFLTMODE SYMBOL) (NA NA NA)
177       ARG
178       #f
179 )
180
181 ; Return the index of an operand.
182 ; For registers this is the register number.
183 ; ??? Mode handling incomplete.
184
185 (dron (index-of &options &mode op-rtx)
186       (OPTIONS DFLTMODE RTX) (NA NA ANY)
187       ARG
188       (let* ((operand (rtx-eval-with-estate op-rtx 'DFLT *estate*))
189              (f (hw-index:value (op:index operand)))
190              (f-name (obj:name f)))
191         (make <operand> f-name f-name
192               (atlist-cons (bool-attr-make 'SEM-ONLY #t)
193                            (obj-atlist f))
194               (obj:name (ifld-hw-type f))
195               (obj:name (ifld-mode f))
196               (make <hw-index> 'anonymous
197                     'ifield
198                     (ifld-mode f)
199                     ; (send (op:type op) 'get-index-mode)
200                     f)
201               nil #f #f))
202 )
203
204 ; Same as index-of, but improves readability for registers.
205
206 (drmn (regno reg)
207       (list 'index-of reg)
208 )
209 \f
210 ; Hardware elements.
211
212 ; Describe a random hardware object.
213 ; If INDX is missing, assume the element is a scalar.  We pass 0 so s-hw
214 ; doesn't have to unpack the list that would be passed if it were defined as
215 ; (hw mode hw-name . indx).  This is an internal implementation detail
216 ; and thus harmless to the description language.
217 ; These are implemented as syntax nodes as we must pass INDX to `s-hw'
218 ; unevaluated.
219 ; ??? Not currently supported.  Not sure whether it should be.
220 ;(drsn (hw &options &mode hw-elm . indx-sel)
221 ;      (OPTIONS ANYMODE SYMBOL . RTX) (NA NA NA . INT)
222 ;      ARG
223 ;      (let ((indx (if (pair? indx-sel) (car indx-sel) 0))
224 ;            (selector (if (and (pair? indx-sel) (pair? (cdr indx-sel)))
225 ;                          (cadr indx-sel)
226 ;                          hw-selector-default))))
227 ;      (s-hw *estate* mode hw-elm indx selector)
228 ;)
229
230 ; Register accesses.
231 ; INDX-SEL is an optional index and possible selector.
232 (dron (reg &options &mode hw-elm . indx-sel)
233       (OPTIONS ANYMODE SYMBOL . RTX) (NA NA NA . INT)
234       ARG
235       (let ((indx (if (pair? indx-sel) (car indx-sel) 0))
236             (selector (if (and (pair? indx-sel) (pair? (cdr indx-sel)))
237                           (cadr indx-sel)
238                           hw-selector-default)))
239         (s-hw *estate* mode hw-elm indx selector))          
240 )
241
242 ; A raw-reg bypasses the getter/setter stuff.  It's usually used in
243 ; getter/setter definitions.
244
245 (dron (raw-reg &options &mode hw-elm . indx-sel)
246       (OPTIONS ANYMODE SYMBOL . RTX) (NA NA NA . INT)
247       ARG
248       (let ((indx (if (pair? indx-sel) (car indx-sel) 0))
249             (selector (if (and (pair? indx-sel) (pair? (cdr indx-sel)))
250                           (cadr indx-sel)
251                           hw-selector-default)))
252         (let ((result (s-hw *estate* mode hw-elm indx selector)))
253           (obj-cons-attr! result (bool-attr-make 'RAW #t))
254           result))
255 )
256
257 ; Memory accesses.
258 (dron (mem &options &mode addr . sel)
259       (OPTIONS EXPLNUMMODE RTX . RTX) (NA NA AI . INT)
260       ARG
261       (s-hw *estate* mode 'h-memory addr
262             (if (pair? sel) (car sel) hw-selector-default))
263 )
264 \f
265 ; Instruction execution support.
266 ; There are no jumps, per se.  A jump is a set of `pc'.
267
268 ; The program counter.
269 ; ??? Hmmm... needed?  The pc is usually specified as `pc' which is shorthand
270 ; for (operand pc).
271 (dron (pc) () () ARG s-pc)
272
273 ; Fetch bytes from the instruction stream of size MODE.
274 ; FIXME: Later need to augment this by passing an indicator to the mem-fetch
275 ; routines that we're doing an ifetch.
276 ; ??? wip!
277
278 (drmn (ifetch mode pc)
279       (list 'mem mode pc) ; hw-selector-ispace
280 )
281
282 ; NUM is the instruction number.  Generally it is zero but if more than one
283 ; insn is decoded at a time, it is non-zero.  This is used, for example, to
284 ; index into the scache [as an offset from the first insn].
285 ; ??? wip!
286
287 (drmn (decode mode pc insn num)
288       (list 'c-call mode 'EXTRACT pc insn num)
289 )
290
291 ; NUM is the same number passed to `decode'.
292 ; ??? wip!
293
294 (drmn (execute mode num)
295       (list 'c-call mode 'EXECUTE num)
296 )
297 \f
298 ; Control Transfer Instructions
299
300 ; Sets of pc are handled like other sets so there are no branch rtx's.
301
302 ; Indicate there are N delay slots in the processing of RTX.
303 ; N is a `const' node.
304 ; ??? wip!
305
306 (drn (delay &options &mode n rtx)
307      (OPTIONS DFLTMODE RTX RTX) (NA NA INT ANY)
308      MISC
309      #f ; (s-sequence *estate* VOID '() rtx) ; wip!
310 )
311
312 ; Annul the following insn if YES? is non-zero.
313 ; PC is the address of the annuling insn.
314 ; The target is required to define SEM_ANNUL_INSN.
315 ; ??? wip!
316
317 (drmn (annul yes?)
318       ; The pc reference here is hidden in c-code to not generate a spurious
319       ; pc input operand.
320       (list 'c-call 'VOID "SEM_ANNUL_INSN" (list 'c-code 'IAI "pc") yes?)
321 )
322
323 ; Skip the following insn if YES? is non-zero.
324 ; The target is required to define SEM_SKIP_INSN.
325 ; ??? This is similar to annul.  Deletion of one of them defered.
326 ; ??? wip!
327
328 (drn (skip &options &mode yes?)
329      (OPTIONS DFLTMODE RTX) (NA NA INT)
330      MISC
331      #f
332 )
333 \f
334 ; Attribute support.
335
336 ; Return a boolean indicating if attribute named ATTR is VALUE in OWNER.
337 ; If VALUE is a list, return "true" if ATTR is any of the listed values.
338 ; ??? Don't yet support !VALUE.
339 ; OWNER is the result of either (current-insn) or (current-mach)
340 ; [note that canonicalization will turn them into
341 ; (current-{insn,mach} () DFLT)].
342 ; The result is always of mode INT.
343 ; FIXME: wip
344 ;
345 ; This is a syntax node so the args are not pre-evaluated.
346 ; We just want the symbols.
347 ; FIXME: Hmmm... it currently isn't a syntax node.
348
349 (drn (eq-attr &options &mode owner attr value)
350       (OPTIONS DFLTMODE RTX SYMBOL SYMORNUM) (NA NA ANY NA NA)
351       MISC
352       (let ((atval (if owner
353                        (obj-attr-value owner attr)
354                        (attr-lookup-default attr #f))))
355         (if (list? value)
356             (->bool (memq atval value))
357             (eq? atval value)))
358 )
359
360 ; Get the value of attribute ATTR-NAME.
361 ; OBJ is the result of either (current-insn) or (current-mach)
362 ; [note that canonicalization will turn them into
363 ; (current-{insn,mach} () DFLT)].
364 ; FIXME:wip
365
366 (drn (attr &options &mode obj attr-name)
367      (OPTIONS DFLTMODE RTX SYMBOL) (NA NA NA NA)
368      MISC
369      #f
370 )
371
372 ; Same as `quote', for use in attributes cus "quote" sounds too jargonish.
373 ; [Ok, not a strong argument for using "symbol", but so what?]
374
375 (drsn (symbol &options &mode name)
376       (OPTIONS DFLTMODE SYMBOL) (NA NA NA)
377       ARG
378       name
379 )
380
381 ; Return the current instruction.
382
383 (drn (current-insn &options &mode)
384      (OPTIONS DFLTMODE) (NA NA)
385      MISC
386      (let ((obj (estate-owner *estate*)))
387        (if (not (insn? obj))
388            (error "current context not an insn"))
389        obj)
390 )
391
392 ; Return the currently selected machine.
393 ; This can either be a compile-time or run-time value.
394
395 (drn (current-mach &options &mode)
396      (OPTIONS DFLTMODE) (NA NA)
397      MISC
398      -rtx-current-mach
399 )
400 \f
401 ; Constants.
402
403 ; FIXME: Need to consider 64 bit hosts.
404 (drn (const &options &mode c)
405      (OPTIONS NUMMODE NUMBER) (NA NA NA)
406      ARG
407      ; When computing a value, just return the constant unchanged.
408      c
409 )
410 \f
411 ; Large mode support.
412
413 ; Combine smaller modes into a larger one.
414 ; Arguments are specified most significant to least significant.
415 ; ??? May also want an endian dependent argument order.  That can be
416 ; implemented on top of or beside this.
417 ; ??? Not all of the combinations are supported in the simulator.
418 ; They'll get added as necessary.
419 (drn (join &options &out-mode in-mode arg1 . arg-rest)
420      (OPTIONS NUMMODE NUMMODE RTX . RTX) (NA NA NA ANY . ANY)
421      MISC
422      ; FIXME: Ensure correct number of args for in/out modes.
423      ; FIXME: Ensure compatible modes.
424      #f
425 )
426
427 ; GCC's subreg.
428 ; Called subword 'cus it's not exactly subreg.
429 ; Word numbering is from most significant (word 0) to least (word N-1).
430 ; ??? May also want an endian dependent word ordering.  That can be
431 ; implemented on top of or beside this.
432 ; ??? GCC plans to switch to SUBREG_BYTE.  Keep an eye out for the switch
433 ; (which is extensive so probably won't happen anytime soon).
434 ;
435 ; The mode spec of operand0 use to be OP0, but subword is not a normal rtx.
436 ; The mode of operand0 is not necessarily the same as the mode of the result,
437 ; and code which analyzes it would otherwise use the result mode (specified by
438 ; `&mode') for the mode of operand0.
439
440 (drn (subword &options &mode value word-num)
441      (OPTIONS NUMMODE RTX RTX) (NA NA ANY INT)
442      ARG
443      #f
444 )
445
446 ; ??? The split and concat stuff is just an experiment and should not be used.
447 ; What's there now is just "thoughts put down on paper."
448
449 (drmn (split split-mode in-mode di)
450       ; FIXME: Ensure compatible modes
451       ;(list 'c-raw-call 'BLK (string-append "SPLIT" in-mode split-mode) di)
452       '(const 0)
453 )
454
455 (drmn (concat modes arg1 . arg-rest)
456       ; FIXME: Here might be the place to ensure
457       ; (= (length modes) (length (cons arg1 arg-rest))).
458       ;(cons 'c-raw-call (cons modes (cons "CONCAT" (cons arg1 arg-rest))))
459       '(const 0)
460 )
461 \f
462 ; Support for explicit C code.
463 ; ??? GCC RTL calls this "unspec" which is arguably a more application
464 ; independent name.
465
466 (drn (c-code &options &mode text)
467      (OPTIONS ANYMODE STRING) (NA NA NA)
468      UNSPEC
469      #f
470 )
471
472 ; Invoke C functions passing them arguments from the semantic code.
473 ; The arguments are passed as is, no conversion is done here.
474 ; Usage is:
475 ;           (c-call mode name arg1 arg2 ...)
476 ; which is converted into a C function call:
477 ;           name (current_cpu, arg1, arg2, ...)
478 ; Mode is the mode of the result.
479 ; If it is VOID this call is a statement and ';' is appended.
480 ; Otherwise it is part of an expression.
481
482 (drn (c-call &options &mode name . args)
483      (OPTIONS ANYMODE STRING . RTX) (NA NA NA . ANY)
484      UNSPEC
485      #f
486 )
487
488 ; Same as c-call but without implicit first arg of `current_cpu'.
489
490 (drn (c-raw-call &options &mode name . args)
491      (OPTIONS ANYMODE STRING . RTX) (NA NA NA . ANY)
492      UNSPEC
493      #f
494 )
495 \f
496 ; Set/get/miscellaneous
497
498 (drn (nop &options &mode)
499      (OPTIONS VOIDMODE) (NA NA)
500      MISC
501      #f
502 )
503
504 ; Clobber - mark an object as modified without explaining why or how.
505
506 (drn (clobber &options &mode object)
507      (OPTIONS ANYMODE RTX) (NA NA OP0)
508      MISC
509      #f
510 )
511
512 ; The `set' rtx.
513 ; MODE is the mode of DST.  If DFLT, use DST's default mode.
514 ; The mode of the result is always VOID.
515 ;
516 ; ??? It might be more consistent to rename set -> set-trace, but that's
517 ; too wordy.  The `set' rtx is the normal one and we want the normal one to
518 ; be the verbose one (prints result tracing messages).  `set-quiet' is the
519 ; atypical one, it doesn't print tracing messages.  It may also turn out that
520 ; a different mechanism (rather than the name "set-quiet") is used some day.
521 ; One way would be to record the "quietness" state with the traversal state and
522 ; use something like (with-quiet (set foo bar)) akin to with-output-to-string
523 ; in Guile.
524 ;
525 ; i.e. set -> gen-set-trace
526 ;      set-quiet -> gen-set-quiet
527 ;
528 ; ??? One might want a `!' suffix as in `set!', but methinks that's following
529 ; Scheme too closely.
530
531 (drn (set &options &mode dst src)
532      (OPTIONS ANYMODE SETRTX RTX) (NA NA OP0 MATCH1)
533      SET
534      #f
535 )
536
537 (drn (set-quiet &options &mode dst src)
538      (OPTIONS ANYMODE SETRTX RTX) (NA NA OP0 MATCH1)
539      SET
540      #f
541 )
542 \f
543 ; Standard arithmetic operations.
544
545 ; It's nice emitting macro calls to the actual C operation in that the RTX
546 ; expression is preserved, albeit in C.  On the one hand it's one extra thing
547 ; the programmer has to know when looking at the code.  But on the other it's
548 ; trivial stuff, and having a layer between RTX and C allows the
549 ; macros/functions to be modified to handle unexpected situations.
550
551 ; We do emit C directly for cases other than cpu semantics
552 ; (e.g. the assembler).
553 ;
554 ; The language is defined such that we assume ANSI C semantics while avoiding
555 ; implementation defined areas, with as few exceptions as possible.
556 ;
557 ; Current exceptions:
558 ; - signed shift right assumes the sign bit is replicated.
559 ;
560 ; Additional notes [perhaps repeating what's in ANSI C for emphasis]:
561 ; - callers of division and modulus fns must test for 0 beforehand
562 ;   if necessary
563 ; - division and modulus fns have unspecified behavior for negative args
564 ;   [yes I know the C standard says implementation defined, here its
565 ;   unspecified]
566 ; - later add versions of div/mod that have an explicit behaviour for -ve args
567 ; - signedness is part of the rtx operation name, and is not determined
568 ;   from the arguments [elsewhere is a description of the tradeoffs]
569 ; - ???
570
571 (drn (neg &options &mode s1)
572      (OPTIONS ANYMODE RTX) (NA NA OP0)
573      UNARY
574      #f
575 )
576
577 (drn (abs &options &mode s1)
578      (OPTIONS ANYMODE RTX) (NA NA OP0)
579      UNARY
580      #f
581 )
582
583 ; For integer values this is a bitwise operation (each bit inverted).
584 ; For floating point values this produces 1/x.
585 ; ??? Might want different names.
586 (drn (inv &options &mode s1)
587      (OPTIONS ANYMODE RTX) (NA NA OP0)
588      UNARY
589      #f
590 )
591
592 ; This is a boolean operation.
593 ; MODE is the mode of S1.  The result always has mode BI.
594 ; ??? Perhaps `mode' shouldn't be here.
595 (drn (not &options &mode s1)
596      (OPTIONS ANYMODE RTX) (NA NA OP0)
597      UNARY
598      #f
599 )
600
601 (drn (add &options &mode s1 s2)
602      (OPTIONS ANYMODE RTX RTX) (NA NA OP0 MATCH1)
603      BINARY
604      #f
605 )
606 (drn (sub &options &mode s1 s2)
607      (OPTIONS ANYMODE RTX RTX) (NA NA OP0 MATCH1)
608      BINARY
609      #f
610 )
611
612 ; "OF" for "overflow flag", "CF" for "carry flag",
613 ; "s3" here must have type BI.
614 ; For the *flag rtx's, MODE is the mode of S1,S2; the result always has
615 ; mode BI.
616 (drn (addc &options &mode s1 s2 s3)
617      (OPTIONS ANYMODE RTX RTX RTX) (NA NA OP0 MATCH1 BI)
618      TRINARY
619      #f
620 )
621 (drn (add-cflag &options &mode s1 s2 s3) ; FIXME: rename to addc-cflag
622      (OPTIONS ANYMODE RTX RTX RTX) (NA NA OP0 MATCH1 BI)
623      TRINARY
624      #f
625 )
626 (drn (add-oflag &options &mode s1 s2 s3) ; FIXME: rename to addc-vflag
627      (OPTIONS ANYMODE RTX RTX RTX) (NA NA OP0 MATCH1 BI)
628      TRINARY
629      #f
630 )
631 (drn (subc &options &mode s1 s2 s3)
632      (OPTIONS ANYMODE RTX RTX RTX) (NA NA OP0 MATCH1 BI)
633      TRINARY
634      #f
635 )
636 (drn (sub-cflag &options &mode s1 s2 s3) ; FIXME: rename to subc-cflag
637      (OPTIONS ANYMODE RTX RTX RTX) (NA NA OP0 MATCH1 BI)
638      TRINARY
639      #f
640 )
641 (drn (sub-oflag &options &mode s1 s2 s3) ; FIXME: rename to subc-vflag
642      (OPTIONS ANYMODE RTX RTX RTX) (NA NA OP0 MATCH1 BI)
643      TRINARY
644      #f
645 )
646
647 ; Usurp these names so that we have consistent rtl should a program generator
648 ; ever want to infer more about what the semantics are doing.
649 ; For now these are just macros that expand to real rtl to perform the
650 ; operation.
651
652 ; Return bit indicating if VALUE is zero/non-zero.
653 (drmn (zflag arg1 . rest) ; mode value)
654       (if (null? rest) ; mode missing?
655           (list 'eq 'DFLT arg1 0)
656           (list 'eq arg1 (car rest) 0))
657 )
658
659 ; Return bit indicating if VALUE is negative/non-negative.
660 (drmn (nflag arg1 . rest) ; mode value)
661       (if (null? rest) ; mode missing?
662           (list 'lt 'DFLT arg1 0)
663           (list 'lt arg1 (car rest) 0))
664 )
665
666 ; Multiply/divide.
667
668 (drn (mul &options &mode s1 s2)
669      (OPTIONS ANYMODE RTX RTX) (NA NA OP0 MATCH1)
670      BINARY
671      #f
672 )
673 ; ??? In non-sim case, ensure s1,s2 is in right C type for right result.
674 ; ??? Need two variants, one that avoids implementation defined situations
675 ; [both host and target], and one that specifies implementation defined
676 ; situations [target].
677 (drn (div &options &mode s1 s2)
678      (OPTIONS ANYMODE RTX RTX) (NA NA OP0 MATCH1)
679      BINARY
680      #f
681 )
682 (drn (udiv &options &mode s1 s2)
683      (OPTIONS ANYMODE RTX RTX) (NA NA OP0 MATCH1)
684      BINARY
685      #f
686 )
687 (drn (mod &options &mode s1 s2)
688      (OPTIONS ANYMODE RTX RTX) (NA NA OP0 MATCH1)
689      BINARY
690      #f
691 )
692 (drn (umod &options &mode s1 s2)
693      (OPTIONS ANYMODE RTX RTX) (NA NA OP0 MATCH1)
694      BINARY
695      #f
696 )
697
698 ; wip: mixed mode mul/div
699
700 ; various floating point routines
701
702 (drn (sqrt &options &mode s1)
703      (OPTIONS FLOATMODE RTX) (NA NA OP0)
704      UNARY
705      #f
706 )
707
708 (drn (cos &options &mode s1)
709      (OPTIONS FLOATMODE RTX) (NA NA OP0)
710      UNARY
711      #f
712 )
713
714 (drn (sin &options &mode s1)
715      (OPTIONS FLOATMODE RTX) (NA NA OP0)
716      UNARY
717      #f
718 )
719
720 ; min/max
721
722 (drn (min &options &mode s1 s2)
723      (OPTIONS ANYMODE RTX RTX) (NA NA OP0 MATCH1)
724      BINARY
725      #f
726 )
727
728 (drn (max &options &mode s1 s2)
729      (OPTIONS ANYMODE RTX RTX) (NA NA OP0 MATCH1)
730      BINARY
731      #f
732 )
733
734 (drn (umin &options &mode s1 s2)
735      (OPTIONS INTMODE RTX RTX) (NA NA OP0 MATCH1)
736      BINARY
737      #f
738 )
739
740 (drn (umax &options &mode s1 s2)
741      (OPTIONS INTMODE RTX RTX) (NA NA OP0 MATCH1)
742      BINARY
743      #f
744 )
745
746 ; These are bitwise operations.
747 (drn (and &options &mode s1 s2)
748      (OPTIONS ANYMODE RTX RTX) (NA NA OP0 MATCH1)
749      BINARY
750      #f
751 )
752 (drn (or &options &mode s1 s2)
753      (OPTIONS ANYMODE RTX RTX) (NA NA OP0 MATCH1)
754      BINARY
755      #f
756 )
757 (drn (xor &options &mode s1 s2)
758      (OPTIONS ANYMODE RTX RTX) (NA NA OP0 MATCH1)
759      BINARY
760      #f
761 )
762
763 ; Shift operations.
764
765 (drn (sll &options &mode s1 s2)
766      (OPTIONS ANYMODE RTX RTX) (NA NA OP0 INT)
767      BINARY
768      #f
769 )
770 (drn (srl &options &mode s1 s2)
771      (OPTIONS ANYMODE RTX RTX) (NA NA OP0 INT)
772      BINARY
773      #f
774 )
775 ; ??? In non-sim case, ensure s1 is in right C type for right result.
776 (drn (sra &options &mode s1 s2)
777      (OPTIONS ANYMODE RTX RTX) (NA NA OP0 INT)
778      BINARY
779      #f
780 )
781 ; Rotates don't really have a sign, so doesn't matter what we say.
782 (drn (ror &options &mode s1 s2)
783      (OPTIONS ANYMODE RTX RTX) (NA NA OP0 INT)
784      BINARY
785      #f
786 )
787 (drn (rol &options &mode s1 s2)
788      (OPTIONS ANYMODE RTX RTX) (NA NA OP0 INT)
789      BINARY
790      #f
791 )
792 ; ??? Will also need rotate-with-carry [duh...].
793
794 ; These are boolean operations (e.g. C &&, ||).
795 ; The result always has mode BI.
796 ; ??? 'twould be more Schemey to take a variable number of args.
797 ; ??? 'twould also simplify several .cpu description entries.
798 ; On the other hand, handling an arbitrary number of args isn't supported by
799 ; ISA's, which the main goal of what we're trying to represent.
800 (drn (andif &options &mode s1 s2)
801      (OPTIONS DFLTMODE RTX RTX) (NA NA ANY ANY)
802      BINARY ; IF?
803      #f
804 )
805 (drn (orif &options &mode s1 s2)
806      (OPTIONS DFLTMODE RTX RTX) (NA NA ANY ANY)
807      BINARY ; IF?
808      #f
809 )
810 \f
811 ; `bitfield' is an experimental operation.
812 ; It's not really needed but it might help simplify some things.
813 ;
814 ;(drn (bitfield mode src start length)
815 ;     ...
816 ;     ...
817 ;)
818 \f
819 ; Conversions.
820
821 (drn (ext &options &mode s1)
822      (OPTIONS INTMODE RTX) (NA NA ANY)
823      UNARY
824      #f
825 )
826 (drn (zext &options &mode s1)
827      (OPTIONS INTMODE RTX) (NA NA ANY)
828      UNARY
829      #f
830 )
831 (drn (trunc &options &mode s1)
832      (OPTIONS INTMODE RTX) (NA NA ANY)
833      UNARY
834      #f
835 )
836 (drn (fext &options &mode s1)
837      (OPTIONS FLOATMODE RTX) (NA NA ANY)
838      UNARY
839      #f
840 )
841 (drn (ftrunc &options &mode s1)
842      (OPTIONS FLOATMODE RTX) (NA NA ANY)
843      UNARY
844      #f
845 )
846 (drn (float &options &mode s1)
847      (OPTIONS FLOATMODE RTX) (NA NA ANY)
848      UNARY
849      #f
850 )
851 (drn (ufloat &options &mode s1)
852      (OPTIONS FLOATMODE RTX) (NA NA ANY)
853      UNARY
854      #f
855 )
856 (drn (fix &options &mode s1)
857      (OPTIONS INTMODE RTX) (NA NA ANY)
858      UNARY
859      #f
860 )
861 (drn (ufix &options &mode s1)
862      (OPTIONS INTMODE RTX) (NA NA ANY)
863      UNARY
864      #f
865 )
866 \f
867 ; Comparisons.
868 ; MODE is the mode of S1,S2.  The result always has mode BI.
869
870 (drn (eq &options &mode s1 s2)
871      (OPTIONS ANYMODE RTX RTX) (NA NA OP0 MATCH1)
872      BINARY
873      #f
874 )
875 (drn (ne &options &mode s1 s2)
876      (OPTIONS ANYMODE RTX RTX) (NA NA OP0 MATCH1)
877      BINARY
878      #f
879 )
880 ; ??? In non-sim case, ensure s1,s2 is in right C type for right result.
881 (drn (lt &options &mode s1 s2)
882      (OPTIONS ANYMODE RTX RTX) (NA NA OP0 MATCH1)
883      BINARY
884      #f
885 )
886 (drn (le &options &mode s1 s2)
887      (OPTIONS ANYMODE RTX RTX) (NA NA OP0 MATCH1)
888      BINARY
889      #f
890 )
891 (drn (gt &options &mode s1 s2)
892      (OPTIONS ANYMODE RTX RTX) (NA NA OP0 MATCH1)
893      BINARY
894      #f
895 )
896 (drn (ge &options &mode s1 s2)
897      (OPTIONS ANYMODE RTX RTX) (NA NA OP0 MATCH1)
898      BINARY
899      #f
900 )
901 ; ??? In non-sim case, ensure s1,s2 is in right C type for right result.
902 (drn (ltu &options &mode s1 s2)
903      (OPTIONS ANYMODE RTX RTX) (NA NA OP0 MATCH1)
904      BINARY
905      #f
906 )
907 (drn (leu &options &mode s1 s2)
908      (OPTIONS ANYMODE RTX RTX) (NA NA OP0 MATCH1)
909      BINARY
910      #f
911 )
912 (drn (gtu &options &mode s1 s2)
913      (OPTIONS ANYMODE RTX RTX) (NA NA OP0 MATCH1)
914      BINARY
915      #f
916 )
917 (drn (geu &options &mode s1 s2)
918      (OPTIONS ANYMODE RTX RTX) (NA NA OP0 MATCH1)
919      BINARY
920      #f
921 )
922 \f
923 ; Set membership.
924 ; Useful in ifield assertions.
925
926 ; Return a boolean (BI mode) indicating if VALUE is in SET.
927 ; VALUE is any constant rtx.  SET is a `number-list' rtx.
928
929 (drn (member &options &mode value set)
930      (OPTIONS DFLTMODE RTX RTX) (NA NA INT INT)
931      MISC
932      (begin
933        (if (not (rtx-constant? value))
934            (context-error (estate-context *estate*) "value is not a constant" value))
935        (if (not (rtx-kind? 'number-list set))
936            (context-error (estate-context *estate*) "set is not a `number-list' rtx" set))
937        (if (memq (rtx-constant-value value) (rtx-number-list-values set))
938            (rtx-true)
939            (rtx-false)))
940 )
941
942 (drn (number-list &options &mode value-list)
943      (OPTIONS INTMODE NUMBER . NUMBER) (NA NA NA . NA)
944      MISC
945      #f
946 )
947 \f
948 ; Conditional execution.
949
950 ; FIXME: make syntax node?
951 (drn (if &options &mode cond then . else)
952      (OPTIONS ANYMODE TESTRTX RTX . RTX) (NA NA ANY OP0 . MATCH2)
953      IF
954      (apply e-if (append! (list *estate* mode cond then) else))
955 )
956
957 ; ??? The syntax here isn't quite that of Scheme.  A condition must be
958 ; followed by a result expression.
959 ; ??? Intermediate expressions (the ones before the last one) needn't have
960 ; the same mode as the result.
961 (drsn (cond &options &mode . cond-code-list)
962       (OPTIONS ANYMODE . CONDRTX) (NA NA . OP0)
963       COND
964       #f
965 )
966
967 ; ??? Intermediate expressions (the ones before the last one) needn't have
968 ; the same mode as the result.
969 (drn (case &options &mode test . case-list)
970      (OPTIONS ANYMODE RTX . CASERTX) (NA NA ANY . OP0)
971      COND
972      #f
973 )
974 \f
975 ; Parallels and Sequences
976
977 ; This has to be a syntax node as we don't want EXPRS to be pre-evaluated.
978 ; All semantic ops must have a mode, though here it must be VOID.
979 ; IGNORE is for consistency with sequence.  ??? Delete some day.
980 ; ??? There's no real need for mode either.
981
982 (drsn (parallel &options &mode ignore expr . exprs)
983       (OPTIONS VOIDMODE LOCALS RTX . RTX) (NA NA NA VOID . VOID)
984       SEQUENCE
985       #f
986 )
987
988 ; This has to be a syntax node to handle locals properly: they're not defined
989 ; yet and thus pre-evaluating the expressions doesn't work.
990 ; ??? This should create a closure.
991
992 (drsn (sequence &options &mode locals expr . exprs)
993       (OPTIONS ANYMODE LOCALS RTX . RTX) (NA NA NA OP0 . OP0)
994       SEQUENCE
995       #f
996 )
997 \f
998 ; Internal rtx to create a closure.
999 ; Internal, so it does not appear in rtl.texi.
1000
1001 (drsn (closure &options &mode expr env)
1002       (OPTIONS DFLTMODE RTX ENV) (NA NA NA NA)
1003       MISC
1004       #f
1005 )
1006 \f
1007 )) ; End of def-rtx-funcs