From c6e25b752f2576b18f12685149f69fa81046da36 Mon Sep 17 00:00:00 2001 From: Bill Zorn Date: Mon, 23 Jul 2018 18:32:31 -0700 Subject: [PATCH] the beginnings of posit interface --- cposit.pxd | 9 +++++++++ posit.pyx | 11 +++++++++++ setup.py | 14 ++++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 cposit.pxd create mode 100644 posit.pyx create mode 100644 setup.py diff --git a/cposit.pxd b/cposit.pxd new file mode 100644 index 0000000..b15cc10 --- /dev/null +++ b/cposit.pxd @@ -0,0 +1,9 @@ +from libc.stdint cimport * + +cdef extern from 'SoftPosit/source/include/softposit.h': + + ctypedef struct posit8_t: + pass + + posit8_t i64_to_p8( int64_t ); + int_fast64_t p8_to_i64( posit8_t); diff --git a/posit.pyx b/posit.pyx new file mode 100644 index 0000000..3bbeabf --- /dev/null +++ b/posit.pyx @@ -0,0 +1,11 @@ +cimport cposit + +cdef class Posit8: + cdef cposit.posit8_t _c_posit + + def __cinit__(self): + self._c_posit = cposit.i64_to_p8(1) + + cpdef show(self): + print(cposit.p8_to_i64(self._c_posit)) + diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..82b066d --- /dev/null +++ b/setup.py @@ -0,0 +1,14 @@ +from distutils.core import setup +from distutils.extension import Extension +from Cython.Build import cythonize + +ext = Extension('posit', ['posit.pyx'], + include_dirs=['SoftPosit/source/include/'], + extra_objects=['./SoftPosit/build/Linux-x86_64-GCC/softposit.a'], + libraries=['m'], +) + +setup( + name='sfpy', + ext_modules=cythonize([ext]), +) -- 2.30.2