annotate test/sign/sign.c @ 0:3e629dc19168

initial from svn dyncall-1745
author Daniel Adler
date Thu, 19 Mar 2015 22:24:28 +0100
parents
children f5577f6bf97a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
1 /*
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
2
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
3 Package: dyncall
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
4 Library: test
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
5 File: test/sign/sign.c
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
6 Description:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
7 License:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
8
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
9 Copyright (c) 2011-2015 Daniel Adler <dadler@uni-goettingen.de>,
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
10 Tassilo Philipp <tphilipp@potion-studios.com>
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
11
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
12 Permission to use, copy, modify, and distribute this software for any
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
13 purpose with or without fee is hereby granted, provided that the above
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
14 copyright notice and this permission notice appear in all copies.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
15
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
16 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
17 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
18 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
19 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
23
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
24 */
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
25
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
26
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
27 #include "dyncall.h"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
28 #include "../common/platformInit.h"
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
29
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
30 // This program demonstrates the need for 'unsigned' integers and the
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
31 // ability to implement zero/sign extensions for small integers.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
32 // This test program indicates failure on powerpc 32-bit with
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
33 // compiler optimizations enabled (e.g. '-O2' compilation flags).
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
34 //
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
35 // A fix to be incorporated in the API is also given.
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
36 //
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
37
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
38 int add1s(unsigned short x) { return x + 1; }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
39
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
40 // API BUGFIX:
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
41 #define dcArgUShort(vm,x) dcArgInt(vm,(int)(unsigned int)(x))
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
42
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
43 // OLD TEST: int add1(unsigned char x) { return x + 1; }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
44
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
45 int main(int argc, char* argv[])
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
46 {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
47 DCCallVM* vm;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
48 int result;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
49 int total;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
50 vm = dcNewCallVM(4096);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
51 dcReset(vm);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
52
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
53 dcArgShort(vm, 0xFFFF );
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
54 result = dcCallInt( vm, &add1s );
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
55 total = (result == 0x10000);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
56 printf("result: sign: %d\n", total);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
57
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
58 if (!total) {
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
59 //
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
60 // TEST BUGFIX: use instead..
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
61 //
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
62 dcReset(vm);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
63 dcArgUShort( vm, 0xFFFF );
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
64 result = dcCallInt( vm, &add1s );
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
65 total = (result == 0x10000);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
66 printf("result: sign (bugfix): %d\n", total);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
67 }
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
68
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
69 // result = dcCallInt( vm, &add1s );
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
70 // total = (result == 0x10000);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
71
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
72 // OLD TEST: updated to using 'short'
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
73 // dcArgChar( vm, (char) 255 );
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
74 // result = dcCallInt( vm, &add1 );
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
75 // total = (result == 256);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
76
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
77 // printf("result: sign: %d\n", total);
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
78 return 0;
3e629dc19168 initial from svn dyncall-1745
Daniel Adler
parents:
diff changeset
79 }