float_va.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* Area: fp and variadics
  2. Purpose: check fp inputs and returns work on variadics, even the fixed params
  3. Limitations: None
  4. PR: none
  5. Originator: <david.gilbert@linaro.org> 2011-01-25
  6. Intended to stress the difference in ABI on ARM vfp
  7. */
  8. /* { dg-do run } */
  9. #include <stdarg.h>
  10. #include "ffitest.h"
  11. /* prints out all the parameters, and returns the sum of them all.
  12. * 'x' is the number of variadic parameters all of which are double in this test
  13. */
  14. double float_va_fn(unsigned int x, double y,...)
  15. {
  16. double total=0.0;
  17. va_list ap;
  18. unsigned int i;
  19. total+=(double)x;
  20. total+=y;
  21. printf("%u: %.1f :", x, y);
  22. va_start(ap, y);
  23. for(i=0;i<x;i++)
  24. {
  25. double arg=va_arg(ap, double);
  26. total+=arg;
  27. printf(" %d:%.1f ", i, arg);
  28. }
  29. va_end(ap);
  30. printf(" total: %.1f\n", total);
  31. return total;
  32. }
  33. int main (void)
  34. {
  35. ffi_cif cif;
  36. ffi_type *arg_types[5];
  37. void *values[5];
  38. double doubles[5];
  39. unsigned int firstarg;
  40. double resfp;
  41. /* First test, pass float_va_fn(0,2.0) - note there are no actual
  42. * variadic parameters, but it's declared variadic so the ABI may be
  43. * different. */
  44. /* Call it statically and then via ffi */
  45. resfp=float_va_fn(0,2.0);
  46. /* { dg-output "0: 2.0 : total: 2.0" } */
  47. printf("compiled: %.1f\n", resfp);
  48. /* { dg-output "\ncompiled: 2.0" } */
  49. arg_types[0] = &ffi_type_uint;
  50. arg_types[1] = &ffi_type_double;
  51. arg_types[2] = NULL;
  52. CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 2, 2,
  53. &ffi_type_double, arg_types) == FFI_OK);
  54. firstarg = 0;
  55. doubles[0] = 2.0;
  56. values[0] = &firstarg;
  57. values[1] = &doubles[0];
  58. ffi_call(&cif, FFI_FN(float_va_fn), &resfp, values);
  59. /* { dg-output "\n0: 2.0 : total: 2.0" } */
  60. printf("ffi: %.1f\n", resfp);
  61. /* { dg-output "\nffi: 2.0" } */
  62. /* Second test, float_va_fn(2,2.0,3.0,4.0), now with variadic params */
  63. /* Call it statically and then via ffi */
  64. resfp=float_va_fn(2,2.0,3.0,4.0);
  65. /* { dg-output "\n2: 2.0 : 0:3.0 1:4.0 total: 11.0" } */
  66. printf("compiled: %.1f\n", resfp);
  67. /* { dg-output "\ncompiled: 11.0" } */
  68. arg_types[0] = &ffi_type_uint;
  69. arg_types[1] = &ffi_type_double;
  70. arg_types[2] = &ffi_type_double;
  71. arg_types[3] = &ffi_type_double;
  72. arg_types[4] = NULL;
  73. CHECK(ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 2, 4,
  74. &ffi_type_double, arg_types) == FFI_OK);
  75. firstarg = 2;
  76. doubles[0] = 2.0;
  77. doubles[1] = 3.0;
  78. doubles[2] = 4.0;
  79. values[0] = &firstarg;
  80. values[1] = &doubles[0];
  81. values[2] = &doubles[1];
  82. values[3] = &doubles[2];
  83. ffi_call(&cif, FFI_FN(float_va_fn), &resfp, values);
  84. /* { dg-output "\n2: 2.0 : 0:3.0 1:4.0 total: 11.0" } */
  85. printf("ffi: %.1f\n", resfp);
  86. /* { dg-output "\nffi: 11.0" } */
  87. exit(0);
  88. }