(root)/
gmp-6.3.0/
tests/
mpn/
t-asmtype.c
       1  /* Test .type directives on assembler functions.
       2  
       3  Copyright 2001 Free Software Foundation, Inc.
       4  
       5  This file is part of the GNU MP Library test suite.
       6  
       7  The GNU MP Library test suite is free software; you can redistribute it
       8  and/or modify it under the terms of the GNU General Public License as
       9  published by the Free Software Foundation; either version 3 of the License,
      10  or (at your option) any later version.
      11  
      12  The GNU MP Library test suite is distributed in the hope that it will be
      13  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
      14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
      15  Public License for more details.
      16  
      17  You should have received a copy of the GNU General Public License along with
      18  the GNU MP Library test suite.  If not, see https://www.gnu.org/licenses/.  */
      19  
      20  #include <stdio.h>
      21  #include <stdlib.h>
      22  
      23  #include "gmp-impl.h"
      24  
      25  #include "tests.h"
      26  
      27  
      28  /* This apparently trivial test is designed to detect missing .type and
      29     .size directives in asm code, per the problem described under
      30     GMP_ASM_TYPE in acinclude.m4.
      31  
      32     A failure can be provoked in a shared or shared+static build by making
      33     TYPE and SIZE in config.m4 empty, either by editing it or by configuring
      34     with
      35  
      36         ./configure gmp_cv_asm_type= gmp_cv_asm_size=
      37  
      38     mpn_add_n is used for the test because normally it's implemented in
      39     assembler on a CPU that has any asm code.
      40  
      41     Enhancement: As noted with GMP_ASM_TYPE, if .type is wrong but .size is
      42     right then everything works, but uses code copied down to the mainline
      43     data area.  Maybe we could detect that if we built a test library with an
      44     object that had .size deliberately disabled.  */
      45  
      46  int
      47  main (void)
      48  {
      49    static const mp_limb_t x[3]    = { 1, 2, 3 };
      50    static const mp_limb_t y[3]    = { 4, 5, 6 };
      51    static const mp_limb_t want[3] = { 5, 7, 9 };
      52    mp_limb_t  got[3];
      53  
      54    mpn_add_n (got, x, y, (mp_size_t) 3);
      55  
      56    if (refmpn_cmp (got, want, (mp_size_t) 3) != 0)
      57      {
      58        printf ("Wrong result from mpn_add_n\n");
      59        abort ();
      60      }
      61  
      62    exit (0);
      63  }