source: mainline/uspace/app/tester/float/softfloat1.c@ 289fa65

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 289fa65 was b6636dc, checked in by Martin Decky <martin@…>, 13 years ago

implement a basic softfloat unit test (currently failing)
resurrect an old kernel floating point test and port it to user space

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/*
2 * Copyright (c) 2012 Martin Decky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <stdio.h>
30#include <stdlib.h>
31#include <sftypes.h>
32#include <add.h>
33#include <bool.h>
34#include "../tester.h"
35
36#define OPERANDS 5
37#define PRECISION 10000
38
39#define PRIdCMPTYPE PRId32
40
41typedef int32_t cmptype_t;
42
43static float float_op_a[OPERANDS] =
44 {3.5, -2.1, 100.0, 50.0, -1024.0};
45
46static float float_op_b[OPERANDS] =
47 {-2.1, 100.0, 50.0, -1024.0, 3.5};
48
49static cmptype_t cmpabs(cmptype_t a)
50{
51 if (a >= 0)
52 return a;
53
54 return -a;
55}
56
57static bool test_float_add(void)
58{
59 bool correct = true;
60
61 for (unsigned int i = 0; i < OPERANDS; i++) {
62 for (unsigned int j = 0; j < OPERANDS; j++) {
63 float a = float_op_a[i];
64 float b = float_op_b[j];
65 float c = a + b;
66
67 float_t sa;
68 float_t sb;
69 float_t sc;
70
71 sa.val = float_op_a[i];
72 sb.val = float_op_b[i];
73 sc.data = add_float(sa.data, sb.data);
74
75 cmptype_t ic = (cmptype_t) (c * PRECISION);
76 cmptype_t isc = (cmptype_t) (sc.val * PRECISION);
77 cmptype_t diff = cmpabs(ic - isc);
78
79 if (diff != 0) {
80 TPRINTF("i=%u, j=%u diff=%" PRIdCMPTYPE "\n", i, j, diff);
81 correct = false;
82 }
83 }
84 }
85
86 return correct;
87}
88
89const char *test_softfloat1(void)
90{
91 if (!test_float_add())
92 return "Float addition failed";
93
94 return NULL;
95}
Note: See TracBrowser for help on using the repository browser.