github.com/aergoio/aergo@v1.3.1/libtool/src/gmp-6.1.2/mpn/asm-defs.m4 (about)

     1  divert(-1)
     2  dnl
     3  dnl  m4 macros for gmp assembly code, shared by all CPUs.
     4  
     5  dnl  Copyright 1999-2006, 2011 Free Software Foundation, Inc.
     6  
     7  dnl  This file is part of the GNU MP Library.
     8  dnl
     9  dnl  The GNU MP Library is free software; you can redistribute it and/or modify
    10  dnl  it under the terms of either:
    11  dnl
    12  dnl    * the GNU Lesser General Public License as published by the Free
    13  dnl      Software Foundation; either version 3 of the License, or (at your
    14  dnl      option) any later version.
    15  dnl
    16  dnl  or
    17  dnl
    18  dnl    * the GNU General Public License as published by the Free Software
    19  dnl      Foundation; either version 2 of the License, or (at your option) any
    20  dnl      later version.
    21  dnl
    22  dnl  or both in parallel, as here.
    23  dnl
    24  dnl  The GNU MP Library is distributed in the hope that it will be useful, but
    25  dnl  WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    26  dnl  or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    27  dnl  for more details.
    28  dnl
    29  dnl  You should have received copies of the GNU General Public License and the
    30  dnl  GNU Lesser General Public License along with the GNU MP Library.  If not,
    31  dnl  see https://www.gnu.org/licenses/.
    32  
    33  
    34  dnl  These macros are designed for use with any m4 and have been used on
    35  dnl  GNU, FreeBSD, NetBSD, OpenBSD and SysV.
    36  dnl
    37  dnl  GNU m4 and OpenBSD 2.7 m4 will give filenames and line numbers in error
    38  dnl  messages.
    39  dnl
    40  dnl
    41  dnl  Macros:
    42  dnl
    43  dnl  Most new m4 specific macros have an "m4_" prefix to emphasise they're
    44  dnl  m4 expansions.  But new defining things like deflit() and defreg() are
    45  dnl  named like the builtin define(), and forloop() is named following the
    46  dnl  GNU m4 example on which it's based.
    47  dnl
    48  dnl  GNU m4 with the -P option uses "m4_" as a prefix for builtins, but that
    49  dnl  option isn't going to be used, so there's no conflict or confusion.
    50  dnl
    51  dnl
    52  dnl  Comments in output:
    53  dnl
    54  dnl  The m4 comment delimiters are left at # and \n, the normal assembler
    55  dnl  commenting for most CPUs.  m4 passes comment text through without
    56  dnl  expanding macros in it, which is generally a good thing since it stops
    57  dnl  unexpected expansions and possible resultant errors.
    58  dnl
    59  dnl  But note that when a quoted string is being read, a # isn't special, so
    60  dnl  apostrophes in comments in quoted strings must be avoided or they'll be
    61  dnl  interpreted as a closing quote mark.  But when the quoted text is
    62  dnl  re-read # will still act like a normal comment, suppressing macro
    63  dnl  expansion.
    64  dnl
    65  dnl  For example,
    66  dnl
    67  dnl          # apostrophes in comments that're outside quotes are ok
    68  dnl          # and using macro names like PROLOGUE is ok too
    69  dnl          ...
    70  dnl          ifdef(`PIC',`
    71  dnl                  # but apostrophes aren't ok inside quotes
    72  dnl                  #                     ^--wrong
    73  dnl                  ...
    74  dnl                  # though macro names like PROLOGUE are still ok
    75  dnl                  ...
    76  dnl          ')
    77  dnl
    78  dnl  If macro expansion in a comment is wanted, use `#' in the .asm (ie. a
    79  dnl  quoted hash symbol), which will turn into # in the .s but get
    80  dnl  expansions done on that line.  This can make the .s more readable to
    81  dnl  humans, but it won't make a blind bit of difference to the assembler.
    82  dnl
    83  dnl  All the above applies, mutatis mutandis, when changecom() is used to
    84  dnl  select @ ! ; or whatever other commenting.
    85  dnl
    86  dnl
    87  dnl  Variations in m4 affecting gmp:
    88  dnl
    89  dnl  $# - When a macro is called as "foo" with no brackets, BSD m4 sets $#
    90  dnl       to 1, whereas GNU or SysV m4 set it to 0.  In all cases though
    91  dnl       "foo()" sets $# to 1.  This is worked around in various places.
    92  dnl
    93  dnl  len() - When "len()" is given an empty argument, BSD m4 evaluates to
    94  dnl       nothing, whereas GNU, SysV, and the new OpenBSD, evaluate to 0.
    95  dnl       See m4_length() below which works around this.
    96  dnl
    97  dnl  translit() - GNU m4 accepts character ranges like A-Z, and the new
    98  dnl       OpenBSD m4 does under option -g, but basic BSD and SysV don't.
    99  dnl
   100  dnl  popdef() - in BSD and SysV m4 popdef() takes multiple arguments and
   101  dnl       pops each, but GNU m4 only takes one argument.
   102  dnl
   103  dnl  push back - BSD m4 has some limits on the amount of text that can be
   104  dnl       pushed back.  The limit is reasonably big and so long as macros
   105  dnl       don't gratuitously duplicate big arguments it isn't a problem.
   106  dnl       Normally an error message is given, but sometimes it just hangs.
   107  dnl
   108  dnl  eval() &,|,^ - GNU and SysV m4 have bitwise operators &,|,^ available,
   109  dnl       but BSD m4 doesn't (contrary to what the man page suggests) and
   110  dnl       instead ^ is exponentiation.
   111  dnl
   112  dnl  eval() ?: - The C ternary operator "?:" is available in BSD m4, but not
   113  dnl       in SysV or GNU m4 (as of GNU m4 1.4 and betas of 1.5).
   114  dnl
   115  dnl  eval() -2^31 - BSD m4 has a bug where an eval() resulting in -2^31
   116  dnl       (ie. -2147483648) gives "-(".  Using -2147483648 within an
   117  dnl       expression is ok, it just can't be a final result.  "-(" will of
   118  dnl       course upset parsing, with all sorts of strange effects.
   119  dnl
   120  dnl  eval() <<,>> - SysV m4 doesn't support shift operators in eval() (on
   121  dnl       Solaris 7 /usr/xpg4/m4 has them but /usr/ccs/m4 doesn't).  See
   122  dnl       m4_lshift() and m4_rshift() below for workarounds.
   123  dnl
   124  dnl  ifdef() - OSF 4.0 m4 considers a macro defined to a zero value `0' or
   125  dnl       `00' etc as not defined.  See m4_ifdef below for a workaround.
   126  dnl
   127  dnl  m4wrap() sequence - in BSD m4, m4wrap() replaces any previous m4wrap()
   128  dnl       string, in SysV m4 it appends to it, and in GNU m4 it prepends.
   129  dnl       See m4wrap_prepend() below which brings uniformity to this.
   130  dnl
   131  dnl  m4wrap() 0xFF - old versions of BSD m4 store EOF in a C "char" under an
   132  dnl       m4wrap() and on systems where char is unsigned by default a
   133  dnl       spurious 0xFF is output.  This has been observed on recent Cray
   134  dnl       Unicos Alpha, Apple MacOS X, and HPUX 11 systems.  An autoconf
   135  dnl       test is used to check for this, see the m4wrap handling below.  It
   136  dnl       might work to end the m4wrap string with a dnl to consume the
   137  dnl       0xFF, but that probably induces the offending m4's to read from an
   138  dnl       already closed "FILE *", which could be bad on a glibc style
   139  dnl       stdio.
   140  dnl
   141  dnl  __file__,__line__ - GNU m4 and OpenBSD 2.7 m4 provide these, and
   142  dnl       they're used here to make error messages more informative.  GNU m4
   143  dnl       gives an unhelpful "NONE 0" in an m4wrap(), but that's worked
   144  dnl       around.
   145  dnl
   146  dnl  __file__ quoting - OpenBSD m4, unlike GNU m4, doesn't quote the
   147  dnl       filename in __file__, so care should be taken that no macro has
   148  dnl       the same name as a file, or an unwanted expansion will occur when
   149  dnl       printing an error or warning.
   150  dnl
   151  dnl  changecom() - BSD m4 changecom doesn't quite work like the man page
   152  dnl       suggests, in particular "changecom" or "changecom()" doesn't
   153  dnl       disable the comment feature, and multi-character comment sequences
   154  dnl       don't seem to work.  If the default `#' and newline aren't
   155  dnl       suitable it's necessary to change it to something else,
   156  dnl       eg. changecom(;).
   157  dnl
   158  dnl  OpenBSD 2.6 m4 - in this m4, eval() rejects decimal constants containing
   159  dnl       an 8 or 9, making it pretty much unusable.  The bug is confined to
   160  dnl       version 2.6 (it's not in 2.5, and was fixed in 2.7).
   161  dnl
   162  dnl  SunOS /usr/bin/m4 - this m4 lacks a number of desired features,
   163  dnl       including $# and $@, defn(), m4exit(), m4wrap(), pushdef(),
   164  dnl       popdef().  /usr/5bin/m4 is a SysV style m4 which should always be
   165  dnl       available, and "configure" will reject /usr/bin/m4 in favour of
   166  dnl       /usr/5bin/m4 (if necessary).
   167  dnl
   168  dnl       The sparc code actually has modest m4 requirements currently and
   169  dnl       could manage with /usr/bin/m4, but there's no reason to put our
   170  dnl       macros through contortions when /usr/5bin/m4 is available or GNU
   171  dnl       m4 can be installed.
   172  
   173  
   174  ifdef(`__ASM_DEFS_M4_INCLUDED__',
   175  `m4_error(`asm-defs.m4 already included, dont include it twice
   176  ')m4exit(1)')
   177  define(`__ASM_DEFS_M4_INCLUDED__')
   178  
   179  
   180  dnl  Detect and give a message about the unsuitable OpenBSD 2.6 m4.
   181  
   182  ifelse(eval(89),89,,
   183  `errprint(
   184  `This m4 doesnt accept 8 and/or 9 in constants in eval(), making it unusable.
   185  This is probably OpenBSD 2.6 m4 (September 1999).  Upgrade to OpenBSD 2.7,
   186  or get a bug fix from the CVS (expr.c rev 1.9), or get GNU m4.  Dont forget
   187  to configure with M4=/wherever/m4 if you install one of these in a directory
   188  not in $PATH.
   189  ')m4exit(1)')
   190  
   191  
   192  dnl  Detect and give a message about the unsuitable SunOS /usr/bin/m4.
   193  dnl
   194  dnl  Unfortunately this test doesn't work when m4 is run in the normal way
   195  dnl  from mpn/Makefile with "m4 -DOPERATION_foo foo.asm", since the bad m4
   196  dnl  takes "-" in "-D..." to mean read stdin, so it will look like it just
   197  dnl  hangs.  But running "m4 asm-defs.m4" to try it out will work.
   198  dnl
   199  dnl  We'd like to abort immediately on finding a problem, but unfortunately
   200  dnl  the bad m4 doesn't have an m4exit(), nor does an invalid eval() kill
   201  dnl  it.  Unexpanded $#'s in some m4_assert_numargs() later on will comment
   202  dnl  out some closing parentheses and kill it with "m4: arg stack overflow".
   203  
   204  define(m4_dollarhash_works_test,``$#'')
   205  ifelse(m4_dollarhash_works_test(x),1,,
   206  `errprint(
   207  `This m4 doesnt support $# and cant be used for GMP asm processing.
   208  If this is on SunOS, ./configure should choose /usr/5bin/m4 if you have that
   209  or can get it, otherwise install GNU m4.  Dont forget to configure with
   210  M4=/wherever/m4 if you install in a directory not in $PATH.
   211  ')')
   212  undefine(`m4_dollarhash_works_test')
   213  
   214  
   215  dnl  --------------------------------------------------------------------------
   216  dnl  Basic error handling things.
   217  
   218  
   219  dnl  Usage: m4_dollarhash_1_if_noparen_p
   220  dnl
   221  dnl  Expand to 1 if a call "foo" gives $# set to 1 (as opposed to 0 like GNU
   222  dnl  and SysV m4 give).
   223  
   224  define(m4_dollarhash_1_if_noparen_test,`$#')
   225  define(m4_dollarhash_1_if_noparen_p,
   226  eval(m4_dollarhash_1_if_noparen_test==1))
   227  undefine(`m4_dollarhash_1_if_noparen_test')
   228  
   229  
   230  dnl  Usage: m4wrap_prepend(string)
   231  dnl
   232  dnl  Prepend the given string to what will be expanded under m4wrap at the
   233  dnl  end of input.
   234  dnl
   235  dnl  This macro exists to work around variations in m4wrap() behaviour in
   236  dnl  the various m4s (notes at the start of this file).  Don't use m4wrap()
   237  dnl  directly since it will interfere with this scheme.
   238  
   239  define(m4wrap_prepend,
   240  m4_assert_numargs(1)
   241  `define(`m4wrap_string',`$1'defn(`m4wrap_string'))')
   242  
   243  define(m4wrap_string,`')
   244  
   245  define(m4wrap_works_p,
   246  `ifelse(M4WRAP_SPURIOUS,yes,0,1)')
   247  
   248  ifelse(m4wrap_works_p,1,
   249  `m4wrap(`m4wrap_string')')
   250  
   251  
   252  dnl  Usage: m4_file_and_line
   253  dnl
   254  dnl  Expand to the current file and line number, if the GNU m4 extensions
   255  dnl  __file__ and __line__ are available.
   256  dnl
   257  dnl  In GNU m4 1.4 at the end of input when m4wrap text is expanded,
   258  dnl  __file__ is NONE and __line__ is 0, which is not a helpful thing to
   259  dnl  print.  If m4_file_seen() has been called to note the last file seen,
   260  dnl  then that file at a big line number is used, otherwise "end of input"
   261  dnl  is used (although "end of input" won't parse as an error message).
   262  
   263  define(m4_file_and_line,
   264  `ifdef(`__file__',
   265  `ifelse(__file__`'__line__,`NONE0',
   266  `ifdef(`m4_file_seen_last',`m4_file_seen_last: 999999: ',`end of input: ')',
   267  `__file__: __line__: ')')')
   268  
   269  
   270  dnl  Usage: m4_errprint_commas(arg,...)
   271  dnl
   272  dnl  The same as errprint(), but commas are printed between arguments
   273  dnl  instead of spaces.
   274  
   275  define(m4_errprint_commas,
   276  `errprint(`$1')dnl
   277  ifelse(eval($#>1),1,`errprint(`,')m4_errprint_commas(shift($@))')')
   278  
   279  
   280  dnl  Usage: m4_error(args...)
   281  dnl         m4_warning(args...)
   282  dnl
   283  dnl  Print an error message, using m4_errprint_commas, prefixed with the
   284  dnl  current filename and line number (if available).  m4_error sets up to
   285  dnl  give an error exit at the end of processing, m4_warning just prints.
   286  dnl  These macros are the recommended way to print errors.
   287  dnl
   288  dnl  The arguments here should be quoted in the usual way to prevent them
   289  dnl  being expanded when the macro call is read.  (m4_error takes care not
   290  dnl  to do any further expansion.)
   291  dnl
   292  dnl  For example,
   293  dnl
   294  dnl         m4_error(`some error message
   295  dnl         ')
   296  dnl
   297  dnl  which prints
   298  dnl
   299  dnl         foo.asm:123: some error message
   300  dnl
   301  dnl  or if __file__ and __line__ aren't available
   302  dnl
   303  dnl         some error message
   304  dnl
   305  dnl  The "file:line:" format is a basic style, used by gcc and GNU m4, so
   306  dnl  emacs and other editors will recognise it in their normal error message
   307  dnl  parsing.
   308  
   309  define(m4_warning,
   310  `m4_errprint_commas(m4_file_and_line`'$@)')
   311  
   312  define(m4_error,
   313  `define(`m4_error_occurred',1)m4_warning($@)dnl
   314  ifelse(m4wrap_works_p,0,`m4exit(1)')')
   315  
   316  define(`m4_error_occurred',0)
   317  
   318  dnl  This m4wrap_prepend() is first, so it'll be executed last.
   319  m4wrap_prepend(
   320  `ifelse(m4_error_occurred,1,
   321  `m4_error(`Errors occurred during m4 processing
   322  ')m4exit(1)')')
   323  
   324  
   325  dnl  Usage: m4_assert_numargs(num)
   326  dnl
   327  dnl  Put this unquoted on a line on its own at the start of a macro
   328  dnl  definition to add some code to check that num many arguments get passed
   329  dnl  to the macro.  For example,
   330  dnl
   331  dnl         define(foo,
   332  dnl         m4_assert_numargs(2)
   333  dnl         `something `$1' and `$2' blah blah')
   334  dnl
   335  dnl  Then a call like foo(one,two,three) will provoke an error like
   336  dnl
   337  dnl         file:10: foo expected 2 arguments, got 3 arguments
   338  dnl
   339  dnl  Here are some calls and how many arguments they're interpreted as passing.
   340  dnl
   341  dnl         foo(abc,def)  2
   342  dnl         foo(xyz)      1
   343  dnl         foo()         0
   344  dnl         foo          -1
   345  dnl
   346  dnl  The -1 for no parentheses at all means a macro that's meant to be used
   347  dnl  that way can be checked with m4_assert_numargs(-1).  For example,
   348  dnl
   349  dnl         define(SPECIAL_SUFFIX,
   350  dnl         m4_assert_numargs(-1)
   351  dnl         `ifdef(`FOO',`_foo',`_bar')')
   352  dnl
   353  dnl  But as an alternative see also deflit() below where parenthesized
   354  dnl  expressions following a macro are passed through to the output.
   355  dnl
   356  dnl  Note that in BSD m4 there's no way to differentiate calls "foo" and
   357  dnl  "foo()", so in BSD m4 the distinction between the two isn't enforced.
   358  dnl  (In GNU and SysV m4 it can be checked, and is.)
   359  
   360  
   361  dnl  m4_assert_numargs is able to check its own arguments by calling
   362  dnl  assert_numargs_internal directly.
   363  dnl
   364  dnl  m4_doublequote($`'0) expands to ``$0'', whereas ``$`'0'' would expand
   365  dnl  to `$`'0' and do the wrong thing, and likewise for $1.  The same is
   366  dnl  done in other assert macros.
   367  dnl
   368  dnl  $`#' leaves $# in the new macro being defined, and stops # being
   369  dnl  interpreted as a comment character.
   370  dnl
   371  dnl  `dnl ' means an explicit dnl isn't necessary when m4_assert_numargs is
   372  dnl  used.  The space means that if there is a dnl it'll still work.
   373  
   374  dnl  Usage: m4_doublequote(x) expands to ``x''
   375  define(m4_doublequote,
   376  `m4_assert_numargs_internal(`$0',1,$#,len(`$1'))``$1''')
   377  
   378  define(m4_assert_numargs,
   379  `m4_assert_numargs_internal(`$0',1,$#,len(`$1'))dnl
   380  `m4_assert_numargs_internal'(m4_doublequote($`'0),$1,$`#',`len'(m4_doublequote($`'1)))`dnl '')
   381  
   382  dnl  Called: m4_assert_numargs_internal(`macroname',wantargs,$#,len(`$1'))
   383  define(m4_assert_numargs_internal,
   384  `m4_assert_numargs_internal_check(`$1',`$2',m4_numargs_count(`$3',`$4'))')
   385  
   386  dnl  Called: m4_assert_numargs_internal_check(`macroname',wantargs,gotargs)
   387  dnl
   388  dnl  If m4_dollarhash_1_if_noparen_p (BSD m4) then gotargs can be 0 when it
   389  dnl  should be -1.  If wantargs is -1 but gotargs is 0 and the two can't be
   390  dnl  distinguished then it's allowed to pass.
   391  dnl
   392  define(m4_assert_numargs_internal_check,
   393  `ifelse(eval($2 == $3
   394               || ($2==-1 && $3==0 && m4_dollarhash_1_if_noparen_p)),0,
   395  `m4_error(`$1 expected 'm4_Narguments(`$2')`, got 'm4_Narguments(`$3')
   396  )')')
   397  
   398  dnl  Called: m4_numargs_count($#,len(`$1'))
   399  dnl  If $#==0 then -1 args, if $#==1 but len(`$1')==0 then 0 args, otherwise
   400  dnl  $# args.
   401  define(m4_numargs_count,
   402  `ifelse($1,0, -1,
   403  `ifelse(eval($1==1 && $2-0==0),1, 0, $1)')')
   404  
   405  dnl  Usage: m4_Narguments(N)
   406  dnl  "$1 argument" or "$1 arguments" with the plural according to $1.
   407  define(m4_Narguments,
   408  `$1 argument`'ifelse(`$1',1,,s)')
   409  
   410  
   411  dnl  --------------------------------------------------------------------------
   412  dnl  Additional error checking things.
   413  
   414  
   415  dnl  Usage: m4_file_seen()
   416  dnl
   417  dnl  Record __file__ for the benefit of m4_file_and_line in m4wrap text.
   418  dnl
   419  dnl  The basic __file__ macro comes out quoted in GNU m4, like `foo.asm',
   420  dnl  and m4_file_seen_last is defined like that too.
   421  dnl
   422  dnl  This is used by PROLOGUE, since that's normally in the main .asm file,
   423  dnl  and in particular it sets up m4wrap error checks for missing EPILOGUE.
   424  
   425  define(m4_file_seen,
   426  m4_assert_numargs(0)
   427  `ifelse(__file__,`NONE',,
   428  `define(`m4_file_seen_last',m4_doublequote(__file__))')')
   429  
   430  
   431  dnl  Usage: m4_assert_onearg()
   432  dnl
   433  dnl  Put this, unquoted, at the start of a macro definition to add some code
   434  dnl  to check that one argument is passed to the macro, but with that
   435  dnl  argument allowed to be empty.  For example,
   436  dnl
   437  dnl          define(foo,
   438  dnl          m4_assert_onearg()
   439  dnl          `blah blah $1 blah blah')
   440  dnl
   441  dnl  Calls "foo(xyz)" or "foo()" are accepted.  A call "foo(xyz,abc)" fails.
   442  dnl  A call "foo" fails too, but BSD m4 can't detect this case (GNU and SysV
   443  dnl  m4 can).
   444  
   445  define(m4_assert_onearg,
   446  m4_assert_numargs(0)
   447  `m4_assert_onearg_internal'(m4_doublequote($`'0),$`#')`dnl ')
   448  
   449  dnl  Called: m4_assert_onearg(`macroname',$#)
   450  define(m4_assert_onearg_internal,
   451  `ifelse($2,1,,
   452  `m4_error(`$1 expected 1 argument, got 'm4_Narguments(`$2')
   453  )')')
   454  
   455  
   456  dnl  Usage: m4_assert_numargs_range(low,high)
   457  dnl
   458  dnl  Put this, unquoted, at the start of a macro definition to add some code
   459  dnl  to check that between low and high many arguments get passed to the
   460  dnl  macro.  For example,
   461  dnl
   462  dnl         define(foo,
   463  dnl         m4_assert_numargs_range(3,5)
   464  dnl         `mandatory $1 $2 $3 optional $4 $5 end')
   465  dnl
   466  dnl  See m4_assert_numargs() for more info.
   467  
   468  define(m4_assert_numargs_range,
   469  m4_assert_numargs(2)
   470  ``m4_assert_numargs_range_internal'(m4_doublequote($`'0),$1,$2,$`#',`len'(m4_doublequote($`'1)))`dnl '')
   471  
   472  dnl  Called: m4_assert_numargs_range_internal(`name',low,high,$#,len(`$1'))
   473  define(m4_assert_numargs_range_internal,
   474  m4_assert_numargs(5)
   475  `m4_assert_numargs_range_check(`$1',`$2',`$3',m4_numargs_count(`$4',`$5'))')
   476  
   477  dnl  Called: m4_assert_numargs_range_check(`name',low,high,gotargs)
   478  dnl
   479  dnl  If m4_dollarhash_1_if_noparen_p (BSD m4) then gotargs can be 0 when it
   480  dnl  should be -1.  To ensure a `high' of -1 works, a fudge is applied to
   481  dnl  gotargs if it's 0 and the 0 and -1 cases can't be distinguished.
   482  dnl
   483  define(m4_assert_numargs_range_check,
   484  m4_assert_numargs(4)
   485  `ifelse(eval($2 <= $4 &&
   486               ($4 - ($4==0 && m4_dollarhash_1_if_noparen_p) <= $3)),0,
   487  `m4_error(`$1 expected $2 to $3 arguments, got 'm4_Narguments(`$4')
   488  )')')
   489  
   490  
   491  dnl  Usage: m4_assert_defined(symbol)
   492  dnl
   493  dnl  Put this unquoted on a line of its own at the start of a macro
   494  dnl  definition to add some code to check that the given symbol is defined
   495  dnl  when the macro is used.  For example,
   496  dnl
   497  dnl          define(foo,
   498  dnl          m4_assert_defined(`FOO_PREFIX')
   499  dnl          `FOO_PREFIX whatever')
   500  dnl
   501  dnl  This is a convenient way to check that the user or ./configure or
   502  dnl  whatever has defined the things needed by a macro, as opposed to
   503  dnl  silently generating garbage.
   504  
   505  define(m4_assert_defined,
   506  m4_assert_numargs(1)
   507  ``m4_assert_defined_internal'(m4_doublequote($`'0),``$1'')`dnl '')
   508  
   509  dnl  Called: m4_assert_defined_internal(`macroname',`define_required')
   510  define(m4_assert_defined_internal,
   511  m4_assert_numargs(2)
   512  `m4_ifdef(`$2',,
   513  `m4_error(`$1 needs $2 defined
   514  ')')')
   515  
   516  
   517  dnl  Usage: m4_not_for_expansion(`SYMBOL')
   518  dnl         define_not_for_expansion(`SYMBOL')
   519  dnl
   520  dnl  m4_not_for_expansion turns SYMBOL, if defined, into something which
   521  dnl  will give an error if expanded.  For example,
   522  dnl
   523  dnl         m4_not_for_expansion(`PIC')
   524  dnl
   525  dnl  define_not_for_expansion is the same, but always makes a definition.
   526  dnl
   527  dnl  These are for symbols that should be tested with ifdef(`FOO',...)
   528  dnl  rather than be expanded as such.  They guard against accidentally
   529  dnl  omitting the quotes, as in ifdef(FOO,...).  Note though that they only
   530  dnl  catches this when FOO is defined, so be sure to test code both with and
   531  dnl  without each definition.
   532  
   533  define(m4_not_for_expansion,
   534  m4_assert_numargs(1)
   535  `ifdef(`$1',`define_not_for_expansion(`$1')')')
   536  
   537  define(define_not_for_expansion,
   538  m4_assert_numargs(1)
   539  `ifelse(defn(`$1'),,,
   540  `m4_error(``$1' has a non-empty value, maybe it shouldnt be munged with m4_not_for_expansion()
   541  ')')dnl
   542  define(`$1',`m4_not_for_expansion_internal(`$1')')')
   543  
   544  define(m4_not_for_expansion_internal,
   545  `m4_error(``$1' is not meant to be expanded, perhaps you mean `ifdef(`$1',...)'
   546  ')')
   547  
   548  
   549  dnl  --------------------------------------------------------------------------
   550  dnl  Various generic m4 things.
   551  
   552  
   553  dnl  Usage: m4_unquote(macro)
   554  dnl
   555  dnl  Allow the argument text to be re-evaluated.  This is useful for "token
   556  dnl  pasting" like m4_unquote(foo`'bar).
   557  
   558  define(m4_unquote,
   559  m4_assert_onearg()
   560  `$1')
   561  
   562  
   563  dnl  Usage: m4_ifdef(name,yes[,no])
   564  dnl
   565  dnl  Expand to the yes argument if name is defined, or to the no argument if
   566  dnl  not.
   567  dnl
   568  dnl  This is the same as the builtin "ifdef", but avoids an OSF 4.0 m4 bug
   569  dnl  in which a macro with a zero value `0' or `00' etc is considered not
   570  dnl  defined.
   571  dnl
   572  dnl  There's no particular need to use this everywhere, only if there might
   573  dnl  be a zero value.
   574  
   575  define(m4_ifdef,
   576  m4_assert_numargs_range(2,3)
   577  `ifelse(eval(ifdef(`$1',1,0)+m4_length(defn(`$1'))),0,
   578  `$3',`$2')')
   579  
   580  
   581  dnl  Usage: m4_ifdef_anyof_p(`symbol',...)
   582  dnl
   583  dnl  Expand to 1 if any of the symbols in the argument list are defined, or
   584  dnl  to 0 if not.
   585  
   586  define(m4_ifdef_anyof_p,
   587  `ifelse(eval($#<=1 && m4_length(`$1')==0),1, 0,
   588  `ifdef(`$1', 1,
   589  `m4_ifdef_anyof_p(shift($@))')')')
   590  
   591  
   592  dnl  Usage: m4_length(string)
   593  dnl
   594  dnl  Determine the length of a string.  This is the same as len(), but
   595  dnl  always expands to a number, working around the BSD len() which
   596  dnl  evaluates to nothing given an empty argument.
   597  
   598  define(m4_length,
   599  m4_assert_onearg()
   600  `eval(len(`$1')-0)')
   601  
   602  
   603  dnl  Usage: m4_stringequal_p(x,y)
   604  dnl
   605  dnl  Expand to 1 or 0 according as strings x and y are equal or not.
   606  
   607  define(m4_stringequal_p,
   608  `ifelse(`$1',`$2',1,0)')
   609  
   610  
   611  dnl  Usage: m4_incr_or_decr(n,last)
   612  dnl
   613  dnl  Do an incr(n) or decr(n), whichever is in the direction of "last".
   614  dnl  Both n and last must be numbers of course.
   615  
   616  define(m4_incr_or_decr,
   617  m4_assert_numargs(2)
   618  `ifelse(eval($1<$2),1,incr($1),decr($1))')
   619  
   620  
   621  dnl  Usage: forloop(i, first, last, statement)
   622  dnl
   623  dnl  Based on GNU m4 examples/forloop.m4, but extended.
   624  dnl
   625  dnl  statement is expanded repeatedly, with i successively defined as
   626  dnl
   627  dnl         first, first+1, ..., last-1, last
   628  dnl
   629  dnl  Or if first > last, then it's
   630  dnl
   631  dnl         first, first-1, ..., last+1, last
   632  dnl
   633  dnl  If first == last, then one expansion is done.
   634  dnl
   635  dnl  A pushdef/popdef of i is done to preserve any previous definition (or
   636  dnl  lack of definition).  first and last are eval()ed and so can be
   637  dnl  expressions.
   638  dnl
   639  dnl  forloop_first is defined to 1 on the first iteration, 0 on the rest.
   640  dnl  forloop_last is defined to 1 on the last iteration, 0 on the others.
   641  dnl  Nested forloops are allowed, in which case forloop_first and
   642  dnl  forloop_last apply to the innermost loop that's open.
   643  dnl
   644  dnl  A simple example,
   645  dnl
   646  dnl         forloop(i, 1, 2*2+1, `dnl
   647  dnl         iteration number i ... ifelse(forloop_first,1,FIRST)
   648  dnl         ')
   649  
   650  
   651  dnl  "i" and "statement" are carefully quoted, but "first" and "last" are
   652  dnl  just plain numbers once eval()ed.
   653  
   654  define(`forloop',
   655  m4_assert_numargs(4)
   656  `pushdef(`$1',eval(`$2'))dnl
   657  pushdef(`forloop_first',1)dnl
   658  pushdef(`forloop_last',0)dnl
   659  forloop_internal(`$1',eval(`$3'),`$4')`'dnl
   660  popdef(`forloop_first')dnl
   661  popdef(`forloop_last')dnl
   662  popdef(`$1')')
   663  
   664  dnl  Called: forloop_internal(`var',last,statement)
   665  define(`forloop_internal',
   666  m4_assert_numargs(3)
   667  `ifelse($1,$2,
   668  `define(`forloop_last',1)$3',
   669  `$3`'dnl
   670  define(`forloop_first',0)dnl
   671  define(`$1',m4_incr_or_decr($1,$2))dnl
   672  forloop_internal(`$1',$2,`$3')')')
   673  
   674  
   675  dnl  Usage: foreach(var,body, item1,item2,...,itemN)
   676  dnl
   677  dnl  For each "item" argument, define "var" to that value and expand "body".
   678  dnl  For example,
   679  dnl
   680  dnl         foreach(i, `something i
   681  dnl         ', one, two)
   682  dnl  gives
   683  dnl         something one
   684  dnl         something two
   685  dnl
   686  dnl  Any previous definition of "var", or lack thereof, is saved and
   687  dnl  restored.  Empty "item"s are not allowed.
   688  
   689  define(foreach,
   690  m4_assert_numargs_range(2,1000)
   691  `ifelse(`$3',,,
   692  `pushdef(`$1',`$3')$2`'popdef(`$1')dnl
   693  foreach(`$1',`$2',shift(shift(shift($@))))')')
   694  
   695  
   696  dnl  Usage: m4_toupper(x)
   697  dnl         m4_tolower(x)
   698  dnl
   699  dnl  Convert the argument string to upper or lower case, respectively.
   700  dnl  Only one argument accepted.
   701  dnl
   702  dnl  BSD m4 doesn't take ranges like a-z in translit(), so the full alphabet
   703  dnl  is written out.
   704  
   705  define(m4_alphabet_lower, `abcdefghijklmnopqrstuvwxyz')
   706  define(m4_alphabet_upper, `ABCDEFGHIJKLMNOPQRSTUVWXYZ')
   707  
   708  define(m4_toupper,
   709  m4_assert_onearg()
   710  `translit(`$1', m4_alphabet_lower, m4_alphabet_upper)')
   711  
   712  define(m4_tolower,
   713  m4_assert_onearg()
   714  `translit(`$1', m4_alphabet_upper, m4_alphabet_lower)')
   715  
   716  
   717  dnl  Usage: m4_empty_if_zero(x)
   718  dnl
   719  dnl  Evaluate to x, or to nothing if x is 0.  x is eval()ed and so can be an
   720  dnl  expression.
   721  dnl
   722  dnl  This is useful for x86 addressing mode displacements since forms like
   723  dnl  (%ebx) are one byte shorter than 0(%ebx).  A macro `foo' for use as
   724  dnl  foo(%ebx) could be defined with the following so it'll be empty if the
   725  dnl  expression comes out zero.
   726  dnl
   727  dnl	   deflit(`foo', `m4_empty_if_zero(a+b*4-c)')
   728  dnl
   729  dnl  Naturally this shouldn't be done if, say, a computed jump depends on
   730  dnl  the code being a particular size.
   731  
   732  define(m4_empty_if_zero,
   733  m4_assert_onearg()
   734  `ifelse(eval($1),0,,eval($1))')
   735  
   736  
   737  dnl  Usage: m4_log2(x)
   738  dnl
   739  dnl  Calculate a logarithm to base 2.
   740  dnl  x must be an integral power of 2, between 2**0 and 2**30.
   741  dnl  x is eval()ed, so it can be an expression.
   742  dnl  An error results if x is invalid.
   743  dnl
   744  dnl  2**31 isn't supported, because an unsigned 2147483648 is out of range
   745  dnl  of a 32-bit signed int.  Also, the bug in BSD m4 where an eval()
   746  dnl  resulting in 2147483648 (or -2147483648 as the case may be) gives `-('
   747  dnl  means tests like eval(1<<31==(x)) would be necessary, but that then
   748  dnl  gives an unattractive explosion of eval() error messages if x isn't
   749  dnl  numeric.
   750  
   751  define(m4_log2,
   752  m4_assert_numargs(1)
   753  `m4_log2_internal(0,1,eval(`$1'))')
   754  
   755  dnl  Called: m4_log2_internal(n,2**n,target)
   756  define(m4_log2_internal,
   757  m4_assert_numargs(3)
   758  `ifelse($2,$3,$1,
   759  `ifelse($1,30,
   760  `m4_error(`m4_log2() argument too big or not a power of two: $3
   761  ')',
   762  `m4_log2_internal(incr($1),eval(2*$2),$3)')')')
   763  
   764  
   765  dnl  Usage:  m4_div2_towards_zero
   766  dnl
   767  dnl  m4 division is probably whatever a C signed division is, and C doesn't
   768  dnl  specify what rounding gets used on negatives, so this expression forces
   769  dnl  a rounding towards zero.
   770  
   771  define(m4_div2_towards_zero,
   772  m4_assert_numargs(1)
   773  `eval((($1) + ((($1)<0) & ($1))) / 2)')
   774  
   775  
   776  dnl  Usage: m4_lshift(n,count)
   777  dnl         m4_rshift(n,count)
   778  dnl
   779  dnl  Calculate n shifted left or right by count many bits.  Both n and count
   780  dnl  are eval()ed and so can be expressions.
   781  dnl
   782  dnl  Negative counts are allowed and mean a shift in the opposite direction.
   783  dnl  Negative n is allowed and right shifts will be arithmetic (meaning
   784  dnl  divide by 2**count, rounding towards zero, also meaning the sign bit is
   785  dnl  duplicated).
   786  dnl
   787  dnl  Use these macros instead of << and >> in eval() since the basic ccs
   788  dnl  SysV m4 doesn't have those operators.
   789  
   790  define(m4_rshift,
   791  m4_assert_numargs(2)
   792  `m4_lshift(`$1',-(`$2'))')
   793  
   794  define(m4_lshift,
   795  m4_assert_numargs(2)
   796  `m4_lshift_internal(eval(`$1'),eval(`$2'))')
   797  
   798  define(m4_lshift_internal,
   799  m4_assert_numargs(2)
   800  `ifelse(eval($2-0==0),1,$1,
   801  `ifelse(eval($2>0),1,
   802  `m4_lshift_internal(eval($1*2),decr($2))',
   803  `m4_lshift_internal(m4_div2_towards_zero($1),incr($2))')')')
   804  
   805  
   806  dnl  Usage: m4_popcount(n)
   807  dnl
   808  dnl  Expand to the number 1 bits in n.
   809  
   810  define(m4_popcount,
   811  m4_assert_numargs(1)
   812  `m4_popcount_internal(0,eval(`$1'))')
   813  
   814  dnl  Called: m4_popcount_internal(count,rem)
   815  define(m4_popcount_internal,
   816  m4_assert_numargs(2)
   817  `ifelse($2,0,$1,
   818  `m4_popcount_internal(eval($1+($2%2)),eval($2/2))')')
   819  
   820  
   821  dnl  Usage: m4_count_trailing_zeros(N)
   822  dnl
   823  dnl  Determine the number of trailing zero bits on N.  N is eval()ed and so
   824  dnl  can be an expression.  If N is zero an error is generated.
   825  
   826  define(m4_count_trailing_zeros,
   827  m4_assert_numargs(1)
   828  `m4_count_trailing_zeros_internal(eval(`$1'),0)')
   829  
   830  dnl  Called: m4_count_trailing_zeros_internal(val,count)
   831  define(m4_count_trailing_zeros_internal,
   832  m4_assert_numargs(2)
   833  `ifelse($1,0,
   834  `m4_error(`m4_count_trailing_zeros() given a zero value')',
   835  `ifelse(eval(($1)%2),1,`$2',
   836  `m4_count_trailing_zeros_internal(eval($1/2),incr($2))')')')
   837  
   838  
   839  dnl  Usage: deflit(name,value)
   840  dnl
   841  dnl  Like define(), but "name" expands like a literal, rather than taking
   842  dnl  arguments.  For example "name(%eax)" expands to "value(%eax)".
   843  dnl
   844  dnl  Limitations:
   845  dnl
   846  dnl  $ characters in the value part must have quotes to stop them looking
   847  dnl  like macro parameters.  For example, deflit(reg,`123+$`'4+567').  See
   848  dnl  defreg() below for handling simple register definitions like $7 etc.
   849  dnl
   850  dnl  "name()" is turned into "name", unfortunately.  In GNU and SysV m4 an
   851  dnl  error is generated when this happens, but in BSD m4 it will happen
   852  dnl  silently.  The problem is that in BSD m4 $# is 1 in both "name" or
   853  dnl  "name()", so there's no way to differentiate them.  Because we want
   854  dnl  plain "name" to turn into plain "value", we end up with "name()"
   855  dnl  turning into plain "value" too.
   856  dnl
   857  dnl  "name(foo)" will lose any whitespace after commas in "foo", for example
   858  dnl  "disp(%eax, %ecx)" would become "128(%eax,%ecx)".
   859  dnl
   860  dnl  These parentheses oddities shouldn't matter in assembler text, but if
   861  dnl  they do the suggested workaround is to write "name ()" or "name (foo)"
   862  dnl  to stop the parentheses looking like a macro argument list.  If a space
   863  dnl  isn't acceptable in the output, then write "name`'()" or "name`'(foo)".
   864  dnl  The `' is stripped when read, but again stops the parentheses looking
   865  dnl  like parameters.
   866  
   867  dnl  Quoting for deflit_emptyargcheck is similar to m4_assert_numargs.  The
   868  dnl  stuff in the ifelse gives a $#, $1 and $@ evaluated in the new macro
   869  dnl  created, not in deflit.
   870  define(deflit,
   871  m4_assert_numargs(2)
   872  `define(`$1',
   873  `deflit_emptyargcheck'(``$1'',$`#',m4_doublequote($`'1))`dnl
   874  $2`'dnl
   875  ifelse(eval($'`#>1 || m4_length('m4_doublequote($`'1)`)!=0),1,($'`@))')')
   876  
   877  dnl  Called: deflit_emptyargcheck(macroname,$#,`$1')
   878  define(deflit_emptyargcheck,
   879  `ifelse(eval($2==1 && !m4_dollarhash_1_if_noparen_p && m4_length(`$3')==0),1,
   880  `m4_error(`dont use a deflit as $1() because it loses the brackets (see deflit in asm-defs.m4 for more information)
   881  ')')')
   882  
   883  
   884  dnl  Usage: m4_assert(`expr')
   885  dnl
   886  dnl  Test a compile-time requirement with an m4 expression.  The expression
   887  dnl  should be quoted, and will be eval()ed and expected to be non-zero.
   888  dnl  For example,
   889  dnl
   890  dnl         m4_assert(`FOO*2+6 < 14')
   891  
   892  define(m4_assert,
   893  m4_assert_numargs(1)
   894  `ifelse(eval($1),1,,
   895  `m4_error(`assertion failed: $1
   896  ')')')
   897  
   898  
   899  dnl  Usage: m4_repeat(count,text)
   900  dnl
   901  dnl  Expand to the given repetitions of the given text.  A zero count is
   902  dnl  allowed, and expands to nothing.
   903  
   904  define(m4_repeat,
   905  m4_assert_numargs(2)
   906  `m4_repeat_internal(eval($1),`$2')')
   907  
   908  define(m4_repeat_internal,
   909  m4_assert_numargs(2)
   910  `ifelse(`$1',0,,
   911  `forloop(m4_repeat_internal_counter,1,$1,``$2'')')')
   912  
   913  
   914  dnl  Usage: m4_hex_lowmask(bits)
   915  dnl
   916  dnl  Generate a hex constant which is a low mask of the given number of
   917  dnl  bits.  For example m4_hex_lowmask(10) would give 0x3ff.
   918  
   919  define(m4_hex_lowmask,
   920  m4_assert_numargs(1)
   921  `m4_cpu_hex_constant(m4_hex_lowmask_internal1(eval(`$1')))')
   922  
   923  dnl  Called: m4_hex_lowmask_internal1(bits)
   924  define(m4_hex_lowmask_internal1,
   925  m4_assert_numargs(1)
   926  `ifelse($1,0,`0',
   927  `m4_hex_lowmask_internal2(eval(($1)%4),eval(($1)/4))')')
   928  
   929  dnl  Called: m4_hex_lowmask_internal(remainder,digits)
   930  define(m4_hex_lowmask_internal2,
   931  m4_assert_numargs(2)
   932  `ifelse($1,1,`1',
   933  `ifelse($1,2,`3',
   934  `ifelse($1,3,`7')')')dnl
   935  m4_repeat($2,`f')')
   936  
   937  
   938  dnl  --------------------------------------------------------------------------
   939  dnl  The following m4_list functions take a list as multiple arguments.
   940  dnl  Arguments are evaluated multiple times, there's no attempt at strict
   941  dnl  quoting.  Empty list elements are not allowed, since an empty final
   942  dnl  argument is ignored.  These restrictions don't affect the current uses,
   943  dnl  and make the implementation easier.
   944  
   945  
   946  dnl  Usage: m4_list_quote(list,...)
   947  dnl
   948  dnl  Produce a list with quoted commas, so it can be a single argument
   949  dnl  string.  For instance m4_list_quote(a,b,c) gives
   950  dnl
   951  dnl         a`,'b`,'c`,'
   952  dnl
   953  dnl  This can be used to put a list in a define,
   954  dnl
   955  dnl         define(foolist, m4_list_quote(a,b,c))
   956  dnl
   957  dnl  Which can then be used for instance as
   958  dnl
   959  dnl         m4_list_find(target, foolist)
   960  
   961  define(m4_list_quote,
   962  `ifelse(`$1',,,
   963  `$1`,'m4_list_quote(shift($@))')')
   964  
   965  
   966  dnl  Usage: m4_list_find(key,list,...)
   967  dnl
   968  dnl  Evaluate to 1 or 0 according to whether key is in the list elements.
   969  
   970  define(m4_list_find,
   971  m4_assert_numargs_range(1,1000)
   972  `ifelse(`$2',,0,
   973  `ifelse(`$1',`$2',1,
   974  `m4_list_find(`$1',shift(shift($@)))')')')
   975  
   976  
   977  dnl  Usage: m4_list_remove(key,list,...)
   978  dnl
   979  dnl  Evaluate to the given list with `key' removed (if present).
   980  
   981  define(m4_list_remove,
   982  m4_assert_numargs_range(1,1000)
   983  `ifelse(`$2',,,
   984  `ifelse(`$1',`$2',,`$2,')dnl
   985  m4_list_remove(`$1',shift(shift($@)))')')
   986  
   987  
   988  dnl  Usage: m4_list_first(list,...)
   989  dnl
   990  dnl  Evaluate to the first element of the list (if any).
   991  
   992  define(m4_list_first,`$1')
   993  
   994  
   995  dnl  Usage: m4_list_count(list,...)
   996  dnl
   997  dnl  Evaluate to the number of elements in the list.  This can't just use $#
   998  dnl  because the last element might be empty.
   999  
  1000  define(m4_list_count,
  1001  `m4_list_count_internal(0,$@)')
  1002  
  1003  dnl  Called: m4_list_internal(count,list,...)
  1004  define(m4_list_count_internal,
  1005  m4_assert_numargs_range(1,1000)
  1006  `ifelse(`$2',,$1,
  1007  `m4_list_count_internal(eval($1+1),shift(shift($@)))')')
  1008  
  1009  
  1010  dnl  --------------------------------------------------------------------------
  1011  dnl  Various assembler things, not specific to any particular CPU.
  1012  dnl
  1013  
  1014  
  1015  dnl  Usage: include_mpn(`filename')
  1016  dnl
  1017  dnl  Like include(), but adds a path to the mpn source directory.  For
  1018  dnl  example,
  1019  dnl
  1020  dnl         include_mpn(`sparc64/addmul_1h.asm')
  1021  
  1022  define(include_mpn,
  1023  m4_assert_numargs(1)
  1024  m4_assert_defined(`CONFIG_TOP_SRCDIR')
  1025  `include(CONFIG_TOP_SRCDIR`/mpn/$1')')
  1026  
  1027  
  1028  dnl  Usage: C comment ...
  1029  dnl
  1030  dnl  This works like a FORTRAN-style comment character.  It can be used for
  1031  dnl  comments to the right of assembly instructions, where just dnl would
  1032  dnl  remove the newline and concatenate adjacent lines.
  1033  dnl
  1034  dnl  C and/or dnl are useful when an assembler doesn't support comments, or
  1035  dnl  where different assemblers for a particular CPU need different styles.
  1036  dnl  The intermediate ".s" files will end up with no comments, just code.
  1037  dnl
  1038  dnl  Using C is not intended to cause offence to anyone who doesn't like
  1039  dnl  FORTRAN; but if that happens it's an unexpected bonus.
  1040  dnl
  1041  dnl  During development, if comments are wanted in the .s files to help see
  1042  dnl  what's expanding where, C can be redefined with something like
  1043  dnl
  1044  dnl         define(`C',`#')
  1045  
  1046  define(C, `
  1047  dnl')
  1048  
  1049  
  1050  dnl  Normally PIC is defined (or not) by libtool, but it doesn't set it on
  1051  dnl  systems which are always PIC.  PIC_ALWAYS established in config.m4
  1052  dnl  identifies these for us.
  1053  
  1054  ifelse(`PIC_ALWAYS',`yes',`define(`PIC')')
  1055  
  1056  
  1057  dnl  Various possible defines passed from the Makefile that are to be tested
  1058  dnl  with ifdef() rather than be expanded.
  1059  
  1060  m4_not_for_expansion(`PIC')
  1061  m4_not_for_expansion(`DLL_EXPORT')
  1062  
  1063  dnl  aors_n
  1064  m4_not_for_expansion(`OPERATION_add_n')
  1065  m4_not_for_expansion(`OPERATION_sub_n')
  1066  
  1067  dnl  aors_err1_n
  1068  m4_not_for_expansion(`OPERATION_add_err1_n')
  1069  m4_not_for_expansion(`OPERATION_sub_err1_n')
  1070  
  1071  dnl  aors_err2_n
  1072  m4_not_for_expansion(`OPERATION_add_err2_n')
  1073  m4_not_for_expansion(`OPERATION_sub_err2_n')
  1074  
  1075  dnl  aors_err3_n
  1076  m4_not_for_expansion(`OPERATION_add_err3_n')
  1077  m4_not_for_expansion(`OPERATION_sub_err3_n')
  1078  
  1079  dnl  aorsmul_1
  1080  m4_not_for_expansion(`OPERATION_addmul_1')
  1081  m4_not_for_expansion(`OPERATION_submul_1')
  1082  
  1083  dnl  logops_n
  1084  m4_not_for_expansion(`OPERATION_and_n')
  1085  m4_not_for_expansion(`OPERATION_andn_n')
  1086  m4_not_for_expansion(`OPERATION_nand_n')
  1087  m4_not_for_expansion(`OPERATION_ior_n')
  1088  m4_not_for_expansion(`OPERATION_iorn_n')
  1089  m4_not_for_expansion(`OPERATION_nior_n')
  1090  m4_not_for_expansion(`OPERATION_xor_n')
  1091  m4_not_for_expansion(`OPERATION_xnor_n')
  1092  
  1093  dnl  popham
  1094  m4_not_for_expansion(`OPERATION_popcount')
  1095  m4_not_for_expansion(`OPERATION_hamdist')
  1096  
  1097  dnl  lorrshift
  1098  m4_not_for_expansion(`OPERATION_lshift')
  1099  m4_not_for_expansion(`OPERATION_rshift')
  1100  
  1101  dnl  aorslsh1_n
  1102  m4_not_for_expansion(`OPERATION_addlsh1_n')
  1103  m4_not_for_expansion(`OPERATION_sublsh1_n')
  1104  m4_not_for_expansion(`OPERATION_rsblsh1_n')
  1105  
  1106  dnl  aorslsh2_n
  1107  m4_not_for_expansion(`OPERATION_addlsh2_n')
  1108  m4_not_for_expansion(`OPERATION_sublsh2_n')
  1109  m4_not_for_expansion(`OPERATION_rsblsh2_n')
  1110  
  1111  dnl  rsh1aors_n
  1112  m4_not_for_expansion(`OPERATION_rsh1add_n')
  1113  m4_not_for_expansion(`OPERATION_rsh1sub_n')
  1114  
  1115  
  1116  dnl  Usage: m4_config_gmp_mparam(`symbol')
  1117  dnl
  1118  dnl  Check that `symbol' is defined.  If it isn't, issue an error and
  1119  dnl  terminate immediately.  The error message explains that the symbol
  1120  dnl  should be in config.m4, copied from gmp-mparam.h.
  1121  dnl
  1122  dnl  Termination is immediate since missing say SQR_TOOM2_THRESHOLD can
  1123  dnl  lead to infinite loops and endless error messages.
  1124  
  1125  define(m4_config_gmp_mparam,
  1126  m4_assert_numargs(1)
  1127  `ifdef(`$1',,
  1128  `m4_error(`$1 is not defined.
  1129  	"configure" should have extracted this from gmp-mparam.h and put it
  1130  	in config.m4 (or in <cpu>_<file>.asm for a fat binary), but somehow
  1131          this has failed.
  1132  ')m4exit(1)')')
  1133  
  1134  
  1135  dnl  Usage: defreg(name,reg)
  1136  dnl
  1137  dnl  Give a name to a $ style register.  For example,
  1138  dnl
  1139  dnl         defreg(foo,$12)
  1140  dnl
  1141  dnl  defreg() inserts an extra pair of quotes after the $ so that it's not
  1142  dnl  interpreted as an m4 macro parameter, ie. foo is actually $`'12.  m4
  1143  dnl  strips those quotes when foo is expanded.
  1144  dnl
  1145  dnl  deflit() is used to make the new definition, so it will expand
  1146  dnl  literally even if followed by parentheses ie. foo(99) will become
  1147  dnl  $12(99).  (But there's nowhere that would be used is there?)
  1148  dnl
  1149  dnl  When making further definitions from existing defreg() macros, remember
  1150  dnl  to use defreg() again to protect the $ in the new definitions too.  For
  1151  dnl  example,
  1152  dnl
  1153  dnl         defreg(a0,$4)
  1154  dnl         defreg(a1,$5)
  1155  dnl         ...
  1156  dnl
  1157  dnl         defreg(PARAM_DST,a0)
  1158  dnl
  1159  dnl  This is only because a0 is expanding at the time the PARAM_DST
  1160  dnl  definition is made, leaving a literal $4 that must be re-quoted.  On
  1161  dnl  the other hand in something like the following ra is only expanded when
  1162  dnl  ret is used and its $`'31 protection will have its desired effect at
  1163  dnl  that time.
  1164  dnl
  1165  dnl         defreg(ra,$31)
  1166  dnl         ...
  1167  dnl         define(ret,`j ra')
  1168  dnl
  1169  dnl  Note that only $n forms are meant to be used here, and something like
  1170  dnl  128($30) doesn't get protected and will come out wrong.
  1171  
  1172  define(defreg,
  1173  m4_assert_numargs(2)
  1174  `deflit(`$1',
  1175  substr(`$2',0,1)``''substr(`$2',1))')
  1176  
  1177  
  1178  dnl  Usage: m4_instruction_wrapper()
  1179  dnl
  1180  dnl  Put this, unquoted, on a line on its own, at the start of a macro
  1181  dnl  that's a wrapper around an assembler instruction.  It adds code to give
  1182  dnl  a descriptive error message if the macro is invoked without arguments.
  1183  dnl
  1184  dnl  For example, suppose jmp needs to be wrapped,
  1185  dnl
  1186  dnl         define(jmp,
  1187  dnl         m4_instruction_wrapper()
  1188  dnl         m4_assert_numargs(1)
  1189  dnl                 `.byte 0x42
  1190  dnl                 .long  $1
  1191  dnl                 nop')
  1192  dnl
  1193  dnl  The point of m4_instruction_wrapper is to get a better error message
  1194  dnl  than m4_assert_numargs would give if jmp is accidentally used as plain
  1195  dnl  "jmp foo" instead of the intended "jmp( foo)".  "jmp()" with no
  1196  dnl  argument also provokes the error message.
  1197  dnl
  1198  dnl  m4_instruction_wrapper should only be used with wrapped instructions
  1199  dnl  that take arguments, since obviously something meant to be used as say
  1200  dnl  plain "ret" doesn't want to give an error when used that way.
  1201  
  1202  define(m4_instruction_wrapper,
  1203  m4_assert_numargs(0)
  1204  ``m4_instruction_wrapper_internal'(m4_doublequote($`'0),dnl
  1205  ifdef(`__file__',`m4_doublequote(__file__)',``the m4 sources''),dnl
  1206  $`#',m4_doublequote($`'1))`dnl'')
  1207  
  1208  dnl  Called: m4_instruction_wrapper_internal($0,`filename',$#,$1)
  1209  define(m4_instruction_wrapper_internal,
  1210  `ifelse(eval($3<=1 && m4_length(`$4')==0),1,
  1211  `m4_error(`$1 is a macro replacing that instruction and needs arguments, see $2 for details
  1212  ')')')
  1213  
  1214  
  1215  dnl  Usage: m4_cpu_hex_constant(string)
  1216  dnl
  1217  dnl  Expand to the string prefixed by a suitable `0x' hex marker.  This
  1218  dnl  should be redefined as necessary for CPUs with different conventions.
  1219  
  1220  define(m4_cpu_hex_constant,
  1221  m4_assert_numargs(1)
  1222  `0x`$1'')
  1223  
  1224  
  1225  dnl  Usage: UNROLL_LOG2, UNROLL_MASK, UNROLL_BYTES
  1226  dnl         CHUNK_LOG2, CHUNK_MASK, CHUNK_BYTES
  1227  dnl
  1228  dnl  When code supports a variable amount of loop unrolling, the convention
  1229  dnl  is to define UNROLL_COUNT to the number of limbs processed per loop.
  1230  dnl  When testing code this can be varied to see how much the loop overhead
  1231  dnl  is costing.  For example,
  1232  dnl
  1233  dnl         deflit(UNROLL_COUNT, 32)
  1234  dnl
  1235  dnl  If the forloop() generating the unrolled loop has a pattern processing
  1236  dnl  more than one limb, the convention is to express this with CHUNK_COUNT.
  1237  dnl  For example,
  1238  dnl
  1239  dnl         deflit(CHUNK_COUNT, 2)
  1240  dnl
  1241  dnl  The LOG2, MASK and BYTES definitions below are derived from these COUNT
  1242  dnl  definitions.  If COUNT is redefined, the LOG2, MASK and BYTES follow
  1243  dnl  the new definition automatically.
  1244  dnl
  1245  dnl  LOG2 is the log base 2 of COUNT.  MASK is COUNT-1, which can be used as
  1246  dnl  a bit mask.  BYTES is GMP_LIMB_BYTES*COUNT, the number of bytes
  1247  dnl  processed in each unrolled loop.
  1248  dnl
  1249  dnl  GMP_LIMB_BYTES is defined in a CPU specific m4 include file.  It
  1250  dnl  exists only so the BYTES definitions here can be common to all CPUs.
  1251  dnl  In the actual code for a given CPU, an explicit 4 or 8 may as well be
  1252  dnl  used because the code is only for a particular CPU, it doesn't need to
  1253  dnl  be general.
  1254  dnl
  1255  dnl  Note that none of these macros do anything except give conventional
  1256  dnl  names to commonly used things.  You still have to write your own
  1257  dnl  expressions for a forloop() and the resulting address displacements.
  1258  dnl  Something like the following would be typical for 4 bytes per limb.
  1259  dnl
  1260  dnl         forloop(`i',0,UNROLL_COUNT-1,`
  1261  dnl                 deflit(`disp',eval(i*4))
  1262  dnl                 ...
  1263  dnl         ')
  1264  dnl
  1265  dnl  Or when using CHUNK_COUNT,
  1266  dnl
  1267  dnl         forloop(`i',0,UNROLL_COUNT/CHUNK_COUNT-1,`
  1268  dnl                 deflit(`disp0',eval(i*CHUNK_COUNT*4))
  1269  dnl                 deflit(`disp1',eval(disp0+4))
  1270  dnl                 ...
  1271  dnl         ')
  1272  dnl
  1273  dnl  Clearly `i' can be run starting from 1, or from high to low or whatever
  1274  dnl  best suits.
  1275  
  1276  deflit(UNROLL_LOG2,
  1277  m4_assert_defined(`UNROLL_COUNT')
  1278  `m4_log2(UNROLL_COUNT)')
  1279  
  1280  deflit(UNROLL_MASK,
  1281  m4_assert_defined(`UNROLL_COUNT')
  1282  `eval(UNROLL_COUNT-1)')
  1283  
  1284  deflit(UNROLL_BYTES,
  1285  m4_assert_defined(`UNROLL_COUNT')
  1286  m4_assert_defined(`GMP_LIMB_BYTES')
  1287  `eval(UNROLL_COUNT * GMP_LIMB_BYTES)')
  1288  
  1289  deflit(CHUNK_LOG2,
  1290  m4_assert_defined(`CHUNK_COUNT')
  1291  `m4_log2(CHUNK_COUNT)')
  1292  
  1293  deflit(CHUNK_MASK,
  1294  m4_assert_defined(`CHUNK_COUNT')
  1295  `eval(CHUNK_COUNT-1)')
  1296  
  1297  deflit(CHUNK_BYTES,
  1298  m4_assert_defined(`CHUNK_COUNT')
  1299  m4_assert_defined(`GMP_LIMB_BYTES')
  1300  `eval(CHUNK_COUNT * GMP_LIMB_BYTES)')
  1301  
  1302  
  1303  dnl  Usage: MPN(name)
  1304  dnl
  1305  dnl  Add MPN_PREFIX to a name.
  1306  dnl  MPN_PREFIX defaults to "__gmpn_" if not defined.
  1307  dnl
  1308  dnl  m4_unquote is used in MPN so that when it expands to say __gmpn_foo,
  1309  dnl  that identifier will be subject to further macro expansion.  This is
  1310  dnl  used by some of the fat binary support for renaming symbols.
  1311  
  1312  ifdef(`MPN_PREFIX',,
  1313  `define(`MPN_PREFIX',`__gmpn_')')
  1314  
  1315  define(MPN,
  1316  m4_assert_numargs(1)
  1317  `m4_unquote(MPN_PREFIX`'$1)')
  1318  
  1319  
  1320  dnl  Usage: mpn_add_n, etc
  1321  dnl
  1322  dnl  Convenience definitions using MPN(), like the #defines in gmp.h.  Each
  1323  dnl  function that might be implemented in assembler is here.
  1324  
  1325  define(define_mpn,
  1326  m4_assert_numargs(1)
  1327  `deflit(`mpn_$1',`MPN(`$1')')')
  1328  
  1329  define_mpn(add)
  1330  define_mpn(add_1)
  1331  define_mpn(add_err1_n)
  1332  define_mpn(add_err2_n)
  1333  define_mpn(add_err3_n)
  1334  define_mpn(add_n)
  1335  define_mpn(add_nc)
  1336  define_mpn(addlsh1_n)
  1337  define_mpn(addlsh1_nc)
  1338  define_mpn(addlsh2_n)
  1339  define_mpn(addlsh2_nc)
  1340  define_mpn(addlsh_n)
  1341  define_mpn(addlsh_nc)
  1342  define_mpn(addlsh1_n_ip1)
  1343  define_mpn(addlsh1_nc_ip1)
  1344  define_mpn(addlsh2_n_ip1)
  1345  define_mpn(addlsh2_nc_ip1)
  1346  define_mpn(addlsh_n_ip1)
  1347  define_mpn(addlsh_nc_ip1)
  1348  define_mpn(addlsh1_n_ip2)
  1349  define_mpn(addlsh1_nc_ip2)
  1350  define_mpn(addlsh2_n_ip2)
  1351  define_mpn(addlsh2_nc_ip2)
  1352  define_mpn(addlsh_n_ip2)
  1353  define_mpn(addlsh_nc_ip2)
  1354  define_mpn(addmul_1)
  1355  define_mpn(addmul_1c)
  1356  define_mpn(addmul_2)
  1357  define_mpn(addmul_3)
  1358  define_mpn(addmul_4)
  1359  define_mpn(addmul_5)
  1360  define_mpn(addmul_6)
  1361  define_mpn(addmul_7)
  1362  define_mpn(addmul_8)
  1363  define_mpn(addmul_2s)
  1364  define_mpn(add_n_sub_n)
  1365  define_mpn(add_n_sub_nc)
  1366  define_mpn(addaddmul_1msb0)
  1367  define_mpn(and_n)
  1368  define_mpn(andn_n)
  1369  define_mpn(bdiv_q_1)
  1370  define_mpn(pi1_bdiv_q_1)
  1371  define_mpn(bdiv_dbm1c)
  1372  define_mpn(cmp)
  1373  define_mpn(cnd_add_n)
  1374  define_mpn(cnd_sub_n)
  1375  define_mpn(com)
  1376  define_mpn(copyd)
  1377  define_mpn(copyi)
  1378  define_mpn(count_leading_zeros)
  1379  define_mpn(count_trailing_zeros)
  1380  define_mpn(div_qr_1n_pi1)
  1381  define_mpn(div_qr_2)
  1382  define_mpn(div_qr_2n_pi1)
  1383  define_mpn(div_qr_2u_pi1)
  1384  define_mpn(div_qr_2n_pi2)
  1385  define_mpn(div_qr_2u_pi2)
  1386  define_mpn(divexact_1)
  1387  define_mpn(divexact_by3c)
  1388  define_mpn(divrem)
  1389  define_mpn(divrem_1)
  1390  define_mpn(divrem_1c)
  1391  define_mpn(divrem_2)
  1392  define_mpn(divrem_classic)
  1393  define_mpn(divrem_newton)
  1394  define_mpn(dump)
  1395  define_mpn(gcd)
  1396  define_mpn(gcd_1)
  1397  define_mpn(gcdext)
  1398  define_mpn(get_str)
  1399  define_mpn(hamdist)
  1400  define_mpn(invert_limb)
  1401  define_mpn(invert_limb_table)
  1402  define_mpn(ior_n)
  1403  define_mpn(iorn_n)
  1404  define_mpn(lshift)
  1405  define_mpn(lshiftc)
  1406  define_mpn(mod_1_1p)
  1407  define_mpn(mod_1_1p_cps)
  1408  define_mpn(mod_1s_2p)
  1409  define_mpn(mod_1s_2p_cps)
  1410  define_mpn(mod_1s_3p)
  1411  define_mpn(mod_1s_3p_cps)
  1412  define_mpn(mod_1s_4p)
  1413  define_mpn(mod_1s_4p_cps)
  1414  define_mpn(mod_1)
  1415  define_mpn(mod_1c)
  1416  define_mpn(mod_34lsub1)
  1417  define_mpn(modexact_1_odd)
  1418  define_mpn(modexact_1c_odd)
  1419  define_mpn(mul)
  1420  define_mpn(mul_1)
  1421  define_mpn(mul_1c)
  1422  define_mpn(mul_2)
  1423  define_mpn(mul_3)
  1424  define_mpn(mul_4)
  1425  define_mpn(mul_5)
  1426  define_mpn(mul_6)
  1427  define_mpn(mul_basecase)
  1428  define_mpn(mul_n)
  1429  define_mpn(mullo_basecase)
  1430  define_mpn(mulmid_basecase)
  1431  define_mpn(perfect_square_p)
  1432  define_mpn(popcount)
  1433  define_mpn(preinv_divrem_1)
  1434  define_mpn(preinv_mod_1)
  1435  define_mpn(nand_n)
  1436  define_mpn(neg)
  1437  define_mpn(nior_n)
  1438  define_mpn(powm)
  1439  define_mpn(powlo)
  1440  define_mpn(random)
  1441  define_mpn(random2)
  1442  define_mpn(redc_1)
  1443  define_mpn(redc_2)
  1444  define_mpn(rsblsh1_n)
  1445  define_mpn(rsblsh1_nc)
  1446  define_mpn(rsblsh2_n)
  1447  define_mpn(rsblsh2_nc)
  1448  define_mpn(rsblsh_n)
  1449  define_mpn(rsblsh_nc)
  1450  define_mpn(rsh1add_n)
  1451  define_mpn(rsh1add_nc)
  1452  define_mpn(rsh1sub_n)
  1453  define_mpn(rsh1sub_nc)
  1454  define_mpn(rshift)
  1455  define_mpn(rshiftc)
  1456  define_mpn(scan0)
  1457  define_mpn(scan1)
  1458  define_mpn(set_str)
  1459  define_mpn(sqr_basecase)
  1460  define_mpn(sqr_diagonal)
  1461  define_mpn(sqr_diag_addlsh1)
  1462  define_mpn(sub_n)
  1463  define_mpn(sublsh1_n)
  1464  define_mpn(sublsh1_nc)
  1465  define_mpn(sublsh1_n_ip1)
  1466  define_mpn(sublsh1_nc_ip1)
  1467  define_mpn(sublsh2_n)
  1468  define_mpn(sublsh2_nc)
  1469  define_mpn(sublsh2_n_ip1)
  1470  define_mpn(sublsh2_nc_ip1)
  1471  define_mpn(sublsh_n)
  1472  define_mpn(sublsh_nc)
  1473  define_mpn(sublsh_n_ip1)
  1474  define_mpn(sublsh_nc_ip1)
  1475  define_mpn(sqrtrem)
  1476  define_mpn(sub)
  1477  define_mpn(sub_1)
  1478  define_mpn(sub_err1_n)
  1479  define_mpn(sub_err2_n)
  1480  define_mpn(sub_err3_n)
  1481  define_mpn(sub_n)
  1482  define_mpn(sub_nc)
  1483  define_mpn(submul_1)
  1484  define_mpn(submul_1c)
  1485  define_mpn(sec_tabselect)
  1486  define_mpn(umul_ppmm)
  1487  define_mpn(umul_ppmm_r)
  1488  define_mpn(udiv_qrnnd)
  1489  define_mpn(udiv_qrnnd_r)
  1490  define_mpn(xnor_n)
  1491  define_mpn(xor_n)
  1492  
  1493  
  1494  dnl  Defines for C global arrays and variables, with names matching what's
  1495  dnl  used in the C code.
  1496  dnl
  1497  dnl  Notice that GSYM_PREFIX is included, unlike with the function defines
  1498  dnl  above.  Also, "deflit" is used so that something like __clz_tab(%ebx)
  1499  dnl  comes out as __gmpn_clz_tab(%ebx), for the benefit of CPUs with that
  1500  dnl  style assembler syntax.
  1501  
  1502  deflit(__clz_tab,
  1503  m4_assert_defined(`GSYM_PREFIX')
  1504  `GSYM_PREFIX`'MPN(`clz_tab')')
  1505  
  1506  deflit(binvert_limb_table,
  1507  m4_assert_defined(`GSYM_PREFIX')
  1508  `GSYM_PREFIX`'__gmp_binvert_limb_table')
  1509  
  1510  
  1511  dnl  Usage: ASM_START()
  1512  dnl
  1513  dnl  Emit any directives needed once at the start of an assembler file, like
  1514  dnl  ".set noreorder" or whatever.  The default for this is nothing, but
  1515  dnl  it's redefined by CPU specific m4 files.
  1516  
  1517  define(ASM_START)
  1518  
  1519  
  1520  dnl  Usage: ASM_END()
  1521  dnl
  1522  dnl  Emit any directives needed once at the end of an assembler file.  The
  1523  dnl  default for this is nothing, but it's redefined by CPU specific m4 files.
  1524  
  1525  define(ASM_END)
  1526  
  1527  
  1528  dnl  Usage: PROLOGUE(foo[,param])
  1529  dnl         EPILOGUE(foo)
  1530  dnl
  1531  dnl  Emit directives to start or end a function.  GSYM_PREFIX is added by
  1532  dnl  these macros if necessary, so the given "foo" is what the function will
  1533  dnl  be called in C.
  1534  dnl
  1535  dnl  The second parameter to PROLOGUE is used only for some CPUs and should
  1536  dnl  be omitted if not required.
  1537  dnl
  1538  dnl  Nested or overlapping PROLOGUE/EPILOGUE pairs are allowed, if that
  1539  dnl  makes sense for the system.  The name given to EPILOGUE must be a
  1540  dnl  currently open PROLOGUE.
  1541  dnl
  1542  dnl  If only one PROLOGUE is open then the name can be omitted from
  1543  dnl  EPILOGUE.  This is encouraged, since it means the name only has to
  1544  dnl  appear in one place, not two.
  1545  dnl
  1546  dnl  The given name "foo" is not fully quoted here, it will be macro
  1547  dnl  expanded more than once.  This is the way the m4_list macros work, and
  1548  dnl  it also helps the tune/many.pl program do a renaming like
  1549  dnl  -D__gmpn_add_n=mpn_add_n_foo when GSYM_PREFIX is not empty.
  1550  
  1551  define(PROLOGUE,
  1552  m4_assert_numargs_range(1,2)
  1553  `m4_file_seen()dnl
  1554  define(`PROLOGUE_list',m4_list_quote($1,PROLOGUE_list))dnl
  1555  ifelse(`$2',,
  1556  `PROLOGUE_cpu(GSYM_PREFIX`'$1)',
  1557  `PROLOGUE_cpu(GSYM_PREFIX`'$1,`$2')')')
  1558  
  1559  define(EPILOGUE,
  1560  m4_assert_numargs_range(0,1)
  1561  `ifelse(`$1',,
  1562  `ifelse(m4_list_count(PROLOGUE_list),0,
  1563  `m4_error(`no open functions for EPILOGUE
  1564  ')',
  1565  `ifelse(m4_list_count(PROLOGUE_list),1,
  1566  `EPILOGUE_internal(PROLOGUE_current_function)',
  1567  `m4_error(`more than one open function for EPILOGUE
  1568  ')')')',
  1569  `EPILOGUE_internal(`$1')')')
  1570  
  1571  define(EPILOGUE_internal,
  1572  m4_assert_numargs(1)
  1573  m4_assert_defined(`EPILOGUE_cpu')
  1574  `ifelse(m4_list_find($1,PROLOGUE_list),0,
  1575  `m4_error(`EPILOGUE without PROLOGUE: $1
  1576  ')')dnl
  1577  define(`PROLOGUE_list',m4_list_quote(m4_list_remove($1,PROLOGUE_list)))dnl
  1578  EPILOGUE_cpu(GSYM_PREFIX`$1')')
  1579  
  1580  dnl  Currently open PROLOGUEs, as a comma-separated list.
  1581  define(PROLOGUE_list)
  1582  
  1583  
  1584  dnl  Called: PROLOGUE_check(list,...)
  1585  dnl  Check there's no remaining open PROLOGUEs at the end of input.
  1586  define(PROLOGUE_check,
  1587  `ifelse($1,,,
  1588  `m4_error(`no EPILOGUE for: $1
  1589  ')dnl
  1590  PROLOGUE_check(shift($@))')')
  1591  
  1592  m4wrap_prepend(`PROLOGUE_check(PROLOGUE_list)')
  1593  
  1594  
  1595  dnl  Usage: PROLOGUE_current_function
  1596  dnl
  1597  dnl  This macro expands to the current PROLOGUE/EPILOGUE function, or the
  1598  dnl  most recent PROLOGUE if such pairs are nested or overlapped.
  1599  
  1600  define(PROLOGUE_current_function,
  1601  m4_assert_numargs(-1)
  1602  `m4_list_first(PROLOGUE_list)')
  1603  
  1604  
  1605  dnl  Usage: PROLOGUE_cpu(GSYM_PREFIX`'foo[,param])
  1606  dnl         EPILOGUE_cpu(GSYM_PREFIX`'foo)
  1607  dnl
  1608  dnl  These macros hold the CPU-specific parts of PROLOGUE and EPILOGUE.
  1609  dnl  Both are called with the function name, with GSYM_PREFIX already
  1610  dnl  prepended.
  1611  dnl
  1612  dnl  The definitions here are something typical and sensible, but CPU or
  1613  dnl  system specific m4 files should redefine them as necessary.  The
  1614  dnl  optional extra parameter to PROLOGUE_cpu is not expected and not
  1615  dnl  accepted here.
  1616  
  1617  define(PROLOGUE_cpu,
  1618  m4_assert_numargs(1)
  1619  `	TEXT
  1620  	ALIGN(8)
  1621  	GLOBL	`$1' GLOBL_ATTR
  1622  	TYPE(`$1',`function')
  1623  `$1'LABEL_SUFFIX')
  1624  
  1625  define(EPILOGUE_cpu,
  1626  `	SIZE(`$1',.-`$1')')
  1627  
  1628  
  1629  dnl  Usage: L(name)
  1630  dnl
  1631  dnl  Generate a local label with the given name.  This is simply a
  1632  dnl  convenient way to add LSYM_PREFIX.
  1633  dnl
  1634  dnl  LSYM_PREFIX might be L$, so defn() must be used to quote it or the L
  1635  dnl  will expand again as the L macro, making an infinite recursion.
  1636  
  1637  define(`L',
  1638  m4_assert_numargs(1)
  1639  `defn(`LSYM_PREFIX')$1')
  1640  
  1641  
  1642  dnl  Usage: LDEF(name)
  1643  dnl
  1644  dnl  Generate a directive to define a local label.
  1645  dnl
  1646  dnl  On systems with a fixed syntax for defining labels there's no need to
  1647  dnl  use this macro, it's only meant for systems where the syntax varies,
  1648  dnl  like hppa which is "L(foo):" with gas, but just "L(foo)" in column 0
  1649  dnl  with the system `as'.
  1650  dnl
  1651  dnl  The extra `' after LABEL_SUFFIX avoids any chance of a following
  1652  dnl  "(...)"  being interpreted as an argument list.  Not that it'd be
  1653  dnl  sensible to write anything like that after an LDEF(), but just in case.
  1654  
  1655  define(LDEF,
  1656  m4_assert_numargs(1)
  1657  m4_assert_defined(`LABEL_SUFFIX')
  1658  `L(`$1')`'LABEL_SUFFIX`'')
  1659  
  1660  
  1661  dnl  Usage: INT32(label,value)
  1662  dnl         INT64(label,first,second)
  1663  
  1664  define(`INT32',
  1665  m4_assert_defined(`W32')
  1666  `	ALIGN(4)
  1667  LDEF(`$1')
  1668  	W32	$2')
  1669  
  1670  define(`INT64',
  1671  m4_assert_defined(`W32')
  1672  `	ALIGN(8)
  1673  LDEF(`$1')
  1674  	W32	$2
  1675  	W32	$3')
  1676  
  1677  
  1678  dnl  Usage: ALIGN(bytes)
  1679  dnl
  1680  dnl  Emit a ".align" directive.  The alignment is specified in bytes, and
  1681  dnl  will normally need to be a power of 2.  The actual ".align" generated
  1682  dnl  is either bytes or logarithmic according to what ./configure finds the
  1683  dnl  assembler needs.
  1684  dnl
  1685  dnl  If ALIGN_FILL_0x90 is defined and equal to "yes", then ", 0x90" is
  1686  dnl  appended.  This is for x86, see mpn/x86/README.
  1687  
  1688  define(ALIGN,
  1689  m4_assert_numargs(1)
  1690  m4_assert_defined(`ALIGN_LOGARITHMIC')
  1691  `.align	ifelse(ALIGN_LOGARITHMIC,yes,`m4_log2($1)',`eval($1)')dnl
  1692  ifelse(ALIGN_FILL_0x90,yes,`, 0x90')')
  1693  
  1694  
  1695  dnl  Usage: MULFUNC_PROLOGUE(function function...)
  1696  dnl
  1697  dnl  A dummy macro which is grepped for by ./configure to know what
  1698  dnl  functions a multi-function file is providing.  Use this if there aren't
  1699  dnl  explicit PROLOGUE()s for each possible function.
  1700  dnl
  1701  dnl  Multiple MULFUNC_PROLOGUEs can be used, or just one with the function
  1702  dnl  names separated by spaces.
  1703  
  1704  define(`MULFUNC_PROLOGUE',
  1705  m4_assert_numargs(1)
  1706  )
  1707  
  1708  
  1709  dnl  Usage: NAILS_SUPPORT(spec spec ...)
  1710  dnl
  1711  dnl  A dummy macro which is grepped for by ./configure to know what nails
  1712  dnl  are supported in an asm file.
  1713  dnl
  1714  dnl  Ranges can be given, or just individual values.  Multiple values or
  1715  dnl  ranges can be given, separated by spaces.  Multiple NAILS_SUPPORT
  1716  dnl  declarations work too.  Some examples,
  1717  dnl
  1718  dnl         NAILS_SUPPORT(1-20)
  1719  dnl         NAILS_SUPPORT(1 6 9-12)
  1720  dnl         NAILS_SUPPORT(1-10 16-20)
  1721  
  1722  define(NAILS_SUPPORT,
  1723  m4_assert_numargs(1)
  1724  )
  1725  
  1726  
  1727  dnl  Usage: ABI_SUPPORT(abi)
  1728  dnl
  1729  dnl  A dummy macro which is grepped for by ./configure to know what ABIs
  1730  dnl  are supported in an asm file.
  1731  dnl
  1732  dnl  If multiple non-standard ABIs are supported, several ABI_SUPPORT
  1733  dnl  declarations should be used:
  1734  dnl
  1735  dnl         ABI_SUPPORT(FOOABI)
  1736  dnl         ABI_SUPPORT(BARABI)
  1737  
  1738  define(ABI_SUPPORT,
  1739  m4_assert_numargs(1)
  1740  )
  1741  
  1742  
  1743  dnl  Usage: GMP_NUMB_MASK
  1744  dnl
  1745  dnl  A bit mask for the number part of a limb.  Eg. with 6 bit nails in a
  1746  dnl  32 bit limb, GMP_NUMB_MASK would be 0x3ffffff.
  1747  
  1748  define(GMP_NUMB_MASK,
  1749  m4_assert_numargs(-1)
  1750  m4_assert_defined(`GMP_NUMB_BITS')
  1751  `m4_hex_lowmask(GMP_NUMB_BITS)')
  1752  
  1753  
  1754  dnl  Usage: m4append(`variable',`value-to-append')
  1755  
  1756  define(`m4append',
  1757  `define(`$1',  defn(`$1')`$2')
  1758  '
  1759  )
  1760  
  1761  divert`'dnl