@@ -54,6 +54,8 @@ extern "C" {
5454#endif
5555#endif
5656
57+ #ifndef _EZ80
58+
5759NPF_VISIBILITY int npf_snprintf_ (char * NPF_RESTRICT buffer,
5860 size_t bufsz,
5961 const char * NPF_RESTRICT format, ...)
@@ -84,6 +86,8 @@ NPF_VISIBILITY int npf_vpprintf(npf_putc pc,
8486 char const * NPF_RESTRICT format,
8587 va_list vlist) NPF_PRINTF_ATTR(3 , 0 );
8688
89+ #endif /* _EZ80 */
90+
8791#ifdef __cplusplus
8892}
8993#endif
@@ -488,7 +492,9 @@ static int npf_parse_format_spec(char const *format, npf_format_spec_t *out_spec
488492#endif
489493 break ;
490494#if NANOPRINTF_USE_FLOAT_FORMAT_SPECIFIERS == 1
495+ #if !defined(_EZ80) || NANOPRINTF_USE_LONG_DOUBLE_PRECISION
491496 case ' L' : out_spec->length_modifier = NPF_FMT_SPEC_LEN_MOD_LONG_DOUBLE; break ;
497+ #endif /* _EZ80 */
492498#endif
493499#if NANOPRINTF_USE_LARGE_FORMAT_SPECIFIERS == 1
494500 case ' j' : out_spec->length_modifier = NPF_FMT_SPEC_LEN_MOD_LARGE_INTMAX; break ;
@@ -587,6 +593,10 @@ static NPF_NOINLINE int npf_utoa_rev(
587593 typedef float npf_real_t ;
588594 #define NPF_REAL_MANT_DIG FLT_MANT_DIG
589595 #define NPF_REAL_MAX_EXP FLT_MAX_EXP
596+ #elif NANOPRINTF_USE_LONG_DOUBLE_PRECISION
597+ typedef long double npf_real_t ;
598+ #define NPF_REAL_MANT_DIG LDBL_MANT_DIG
599+ #define NPF_REAL_MAX_EXP LDBL_MAX_EXP
590600#else
591601 typedef double npf_real_t ;
592602 #define NPF_REAL_MANT_DIG DBL_MANT_DIG
@@ -643,7 +653,11 @@ static NPF_FORCE_INLINE npf_real_bin_t npf_real_to_int_rep(npf_real_t f) {
643653 npf_real_bin_t bin = 0 ;
644654 char const *src = (char const *)&f;
645655 char *dst = (char *)&bin;
656+ #ifndef _EZ80
646657 for (uint_fast8_t i = 0 ; i < sizeof (f); ++i) { dst[i] = src[i]; }
658+ #else /* _EZ80 */
659+ __builtin_memcpy (dst, src, sizeof (f));
660+ #endif /* _EZ80 */
647661 return bin;
648662}
649663
@@ -813,7 +827,11 @@ static NPF_FORCE_INLINE npf_double_bin_t npf_double_to_int_rep(double f) {
813827 npf_double_bin_t bin = 0 ;
814828 char const *src = (char const *)&f;
815829 char *dst = (char *)&bin;
830+ #ifndef _EZ80
816831 for (uint_fast8_t i = 0 ; i < sizeof (f); ++i) { dst[i] = src[i]; }
832+ #else /* _EZ80 */
833+ __builtin_memcpy (dst, src, sizeof (f));
834+ #endif /* _EZ80 */
817835 return bin;
818836}
819837#else
@@ -932,13 +950,22 @@ typedef struct npf_cnt_putc_ctx {
932950 int n;
933951} npf_cnt_putc_ctx_t ;
934952
953+ #ifdef NANOPRINTF_STATIC_GLOBALS
954+ static npf_cnt_putc_ctx_t pc_cnt;
955+ #endif
956+
935957static void npf_putc_cnt (int c, void *ctx) {
936- npf_cnt_putc_ctx_t *pc_cnt = (npf_cnt_putc_ctx_t *)ctx;
937- ++pc_cnt ->n ;
938- pc_cnt ->pc (c, pc_cnt ->ctx ); // sibling-call optimization
958+ npf_cnt_putc_ctx_t *pc_putc_cnt = (npf_cnt_putc_ctx_t *)ctx;
959+ ++pc_putc_cnt ->n ;
960+ pc_putc_cnt ->pc (c, pc_putc_cnt ->ctx ); // sibling-call optimization
939961}
940962
963+ #ifdef NANOPRINTF_STATIC_GLOBALS
964+ static void NPF_PUTC_IMPL (char VAL) { npf_putc_cnt ((int )(VAL), &pc_cnt); }
965+ #define NPF_PUTC (VAL ) NPF_PUTC_IMPL(VAL)
966+ #else
941967#define NPF_PUTC (VAL ) do { npf_putc_cnt ((int )(VAL), &pc_cnt); } while (0 )
968+ #endif
942969
943970#define NPF_EXTRACT (MOD, CAST_TO, EXTRACT_AS ) \
944971 case NPF_FMT_SPEC_LEN_MOD_##MOD: val = (CAST_TO)va_arg(args, EXTRACT_AS); break
@@ -949,7 +976,9 @@ static void npf_putc_cnt(int c, void *ctx) {
949976int npf_vpprintf (npf_putc pc, void *pc_ctx, char const *format, va_list args) {
950977 npf_format_spec_t fs;
951978 char const *cur = format;
979+ #ifndef NANOPRINTF_STATIC_GLOBALS
952980 npf_cnt_putc_ctx_t pc_cnt;
981+ #endif
953982 pc_cnt.pc = pc;
954983 pc_cnt.ctx = pc_ctx;
955984 pc_cnt.n = 0 ;
@@ -1319,6 +1348,8 @@ int npf_vpprintf(npf_putc pc, void *pc_ctx, char const *format, va_list args) {
13191348#undef NPF_EXTRACT
13201349#undef NPF_WRITEBACK
13211350
1351+ #ifndef _EZ80
1352+
13221353int npf_vsnprintf (char * NPF_RESTRICT buffer,
13231354 size_t bufsz,
13241355 char const * NPF_RESTRICT format,
@@ -1364,6 +1395,8 @@ int npf_snprintf_(char * NPF_RESTRICT buffer,
13641395 return rv;
13651396}
13661397
1398+ #endif /* _EZ80 */
1399+
13671400#if NPF_HAVE_GCC_WARNING_PRAGMAS
13681401 #pragma GCC diagnostic pop
13691402#endif
0 commit comments