Skip to content

Commit

Permalink
Merge "Revert "Support for vector type in printf"" into mtk/4_2_0/master
Browse files Browse the repository at this point in the history
Code for MSA extension support uses C language features which are not
supported by default with clang (like nested function declarations).
Since we don't support MSA for nanoMIPS, these can be summarily removed.

Change-Id: I2e53ebf401cfd5a1c4191d562d1d5b393996e140
  • Loading branch information
farazs-github committed Apr 3, 2024
2 parents 6b2a582 + 45aa5a5 commit cdfc026
Showing 1 changed file with 2 additions and 206 deletions.
208 changes: 2 additions & 206 deletions newlib/libc/stdio/vfprintf.c
Original file line number Diff line number Diff line change
Expand Up @@ -623,7 +623,7 @@ get_arg (struct _reent *data, int n, char *fmt,
#define SHORTINT 0x040 /* short integer */
#define ZEROPAD 0x080 /* zero (as opposed to blank) pad */
#define FPT 0x100 /* Floating point number */
#if defined(_WANT_IO_C99_FORMATS)
#ifdef _WANT_IO_C99_FORMATS
# define CHARINT 0x200 /* char as integer */
#else /* define as 0, to make SARG and UARG occupy fewer instructions */
# define CHARINT 0
Expand Down Expand Up @@ -715,13 +715,6 @@ _VFPRINTF_R (struct _reent *data,
mbstate_t state; /* mbtowc calls from library must not change state */
#endif
char *malloc_buf = NULL;/* handy pointer for malloced buffers */
#ifdef __mips
int vec_size = 2; /* 1 -> 64bits, 2 -> 128bits, 3 -> 256bits, ... */
int elem_idx = 0, elem_num = 0, elem_size = 32;
int processing_vec_type = 0;
int vec_spec = -1; /* format specifier w, W or y */
void *vec_base = NULL;
#endif

/*
* Choose PADSIZE to trade efficiency vs. size. If larger printf
Expand Down Expand Up @@ -847,55 +840,6 @@ _VFPRINTF_R (struct _reent *data,
(u_long)GET_ARG (N, ap, u_int))
#endif

#ifdef __mips
quad_t vec_sarg (void)
{
quad_t val;

if (flags & QUADINT)
val = (quad_t) *((quad_t *) vec_base + elem_idx);
else if (flags & LONGINT)
val = (quad_t) *((long *) vec_base + elem_idx);
else if (flags & SHORTINT)
val = (quad_t) *((short *) vec_base + elem_idx);
else if (flags & CHARINT)
val = (quad_t) *((signed char *) vec_base + elem_idx);
else
val = (quad_t) *((int *) vec_base + elem_idx);

#ifndef _NO_LONGLONG
if ((quad_t)val < 0)
#else
if ((long) val < 0)
#endif
{
val = -val;
sign = '-';
}

return val;
}

u_quad_t vec_uarg (void)
{
u_quad_t val;

if (flags & QUADINT)
val = *((u_quad_t *) vec_base + elem_idx);
else if (flags & LONGINT)
val = *((unsigned long *) vec_base + elem_idx);
else if (flags & SHORTINT)
val = *((unsigned short *) vec_base + elem_idx);
else if (flags & CHARINT)
val = *((unsigned char *) vec_base + elem_idx);
else
val = *((unsigned int *) vec_base + elem_idx);

return val;
}

#endif /* __mips */

#ifndef STRING_ONLY
/* Initialize std streams if not dealing with sprintf family. */
CHECK_INIT (data, fp);
Expand Down Expand Up @@ -1143,14 +1087,6 @@ reswitch: switch (ch) {
goto error;
}
#endif /* !_NO_POS_ARGS */

#ifdef __mips
if (ch == 'w' || ch == 'W' || ch == 'y') {
vec_size = n;
goto reswitch;
}
#endif

width = n;
goto reswitch;
#ifdef FLOATING_POINT
Expand All @@ -1159,7 +1095,7 @@ reswitch: switch (ch) {
goto rflag;
#endif
case 'h':
#if defined(_WANT_IO_C99_FORMATS)
#ifdef _WANT_IO_C99_FORMATS
if (*fmt == 'h') {
fmt++;
flags |= CHARINT;
Expand Down Expand Up @@ -1277,10 +1213,6 @@ reswitch: switch (ch) {
_fpvalue = GET_ARG (N, ap, double);
}

#ifdef __mips
float_number:
#endif

/* do this before tricky precision changes
If the output is infinite or NaN, leading
Expand Down Expand Up @@ -1318,10 +1250,6 @@ reswitch: switch (ch) {
_fpvalue = (_LONG_DOUBLE)GET_ARG (N, ap, double);
}

#ifdef __mips
float_number:
#endif

/* do this before tricky precision changes */
expt = _ldcheck (&_fpvalue);
if (expt == 2) {
Expand Down Expand Up @@ -1637,13 +1565,6 @@ number: if ((dprec = prec) >= 0)
* -- ANSI X3J11
*/
cp = buf + BUF;

#ifdef __mips
/* separate vector elements by space */
if (processing_vec_type == 1 && elem_num >= 2)
*--cp = ' ';
#endif

if (_uquad != 0 || prec != 0) {
/*
* Unsigned mod is hard, and unsigned mod
Expand Down Expand Up @@ -1724,124 +1645,6 @@ number: if ((dprec = prec) >= 0)
size = buf + BUF - cp;
skipsize:
break;

#ifdef __mips
case 'y':
case 'w':
case 'W':

/* preserve the format specifier */
if (vec_spec == -1)
vec_spec = ch;

base = DEC;
if (flags & ALT)
{
if (ch == 'W')
xdigs = "0123456789ABCDEF";
else
xdigs = "0123456789abcdef";
base = HEX;
}

/* find size of each element and number of such elements */
if ((flags & QUADINT) || (flags & LONGDBL))
{
elem_size = 64;
elem_num = (32 << vec_size) / 64;
}
else if (flags & LONGINT)
{
elem_size = 32;
elem_num = (32 << vec_size) / 32;
}
else if (flags & SHORTINT)
{
elem_size = 16;
elem_num = (32 << vec_size) / 16;
}
else if (flags & CHARINT)
{
elem_size = 8;
elem_num = (32 << vec_size) / 8;
}
else
{
elem_size = 32;
elem_num = (32 << vec_size) / 32;
}

/* start the processing of vector data types */
processing_vec_type = 1;

/* fetch the vector base address */
vec_base = (void *) va_arg (ap, void*);
elem_idx = 0;

/* main loop which prints elements in the vector */
mips_print_vec:
/* stop if we have processed elem_num */
if (elem_num <= 0)
{
processing_vec_type = 0; /* end of vector data processing */
vec_spec = -1;
elem_idx = 0;
flags &= ~FPT;
break;
}

#ifdef FLOATING_POINT
if (vec_spec == 'y')
{
ch = 'f';

if (flags & LONGDBL)
{
double *dbl_ptr = (double*) vec_base;
_fpvalue = (double) dbl_ptr[elem_idx];
}
else
{
float *flt_ptr = (float*) vec_base;
_fpvalue = (double) flt_ptr[elem_idx];
}

elem_idx++;
goto float_number;
}
else
#endif
{
if (vec_spec == 'W')
_uquad = vec_uarg (); /* unsigned */
else
_uquad = vec_sarg (); /* signed */

elem_idx++;
goto number; /* process as if it is a normal number */
}

/* back from printing a number */
mips_print_vec_check:

/* print space after a floating point number */
if (vec_spec == 'y' && elem_num >= 2)
PRINT (" ", 1);

elem_num--;
cp = buf + BUF; /* clear the output buffer */
size = 0;
dprec = 0;
sign = '\0';
#ifdef FLOATING_POINT
lead = 0;
#endif
prec = -1;
goto mips_print_vec; /* loop back */

break;
#endif /* __mips */

default: /* "%?" prints ?, unless ? is NUL */
if (ch == '\0')
goto done;
Expand Down Expand Up @@ -1970,13 +1773,6 @@ number: if ((dprec = prec) >= 0)
_free_r (data, malloc_buf);
malloc_buf = NULL;
}

#ifdef __mips
/* loop back to check if there are more elements to process */
if (processing_vec_type == 1)
goto mips_print_vec_check;
#endif

}
done:
FLUSH ();
Expand Down

0 comments on commit cdfc026

Please sign in to comment.