From 267ec305aca39037677145fe1d314a8c7533266f Mon Sep 17 00:00:00 2001 From: Nicolas Roussin Date: Mon, 3 Nov 2025 14:57:23 +0000 Subject: [PATCH] Implement W_negate function. --- lib_basop/enh64.c | 43 +++++++++++++++++++++++++++++++++++++++++++ lib_basop/enh64.h | 1 + lib_debug/wmc_auto.c | 2 +- lib_debug/wmc_auto.h | 1 + 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/lib_basop/enh64.c b/lib_basop/enh64.c index 8bffb620c..08534c8dc 100644 --- a/lib_basop/enh64.c +++ b/lib_basop/enh64.c @@ -128,6 +128,49 @@ Word64 W_sub_nosat( Word64 L64_var1, Word64 L64_var2 ) } +/*__________________________________________________________________________________ + | | + | Function Name : W_negate | + | | + | Purpose : | + | | + | Negate the 64 bit variable L64_var1 with saturation; saturate in the case | + | where input is 0x8000 0000 0000 0000. | + | | + | Complexity weight : 1 | + | | + | Inputs : | + | | + | L64_var1 64 bit long signed integer (Word64) whose value falls in the range: | + | 0x8000 0000 0000 0000 <= L64_var1 <= 0x7fff ffff ffff ffff. | + | | + | Outputs : | + | | + | none | + | | + | Return Value : | + | | + | L64_var_out | + | 64 bit long signed integer (Word64) whose value falls in the range: | + | 0x8000 0000 0000 0000 <= L_var_out <= 0x7fff ffff ffff ffff. | + |_________________________________________________________________________________| +*/ +Word64 W_negate( Word64 L64_var1 ) +{ + Word64 L64_var_out; + + L64_var_out = ( L64_var1 == MIN_64 ) ? MAX_64 : -L64_var1; + +#ifdef WMOPS + multiCounter[currCounter].W_negate++; +#endif + + BASOP_CHECK(); + + return ( L64_var_out ); +} + + /*___________________________________________________________________________ | | | Function Name : W_shl | diff --git a/lib_basop/enh64.h b/lib_basop/enh64.h index c3896bb0d..7358fc56b 100644 --- a/lib_basop/enh64.h +++ b/lib_basop/enh64.h @@ -23,6 +23,7 @@ #ifdef ENH_64_BIT_OPERATOR Word64 W_add_nosat( Word64 L64_var1, Word64 L64_var2 ); Word64 W_sub_nosat( Word64 L64_var1, Word64 L64_var2 ); +Word64 W_negate( Word64 L64_var1 ); Word64 W_shl( Word64 L64_var1, Word16 var2 ); Word64 W_shr( Word64 L64_var1, Word16 var2 ); Word64 W_shl_nosat( Word64 L64_var1, Word16 var2 ); diff --git a/lib_debug/wmc_auto.c b/lib_debug/wmc_auto.c index 5afd9de16..e7cc88031 100644 --- a/lib_debug/wmc_auto.c +++ b/lib_debug/wmc_auto.c @@ -133,7 +133,7 @@ static BASIC_OP op_weight = { #ifdef ENH_64_BIT_OPERATOR /* Weights of new 64 bit basops */ , - 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 #endif /* #ifdef ENH_64_BIT_OPERATOR */ #ifdef ENH_32_BIT_OPERATOR diff --git a/lib_debug/wmc_auto.h b/lib_debug/wmc_auto.h index 64e2c751a..a1465df58 100644 --- a/lib_debug/wmc_auto.h +++ b/lib_debug/wmc_auto.h @@ -879,6 +879,7 @@ typedef struct unsigned int move64; /* Complexity Weight of 1 */ unsigned int W_add_nosat; /* Complexity Weight of 1 */ unsigned int W_sub_nosat; /* Complexity Weight of 1 */ + unsigned int W_negate; /* Complexity Weight of 1 */ unsigned int W_shl; /* Complexity Weight of 1 */ unsigned int W_shr; /* Complexity Weight of 1 */ unsigned int W_shl_nosat; /* Complexity Weight of 1 */ -- GitLab