Skip to content

Commit 4e5d682

Browse files
authored
Add long-float (#1631)
1 parent e013153 commit 4e5d682

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

73 files changed

+4946
-3743
lines changed

RELEASE_NOTES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
## Added
44
* Package lock support, based on SBCL's. Currently ignores local
55
bindings. Thanks @bumblingbats.
6+
* Add support for 80-bit and 128-bit LONG-FLOAT. Extended precision
7+
LONG-FLOAT is available on amd64 and non-Apply arm64 platforms. It
8+
is automatically detected and enabled.
69

710
## Changed
811
* Floating point exceptions FE_INVALID, FE_OVERFLOW and FE_DIVBYZERO

include/clasp/core/array.fwd.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,21 @@ FORWARD(SimpleMDArrayBaseChar);
4848
FORWARD(MDArrayCharacter);
4949
FORWARD(SimpleMDArrayCharacter);
5050
//
51+
FORWARD(SimpleVector_short_float);
52+
FORWARD(MDArray_short_float);
53+
FORWARD(SimpleMDArray_short_float);
54+
FORWARD(ComplexVector_short_float);
55+
//
5156
FORWARD(SimpleVector_double);
5257
FORWARD(MDArray_double);
5358
FORWARD(SimpleMDArray_double);
5459
FORWARD(ComplexVector_double);
5560
//
61+
FORWARD(SimpleVector_long_float);
62+
FORWARD(MDArray_long_float);
63+
FORWARD(SimpleMDArray_long_float);
64+
FORWARD(ComplexVector_long_float);
65+
//
5666
FORWARD(SimpleVector_size_t);
5767
FORWARD(MDArray_size_t);
5868
FORWARD(SimpleMDArray_size_t);

include/clasp/core/array.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ extern core::Symbol_sp& _sym_bit;
101101
extern core::Symbol_sp& _sym_float;
102102
extern core::Symbol_sp& _sym_double_float;
103103
extern core::Symbol_sp& _sym_single_float;
104+
extern core::Symbol_sp& _sym_short_float;
105+
extern core::Symbol_sp& _sym_long_float;
104106
extern core::Symbol_sp& _sym_UnsignedByte;
105107
extern core::Symbol_sp& _sym_T_O;
106108
extern core::Symbol_sp& _sym_simple_string;
@@ -1008,8 +1010,10 @@ template <typename MyArrayType, typename MySimpleType, typename MyParentType> cl
10081010

10091011
#include <clasp/core/array_t.h>
10101012
#include <clasp/core/string.h>
1011-
#include <clasp/core/array_double.h>
1013+
#include <clasp/core/array_short_float.h>
10121014
#include <clasp/core/array_float.h>
1015+
#include <clasp/core/array_double.h>
1016+
#include <clasp/core/array_long_float.h>
10131017
#include <clasp/core/array_size_t.h>
10141018
#include <clasp/core/array_fixnum.h>
10151019
#include <clasp/core/array_int64.h>

include/clasp/core/array_long_float.h

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
#pragma once
2+
// ============================================================
3+
// Arrays specialized for long_float_t
4+
//
5+
6+
namespace core {
7+
8+
FORWARD(SimpleVector_long_float);
9+
FORWARD(MDArray_long_float);
10+
FORWARD(SimpleMDArray_long_float);
11+
FORWARD(ComplexVector_long_float);
12+
13+
}; // namespace core
14+
15+
template <> struct gctools::GCInfo<core::SimpleVector_long_float_O> {
16+
static bool constexpr NeedsInitialization = false;
17+
static bool constexpr NeedsFinalization = false;
18+
static GCInfo_policy constexpr Policy = atomic;
19+
};
20+
21+
namespace core {
22+
class SimpleVector_long_float_O;
23+
24+
typedef template_SimpleVector<SimpleVector_long_float_O, long_float_t, AbstractSimpleVector_O> specialized_SimpleVector_long_float;
25+
26+
class SimpleVector_long_float_O : public specialized_SimpleVector_long_float {
27+
LISP_CLASS(core, CorePkg, SimpleVector_long_float_O, "SimpleVector_long_float", AbstractSimpleVector_O);
28+
virtual ~SimpleVector_long_float_O() {};
29+
30+
public:
31+
typedef specialized_SimpleVector_long_float TemplatedBase;
32+
33+
static value_type default_initial_element(void) { return long_float_t{0.0}; }
34+
static value_type from_object(T_sp obj) { return core::Number_O::as_long_float(obj.as<Number_O>()); };
35+
static T_sp to_object(const value_type& v) { return core::LongFloat_O::create(v); };
36+
37+
SimpleVector_long_float_O(size_t length, value_type initialElement = value_type(), bool initialElementSupplied = false,
38+
size_t initialContentsSize = 0, const value_type* initialContents = NULL)
39+
: TemplatedBase(length, initialElement, initialElementSupplied, initialContentsSize, initialContents) {};
40+
static smart_ptr_type make(size_t length, value_type initialElement = value_type(), bool initialElementSupplied = false,
41+
size_t initialContentsSize = 0, const value_type* initialContents = NULL,
42+
bool static_vector_p = false) {
43+
auto bs = gctools::GC<my_type>::allocate_container<gctools::RuntimeStage>(
44+
static_vector_p, length, initialElement, initialElementSupplied, initialContentsSize, initialContents);
45+
return bs;
46+
}
47+
48+
virtual T_sp element_type() const override { return cl::_sym_long_float; };
49+
50+
static SimpleVector_long_float_sp create(size_t sz) { return make(sz, long_float_t{0.0}, false, 0, NULL); }
51+
long_float_t& element(size_t i) { return this->operator[](i); };
52+
long_float_t& getElement(size_t i) { return this->operator[](i); };
53+
void setElement(size_t i, long_float_t v) { this->operator[](i) = v; };
54+
void addToElement(size_t i, long_float_t v) { this->operator[](i) += v; };
55+
void zero() {
56+
for (size_t i(0), iEnd(this->length()); i < iEnd; ++i)
57+
this->operator[](i) = long_float_t{0.0};
58+
};
59+
size_t size() const { return this->length(); };
60+
};
61+
62+
class MDArray_long_float_O
63+
: public template_Array<MDArray_long_float_O, SimpleMDArray_long_float_O, SimpleVector_long_float_O, MDArray_O> {
64+
LISP_CLASS(core, CorePkg, MDArray_long_float_O, "MDArray_long_float", MDArray_O);
65+
virtual ~MDArray_long_float_O() {};
66+
67+
public:
68+
typedef template_Array<MDArray_long_float_O, SimpleMDArray_long_float_O, SimpleVector_long_float_O, MDArray_O> TemplatedBase;
69+
70+
MDArray_long_float_O(size_t rank, List_sp dimensions, Array_sp data, bool displacedToP, Fixnum_sp displacedIndexOffset)
71+
: TemplatedBase(rank, dimensions, data, displacedToP, displacedIndexOffset) {};
72+
};
73+
74+
class SimpleMDArray_long_float_O
75+
: public template_SimpleArray<SimpleMDArray_long_float_O, SimpleVector_long_float_O, SimpleMDArray_O> {
76+
LISP_CLASS(core, CorePkg, SimpleMDArray_long_float_O, "SimpleMDArray_long_float", SimpleMDArray_O);
77+
virtual ~SimpleMDArray_long_float_O() {};
78+
79+
public:
80+
typedef template_SimpleArray<SimpleMDArray_long_float_O, SimpleVector_long_float_O, SimpleMDArray_O> TemplatedBase;
81+
82+
SimpleMDArray_long_float_O(size_t rank, List_sp dimensions, Array_sp data) : TemplatedBase(rank, dimensions, data) {};
83+
};
84+
85+
class ComplexVector_long_float_O : public template_Vector<ComplexVector_long_float_O, SimpleVector_long_float_O, ComplexVector_O> {
86+
LISP_CLASS(core, CorePkg, ComplexVector_long_float_O, "ComplexVector_long_float", ComplexVector_O);
87+
virtual ~ComplexVector_long_float_O() {};
88+
89+
public:
90+
typedef template_Vector<ComplexVector_long_float_O, SimpleVector_long_float_O, ComplexVector_O> TemplatedBase;
91+
92+
ComplexVector_long_float_O(size_t rank1, size_t dimension, T_sp fillPointer, Array_sp data, bool displacedToP,
93+
Fixnum_sp displacedIndexOffset)
94+
: TemplatedBase(dimension, fillPointer, data, displacedToP, displacedIndexOffset) {};
95+
static smart_ptr_type make_vector(size_t dimension, simple_element_type initialElement /*=simple_element_type()*/,
96+
T_sp fillPointer /*=_Nil<T_O>()*/, T_sp dataOrDisplacedTo /*=_Nil<T_O>()*/,
97+
bool displacedToP /*=false*/, Fixnum_sp displacedIndexOffset /*=clasp_make_fixnum(0)*/) {
98+
LIKELY_if(dataOrDisplacedTo.nilp()) dataOrDisplacedTo = simple_type::make(dimension, initialElement, true);
99+
return gctools::GC<my_type>::allocate_container<gctools::RuntimeStage>(
100+
false, 1 /*CRANK*/, dimension, fillPointer, gc::As_unsafe<Array_sp>(dataOrDisplacedTo), displacedToP, displacedIndexOffset);
101+
}
102+
static smart_ptr_type make_vector(size_t dimension) {
103+
return make_vector(dimension, 0, nil<T_O>(), nil<T_O>(), false, clasp_make_fixnum(0));
104+
}
105+
static smart_ptr_type make(size_t dimension, simple_element_type initialElement, bool initialElementSuppliedP, T_sp fillPointer,
106+
T_sp dataOrDisplacedTo, bool displacedToP, Fixnum_sp displacedIndexOffset) {
107+
(void)initialElementSuppliedP;
108+
return make_vector(dimension, initialElement, fillPointer, dataOrDisplacedTo, displacedToP, displacedIndexOffset);
109+
}
110+
};
111+
}; // namespace core
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
#pragma once
2+
// ============================================================
3+
// Arrays specialized for short_float_t
4+
//
5+
6+
namespace core {
7+
8+
FORWARD(SimpleVector_short_float);
9+
FORWARD(MDArray_short_float);
10+
FORWARD(SimpleMDArray_short_float);
11+
FORWARD(ComplexVector_short_float);
12+
13+
}; // namespace core
14+
15+
template <> struct gctools::GCInfo<core::SimpleVector_short_float_O> {
16+
static bool constexpr NeedsInitialization = false;
17+
static bool constexpr NeedsFinalization = false;
18+
static GCInfo_policy constexpr Policy = atomic;
19+
};
20+
21+
namespace core {
22+
class SimpleVector_short_float_O;
23+
24+
typedef template_SimpleVector<SimpleVector_short_float_O, short_float_t, AbstractSimpleVector_O>
25+
specialized_SimpleVector_short_float;
26+
27+
class SimpleVector_short_float_O : public specialized_SimpleVector_short_float {
28+
LISP_CLASS(core, CorePkg, SimpleVector_short_float_O, "SimpleVector_short_float", AbstractSimpleVector_O);
29+
virtual ~SimpleVector_short_float_O() {};
30+
31+
public:
32+
typedef specialized_SimpleVector_short_float TemplatedBase;
33+
34+
static value_type default_initial_element(void) { return short_float_t{0.0}; }
35+
static value_type from_object(T_sp obj) { return core::Number_O::as_short_float(obj.as<Number_O>()); };
36+
static T_sp to_object(const value_type& v) { return core::ShortFloat_O::create(v); };
37+
38+
SimpleVector_short_float_O(size_t length, value_type initialElement = value_type(), bool initialElementSupplied = false,
39+
size_t initialContentsSize = 0, const value_type* initialContents = NULL)
40+
: TemplatedBase(length, initialElement, initialElementSupplied, initialContentsSize, initialContents) {};
41+
static smart_ptr_type make(size_t length, value_type initialElement = value_type(), bool initialElementSupplied = false,
42+
size_t initialContentsSize = 0, const value_type* initialContents = NULL,
43+
bool static_vector_p = false) {
44+
auto bs = gctools::GC<my_type>::allocate_container<gctools::RuntimeStage>(
45+
static_vector_p, length, initialElement, initialElementSupplied, initialContentsSize, initialContents);
46+
return bs;
47+
}
48+
49+
virtual T_sp element_type() const override { return cl::_sym_short_float; };
50+
51+
static SimpleVector_short_float_sp create(size_t sz) { return make(sz, short_float_t{0.0}, false, 0, NULL); }
52+
short_float_t& element(size_t i) { return this->operator[](i); };
53+
short_float_t& getElement(size_t i) { return this->operator[](i); };
54+
void setElement(size_t i, short_float_t v) { this->operator[](i) = v; };
55+
void addToElement(size_t i, short_float_t v) { this->operator[](i) += v; };
56+
void zero() {
57+
for (size_t i(0), iEnd(this->length()); i < iEnd; ++i)
58+
this->operator[](i) = short_float_t{0.0};
59+
};
60+
size_t size() const { return this->length(); };
61+
};
62+
63+
class MDArray_short_float_O
64+
: public template_Array<MDArray_short_float_O, SimpleMDArray_short_float_O, SimpleVector_short_float_O, MDArray_O> {
65+
LISP_CLASS(core, CorePkg, MDArray_short_float_O, "MDArray_short_float", MDArray_O);
66+
virtual ~MDArray_short_float_O() {};
67+
68+
public:
69+
typedef template_Array<MDArray_short_float_O, SimpleMDArray_short_float_O, SimpleVector_short_float_O, MDArray_O> TemplatedBase;
70+
71+
MDArray_short_float_O(size_t rank, List_sp dimensions, Array_sp data, bool displacedToP, Fixnum_sp displacedIndexOffset)
72+
: TemplatedBase(rank, dimensions, data, displacedToP, displacedIndexOffset) {};
73+
};
74+
75+
class SimpleMDArray_short_float_O
76+
: public template_SimpleArray<SimpleMDArray_short_float_O, SimpleVector_short_float_O, SimpleMDArray_O> {
77+
LISP_CLASS(core, CorePkg, SimpleMDArray_short_float_O, "SimpleMDArray_short_float", SimpleMDArray_O);
78+
virtual ~SimpleMDArray_short_float_O() {};
79+
80+
public:
81+
typedef template_SimpleArray<SimpleMDArray_short_float_O, SimpleVector_short_float_O, SimpleMDArray_O> TemplatedBase;
82+
83+
SimpleMDArray_short_float_O(size_t rank, List_sp dimensions, Array_sp data) : TemplatedBase(rank, dimensions, data) {};
84+
};
85+
86+
class ComplexVector_short_float_O
87+
: public template_Vector<ComplexVector_short_float_O, SimpleVector_short_float_O, ComplexVector_O> {
88+
LISP_CLASS(core, CorePkg, ComplexVector_short_float_O, "ComplexVector_short_float", ComplexVector_O);
89+
virtual ~ComplexVector_short_float_O() {};
90+
91+
public:
92+
typedef template_Vector<ComplexVector_short_float_O, SimpleVector_short_float_O, ComplexVector_O> TemplatedBase;
93+
94+
ComplexVector_short_float_O(size_t rank1, size_t dimension, T_sp fillPointer, Array_sp data, bool displacedToP,
95+
Fixnum_sp displacedIndexOffset)
96+
: TemplatedBase(dimension, fillPointer, data, displacedToP, displacedIndexOffset) {};
97+
static smart_ptr_type make_vector(size_t dimension, simple_element_type initialElement /*=simple_element_type()*/,
98+
T_sp fillPointer /*=_Nil<T_O>()*/, T_sp dataOrDisplacedTo /*=_Nil<T_O>()*/,
99+
bool displacedToP /*=false*/, Fixnum_sp displacedIndexOffset /*=clasp_make_fixnum(0)*/) {
100+
LIKELY_if(dataOrDisplacedTo.nilp()) dataOrDisplacedTo = simple_type::make(dimension, initialElement, true);
101+
return gctools::GC<my_type>::allocate_container<gctools::RuntimeStage>(
102+
false, 1 /*CRANK*/, dimension, fillPointer, gc::As_unsafe<Array_sp>(dataOrDisplacedTo), displacedToP, displacedIndexOffset);
103+
}
104+
static smart_ptr_type make_vector(size_t dimension) {
105+
return make_vector(dimension, 0, nil<T_O>(), nil<T_O>(), false, clasp_make_fixnum(0));
106+
}
107+
static smart_ptr_type make(size_t dimension, simple_element_type initialElement, bool initialElementSuppliedP, T_sp fillPointer,
108+
T_sp dataOrDisplacedTo, bool displacedToP, Fixnum_sp displacedIndexOffset) {
109+
(void)initialElementSuppliedP;
110+
return make_vector(dimension, initialElement, fillPointer, dataOrDisplacedTo, displacedToP, displacedIndexOffset);
111+
}
112+
};
113+
}; // namespace core

0 commit comments

Comments
 (0)