3 dnl m4 macros for gmp assembly code, shared by all CPUs.
5 dnl Copyright 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006 Free Software
8 dnl This file is part of the GNU MP Library.
10 dnl The GNU MP Library is free software; you can redistribute it and/or
11 dnl modify it under the terms of the GNU Lesser General Public License as
12 dnl published by the Free Software Foundation; either version 3 of the
13 dnl License, or (at your option) any later version.
15 dnl The GNU MP Library is distributed in the hope that it will be useful,
16 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
17 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 dnl Lesser General Public License for more details.
20 dnl You should have received a copy of the GNU Lesser General Public License
21 dnl along with the GNU MP Library. If not, see http://www.gnu.org/licenses/.
24 dnl These macros are designed for use with any m4 and have been used on
25 dnl GNU, FreeBSD, NetBSD, OpenBSD and SysV.
27 dnl GNU m4 and OpenBSD 2.7 m4 will give filenames and line numbers in error
33 dnl Most new m4 specific macros have an "m4_" prefix to emphasise they're
34 dnl m4 expansions. But new defining things like deflit() and defreg() are
35 dnl named like the builtin define(), and forloop() is named following the
36 dnl GNU m4 example on which it's based.
38 dnl GNU m4 with the -P option uses "m4_" as a prefix for builtins, but that
39 dnl option isn't going to be used, so there's no conflict or confusion.
42 dnl Comments in output:
44 dnl The m4 comment delimiters are left at # and \n, the normal assembler
45 dnl commenting for most CPUs. m4 passes comment text through without
46 dnl expanding macros in it, which is generally a good thing since it stops
47 dnl unexpected expansions and possible resultant errors.
49 dnl But note that when a quoted string is being read, a # isn't special, so
50 dnl apostrophes in comments in quoted strings must be avoided or they'll be
51 dnl interpreted as a closing quote mark. But when the quoted text is
52 dnl re-read # will still act like a normal comment, suppressing macro
57 dnl # apostrophes in comments that're outside quotes are ok
58 dnl # and using macro names like PROLOGUE is ok too
61 dnl # but apostrophes aren't ok inside quotes
64 dnl # though macro names like PROLOGUE are still ok
68 dnl If macro expansion in a comment is wanted, use `#' in the .asm (ie. a
69 dnl quoted hash symbol), which will turn into # in the .s but get
70 dnl expansions done on that line. This can make the .s more readable to
71 dnl humans, but it won't make a blind bit of difference to the assembler.
73 dnl All the above applies, mutatis mutandis, when changecom() is used to
74 dnl select @ ! ; or whatever other commenting.
77 dnl Variations in m4 affecting gmp:
79 dnl $# - When a macro is called as "foo" with no brackets, BSD m4 sets $#
80 dnl to 1, whereas GNU or SysV m4 set it to 0. In all cases though
81 dnl "foo()" sets $# to 1. This is worked around in various places.
83 dnl len() - When "len()" is given an empty argument, BSD m4 evaluates to
84 dnl nothing, whereas GNU, SysV, and the new OpenBSD, evaluate to 0.
85 dnl See m4_length() below which works around this.
87 dnl translit() - GNU m4 accepts character ranges like A-Z, and the new
88 dnl OpenBSD m4 does under option -g, but basic BSD and SysV don't.
90 dnl popdef() - in BSD and SysV m4 popdef() takes multiple arguments and
91 dnl pops each, but GNU m4 only takes one argument.
93 dnl push back - BSD m4 has some limits on the amount of text that can be
94 dnl pushed back. The limit is reasonably big and so long as macros
95 dnl don't gratuitously duplicate big arguments it isn't a problem.
96 dnl Normally an error message is given, but sometimes it just hangs.
98 dnl eval() &,|,^ - GNU and SysV m4 have bitwise operators &,|,^ available,
99 dnl but BSD m4 doesn't (contrary to what the man page suggests) and
100 dnl instead ^ is exponentiation.
102 dnl eval() ?: - The C ternary operator "?:" is available in BSD m4, but not
103 dnl in SysV or GNU m4 (as of GNU m4 1.4 and betas of 1.5).
105 dnl eval() -2^31 - BSD m4 has a bug where an eval() resulting in -2^31
106 dnl (ie. -2147483648) gives "-(". Using -2147483648 within an
107 dnl expression is ok, it just can't be a final result. "-(" will of
108 dnl course upset parsing, with all sorts of strange effects.
110 dnl eval() <<,>> - SysV m4 doesn't support shift operators in eval() (on
111 dnl Solaris 7 /usr/xpg4/m4 has them but /usr/ccs/m4 doesn't). See
112 dnl m4_lshift() and m4_rshift() below for workarounds.
114 dnl ifdef() - OSF 4.0 m4 considers a macro defined to a zero value `0' or
115 dnl `00' etc as not defined. See m4_ifdef below for a workaround.
117 dnl m4wrap() sequence - in BSD m4, m4wrap() replaces any previous m4wrap()
118 dnl string, in SysV m4 it appends to it, and in GNU m4 it prepends.
119 dnl See m4wrap_prepend() below which brings uniformity to this.
121 dnl m4wrap() 0xFF - old versions of BSD m4 store EOF in a C "char" under an
122 dnl m4wrap() and on systems where char is unsigned by default a
123 dnl spurious 0xFF is output. This has been observed on recent Cray
124 dnl Unicos Alpha, Apple MacOS X, and HPUX 11 systems. An autoconf
125 dnl test is used to check for this, see the m4wrap handling below. It
126 dnl might work to end the m4wrap string with a dnl to consume the
127 dnl 0xFF, but that probably induces the offending m4's to read from an
128 dnl already closed "FILE *", which could be bad on a glibc style
131 dnl __file__,__line__ - GNU m4 and OpenBSD 2.7 m4 provide these, and
132 dnl they're used here to make error messages more informative. GNU m4
133 dnl gives an unhelpful "NONE 0" in an m4wrap(), but that's worked
136 dnl __file__ quoting - OpenBSD m4, unlike GNU m4, doesn't quote the
137 dnl filename in __file__, so care should be taken that no macro has
138 dnl the same name as a file, or an unwanted expansion will occur when
139 dnl printing an error or warning.
141 dnl changecom() - BSD m4 changecom doesn't quite work like the man page
142 dnl suggests, in particular "changecom" or "changecom()" doesn't
143 dnl disable the comment feature, and multi-character comment sequences
144 dnl don't seem to work. If the default `#' and newline aren't
145 dnl suitable it's necessary to change it to something else,
146 dnl eg. changecom(;).
148 dnl OpenBSD 2.6 m4 - in this m4, eval() rejects decimal constants containing
149 dnl an 8 or 9, making it pretty much unusable. The bug is confined to
150 dnl version 2.6 (it's not in 2.5, and was fixed in 2.7).
152 dnl SunOS /usr/bin/m4 - this m4 lacks a number of desired features,
153 dnl including $# and $@, defn(), m4exit(), m4wrap(), pushdef(),
154 dnl popdef(). /usr/5bin/m4 is a SysV style m4 which should always be
155 dnl available, and "configure" will reject /usr/bin/m4 in favour of
156 dnl /usr/5bin/m4 (if necessary).
158 dnl The sparc code actually has modest m4 requirements currently and
159 dnl could manage with /usr/bin/m4, but there's no reason to put our
160 dnl macros through contortions when /usr/5bin/m4 is available or GNU
161 dnl m4 can be installed.
164 ifdef(`__ASM_DEFS_M4_INCLUDED__',
165 `m4_error(`asm-defs.m4 already included, dont include it twice
167 define(`__ASM_DEFS_M4_INCLUDED__')
170 dnl Detect and give a message about the unsuitable OpenBSD 2.6 m4.
174 `This m4 doesnt accept 8 and/or 9 in constants in eval(), making it unusable.
175 This is probably OpenBSD 2.6 m4 (September 1999). Upgrade to OpenBSD 2.7,
176 or get a bug fix from the CVS (expr.c rev 1.9), or get GNU m4. Dont forget
177 to configure with M4=/wherever/m4 if you install one of these in a directory
182 dnl Detect and give a message about the unsuitable SunOS /usr/bin/m4.
184 dnl Unfortunately this test doesn't work when m4 is run in the normal way
185 dnl from mpn/Makefile with "m4 -DOPERATION_foo foo.asm", since the bad m4
186 dnl takes "-" in "-D..." to mean read stdin, so it will look like it just
187 dnl hangs. But running "m4 asm-defs.m4" to try it out will work.
189 dnl We'd like to abort immediately on finding a problem, but unfortunately
190 dnl the bad m4 doesn't have an m4exit(), nor does an invalid eval() kill
191 dnl it. Unexpanded $#'s in some m4_assert_numargs() later on will comment
192 dnl out some closing parentheses and kill it with "m4: arg stack overflow".
194 define(m4_dollarhash_works_test,``$#'')
195 ifelse(m4_dollarhash_works_test(x),1,,
197 `This m4 doesnt support $# and cant be used for GMP asm processing.
198 If this is on SunOS, ./configure should choose /usr/5bin/m4 if you have that
199 or can get it, otherwise install GNU m4. Dont forget to configure with
200 M4=/wherever/m4 if you install in a directory not in $PATH.
202 undefine(`m4_dollarhash_works_test')
205 dnl --------------------------------------------------------------------------
206 dnl Basic error handling things.
209 dnl Usage: m4_dollarhash_1_if_noparen_p
211 dnl Expand to 1 if a call "foo" gives $# set to 1 (as opposed to 0 like GNU
212 dnl and SysV m4 give).
214 define(m4_dollarhash_1_if_noparen_test,`$#')
215 define(m4_dollarhash_1_if_noparen_p,
216 eval(m4_dollarhash_1_if_noparen_test==1))
217 undefine(`m4_dollarhash_1_if_noparen_test')
220 dnl Usage: m4wrap_prepend(string)
222 dnl Prepend the given string to what will be expanded under m4wrap at the
225 dnl This macro exists to work around variations in m4wrap() behaviour in
226 dnl the various m4s (notes at the start of this file). Don't use m4wrap()
227 dnl directly since it will interfere with this scheme.
229 define(m4wrap_prepend,
231 `define(`m4wrap_string',`$1'defn(`m4wrap_string'))')
233 define(m4wrap_string,`')
235 define(m4wrap_works_p,
236 `ifelse(M4WRAP_SPURIOUS,yes,0,1)')
238 ifelse(m4wrap_works_p,1,
239 `m4wrap(`m4wrap_string')')
242 dnl Usage: m4_file_and_line
244 dnl Expand to the current file and line number, if the GNU m4 extensions
245 dnl __file__ and __line__ are available.
247 dnl In GNU m4 1.4 at the end of input when m4wrap text is expanded,
248 dnl __file__ is NONE and __line__ is 0, which is not a helpful thing to
249 dnl print. If m4_file_seen() has been called to note the last file seen,
250 dnl then that file at a big line number is used, otherwise "end of input"
251 dnl is used (although "end of input" won't parse as an error message).
253 define(m4_file_and_line,
255 `ifelse(__file__`'__line__,`NONE0',
256 `ifdef(`m4_file_seen_last',`m4_file_seen_last: 999999: ',`end of input: ')',
257 `__file__: __line__: ')')')
260 dnl Usage: m4_errprint_commas(arg,...)
262 dnl The same as errprint(), but commas are printed between arguments
263 dnl instead of spaces.
265 define(m4_errprint_commas,
267 ifelse(eval($#>1),1,`errprint(`,')m4_errprint_commas(shift($@))')')
270 dnl Usage: m4_error(args...)
271 dnl m4_warning(args...)
273 dnl Print an error message, using m4_errprint_commas, prefixed with the
274 dnl current filename and line number (if available). m4_error sets up to
275 dnl give an error exit at the end of processing, m4_warning just prints.
276 dnl These macros are the recommended way to print errors.
278 dnl The arguments here should be quoted in the usual way to prevent them
279 dnl being expanded when the macro call is read. (m4_error takes care not
280 dnl to do any further expansion.)
284 dnl m4_error(`some error message
289 dnl foo.asm:123: some error message
291 dnl or if __file__ and __line__ aren't available
293 dnl some error message
295 dnl The "file:line:" format is a basic style, used by gcc and GNU m4, so
296 dnl emacs and other editors will recognise it in their normal error message
300 `m4_errprint_commas(m4_file_and_line`'$@)')
303 `define(`m4_error_occurred',1)m4_warning($@)dnl
304 ifelse(m4wrap_works_p,0,`m4exit(1)')')
306 define(`m4_error_occurred',0)
308 dnl This m4wrap_prepend() is first, so it'll be executed last.
310 `ifelse(m4_error_occurred,1,
311 `m4_error(`Errors occurred during m4 processing
315 dnl Usage: m4_assert_numargs(num)
317 dnl Put this unquoted on a line on its own at the start of a macro
318 dnl definition to add some code to check that num many arguments get passed
319 dnl to the macro. For example,
322 dnl m4_assert_numargs(2)
323 dnl `something `$1' and `$2' blah blah')
325 dnl Then a call like foo(one,two,three) will provoke an error like
327 dnl file:10: foo expected 2 arguments, got 3 arguments
329 dnl Here are some calls and how many arguments they're interpreted as passing.
336 dnl The -1 for no parentheses at all means a macro that's meant to be used
337 dnl that way can be checked with m4_assert_numargs(-1). For example,
339 dnl define(SPECIAL_SUFFIX,
340 dnl m4_assert_numargs(-1)
341 dnl `ifdef(`FOO',`_foo',`_bar')')
343 dnl But as an alternative see also deflit() below where parenthesized
344 dnl expressions following a macro are passed through to the output.
346 dnl Note that in BSD m4 there's no way to differentiate calls "foo" and
347 dnl "foo()", so in BSD m4 the distinction between the two isn't enforced.
348 dnl (In GNU and SysV m4 it can be checked, and is.)
351 dnl m4_assert_numargs is able to check its own arguments by calling
352 dnl assert_numargs_internal directly.
354 dnl m4_doublequote($`'0) expands to ``$0'', whereas ``$`'0'' would expand
355 dnl to `$`'0' and do the wrong thing, and likewise for $1. The same is
356 dnl done in other assert macros.
358 dnl $`#' leaves $# in the new macro being defined, and stops # being
359 dnl interpreted as a comment character.
361 dnl `dnl ' means an explicit dnl isn't necessary when m4_assert_numargs is
362 dnl used. The space means that if there is a dnl it'll still work.
364 dnl Usage: m4_doublequote(x) expands to ``x''
365 define(m4_doublequote,
366 `m4_assert_numargs_internal(`$0',1,$#,len(`$1'))``$1''')
368 define(m4_assert_numargs,
369 `m4_assert_numargs_internal(`$0',1,$#,len(`$1'))dnl
370 `m4_assert_numargs_internal'(m4_doublequote($`'0),$1,$`#',`len'(m4_doublequote($`'1)))`dnl '')
372 dnl Called: m4_assert_numargs_internal(`macroname',wantargs,$#,len(`$1'))
373 define(m4_assert_numargs_internal,
374 `m4_assert_numargs_internal_check(`$1',`$2',m4_numargs_count(`$3',`$4'))')
376 dnl Called: m4_assert_numargs_internal_check(`macroname',wantargs,gotargs)
378 dnl If m4_dollarhash_1_if_noparen_p (BSD m4) then gotargs can be 0 when it
379 dnl should be -1. If wantargs is -1 but gotargs is 0 and the two can't be
380 dnl distinguished then it's allowed to pass.
382 define(m4_assert_numargs_internal_check,
383 `ifelse(eval($2 == $3
384 || ($2==-1 && $3==0 && m4_dollarhash_1_if_noparen_p)),0,
385 `m4_error(`$1 expected 'm4_Narguments(`$2')`, got 'm4_Narguments(`$3')
388 dnl Called: m4_numargs_count($#,len(`$1'))
389 dnl If $#==0 then -1 args, if $#==1 but len(`$1')==0 then 0 args, otherwise
391 define(m4_numargs_count,
393 `ifelse(eval($1==1 && $2-0==0),1, 0, $1)')')
395 dnl Usage: m4_Narguments(N)
396 dnl "$1 argument" or "$1 arguments" with the plural according to $1.
397 define(m4_Narguments,
398 `$1 argument`'ifelse(`$1',1,,s)')
401 dnl --------------------------------------------------------------------------
402 dnl Additional error checking things.
405 dnl Usage: m4_file_seen()
407 dnl Record __file__ for the benefit of m4_file_and_line in m4wrap text.
409 dnl The basic __file__ macro comes out quoted in GNU m4, like `foo.asm',
410 dnl and m4_file_seen_last is defined like that too.
412 dnl This is used by PROLOGUE, since that's normally in the main .asm file,
413 dnl and in particular it sets up m4wrap error checks for missing EPILOGUE.
417 `ifelse(__file__,`NONE',,
418 `define(`m4_file_seen_last',m4_doublequote(__file__))')')
421 dnl Usage: m4_assert_onearg()
423 dnl Put this, unquoted, at the start of a macro definition to add some code
424 dnl to check that one argument is passed to the macro, but with that
425 dnl argument allowed to be empty. For example,
428 dnl m4_assert_onearg()
429 dnl `blah blah $1 blah blah')
431 dnl Calls "foo(xyz)" or "foo()" are accepted. A call "foo(xyz,abc)" fails.
432 dnl A call "foo" fails too, but BSD m4 can't detect this case (GNU and SysV
435 define(m4_assert_onearg,
437 `m4_assert_onearg_internal'(m4_doublequote($`'0),$`#')`dnl ')
439 dnl Called: m4_assert_onearg(`macroname',$#)
440 define(m4_assert_onearg_internal,
442 `m4_error(`$1 expected 1 argument, got 'm4_Narguments(`$2')
446 dnl Usage: m4_assert_numargs_range(low,high)
448 dnl Put this, unquoted, at the start of a macro definition to add some code
449 dnl to check that between low and high many arguments get passed to the
450 dnl macro. For example,
453 dnl m4_assert_numargs_range(3,5)
454 dnl `mandatory $1 $2 $3 optional $4 $5 end')
456 dnl See m4_assert_numargs() for more info.
458 define(m4_assert_numargs_range,
460 ``m4_assert_numargs_range_internal'(m4_doublequote($`'0),$1,$2,$`#',`len'(m4_doublequote($`'1)))`dnl '')
462 dnl Called: m4_assert_numargs_range_internal(`name',low,high,$#,len(`$1'))
463 define(m4_assert_numargs_range_internal,
465 `m4_assert_numargs_range_check(`$1',`$2',`$3',m4_numargs_count(`$4',`$5'))')
467 dnl Called: m4_assert_numargs_range_check(`name',low,high,gotargs)
469 dnl If m4_dollarhash_1_if_noparen_p (BSD m4) then gotargs can be 0 when it
470 dnl should be -1. To ensure a `high' of -1 works, a fudge is applied to
471 dnl gotargs if it's 0 and the 0 and -1 cases can't be distinguished.
473 define(m4_assert_numargs_range_check,
475 `ifelse(eval($2 <= $4 &&
476 ($4 - ($4==0 && m4_dollarhash_1_if_noparen_p) <= $3)),0,
477 `m4_error(`$1 expected $2 to $3 arguments, got 'm4_Narguments(`$4')
481 dnl Usage: m4_assert_defined(symbol)
483 dnl Put this unquoted on a line of its own at the start of a macro
484 dnl definition to add some code to check that the given symbol is defined
485 dnl when the macro is used. For example,
488 dnl m4_assert_defined(`FOO_PREFIX')
489 dnl `FOO_PREFIX whatever')
491 dnl This is a convenient way to check that the user or ./configure or
492 dnl whatever has defined the things needed by a macro, as opposed to
493 dnl silently generating garbage.
495 define(m4_assert_defined,
497 ``m4_assert_defined_internal'(m4_doublequote($`'0),``$1'')`dnl '')
499 dnl Called: m4_assert_defined_internal(`macroname',`define_required')
500 define(m4_assert_defined_internal,
503 `m4_error(`$1 needs $2 defined
507 dnl Usage: m4_not_for_expansion(`SYMBOL')
508 dnl define_not_for_expansion(`SYMBOL')
510 dnl m4_not_for_expansion turns SYMBOL, if defined, into something which
511 dnl will give an error if expanded. For example,
513 dnl m4_not_for_expansion(`PIC')
515 dnl define_not_for_expansion is the same, but always makes a definition.
517 dnl These are for symbols that should be tested with ifdef(`FOO',...)
518 dnl rather than be expanded as such. They guard against accidentally
519 dnl omitting the quotes, as in ifdef(FOO,...). Note though that they only
520 dnl catches this when FOO is defined, so be sure to test code both with and
521 dnl without each definition.
523 define(m4_not_for_expansion,
525 `ifdef(`$1',`define_not_for_expansion(`$1')')')
527 define(define_not_for_expansion,
529 `ifelse(defn(`$1'),,,
530 `m4_error(``$1' has a non-empty value, maybe it shouldnt be munged with m4_not_for_expansion()
532 define(`$1',`m4_not_for_expansion_internal(`$1')')')
534 define(m4_not_for_expansion_internal,
535 `m4_error(``$1' is not meant to be expanded, perhaps you mean `ifdef(`$1',...)'
539 dnl --------------------------------------------------------------------------
540 dnl Various generic m4 things.
543 dnl Usage: m4_unquote(macro)
545 dnl Allow the argument text to be re-evaluated. This is useful for "token
546 dnl pasting" like m4_unquote(foo`'bar).
553 dnl Usage: m4_ifdef(name,yes[,no])
555 dnl Expand to the yes argument if name is defined, or to the no argument if
558 dnl This is the same as the builtin "ifdef", but avoids an OSF 4.0 m4 bug
559 dnl in which a macro with a zero value `0' or `00' etc is considered not
562 dnl There's no particular need to use this everywhere, only if there might
566 m4_assert_numargs_range(2,3)
567 `ifelse(eval(ifdef(`$1',1,0)+m4_length(defn(`$1'))),0,
571 dnl Usage: m4_ifdef_anyof_p(`symbol',...)
573 dnl Expand to 1 if any of the symbols in the argument list are defined, or
576 define(m4_ifdef_anyof_p,
577 `ifelse(eval($#<=1 && m4_length(`$1')==0),1, 0,
579 `m4_ifdef_anyof_p(shift($@))')')')
582 dnl Usage: m4_length(string)
584 dnl Determine the length of a string. This is the same as len(), but
585 dnl always expands to a number, working around the BSD len() which
586 dnl evaluates to nothing given an empty argument.
593 dnl Usage: m4_stringequal_p(x,y)
595 dnl Expand to 1 or 0 according as strings x and y are equal or not.
597 define(m4_stringequal_p,
598 `ifelse(`$1',`$2',1,0)')
601 dnl Usage: m4_incr_or_decr(n,last)
603 dnl Do an incr(n) or decr(n), whichever is in the direction of "last".
604 dnl Both n and last must be numbers of course.
606 define(m4_incr_or_decr,
608 `ifelse(eval($1<$2),1,incr($1),decr($1))')
611 dnl Usage: forloop(i, first, last, statement)
613 dnl Based on GNU m4 examples/forloop.m4, but extended.
615 dnl statement is expanded repeatedly, with i successively defined as
617 dnl first, first+1, ..., last-1, last
619 dnl Or if first > last, then it's
621 dnl first, first-1, ..., last+1, last
623 dnl If first == last, then one expansion is done.
625 dnl A pushdef/popdef of i is done to preserve any previous definition (or
626 dnl lack of definition). first and last are eval()ed and so can be
629 dnl forloop_first is defined to 1 on the first iteration, 0 on the rest.
630 dnl forloop_last is defined to 1 on the last iteration, 0 on the others.
631 dnl Nested forloops are allowed, in which case forloop_first and
632 dnl forloop_last apply to the innermost loop that's open.
634 dnl A simple example,
636 dnl forloop(i, 1, 2*2+1, `dnl
637 dnl iteration number i ... ifelse(forloop_first,1,FIRST)
641 dnl "i" and "statement" are carefully quoted, but "first" and "last" are
642 dnl just plain numbers once eval()ed.
646 `pushdef(`$1',eval(`$2'))dnl
647 pushdef(`forloop_first',1)dnl
648 pushdef(`forloop_last',0)dnl
649 forloop_internal(`$1',eval(`$3'),`$4')`'dnl
650 popdef(`forloop_first')dnl
651 popdef(`forloop_last')dnl
654 dnl Called: forloop_internal(`var',last,statement)
655 define(`forloop_internal',
658 `define(`forloop_last',1)$3',
660 define(`forloop_first',0)dnl
661 define(`$1',m4_incr_or_decr($1,$2))dnl
662 forloop_internal(`$1',$2,`$3')')')
665 dnl Usage: foreach(var,body, item1,item2,...,itemN)
667 dnl For each "item" argument, define "var" to that value and expand "body".
670 dnl foreach(i, `something i
676 dnl Any previous definition of "var", or lack thereof, is saved and
677 dnl restored. Empty "item"s are not allowed.
680 m4_assert_numargs_range(2,1000)
682 `pushdef(`$1',`$3')$2`'popdef(`$1')dnl
683 foreach(`$1',`$2',shift(shift(shift($@))))')')
686 dnl Usage: m4_toupper(x)
689 dnl Convert the argument string to upper or lower case, respectively.
690 dnl Only one argument accepted.
692 dnl BSD m4 doesn't take ranges like a-z in translit(), so the full alphabet
695 define(m4_alphabet_lower, `abcdefghijklmnopqrstuvwxyz')
696 define(m4_alphabet_upper, `ABCDEFGHIJKLMNOPQRSTUVWXYZ')
700 `translit(`$1', m4_alphabet_lower, m4_alphabet_upper)')
704 `translit(`$1', m4_alphabet_upper, m4_alphabet_lower)')
707 dnl Usage: m4_empty_if_zero(x)
709 dnl Evaluate to x, or to nothing if x is 0. x is eval()ed and so can be an
712 dnl This is useful for x86 addressing mode displacements since forms like
713 dnl (%ebx) are one byte shorter than 0(%ebx). A macro `foo' for use as
714 dnl foo(%ebx) could be defined with the following so it'll be empty if the
715 dnl expression comes out zero.
717 dnl deflit(`foo', `m4_empty_if_zero(a+b*4-c)')
719 dnl Naturally this shouldn't be done if, say, a computed jump depends on
720 dnl the code being a particular size.
722 define(m4_empty_if_zero,
724 `ifelse(eval($1),0,,eval($1))')
727 dnl Usage: m4_log2(x)
729 dnl Calculate a logarithm to base 2.
730 dnl x must be an integral power of 2, between 2**0 and 2**30.
731 dnl x is eval()ed, so it can be an expression.
732 dnl An error results if x is invalid.
734 dnl 2**31 isn't supported, because an unsigned 2147483648 is out of range
735 dnl of a 32-bit signed int. Also, the bug in BSD m4 where an eval()
736 dnl resulting in 2147483648 (or -2147483648 as the case may be) gives `-('
737 dnl means tests like eval(1<<31==(x)) would be necessary, but that then
738 dnl gives an unattractive explosion of eval() error messages if x isn't
743 `m4_log2_internal(0,1,eval(`$1'))')
745 dnl Called: m4_log2_internal(n,2**n,target)
746 define(m4_log2_internal,
750 `m4_error(`m4_log2() argument too big or not a power of two: $3
752 `m4_log2_internal(incr($1),eval(2*$2),$3)')')')
755 dnl Usage: m4_div2_towards_zero
757 dnl m4 division is probably whatever a C signed division is, and C doesn't
758 dnl specify what rounding gets used on negatives, so this expression forces
759 dnl a rounding towards zero.
761 define(m4_div2_towards_zero,
763 `eval((($1) + ((($1)<0) & ($1))) / 2)')
766 dnl Usage: m4_lshift(n,count)
767 dnl m4_rshift(n,count)
769 dnl Calculate n shifted left or right by count many bits. Both n and count
770 dnl are eval()ed and so can be expressions.
772 dnl Negative counts are allowed and mean a shift in the opposite direction.
773 dnl Negative n is allowed and right shifts will be arithmetic (meaning
774 dnl divide by 2**count, rounding towards zero, also meaning the sign bit is
777 dnl Use these macros instead of << and >> in eval() since the basic ccs
778 dnl SysV m4 doesn't have those operators.
782 `m4_lshift(`$1',-(`$2'))')
786 `m4_lshift_internal(eval(`$1'),eval(`$2'))')
788 define(m4_lshift_internal,
790 `ifelse(eval($2-0==0),1,$1,
791 `ifelse(eval($2>0),1,
792 `m4_lshift_internal(eval($1*2),decr($2))',
793 `m4_lshift_internal(m4_div2_towards_zero($1),incr($2))')')')
796 dnl Usage: m4_popcount(n)
798 dnl Expand to the number 1 bits in n.
802 `m4_popcount_internal(0,eval(`$1'))')
804 dnl Called: m4_popcount_internal(count,rem)
805 define(m4_popcount_internal,
808 `m4_popcount_internal(eval($1+($2%2)),eval($2/2))')')
811 dnl Usage: m4_count_trailing_zeros(N)
813 dnl Determine the number of trailing zero bits on N. N is eval()ed and so
814 dnl can be an expression. If N is zero an error is generated.
816 define(m4_count_trailing_zeros,
818 `m4_count_trailing_zeros_internal(eval(`$1'),0)')
820 dnl Called: m4_count_trailing_zeros_internal(val,count)
821 define(m4_count_trailing_zeros_internal,
824 `m4_error(`m4_count_trailing_zeros() given a zero value')',
825 `ifelse(eval(($1)%2),1,`$2',
826 `m4_count_trailing_zeros_internal(eval($1/2),incr($2))')')')
829 dnl Usage: deflit(name,value)
831 dnl Like define(), but "name" expands like a literal, rather than taking
832 dnl arguments. For example "name(%eax)" expands to "value(%eax)".
836 dnl $ characters in the value part must have quotes to stop them looking
837 dnl like macro parameters. For example, deflit(reg,`123+$`'4+567'). See
838 dnl defreg() below for handling simple register definitions like $7 etc.
840 dnl "name()" is turned into "name", unfortunately. In GNU and SysV m4 an
841 dnl error is generated when this happens, but in BSD m4 it will happen
842 dnl silently. The problem is that in BSD m4 $# is 1 in both "name" or
843 dnl "name()", so there's no way to differentiate them. Because we want
844 dnl plain "name" to turn into plain "value", we end up with "name()"
845 dnl turning into plain "value" too.
847 dnl "name(foo)" will lose any whitespace after commas in "foo", for example
848 dnl "disp(%eax, %ecx)" would become "128(%eax,%ecx)".
850 dnl These parentheses oddities shouldn't matter in assembler text, but if
851 dnl they do the suggested workaround is to write "name ()" or "name (foo)"
852 dnl to stop the parentheses looking like a macro argument list. If a space
853 dnl isn't acceptable in the output, then write "name`'()" or "name`'(foo)".
854 dnl The `' is stripped when read, but again stops the parentheses looking
857 dnl Quoting for deflit_emptyargcheck is similar to m4_assert_numargs. The
858 dnl stuff in the ifelse gives a $#, $1 and $@ evaluated in the new macro
859 dnl created, not in deflit.
863 `deflit_emptyargcheck'(``$1'',$`#',m4_doublequote($`'1))`dnl
865 ifelse(eval($'`#>1 || m4_length('m4_doublequote($`'1)`)!=0),1,($'`@))')')
867 dnl Called: deflit_emptyargcheck(macroname,$#,`$1')
868 define(deflit_emptyargcheck,
869 `ifelse(eval($2==1 && !m4_dollarhash_1_if_noparen_p && m4_length(`$3')==0),1,
870 `m4_error(`dont use a deflit as $1() because it loses the brackets (see deflit in asm-incl.m4 for more information)
874 dnl Usage: m4_assert(`expr')
876 dnl Test a compile-time requirement with an m4 expression. The expression
877 dnl should be quoted, and will be eval()ed and expected to be non-zero.
880 dnl m4_assert(`FOO*2+6 < 14')
885 `m4_error(`assertion failed: $1
889 dnl Usage: m4_repeat(count,text)
891 dnl Expand to the given repetitions of the given text. A zero count is
892 dnl allowed, and expands to nothing.
896 `m4_repeat_internal(eval($1),`$2')')
898 define(m4_repeat_internal,
901 `forloop(m4_repeat_internal_counter,1,$1,``$2'')')')
904 dnl Usage: m4_hex_lowmask(bits)
906 dnl Generate a hex constant which is a low mask of the given number of
907 dnl bits. For example m4_hex_lowmask(10) would give 0x3ff.
909 define(m4_hex_lowmask,
911 `m4_cpu_hex_constant(m4_hex_lowmask_internal1(eval(`$1')))')
913 dnl Called: m4_hex_lowmask_internal1(bits)
914 define(m4_hex_lowmask_internal1,
917 `m4_hex_lowmask_internal2(eval(($1)%4),eval(($1)/4))')')
919 dnl Called: m4_hex_lowmask_internal(remainder,digits)
920 define(m4_hex_lowmask_internal2,
924 `ifelse($1,3,`7')')')dnl
928 dnl --------------------------------------------------------------------------
929 dnl The following m4_list functions take a list as multiple arguments.
930 dnl Arguments are evaluated multiple times, there's no attempt at strict
931 dnl quoting. Empty list elements are not allowed, since an empty final
932 dnl argument is ignored. These restrictions don't affect the current uses,
933 dnl and make the implementation easier.
936 dnl Usage: m4_list_quote(list,...)
938 dnl Produce a list with quoted commas, so it can be a single argument
939 dnl string. For instance m4_list_quote(a,b,c) gives
943 dnl This can be used to put a list in a define,
945 dnl define(foolist, m4_list_quote(a,b,c))
947 dnl Which can then be used for instance as
949 dnl m4_list_find(target, foolist)
951 define(m4_list_quote,
953 `$1`,'m4_list_quote(shift($@))')')
956 dnl Usage: m4_list_find(key,list,...)
958 dnl Evaluate to 1 or 0 according to whether key is in the list elements.
961 m4_assert_numargs_range(1,1000)
964 `m4_list_find(`$1',shift(shift($@)))')')')
967 dnl Usage: m4_list_remove(key,list,...)
969 dnl Evaluate to the given list with `key' removed (if present).
971 define(m4_list_remove,
972 m4_assert_numargs_range(1,1000)
974 `ifelse(`$1',`$2',,`$2,')dnl
975 m4_list_remove(`$1',shift(shift($@)))')')
978 dnl Usage: m4_list_first(list,...)
980 dnl Evaluate to the first element of the list (if any).
982 define(m4_list_first,`$1')
985 dnl Usage: m4_list_count(list,...)
987 dnl Evaluate to the number of elements in the list. This can't just use $#
988 dnl because the last element might be empty.
990 define(m4_list_count,
991 `m4_list_count_internal(0,$@)')
993 dnl Called: m4_list_internal(count,list,...)
994 define(m4_list_count_internal,
995 m4_assert_numargs_range(1,1000)
997 `m4_list_count_internal(eval($1+1),shift(shift($@)))')')
1000 dnl --------------------------------------------------------------------------
1001 dnl Various assembler things, not specific to any particular CPU.
1005 dnl Usage: include_mpn(`filename')
1007 dnl Like include(), but adds a path to the mpn source directory. For
1010 dnl include_mpn(`sparc64/addmul_1h.asm')
1013 m4_assert_numargs(1)
1014 m4_assert_defined(`CONFIG_TOP_SRCDIR')
1015 `include(CONFIG_TOP_SRCDIR`/mpn/$1')')
1018 dnl Usage: C comment ...
1020 dnl This works like a FORTRAN-style comment character. It can be used for
1021 dnl comments to the right of assembly instructions, where just dnl would
1022 dnl remove the newline and concatenate adjacent lines.
1024 dnl C and/or dnl are useful when an assembler doesn't support comments, or
1025 dnl where different assemblers for a particular CPU need different styles.
1026 dnl The intermediate ".s" files will end up with no comments, just code.
1028 dnl Using C is not intended to cause offence to anyone who doesn't like
1029 dnl FORTRAN; but if that happens it's an unexpected bonus.
1031 dnl During development, if comments are wanted in the .s files to help see
1032 dnl what's expanding where, C can be redefined with something like
1040 dnl Normally PIC is defined (or not) by libtool, but it doesn't set it on
1041 dnl systems which are always PIC. PIC_ALWAYS established in config.m4
1042 dnl identifies these for us.
1044 ifelse(`PIC_ALWAYS',`yes',`define(`PIC')')
1047 dnl Various possible defines passed from the Makefile that are to be tested
1048 dnl with ifdef() rather than be expanded.
1050 m4_not_for_expansion(`PIC')
1051 m4_not_for_expansion(`DLL_EXPORT')
1054 m4_not_for_expansion(`OPERATION_add_n')
1055 m4_not_for_expansion(`OPERATION_sub_n')
1058 m4_not_for_expansion(`OPERATION_addmul_1')
1059 m4_not_for_expansion(`OPERATION_submul_1')
1062 m4_not_for_expansion(`OPERATION_and_n')
1063 m4_not_for_expansion(`OPERATION_andn_n')
1064 m4_not_for_expansion(`OPERATION_nand_n')
1065 m4_not_for_expansion(`OPERATION_ior_n')
1066 m4_not_for_expansion(`OPERATION_iorn_n')
1067 m4_not_for_expansion(`OPERATION_nior_n')
1068 m4_not_for_expansion(`OPERATION_xor_n')
1069 m4_not_for_expansion(`OPERATION_xnor_n')
1072 m4_not_for_expansion(`OPERATION_popcount')
1073 m4_not_for_expansion(`OPERATION_hamdist')
1076 m4_not_for_expansion(`OPERATION_lshift')
1077 m4_not_for_expansion(`OPERATION_rshift')
1080 m4_not_for_expansion(`OPERATION_addlsh1_n')
1081 m4_not_for_expansion(`OPERATION_sublsh1_n')
1082 m4_not_for_expansion(`OPERATION_rsblsh1_n')
1085 m4_not_for_expansion(`OPERATION_addlsh2_n')
1086 m4_not_for_expansion(`OPERATION_sublsh2_n')
1087 m4_not_for_expansion(`OPERATION_rsblsh2_n')
1090 m4_not_for_expansion(`OPERATION_rsh1add_n')
1091 m4_not_for_expansion(`OPERATION_rsh1sub_n')
1094 dnl Usage: m4_config_gmp_mparam(`symbol')
1096 dnl Check that `symbol' is defined. If it isn't, issue an error and
1097 dnl terminate immediately. The error message explains that the symbol
1098 dnl should be in config.m4, copied from gmp-mparam.h.
1100 dnl Termination is immediate since missing say SQR_TOOM2_THRESHOLD can
1101 dnl lead to infinite loops and endless error messages.
1103 define(m4_config_gmp_mparam,
1104 m4_assert_numargs(1)
1106 `m4_error(`$1 is not defined.
1107 "configure" should have extracted this from gmp-mparam.h and put it
1108 in config.m4 (or in <cpu>_<file>.asm for a fat binary), but somehow
1113 dnl Usage: defreg(name,reg)
1115 dnl Give a name to a $ style register. For example,
1119 dnl defreg() inserts an extra pair of quotes after the $ so that it's not
1120 dnl interpreted as an m4 macro parameter, ie. foo is actually $`'12. m4
1121 dnl strips those quotes when foo is expanded.
1123 dnl deflit() is used to make the new definition, so it will expand
1124 dnl literally even if followed by parentheses ie. foo(99) will become
1125 dnl $12(99). (But there's nowhere that would be used is there?)
1127 dnl When making further definitions from existing defreg() macros, remember
1128 dnl to use defreg() again to protect the $ in the new definitions too. For
1135 dnl defreg(PARAM_DST,a0)
1137 dnl This is only because a0 is expanding at the time the PARAM_DST
1138 dnl definition is made, leaving a literal $4 that must be re-quoted. On
1139 dnl the other hand in something like the following ra is only expanded when
1140 dnl ret is used and its $`'31 protection will have its desired effect at
1145 dnl define(ret,`j ra')
1147 dnl Note that only $n forms are meant to be used here, and something like
1148 dnl 128($30) doesn't get protected and will come out wrong.
1151 m4_assert_numargs(2)
1153 substr(`$2',0,1)``''substr(`$2',1))')
1156 dnl Usage: m4_instruction_wrapper()
1158 dnl Put this, unquoted, on a line on its own, at the start of a macro
1159 dnl that's a wrapper around an assembler instruction. It adds code to give
1160 dnl a descriptive error message if the macro is invoked without arguments.
1162 dnl For example, suppose jmp needs to be wrapped,
1165 dnl m4_instruction_wrapper()
1166 dnl m4_assert_numargs(1)
1171 dnl The point of m4_instruction_wrapper is to get a better error message
1172 dnl than m4_assert_numargs would give if jmp is accidentally used as plain
1173 dnl "jmp foo" instead of the intended "jmp( foo)". "jmp()" with no
1174 dnl argument also provokes the error message.
1176 dnl m4_instruction_wrapper should only be used with wrapped instructions
1177 dnl that take arguments, since obviously something meant to be used as say
1178 dnl plain "ret" doesn't want to give an error when used that way.
1180 define(m4_instruction_wrapper,
1181 m4_assert_numargs(0)
1182 ``m4_instruction_wrapper_internal'(m4_doublequote($`'0),dnl
1183 ifdef(`__file__',`m4_doublequote(__file__)',``the m4 sources''),dnl
1184 $`#',m4_doublequote($`'1))`dnl'')
1186 dnl Called: m4_instruction_wrapper_internal($0,`filename',$#,$1)
1187 define(m4_instruction_wrapper_internal,
1188 `ifelse(eval($3<=1 && m4_length(`$4')==0),1,
1189 `m4_error(`$1 is a macro replacing that instruction and needs arguments, see $2 for details
1193 dnl Usage: m4_cpu_hex_constant(string)
1195 dnl Expand to the string prefixed by a suitable `0x' hex marker. This
1196 dnl should be redefined as necessary for CPUs with different conventions.
1198 define(m4_cpu_hex_constant,
1199 m4_assert_numargs(1)
1203 dnl Usage: UNROLL_LOG2, UNROLL_MASK, UNROLL_BYTES
1204 dnl CHUNK_LOG2, CHUNK_MASK, CHUNK_BYTES
1206 dnl When code supports a variable amount of loop unrolling, the convention
1207 dnl is to define UNROLL_COUNT to the number of limbs processed per loop.
1208 dnl When testing code this can be varied to see how much the loop overhead
1209 dnl is costing. For example,
1211 dnl deflit(UNROLL_COUNT, 32)
1213 dnl If the forloop() generating the unrolled loop has a pattern processing
1214 dnl more than one limb, the convention is to express this with CHUNK_COUNT.
1217 dnl deflit(CHUNK_COUNT, 2)
1219 dnl The LOG2, MASK and BYTES definitions below are derived from these COUNT
1220 dnl definitions. If COUNT is redefined, the LOG2, MASK and BYTES follow
1221 dnl the new definition automatically.
1223 dnl LOG2 is the log base 2 of COUNT. MASK is COUNT-1, which can be used as
1224 dnl a bit mask. BYTES is BYTES_PER_MP_LIMB*COUNT, the number of bytes
1225 dnl processed in each unrolled loop.
1227 dnl BYTES_PER_MP_LIMB is defined in a CPU specific m4 include file. It
1228 dnl exists only so the BYTES definitions here can be common to all CPUs.
1229 dnl In the actual code for a given CPU, an explicit 4 or 8 may as well be
1230 dnl used because the code is only for a particular CPU, it doesn't need to
1233 dnl Note that none of these macros do anything except give conventional
1234 dnl names to commonly used things. You still have to write your own
1235 dnl expressions for a forloop() and the resulting address displacements.
1236 dnl Something like the following would be typical for 4 bytes per limb.
1238 dnl forloop(`i',0,UNROLL_COUNT-1,`
1239 dnl deflit(`disp',eval(i*4))
1243 dnl Or when using CHUNK_COUNT,
1245 dnl forloop(`i',0,UNROLL_COUNT/CHUNK_COUNT-1,`
1246 dnl deflit(`disp0',eval(i*CHUNK_COUNT*4))
1247 dnl deflit(`disp1',eval(disp0+4))
1251 dnl Clearly `i' can be run starting from 1, or from high to low or whatever
1255 m4_assert_defined(`UNROLL_COUNT')
1256 `m4_log2(UNROLL_COUNT)')
1259 m4_assert_defined(`UNROLL_COUNT')
1260 `eval(UNROLL_COUNT-1)')
1262 deflit(UNROLL_BYTES,
1263 m4_assert_defined(`UNROLL_COUNT')
1264 m4_assert_defined(`BYTES_PER_MP_LIMB')
1265 `eval(UNROLL_COUNT * BYTES_PER_MP_LIMB)')
1268 m4_assert_defined(`CHUNK_COUNT')
1269 `m4_log2(CHUNK_COUNT)')
1272 m4_assert_defined(`CHUNK_COUNT')
1273 `eval(CHUNK_COUNT-1)')
1276 m4_assert_defined(`CHUNK_COUNT')
1277 m4_assert_defined(`BYTES_PER_MP_LIMB')
1278 `eval(CHUNK_COUNT * BYTES_PER_MP_LIMB)')
1281 dnl Usage: MPN(name)
1283 dnl Add MPN_PREFIX to a name.
1284 dnl MPN_PREFIX defaults to "__gmpn_" if not defined.
1286 dnl m4_unquote is used in MPN so that when it expands to say __gmpn_foo,
1287 dnl that identifier will be subject to further macro expansion. This is
1288 dnl used by some of the fat binary support for renaming symbols.
1290 ifdef(`MPN_PREFIX',,
1291 `define(`MPN_PREFIX',`__gmpn_')')
1294 m4_assert_numargs(1)
1295 `m4_unquote(MPN_PREFIX`'$1)')
1298 dnl Usage: mpn_add_n, etc
1300 dnl Convenience definitions using MPN(), like the #defines in gmp.h. Each
1301 dnl function that might be implemented in assembler is here.
1304 m4_assert_numargs(1)
1305 `define(`mpn_$1',`MPN(`$1')')')
1311 define_mpn(addlsh1_n)
1312 define_mpn(addlsh2_n)
1313 define_mpn(addlsh_n)
1314 define_mpn(addmul_1)
1315 define_mpn(addmul_1c)
1316 define_mpn(addmul_2)
1317 define_mpn(addmul_3)
1318 define_mpn(addmul_4)
1319 define_mpn(add_n_sub_n)
1320 define_mpn(add_n_sub_nc)
1321 define_mpn(addaddmul_1msb0)
1324 define_mpn(bdiv_q_1)
1325 define_mpn(pi1_bdiv_q_1)
1326 define_mpn(bdiv_dbm1c)
1331 define_mpn(count_leading_zeros)
1332 define_mpn(count_trailing_zeros)
1333 define_mpn(divexact_1)
1334 define_mpn(divexact_by3c)
1336 define_mpn(divrem_1)
1337 define_mpn(divrem_1c)
1338 define_mpn(divrem_2)
1339 define_mpn(divrem_classic)
1340 define_mpn(divrem_newton)
1347 define_mpn(invert_limb)
1352 define_mpn(mod_1_1p)
1353 define_mpn(mod_1_1p_cps)
1354 define_mpn(mod_1s_2p)
1355 define_mpn(mod_1s_2p_cps)
1356 define_mpn(mod_1s_3p)
1357 define_mpn(mod_1s_3p_cps)
1358 define_mpn(mod_1s_4p)
1359 define_mpn(mod_1s_4p_cps)
1362 define_mpn(mod_34lsub1)
1363 define_mpn(modexact_1_odd)
1364 define_mpn(modexact_1c_odd)
1371 define_mpn(mul_basecase)
1373 define_mpn(mullo_basecase)
1374 define_mpn(perfect_square_p)
1375 define_mpn(popcount)
1376 define_mpn(preinv_divrem_1)
1377 define_mpn(preinv_mod_1)
1387 define_mpn(rsblsh1_n)
1388 define_mpn(rsblsh2_n)
1389 define_mpn(rsblsh_n)
1390 define_mpn(rsh1add_n)
1391 define_mpn(rsh1add_nc)
1392 define_mpn(rsh1sub_n)
1393 define_mpn(rsh1sub_nc)
1399 define_mpn(sqr_basecase)
1400 define_mpn(sqr_diagonal)
1402 define_mpn(sublsh1_n)
1403 define_mpn(sublsh2_n)
1409 define_mpn(submul_1)
1410 define_mpn(submul_1c)
1411 define_mpn(umul_ppmm)
1412 define_mpn(umul_ppmm_r)
1413 define_mpn(udiv_qrnnd)
1414 define_mpn(udiv_qrnnd_r)
1419 dnl Defines for C global arrays and variables, with names matching what's
1420 dnl used in the C code.
1422 dnl Notice that GSYM_PREFIX is included, unlike with the function defines
1423 dnl above. Also, "deflit" is used so that something like __clz_tab(%ebx)
1424 dnl comes out as __gmpn_clz_tab(%ebx), for the benefit of CPUs with that
1425 dnl style assembler syntax.
1428 m4_assert_defined(`GSYM_PREFIX')
1429 `GSYM_PREFIX`'MPN(`clz_tab')')
1431 deflit(binvert_limb_table,
1432 m4_assert_defined(`GSYM_PREFIX')
1433 `GSYM_PREFIX`'__gmp_binvert_limb_table')
1436 dnl Usage: ASM_START()
1438 dnl Emit any directives needed once at the start of an assembler file, like
1439 dnl ".set noreorder" or whatever. The default for this is nothing, but
1440 dnl it's redefined by CPU specific m4 files.
1445 dnl Usage: ASM_END()
1447 dnl Emit any directives needed once at the end of an assembler file. The
1448 dnl default for this is nothing, but it's redefined by CPU specific m4 files.
1453 dnl Usage: PROLOGUE(foo[,param])
1456 dnl Emit directives to start or end a function. GSYM_PREFIX is added by
1457 dnl these macros if necessary, so the given "foo" is what the function will
1460 dnl The second parameter to PROLOGUE is used only for some CPUs and should
1461 dnl be omitted if not required.
1463 dnl Nested or overlapping PROLOGUE/EPILOGUE pairs are allowed, if that
1464 dnl makes sense for the system. The name given to EPILOGUE must be a
1465 dnl currently open PROLOGUE.
1467 dnl If only one PROLOGUE is open then the name can be omitted from
1468 dnl EPILOGUE. This is encouraged, since it means the name only has to
1469 dnl appear in one place, not two.
1471 dnl The given name "foo" is not fully quoted here, it will be macro
1472 dnl expanded more than once. This is the way the m4_list macros work, and
1473 dnl it also helps the tune/many.pl program do a renaming like
1474 dnl -D__gmpn_add_n=mpn_add_n_foo when GSYM_PREFIX is not empty.
1477 m4_assert_numargs_range(1,2)
1479 define(`PROLOGUE_list',m4_list_quote($1,PROLOGUE_list))dnl
1481 `PROLOGUE_cpu(GSYM_PREFIX`'$1)',
1482 `PROLOGUE_cpu(GSYM_PREFIX`'$1,`$2')')')
1485 m4_assert_numargs_range(0,1)
1487 `ifelse(m4_list_count(PROLOGUE_list),0,
1488 `m4_error(`no open functions for EPILOGUE
1490 `ifelse(m4_list_count(PROLOGUE_list),1,
1491 `EPILOGUE_internal(PROLOGUE_current_function)',
1492 `m4_error(`more than one open function for EPILOGUE
1494 `EPILOGUE_internal(`$1')')')
1496 define(EPILOGUE_internal,
1497 m4_assert_numargs(1)
1498 m4_assert_defined(`EPILOGUE_cpu')
1499 `ifelse(m4_list_find($1,PROLOGUE_list),0,
1500 `m4_error(`EPILOGUE without PROLOGUE: $1
1502 define(`PROLOGUE_list',m4_list_quote(m4_list_remove($1,PROLOGUE_list)))dnl
1503 EPILOGUE_cpu(GSYM_PREFIX`$1')')
1505 dnl Currently open PROLOGUEs, as a comma-separated list.
1506 define(PROLOGUE_list)
1509 dnl Called: PROLOGUE_check(list,...)
1510 dnl Check there's no remaining open PROLOGUEs at the end of input.
1511 define(PROLOGUE_check,
1513 `m4_error(`no EPILOGUE for: $1
1515 PROLOGUE_check(shift($@))')')
1517 m4wrap_prepend(`PROLOGUE_check(PROLOGUE_list)')
1520 dnl Usage: PROLOGUE_current_function
1522 dnl This macro expands to the current PROLOGUE/EPILOGUE function, or the
1523 dnl most recent PROLOGUE if such pairs are nested or overlapped.
1525 define(PROLOGUE_current_function,
1526 m4_assert_numargs(-1)
1527 `m4_list_first(PROLOGUE_list)')
1530 dnl Usage: PROLOGUE_cpu(GSYM_PREFIX`'foo[,param])
1531 dnl EPILOGUE_cpu(GSYM_PREFIX`'foo)
1533 dnl These macros hold the CPU-specific parts of PROLOGUE and EPILOGUE.
1534 dnl Both are called with the function name, with GSYM_PREFIX already
1537 dnl The definitions here are something typical and sensible, but CPU or
1538 dnl system specific m4 files should redefine them as necessary. The
1539 dnl optional extra parameter to PROLOGUE_cpu is not expected and not
1542 define(PROLOGUE_cpu,
1543 m4_assert_numargs(1)
1546 GLOBL `$1' GLOBL_ATTR
1547 TYPE(`$1',`function')
1550 define(EPILOGUE_cpu,
1551 ` SIZE(`$1',.-`$1')')
1556 dnl Generate a local label with the given name. This is simply a
1557 dnl convenient way to add LSYM_PREFIX.
1559 dnl LSYM_PREFIX might be L$, so defn() must be used to quote it or the L
1560 dnl will expand again as the L macro, making an infinite recursion.
1563 m4_assert_numargs(1)
1564 `defn(`LSYM_PREFIX')$1')
1567 dnl Usage: LDEF(name)
1569 dnl Generate a directive to define a local label.
1571 dnl On systems with a fixed syntax for defining labels there's no need to
1572 dnl use this macro, it's only meant for systems where the syntax varies,
1573 dnl like hppa which is "L(foo):" with gas, but just "L(foo)" in column 0
1574 dnl with the system `as'.
1576 dnl The extra `' after LABEL_SUFFIX avoids any chance of a following
1577 dnl "(...)" being interpreted as an argument list. Not that it'd be
1578 dnl sensible to write anything like that after an LDEF(), but just in case.
1581 m4_assert_numargs(1)
1582 m4_assert_defined(`LABEL_SUFFIX')
1583 `L(`$1')`'LABEL_SUFFIX`'')
1586 dnl Usage: INT32(label,value)
1587 dnl INT64(label,first,second)
1590 m4_assert_defined(`W32')
1596 m4_assert_defined(`W32')
1603 dnl Usage: ALIGN(bytes)
1605 dnl Emit a ".align" directive. The alignment is specified in bytes, and
1606 dnl will normally need to be a power of 2. The actual ".align" generated
1607 dnl is either bytes or logarithmic according to what ./configure finds the
1608 dnl assembler needs.
1610 dnl If ALIGN_FILL_0x90 is defined and equal to "yes", then ", 0x90" is
1611 dnl appended. This is for x86, see mpn/x86/README.
1614 m4_assert_numargs(1)
1615 m4_assert_defined(`ALIGN_LOGARITHMIC')
1616 `.align ifelse(ALIGN_LOGARITHMIC,yes,`m4_log2($1)',`eval($1)')dnl
1617 ifelse(ALIGN_FILL_0x90,yes,`, 0x90')')
1620 dnl Usage: MULFUNC_PROLOGUE(function function...)
1622 dnl A dummy macro which is grepped for by ./configure to know what
1623 dnl functions a multi-function file is providing. Use this if there aren't
1624 dnl explicit PROLOGUE()s for each possible function.
1626 dnl Multiple MULFUNC_PROLOGUEs can be used, or just one with the function
1627 dnl names separated by spaces.
1629 define(`MULFUNC_PROLOGUE',
1630 m4_assert_numargs(1)
1634 dnl Usage: NAILS_SUPPORT(spec spec ...)
1636 dnl A dummy macro which is grepped for by ./configure to know what nails
1637 dnl are supported in an asm file.
1639 dnl Ranges can be given, or just individual values. Multiple values or
1640 dnl ranges can be given, separated by spaces. Multiple NAILS_SUPPORT
1641 dnl declarations work too. Some examples,
1643 dnl NAILS_SUPPORT(1-20)
1644 dnl NAILS_SUPPORT(1 6 9-12)
1645 dnl NAILS_SUPPORT(1-10 16-20)
1647 define(NAILS_SUPPORT,
1648 m4_assert_numargs(1)
1652 dnl Usage: GMP_NUMB_MASK
1654 dnl A bit mask for the number part of a limb. Eg. with 6 bit nails in a
1655 dnl 32 bit limb, GMP_NUMB_MASK would be 0x3ffffff.
1657 define(GMP_NUMB_MASK,
1658 m4_assert_numargs(-1)
1659 m4_assert_defined(`GMP_NUMB_BITS')
1660 `m4_hex_lowmask(GMP_NUMB_BITS)')