Skip to content

Commit 0a8e7d3

Browse files
authored
[SYCL] Add external arbitrary floating point functions (#2114)
Add support of functions that operate on arbitrary precision floating point numbers. This datatype and its corresponding operations can be useful on targets that can take advantage of narrower representation such as FPGAs. Arbitrary precision floating point numbers are represented using arbitrary precision integers (_ExtInt(N)). Additional parameters are: * _E_: represents the number of exponent bits * _M_: represents the number of mantissa bits The total width of the type is `E+M+1` where the last bit is used to represent the sign. The data layout is shown below: `[ S (sign bit) ][ E (Exponent) ][ M (Mantissa) ]` The width of the data `(E+M+1)` is encoded with the width of the arbitrary precision integer variable. Mantissa (namely `M`) is encoded within each of the signature of the operations. Exponent values (namely `E`) are inferred from the width of corresponding variable. Usage example: _ExtInt(Wa) a; _ExtInt(Wb) b; _ExtInt(Wout) res = __spirv_ArbitraryFloatAddINTEL<Wa, Wb, Wout>(a, Ma, b, Mb, Mout); Signed-off-by: Mikhail Lychkov <[email protected]>
1 parent 8a4810a commit 0a8e7d3

File tree

2 files changed

+674
-8
lines changed

2 files changed

+674
-8
lines changed

sycl/include/CL/__spirv/spirv_ops.hpp

Lines changed: 234 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,14 @@ __SYCL_CONVERGENT__ extern SYCL_EXTERNAL void
205205
__spirv_SubgroupBlockWriteINTEL(__attribute__((opencl_global)) uint32_t *Ptr,
206206
dataT Data) noexcept;
207207

208+
template <typename dataT>
209+
__SYCL_CONVERGENT__ extern SYCL_EXTERNAL dataT __spirv_SubgroupBlockReadINTEL(
210+
const __attribute__((opencl_global)) uint64_t *Ptr) noexcept;
211+
212+
template <typename dataT>
213+
__SYCL_CONVERGENT__ extern SYCL_EXTERNAL void
214+
__spirv_SubgroupBlockWriteINTEL(__attribute__((opencl_global)) uint64_t *Ptr,
215+
dataT Data) noexcept;
208216
template <int W, int rW>
209217
extern SYCL_EXTERNAL ap_int<rW>
210218
__spirv_FixedSqrtINTEL(ap_int<W> a, bool S, int32_t I, int32_t rI,
@@ -256,14 +264,232 @@ extern SYCL_EXTERNAL ap_int<rW>
256264
__spirv_FixedExpINTEL(ap_int<W> a, bool S, int32_t I, int32_t rI,
257265
int32_t Quantization = 0, int32_t Overflow = 0) noexcept;
258266

259-
template <typename dataT>
260-
__SYCL_CONVERGENT__ extern SYCL_EXTERNAL dataT __spirv_SubgroupBlockReadINTEL(
261-
const __attribute__((opencl_global)) uint64_t *Ptr) noexcept;
262-
263-
template <typename dataT>
264-
__SYCL_CONVERGENT__ extern SYCL_EXTERNAL void
265-
__spirv_SubgroupBlockWriteINTEL(__attribute__((opencl_global)) uint64_t *Ptr,
266-
dataT Data) noexcept;
267+
// In the following built-ins width of arbitrary precision integer type for
268+
// a floating point variable should be equal to sum of corresponding
269+
// exponent width E, mantissa width M and 1 for sign bit. I.e. WA = EA + MA + 1.
270+
template <int WA, int Wout>
271+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatCastINTEL(
272+
ap_int<WA> A, int32_t MA, int32_t Mout, int32_t EnableSubnormals = 0,
273+
int32_t RoundingMode = 0, int32_t RoundingAccuracy = 0) noexcept;
274+
275+
template <int WA, int Wout>
276+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatCastFromIntINTEL(
277+
ap_int<WA> A, int32_t Mout, int32_t EnableSubnormals = 0,
278+
int32_t RoundingMode = 0, int32_t RoundingAccuracy = 0) noexcept;
279+
280+
template <int WA, int Wout>
281+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatCastToIntINTEL(
282+
ap_int<WA> A, int32_t MA, int32_t EnableSubnormals = 0,
283+
int32_t RoundingMode = 0, int32_t RoundingAccuracy = 0) noexcept;
284+
285+
template <int WA, int WB, int Wout>
286+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatAddINTEL(
287+
ap_int<WA> A, int32_t MA, ap_int<WB> B, int32_t MB, int32_t Mout,
288+
int32_t EnableSubnormals = 0, int32_t RoundingMode = 0,
289+
int32_t RoundingAccuracy = 0) noexcept;
290+
291+
template <int WA, int WB, int Wout>
292+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatSubINTEL(
293+
ap_int<WA> A, int32_t MA, ap_int<WB> B, int32_t MB, int32_t Mout,
294+
int32_t EnableSubnormals = 0, int32_t RoundingMode = 0,
295+
int32_t RoundingAccuracy = 0) noexcept;
296+
297+
template <int WA, int WB, int Wout>
298+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatMulINTEL(
299+
ap_int<WA> A, int32_t MA, ap_int<WB> B, int32_t MB, int32_t Mout,
300+
int32_t EnableSubnormals = 0, int32_t RoundingMode = 0,
301+
int32_t RoundingAccuracy = 0) noexcept;
302+
303+
template <int WA, int WB, int Wout>
304+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatDivINTEL(
305+
ap_int<WA> A, int32_t MA, ap_int<WB> B, int32_t MB, int32_t Mout,
306+
int32_t EnableSubnormals = 0, int32_t RoundingMode = 0,
307+
int32_t RoundingAccuracy = 0) noexcept;
308+
309+
// Comparison built-ins don't use Subnormal Support, Rounding Mode and
310+
// Rounding Accuracy.
311+
template <int WA, int WB>
312+
extern SYCL_EXTERNAL bool
313+
__spirv_ArbitraryFloatGTINTEL(ap_int<WA> A, int32_t MA, ap_int<WB> B,
314+
int32_t MB) noexcept;
315+
316+
template <int WA, int WB>
317+
extern SYCL_EXTERNAL bool
318+
__spirv_ArbitraryFloatGEINTEL(ap_int<WA> A, int32_t MA, ap_int<WB> B,
319+
int32_t MB) noexcept;
320+
321+
template <int WA, int WB>
322+
extern SYCL_EXTERNAL bool
323+
__spirv_ArbitraryFloatLTINTEL(ap_int<WA> A, int32_t MA, ap_int<WB> B,
324+
int32_t MB) noexcept;
325+
326+
template <int WA, int WB>
327+
extern SYCL_EXTERNAL bool
328+
__spirv_ArbitraryFloatLEINTEL(ap_int<WA> A, int32_t MA, ap_int<WB> B,
329+
int32_t MB) noexcept;
330+
331+
template <int WA, int WB>
332+
extern SYCL_EXTERNAL bool
333+
__spirv_ArbitraryFloatEQINTEL(ap_int<WA> A, int32_t MA, ap_int<WB> B,
334+
int32_t MB) noexcept;
335+
336+
template <int WA, int Wout>
337+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatRecipINTEL(
338+
ap_int<WA> A, int32_t MA, int32_t Mout, int32_t EnableSubnormals = 0,
339+
int32_t RoundingMode = 0, int32_t RoundingAccuracy = 0) noexcept;
340+
341+
template <int WA, int Wout>
342+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatRSqrtINTEL(
343+
ap_int<WA> A, int32_t MA, int32_t Mout, int32_t EnableSubnormals = 0,
344+
int32_t RoundingMode = 0, int32_t RoundingAccuracy = 0) noexcept;
345+
346+
template <int WA, int Wout>
347+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatCbrtINTEL(
348+
ap_int<WA> A, int32_t MA, int32_t Mout, int32_t EnableSubnormals = 0,
349+
int32_t RoundingMode = 0, int32_t RoundingAccuracy = 0) noexcept;
350+
351+
template <int WA, int WB, int Wout>
352+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatHypotINTEL(
353+
ap_int<WA> A, int32_t MA, ap_int<WB> B, int32_t MB, int32_t Mout,
354+
int32_t EnableSubnormals = 0, int32_t RoundingMode = 0,
355+
int32_t RoundingAccuracy = 0) noexcept;
356+
357+
template <int WA, int Wout>
358+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatSqrtINTEL(
359+
ap_int<WA> A, int32_t MA, int32_t Mout, int32_t EnableSubnormals = 0,
360+
int32_t RoundingMode = 0, int32_t RoundingAccuracy = 0) noexcept;
361+
362+
template <int WA, int Wout>
363+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatLogINTEL(
364+
ap_int<WA> A, int32_t MA, int32_t Mout, int32_t EnableSubnormals = 0,
365+
int32_t RoundingMode = 0, int32_t RoundingAccuracy = 0) noexcept;
366+
367+
template <int WA, int Wout>
368+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatLog2INTEL(
369+
ap_int<WA> A, int32_t MA, int32_t Mout, int32_t EnableSubnormals = 0,
370+
int32_t RoundingMode = 0, int32_t RoundingAccuracy = 0) noexcept;
371+
372+
template <int WA, int Wout>
373+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatLog10INTEL(
374+
ap_int<WA> A, int32_t MA, int32_t Mout, int32_t EnableSubnormals = 0,
375+
int32_t RoundingMode = 0, int32_t RoundingAccuracy = 0) noexcept;
376+
377+
template <int WA, int Wout>
378+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatLog1pINTEL(
379+
ap_int<WA> A, int32_t MA, int32_t Mout, int32_t EnableSubnormals = 0,
380+
int32_t RoundingMode = 0, int32_t RoundingAccuracy = 0) noexcept;
381+
382+
template <int WA, int Wout>
383+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatExpINTEL(
384+
ap_int<WA> A, int32_t MA, int32_t Mout, int32_t EnableSubnormals = 0,
385+
int32_t RoundingMode = 0, int32_t RoundingAccuracy = 0) noexcept;
386+
387+
template <int WA, int Wout>
388+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatExp2INTEL(
389+
ap_int<WA> A, int32_t MA, int32_t Mout, int32_t EnableSubnormals = 0,
390+
int32_t RoundingMode = 0, int32_t RoundingAccuracy = 0) noexcept;
391+
392+
template <int WA, int Wout>
393+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatExp10INTEL(
394+
ap_int<WA> A, int32_t MA, int32_t Mout, int32_t EnableSubnormals = 0,
395+
int32_t RoundingMode = 0, int32_t RoundingAccuracy = 0) noexcept;
396+
397+
template <int WA, int Wout>
398+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatExpm1INTEL(
399+
ap_int<WA> A, int32_t MA, int32_t Mout, int32_t EnableSubnormals = 0,
400+
int32_t RoundingMode = 0, int32_t RoundingAccuracy = 0) noexcept;
401+
402+
template <int WA, int Wout>
403+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatSinINTEL(
404+
ap_int<WA> A, int32_t MA, int32_t Mout, int32_t EnableSubnormals = 0,
405+
int32_t RoundingMode = 0, int32_t RoundingAccuracy = 0) noexcept;
406+
407+
template <int WA, int Wout>
408+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatCosINTEL(
409+
ap_int<WA> A, int32_t MA, int32_t Mout, int32_t EnableSubnormals = 0,
410+
int32_t RoundingMode = 0, int32_t RoundingAccuracy = 0) noexcept;
411+
412+
// Result value contains both values of sine and cosine and so has the size of
413+
// 2 * Wout where Wout is equal to (1 + Eout + Mout).
414+
template <int WA, int Wout>
415+
extern SYCL_EXTERNAL ap_int<2 * Wout> __spirv_ArbitraryFloatSinCosINTEL(
416+
ap_int<WA> A, int32_t MA, int32_t Mout, int32_t EnableSubnormals = 0,
417+
int32_t RoundingMode = 0, int32_t RoundingAccuracy = 0) noexcept;
418+
419+
template <int WA, int Wout>
420+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatSinPiINTEL(
421+
ap_int<WA> A, int32_t MA, int32_t Mout, int32_t EnableSubnormals = 0,
422+
int32_t RoundingMode = 0, int32_t RoundingAccuracy = 0) noexcept;
423+
424+
template <int WA, int Wout>
425+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatCosPiINTEL(
426+
ap_int<WA> A, int32_t MA, int32_t Mout, int32_t EnableSubnormals = 0,
427+
int32_t RoundingMode = 0, int32_t RoundingAccuracy = 0) noexcept;
428+
429+
// Result value contains both values of sine(A*pi) and cosine(A*pi) and so has
430+
// the size of 2 * Wout where Wout is equal to (1 + Eout + Mout).
431+
template <int WA, int Wout>
432+
extern SYCL_EXTERNAL ap_int<2 * Wout> __spirv_ArbitraryFloatSinCosPiINTEL(
433+
ap_int<WA> A, int32_t MA, int32_t Mout, int32_t EnableSubnormals = 0,
434+
int32_t RoundingMode = 0, int32_t RoundingAccuracy = 0) noexcept;
435+
436+
template <int WA, int Wout>
437+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatASinINTEL(
438+
ap_int<WA> A, int32_t MA, int32_t Mout, int32_t EnableSubnormals = 0,
439+
int32_t RoundingMode = 0, int32_t RoundingAccuracy = 0) noexcept;
440+
441+
template <int WA, int Wout>
442+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatASinPiINTEL(
443+
ap_int<WA> A, int32_t MA, int32_t Mout, int32_t EnableSubnormals = 0,
444+
int32_t RoundingMode = 0, int32_t RoundingAccuracy = 0) noexcept;
445+
446+
template <int WA, int Wout>
447+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatACosINTEL(
448+
ap_int<WA> A, int32_t MA, int32_t Mout, int32_t EnableSubnormals = 0,
449+
int32_t RoundingMode = 0, int32_t RoundingAccuracy = 0) noexcept;
450+
451+
template <int WA, int Wout>
452+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatACosPiINTEL(
453+
ap_int<WA> A, int32_t MA, int32_t Mout, int32_t EnableSubnormals = 0,
454+
int32_t RoundingMode = 0, int32_t RoundingAccuracy = 0) noexcept;
455+
456+
template <int WA, int Wout>
457+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatATanINTEL(
458+
ap_int<WA> A, int32_t MA, int32_t Mout, int32_t EnableSubnormals = 0,
459+
int32_t RoundingMode = 0, int32_t RoundingAccuracy = 0) noexcept;
460+
461+
template <int WA, int Wout>
462+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatATanPiINTEL(
463+
ap_int<WA> A, int32_t MA, int32_t Mout, int32_t EnableSubnormals = 0,
464+
int32_t RoundingMode = 0, int32_t RoundingAccuracy = 0) noexcept;
465+
466+
template <int WA, int WB, int Wout>
467+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatATan2INTEL(
468+
ap_int<WA> A, int32_t MA, ap_int<WB> B, int32_t MB, int32_t Mout,
469+
int32_t EnableSubnormals = 0, int32_t RoundingMode = 0,
470+
int32_t RoundingAccuracy = 0) noexcept;
471+
472+
template <int WA, int WB, int Wout>
473+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatPowINTEL(
474+
ap_int<WA> A, int32_t MA, ap_int<WB> B, int32_t MB, int32_t Mout,
475+
int32_t EnableSubnormals = 0, int32_t RoundingMode = 0,
476+
int32_t RoundingAccuracy = 0) noexcept;
477+
478+
template <int WA, int WB, int Wout>
479+
extern SYCL_EXTERNAL ap_int<Wout> __spirv_ArbitraryFloatPowRINTEL(
480+
ap_int<WA> A, int32_t MA, ap_int<WB> B, int32_t MB, int32_t Mout,
481+
int32_t EnableSubnormals = 0, int32_t RoundingMode = 0,
482+
int32_t RoundingAccuracy = 0) noexcept;
483+
484+
// PowN built-in calculates `A^B` where `A` is arbitrary precision floating
485+
// point number and `B` is arbitrary precision integer, i.e. its width doesn't
486+
// depend on sum of exponent and mantissa.
487+
template <int WA, int WB, int Wout>
488+
extern SYCL_EXTERNAL ap_int<Wout>
489+
__spirv_ArbitraryFloatPowNINTEL(ap_int<WA> A, int32_t MA, ap_int<WB> B,
490+
int32_t Mout, int32_t EnableSubnormals = 0,
491+
int32_t RoundingMode = 0,
492+
int32_t RoundingAccuracy = 0) noexcept;
267493

268494
template <typename dataT>
269495
extern SYCL_EXTERNAL int32_t __spirv_ReadPipe(RPipeTy<dataT> Pipe, dataT *Data,

0 commit comments

Comments
 (0)