OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [libffi/] [testsuite/] [libffi.call/] [cls_multi_ushort.c] - Blame information for rev 820

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 732 jeremybenn
/* Area:        ffi_call, closure_call
2
   Purpose:     Check passing of multiple unsigned short values.
3
   Limitations: none.
4
   PR:          PR13221.
5
   Originator:  <andreast@gcc.gnu.org> 20031129  */
6
 
7
/* { dg-do run } */
8
#include "ffitest.h"
9
 
10
unsigned short test_func_fn(unsigned short a1, unsigned short a2)
11
{
12
  unsigned short result;
13
 
14
  result = a1 + a2;
15
 
16
  printf("%d %d: %d\n", a1, a2, result);
17
 
18
  return result;
19
 
20
}
21
 
22
static void test_func_gn(ffi_cif *cif __UNUSED__, void *rval, void **avals,
23
                         void *data __UNUSED__)
24
{
25
  unsigned short a1, a2;
26
 
27
  a1 = *(unsigned short *)avals[0];
28
  a2 = *(unsigned short *)avals[1];
29
 
30
  *(ffi_arg *)rval = test_func_fn(a1, a2);
31
 
32
}
33
 
34
typedef unsigned short (*test_type)(unsigned short, unsigned short);
35
 
36
int main (void)
37
{
38
  ffi_cif cif;
39
  void *code;
40
  ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code);
41
  void * args_dbl[3];
42
  ffi_type * cl_arg_types[3];
43
  ffi_arg res_call;
44
  unsigned short a, b, res_closure;
45
 
46
  a = 2;
47
  b = 32765;
48
 
49
  args_dbl[0] = &a;
50
  args_dbl[1] = &b;
51
  args_dbl[2] = NULL;
52
 
53
  cl_arg_types[0] = &ffi_type_ushort;
54
  cl_arg_types[1] = &ffi_type_ushort;
55
  cl_arg_types[2] = NULL;
56
 
57
  /* Initialize the cif */
58
  CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2,
59
                     &ffi_type_ushort, cl_arg_types) == FFI_OK);
60
 
61
  ffi_call(&cif, FFI_FN(test_func_fn), &res_call, args_dbl);
62
  /* { dg-output "2 32765: 32767" } */
63
  printf("res: %d\n", (unsigned short)res_call);
64
  /* { dg-output "\nres: 32767" } */
65
 
66
  CHECK(ffi_prep_closure_loc(pcl, &cif, test_func_gn, NULL, code)  == FFI_OK);
67
 
68
  res_closure = (*((test_type)code))(2, 32765);
69
  /* { dg-output "\n2 32765: 32767" } */
70
  printf("res: %d\n", res_closure);
71
  /* { dg-output "\nres: 32767" } */
72
 
73
  exit(0);
74
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.