@@ -53,6 +53,8 @@ extern "C" {
5353#endif
5454#endif
5555
56+ #ifndef _EZ80
57+
5658NPF_VISIBILITY int npf_snprintf_ (char * NPF_RESTRICT buffer,
5759 size_t bufsz,
5860 const char * NPF_RESTRICT format, ...)
@@ -83,6 +85,8 @@ NPF_VISIBILITY int npf_vpprintf(npf_putc pc,
8385 char const * NPF_RESTRICT format,
8486 va_list vlist) NPF_PRINTF_ATTR(3 , 0 );
8587
88+ #endif /* _EZ80 */
89+
8690#ifdef __cplusplus
8791}
8892#endif
@@ -487,7 +491,9 @@ static int npf_parse_format_spec(char const *format, npf_format_spec_t *out_spec
487491#endif
488492 break ;
489493#if NANOPRINTF_USE_FLOAT_FORMAT_SPECIFIERS == 1
494+ #if !defined(_EZ80) || NANOPRINTF_USE_LONG_DOUBLE_PRECISION
490495 case ' L' : out_spec->length_modifier = NPF_FMT_SPEC_LEN_MOD_LONG_DOUBLE; break ;
496+ #endif /* _EZ80 */
491497#endif
492498#if NANOPRINTF_USE_LARGE_FORMAT_SPECIFIERS == 1
493499 case ' j' : out_spec->length_modifier = NPF_FMT_SPEC_LEN_MOD_LARGE_INTMAX; break ;
@@ -586,6 +592,10 @@ static NPF_NOINLINE int npf_utoa_rev(
586592 typedef float npf_real_t ;
587593 #define NPF_REAL_MANT_DIG FLT_MANT_DIG
588594 #define NPF_REAL_MAX_EXP FLT_MAX_EXP
595+ #elif NANOPRINTF_USE_LONG_DOUBLE_PRECISION
596+ typedef long double npf_real_t ;
597+ #define NPF_REAL_MANT_DIG LDBL_MANT_DIG
598+ #define NPF_REAL_MAX_EXP LDBL_MAX_EXP
589599#else
590600 typedef double npf_real_t ;
591601 #define NPF_REAL_MANT_DIG DBL_MANT_DIG
@@ -642,7 +652,11 @@ static NPF_FORCE_INLINE npf_real_bin_t npf_real_to_int_rep(npf_real_t f) {
642652 npf_real_bin_t bin = 0 ;
643653 char const *src = (char const *)&f;
644654 char *dst = (char *)&bin;
655+ #ifndef _EZ80
645656 for (uint_fast8_t i = 0 ; i < sizeof (f); ++i) { dst[i] = src[i]; }
657+ #else /* _EZ80 */
658+ __builtin_memcpy (dst, src, sizeof (f));
659+ #endif /* _EZ80 */
646660 return bin;
647661}
648662
@@ -812,7 +826,11 @@ static NPF_FORCE_INLINE npf_double_bin_t npf_double_to_int_rep(double f) {
812826 npf_double_bin_t bin = 0 ;
813827 char const *src = (char const *)&f;
814828 char *dst = (char *)&bin;
829+ #ifndef _EZ80
815830 for (uint_fast8_t i = 0 ; i < sizeof (f); ++i) { dst[i] = src[i]; }
831+ #else /* _EZ80 */
832+ __builtin_memcpy (dst, src, sizeof (f));
833+ #endif /* _EZ80 */
816834 return bin;
817835}
818836#else
@@ -931,13 +949,22 @@ typedef struct npf_cnt_putc_ctx {
931949 int n;
932950} npf_cnt_putc_ctx_t ;
933951
952+ #ifdef NANOPRINTF_STATIC_GLOBALS
953+ static npf_cnt_putc_ctx_t pc_cnt;
954+ #endif
955+
934956static void npf_putc_cnt (int c, void *ctx) {
935- npf_cnt_putc_ctx_t *pc_cnt = (npf_cnt_putc_ctx_t *)ctx;
936- ++pc_cnt ->n ;
937- pc_cnt ->pc (c, pc_cnt ->ctx ); // sibling-call optimization
957+ npf_cnt_putc_ctx_t *pc_putc_cnt = (npf_cnt_putc_ctx_t *)ctx;
958+ ++pc_putc_cnt ->n ;
959+ pc_putc_cnt ->pc (c, pc_putc_cnt ->ctx ); // sibling-call optimization
938960}
939961
962+ #ifdef NANOPRINTF_STATIC_GLOBALS
963+ static void NPF_PUTC_IMPL (char VAL) { npf_putc_cnt ((int )(VAL), &pc_cnt); }
964+ #define NPF_PUTC (VAL ) NPF_PUTC_IMPL(VAL)
965+ #else
940966#define NPF_PUTC (VAL ) do { npf_putc_cnt ((int )(VAL), &pc_cnt); } while (0 )
967+ #endif
941968
942969#define NPF_EXTRACT (MOD, CAST_TO, EXTRACT_AS ) \
943970 case NPF_FMT_SPEC_LEN_MOD_##MOD: val = (CAST_TO)va_arg(args, EXTRACT_AS); break
@@ -948,7 +975,9 @@ static void npf_putc_cnt(int c, void *ctx) {
948975int npf_vpprintf (npf_putc pc, void *pc_ctx, char const *format, va_list args) {
949976 npf_format_spec_t fs;
950977 char const *cur = format;
978+ #ifndef NANOPRINTF_STATIC_GLOBALS
951979 npf_cnt_putc_ctx_t pc_cnt;
980+ #endif
952981 pc_cnt.pc = pc;
953982 pc_cnt.ctx = pc_ctx;
954983 pc_cnt.n = 0 ;
@@ -1318,6 +1347,8 @@ int npf_vpprintf(npf_putc pc, void *pc_ctx, char const *format, va_list args) {
13181347#undef NPF_EXTRACT
13191348#undef NPF_WRITEBACK
13201349
1350+ #ifndef _EZ80
1351+
13211352int npf_vsnprintf (char * NPF_RESTRICT buffer,
13221353 size_t bufsz,
13231354 char const * NPF_RESTRICT format,
@@ -1363,6 +1394,8 @@ int npf_snprintf_(char * NPF_RESTRICT buffer,
13631394 return rv;
13641395}
13651396
1397+ #endif /* _EZ80 */
1398+
13661399#if NPF_HAVE_GCC_WARNING_PRAGMAS
13671400 #pragma GCC diagnostic pop
13681401#endif
0 commit comments