public inbox for cgen@sourceware.org
 help / color / mirror / Atom feed
From: Michael Meissner <cgen-mail@the-meissners.org>
To: cgen@sources.redhat.com
Subject: Nested define-pmacro's
Date: Fri, 20 Jun 2003 02:35:00 -0000	[thread overview]
Message-ID: <20030620023527.GA24021@tiktok.the-meissners.org> (raw)

My machine has lots of instructions, but most of them are fairly regular, so
I've been trying to use nested define-pmacro's to avoid excessive amounts of
typing.  For example, there are 8 different add varients (4 sizes and 2 formats
for each size).  Here is a cut-down example that won't run, but shows you the
flavor of what I'm doing.  When I run it with -v -v -v, I see by the trace that
only the second function is defined.

I see pmacros.scm has this little comment in it:

; ??? Nested pmacros don't bind their arguments the way nested lambda's do.
; Should they?

I'm hoping tomorrow to go into MIT and get a real book on scheme, but pointers
and online sources would be appreciated.

Here the source.  I've tried various different ways of coding the define-pmacro
call.

;; name:	base function name
;; comment:	base comment string
;; attrs:	attribute list
;; syntax1:	initial part of syntax string before the size field
;; syntax2:	syntax string after adding the size field, not including $DREG=$S1REG,$S2REG or $DREG=$S1REG,IMM8
;; format:	format list of the instruction fields, not include the 2 sources or destination
;; imm-bit:	bit to set for the immediate form of the instruction
;; u:		"U" if unsigned, "" if signed
;; semantics:	macro that when expanded does the operation, args are result, arg1, arg2, and mode
;; timing:	timing list

(define-pmacro (expand-osize name comment attrs syntax1 syntax2 format imm-bit bit-21 u semantics timing)
  (begin

    ;; 64-bit reg/reg format
    (dni (.sym name "-64bit-reg-reg")
	 (.str comment ", 64 bit, reg,reg format")
	 attrs
	 (.str syntax1 syntax2 " " "$DREG" "=" "$S1REG" "," "$S2REG")
	 (.splice +
		  (.unsplice format)
		  OSIZE_64
		  DREG
		  S2REG
		  S1REG
	 )

	 (sequence ()
		   (semantics DREG S1REG S2REG (.sym u DI))
	 )

	 timing
    )

    ;; 32-bit reg/reg format
    (dni (.sym name "-32bit-reg-reg")
	 (.str comment ", 32 bit, reg,reg format")
	 attrs
	 (.str syntax1 ".32" syntax2 " " "$DREG" "=" "$S1REG" "," "$S2REG"")
	 (.splice +
		  (.unsplice format)
		  OSIZE_32
		  DREG
		  S2REG
		  S1REG
	 )

	 (sequence ()
		   (semantics (subword (.sym u SI) DREG 0) (subword (.sym u SI) S1REG 0) (subword (.sym u SI) S2REG 0) (.sym u SI))
		   (semantics (subword (.sym u SI) DREG 1) (subword (.sym u SI) S1REG 1) (subword (.sym u SI) S2REG 1) (.sym u SI))
	 )

	 timing
    )

    ;; other 6 formats deleted in the name of brevity
  )
)

(define-pmacro (macro-add ret arg1 arg2 mode) (begin (set ret (add mode arg1 arg2))))
(expand-osize add
	      "add operation"				; comment
	      ()					; attrs
	      "add"					; syntax before size field
	      ""					; syntax after size field, without args
							; format
	      (OPCODE_ADD
	       OTHER_BITS)

	      BIT_35_1					; bit 35 is the immediate bit
	      ""					; signed operation
	      macro-add					; macro to do add operation
	      ()					; timing attributes
)


-- 
Michael Meissner
email: gnu@the-meissners.org
http://www.the-meissners.org

             reply	other threads:[~2003-06-20  2:35 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-06-20  2:35 Michael Meissner [this message]
2003-06-20  4:47 ` Doug Evans
2003-06-20 16:14   ` Michael Meissner
2003-07-02  0:44     ` Ben Elliston

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20030620023527.GA24021@tiktok.the-meissners.org \
    --to=cgen-mail@the-meissners.org \
    --cc=cgen@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).