Fix non simd f16 build (#3097)

This commit is contained in:
Awni Hannun
2026-02-05 07:04:02 -08:00
committed by GitHub
parent f47729c0d8
commit 206cf07e5b
2 changed files with 19 additions and 4 deletions
+8
View File
@@ -29,6 +29,14 @@ struct Simd<T, 1> {
Simd(Simd<U, 1> v) : value(v.value) {}
template <typename U>
Simd(U v) : value(v) {}
T operator[](int) const {
return value;
}
T& operator[](int) {
return value;
}
};
template <typename T, int N>
+11 -4
View File
@@ -155,11 +155,18 @@ struct FromFP8 {
template <int N>
Simd<float, N> operator()(Simd<uint8_t, N> x) {
auto v = Simd<uint16_t, N>(x & 127) << 7;
auto converted = *(Simd<float16_t, N>*)(&v);
converted = converted * 256.0;
Simd<float, N> out;
if constexpr (simd::max_size<float16_t> >= N) {
auto converted = *(Simd<float16_t, N>*)(&v);
out = converted * 256.0;
} else {
for (int i = 0; i < N; ++i) {
auto converted = *(float16_t*)(&v[i]);
out[i] = converted * 256.0;
}
}
auto sign = Simd<bool, N>(x & 128);
Simd<float, N> out = select(sign, -converted, converted);
return out;
return select(sign, -out, out);
}
float operator()(uint8_t x) {
return (*this)(Simd<uint8_t, 1>(x)).value;