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