cls_many_mixed_float_double.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* Area: closure_call
  2. Purpose: Check register allocation for closure calls with many float and double arguments
  3. Limitations: none.
  4. PR: none.
  5. Originator: <david.schneider@picle.org> */
  6. /* { dg-do run } */
  7. #include "ffitest.h"
  8. #include <float.h>
  9. #include <math.h>
  10. #define NARGS 16
  11. static void cls_mixed_float_double_fn(ffi_cif* cif , void* ret, void** args,
  12. void* userdata __UNUSED__)
  13. {
  14. double r = 0;
  15. unsigned int i;
  16. double t;
  17. for(i=0; i < cif->nargs; i++)
  18. {
  19. if(cif->arg_types[i] == &ffi_type_double) {
  20. t = *(((double**)(args))[i]);
  21. } else {
  22. t = *(((float**)(args))[i]);
  23. }
  24. r += t;
  25. }
  26. *((double*)ret) = r;
  27. }
  28. typedef double (*cls_mixed)(double, float, double, double, double, double, double, float, float, double, float, float);
  29. int main (void)
  30. {
  31. ffi_cif cif;
  32. ffi_closure *closure;
  33. void* code;
  34. ffi_type *argtypes[12] = {&ffi_type_double, &ffi_type_float, &ffi_type_double,
  35. &ffi_type_double, &ffi_type_double, &ffi_type_double,
  36. &ffi_type_double, &ffi_type_float, &ffi_type_float,
  37. &ffi_type_double, &ffi_type_float, &ffi_type_float};
  38. closure = ffi_closure_alloc(sizeof(ffi_closure), (void**)&code);
  39. if(closure ==NULL)
  40. abort();
  41. CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 12, &ffi_type_double, argtypes) == FFI_OK);
  42. CHECK(ffi_prep_closure_loc(closure, &cif, cls_mixed_float_double_fn, NULL, code) == FFI_OK);
  43. double ret = ((cls_mixed)code)(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1.0, 1.1, 1.2);
  44. ffi_closure_free(closure);
  45. if(fabs(ret - 7.8) < FLT_EPSILON)
  46. exit(0);
  47. else
  48. abort();
  49. }