cls_longdouble.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /* Area: ffi_call, closure_call
  2. Purpose: Check long double arguments.
  3. Limitations: none.
  4. PR: none.
  5. Originator: Blake Chaffin */
  6. /* This test is known to PASS on armv7l-unknown-linux-gnueabihf, so I have
  7. remove the xfail for arm*-*-* below, until we know more. */
  8. /* { dg-do run { xfail strongarm*-*-* xscale*-*-* } } */
  9. /* { dg-options -mlong-double-128 { target powerpc64*-*-linux* } } */
  10. #include "ffitest.h"
  11. long double cls_ldouble_fn(
  12. long double a1,
  13. long double a2,
  14. long double a3,
  15. long double a4,
  16. long double a5,
  17. long double a6,
  18. long double a7,
  19. long double a8)
  20. {
  21. long double r = a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8;
  22. printf("%Lg %Lg %Lg %Lg %Lg %Lg %Lg %Lg: %Lg\n",
  23. a1, a2, a3, a4, a5, a6, a7, a8, r);
  24. return r;
  25. }
  26. static void
  27. cls_ldouble_gn(ffi_cif* cif __UNUSED__, void* resp,
  28. void** args, void* userdata __UNUSED__)
  29. {
  30. long double a1 = *(long double*)args[0];
  31. long double a2 = *(long double*)args[1];
  32. long double a3 = *(long double*)args[2];
  33. long double a4 = *(long double*)args[3];
  34. long double a5 = *(long double*)args[4];
  35. long double a6 = *(long double*)args[5];
  36. long double a7 = *(long double*)args[6];
  37. long double a8 = *(long double*)args[7];
  38. *(long double*)resp = cls_ldouble_fn(
  39. a1, a2, a3, a4, a5, a6, a7, a8);
  40. }
  41. int main(void)
  42. {
  43. ffi_cif cif;
  44. void* code;
  45. ffi_closure* pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
  46. void* args[9];
  47. ffi_type* arg_types[9];
  48. long double res = 0;
  49. long double arg1 = 1;
  50. long double arg2 = 2;
  51. long double arg3 = 3;
  52. long double arg4 = 4;
  53. long double arg5 = 5;
  54. long double arg6 = 6;
  55. long double arg7 = 7;
  56. long double arg8 = 8;
  57. arg_types[0] = &ffi_type_longdouble;
  58. arg_types[1] = &ffi_type_longdouble;
  59. arg_types[2] = &ffi_type_longdouble;
  60. arg_types[3] = &ffi_type_longdouble;
  61. arg_types[4] = &ffi_type_longdouble;
  62. arg_types[5] = &ffi_type_longdouble;
  63. arg_types[6] = &ffi_type_longdouble;
  64. arg_types[7] = &ffi_type_longdouble;
  65. arg_types[8] = NULL;
  66. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 8, &ffi_type_longdouble,
  67. arg_types) == FFI_OK);
  68. args[0] = &arg1;
  69. args[1] = &arg2;
  70. args[2] = &arg3;
  71. args[3] = &arg4;
  72. args[4] = &arg5;
  73. args[5] = &arg6;
  74. args[6] = &arg7;
  75. args[7] = &arg8;
  76. args[8] = NULL;
  77. ffi_call(&cif, FFI_FN(cls_ldouble_fn), &res, args);
  78. /* { dg-output "1 2 3 4 5 6 7 8: 36" } */
  79. printf("res: %Lg\n", res);
  80. /* { dg-output "\nres: 36" } */
  81. CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ldouble_gn, NULL, code) == FFI_OK);
  82. res = ((long double(*)(long double, long double, long double, long double,
  83. long double, long double, long double, long double))(code))(arg1, arg2,
  84. arg3, arg4, arg5, arg6, arg7, arg8);
  85. /* { dg-output "\n1 2 3 4 5 6 7 8: 36" } */
  86. printf("res: %Lg\n", res);
  87. /* { dg-output "\nres: 36" } */
  88. return 0;
  89. }