Peter Maydell writes:
> helper.c includes some small TCG helper functions used for mostly
> arithmetic instructions. These are TCG only and there's no need for
> them to be in the large and unwieldy helper.c. Move them out to
> their own source file in the tcg/ subdirectory, together with the
> op_addsub.h multiply-included template header that they use.
>
> Since we are moving op_addsub.h, we take the opportunity to
> give it a name which matches our convention for files which
> are not true header files but which are #included from other
> C files: op_addsub.c.inc.
>
> (Ironically, this means that helper.c no longer contains
> any TCG helper function definitions at all.)
What's left? It mostly looks like cpreg related stuff. I guess it could
become cpreg.c?
>
> Signed-off-by: Peter Maydell
> Reviewed-by: Richard Henderson
Anyway:
Reviewed-by: Alex Bennée
> ---
> v1->v2: rename op_addsub.h to op_addsub.c.inc.
> ---
> target/arm/helper.c | 285 -
> target/arm/tcg/arith_helper.c | 296 ++
> .../arm/{op_addsub.h => tcg/op_addsub.c.inc} | 0
> target/arm/tcg/meson.build| 1 +
> 4 files changed, 297 insertions(+), 285 deletions(-)
> create mode 100644 target/arm/tcg/arith_helper.c
> rename target/arm/{op_addsub.h => tcg/op_addsub.c.inc} (100%)
>
> diff --git a/target/arm/helper.c b/target/arm/helper.c
> index 5b595f951b4..63997678513 100644
> --- a/target/arm/helper.c
> +++ b/target/arm/helper.c
> @@ -17,11 +17,9 @@
> #include "qemu/main-loop.h"
> #include "qemu/timer.h"
> #include "qemu/bitops.h"
> -#include "qemu/crc32c.h"
> #include "qemu/qemu-print.h"
> #include "exec/exec-all.h"
> #include "exec/translation-block.h"
> -#include /* for crc32 */
> #include "hw/irq.h"
> #include "system/cpu-timers.h"
> #include "system/kvm.h"
> @@ -10984,289 +10982,6 @@ ARMVAParameters aa64_va_parameters(CPUARMState
> *env, uint64_t va,
> };
> }
>
> -/*
> - * Note that signed overflow is undefined in C. The following routines are
> - * careful to use unsigned types where modulo arithmetic is required.
> - * Failure to do so _will_ break on newer gcc.
> - */
> -
> -/* Signed saturating arithmetic. */
> -
> -/* Perform 16-bit signed saturating addition. */
> -static inline uint16_t add16_sat(uint16_t a, uint16_t b)
> -{
> -uint16_t res;
> -
> -res = a + b;
> -if (((res ^ a) & 0x8000) && !((a ^ b) & 0x8000)) {
> -if (a & 0x8000) {
> -res = 0x8000;
> -} else {
> -res = 0x7fff;
> -}
> -}
> -return res;
> -}
> -
> -/* Perform 8-bit signed saturating addition. */
> -static inline uint8_t add8_sat(uint8_t a, uint8_t b)
> -{
> -uint8_t res;
> -
> -res = a + b;
> -if (((res ^ a) & 0x80) && !((a ^ b) & 0x80)) {
> -if (a & 0x80) {
> -res = 0x80;
> -} else {
> -res = 0x7f;
> -}
> -}
> -return res;
> -}
> -
> -/* Perform 16-bit signed saturating subtraction. */
> -static inline uint16_t sub16_sat(uint16_t a, uint16_t b)
> -{
> -uint16_t res;
> -
> -res = a - b;
> -if (((res ^ a) & 0x8000) && ((a ^ b) & 0x8000)) {
> -if (a & 0x8000) {
> -res = 0x8000;
> -} else {
> -res = 0x7fff;
> -}
> -}
> -return res;
> -}
> -
> -/* Perform 8-bit signed saturating subtraction. */
> -static inline uint8_t sub8_sat(uint8_t a, uint8_t b)
> -{
> -uint8_t res;
> -
> -res = a - b;
> -if (((res ^ a) & 0x80) && ((a ^ b) & 0x80)) {
> -if (a & 0x80) {
> -res = 0x80;
> -} else {
> -res = 0x7f;
> -}
> -}
> -return res;
> -}
> -
> -#define ADD16(a, b, n) RESULT(add16_sat(a, b), n, 16);
> -#define SUB16(a, b, n) RESULT(sub16_sat(a, b), n, 16);
> -#define ADD8(a, b, n) RESULT(add8_sat(a, b), n, 8);
> -#define SUB8(a, b, n) RESULT(sub8_sat(a, b), n, 8);
> -#define PFX q
> -
> -#include "op_addsub.h"
> -
> -/* Unsigned saturating arithmetic. */
> -static inline uint16_t add16_usat(uint16_t a, uint16_t b)
> -{
> -uint16_t res;
> -res = a + b;
> -if (res < a) {
> -res = 0x;
> -}
> -return res;
> -}
> -
> -static inline uint16_t sub16_usat(uint16_t a, uint16_t b)
> -{
> -if (a > b) {
> -return a - b;
> -} else {
> -return 0;
> -}
> -}
> -
> -static inline uint8_t add8_usat(uint8_t a, uint8_t b)
> -{
> -uint8_t res;
> -res = a + b;
> -if (res < a) {
> -res = 0xff;
> -}
> -return res;
> -}
> -
> -static inline uint8_t sub8_usat(uint8_t a, uint8_t b)
> -{
> -if (a > b) {
> -return a - b;
> -} else {
> -return 0;
> -}
> -}
> -
> -#define ADD16(a, b, n) RESULT(add16_usat(a, b), n, 16);
> -#define SUB16(a, b, n) RESULT(sub16_usat(a, b), n, 16);
> -#define ADD8(a, b, n) RESULT(add8_usat(a, b), n, 8);
> -#define SUB8(a, b, n) RESULT(sub8_usat(a, b), n, 8);
>