@samitouri / QOSamiQemu / commits / 6cced95c28

tcg: Expand missing rotri with extract2

Use extract2 to implement rotri. To make this easier, redefine rotli in terms of rotri, rather than the reverse. Reviewed-by: Jim MacArthur <jim.macarthur@linaro.org> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-ID: <20260303010833.1115741-5-richard.henderson@linaro.org> Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>

Richard Henderson committed Jan 1, 2025 at 21:31 UTC 6cced95c28dbf63000eeab4fffe14b1ff9f22bcc
1 file changed +24 -28
tcg/tcg-op.c
+24 -28
@@ -826,23 +826,12 @@ void tcg_gen_rotl_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
826 void tcg_gen_rotli_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
827 {
828 tcg_debug_assert(arg2 >= 0 && arg2 < 32);
829 - /* some cases can be optimized here */
829 if (arg2 == 0) {
830 tcg_gen_mov_i32(ret, arg1);
831 } else if (tcg_op_supported(INDEX_op_rotl, TCG_TYPE_I32, 0)) {
833 - TCGv_i32 t0 = tcg_constant_i32(arg2);
834 - tcg_gen_op3_i32(INDEX_op_rotl, ret, arg1, t0);
835 - } else if (tcg_op_supported(INDEX_op_rotr, TCG_TYPE_I32, 0)) {
836 - TCGv_i32 t0 = tcg_constant_i32(32 - arg2);
837 - tcg_gen_op3_i32(INDEX_op_rotr, ret, arg1, t0);
832 + tcg_gen_op3_i32(INDEX_op_rotl, ret, arg1, tcg_constant_i32(arg2));
833 } else {
839 - TCGv_i32 t0 = tcg_temp_ebb_new_i32();
840 - TCGv_i32 t1 = tcg_temp_ebb_new_i32();
841 - tcg_gen_shli_i32(t0, arg1, arg2);
842 - tcg_gen_shri_i32(t1, arg1, 32 - arg2);
843 - tcg_gen_or_i32(ret, t0, t1);
844 - tcg_temp_free_i32(t0);
845 - tcg_temp_free_i32(t1);
834 + tcg_gen_rotri_i32(ret, arg1, -arg2 & 31);
835 }
836 }
837
@@ -870,7 +859,16 @@ void tcg_gen_rotr_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2)
859 void tcg_gen_rotri_i32(TCGv_i32 ret, TCGv_i32 arg1, int32_t arg2)
860 {
861 tcg_debug_assert(arg2 >= 0 && arg2 < 32);
873 - tcg_gen_rotli_i32(ret, arg1, -arg2 & 31);
862 + if (arg2 == 0) {
863 + tcg_gen_mov_i32(ret, arg1);
864 + } else if (tcg_op_supported(INDEX_op_rotr, TCG_TYPE_I32, 0)) {
865 + tcg_gen_op3_i32(INDEX_op_rotr, ret, arg1, tcg_constant_i32(arg2));
866 + } else if (tcg_op_supported(INDEX_op_rotl, TCG_TYPE_I32, 0)) {
867 + tcg_gen_op3_i32(INDEX_op_rotl, ret, arg1, tcg_constant_i32(32 - arg2));
868 + } else {
869 + /* Do not recurse with the rotri simplification. */
870 + tcg_gen_op4i_i32(INDEX_op_extract2, ret, arg1, arg1, arg2);
871 + }
872 }
873
874 void tcg_gen_deposit_i32(TCGv_i32 ret, TCGv_i32 arg1, TCGv_i32 arg2,
@@ -2042,23 +2040,12 @@ void tcg_gen_rotl_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
2040 void tcg_gen_rotli_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
2041 {
2042 tcg_debug_assert(arg2 >= 0 && arg2 < 64);
2045 - /* some cases can be optimized here */
2043 if (arg2 == 0) {
2044 tcg_gen_mov_i64(ret, arg1);
2045 } else if (tcg_op_supported(INDEX_op_rotl, TCG_TYPE_I64, 0)) {
2049 - TCGv_i64 t0 = tcg_constant_i64(arg2);
2050 - tcg_gen_op3_i64(INDEX_op_rotl, ret, arg1, t0);
2051 - } else if (tcg_op_supported(INDEX_op_rotr, TCG_TYPE_I64, 0)) {
2052 - TCGv_i64 t0 = tcg_constant_i64(64 - arg2);
2053 - tcg_gen_op3_i64(INDEX_op_rotr, ret, arg1, t0);
2046 + tcg_gen_op3_i64(INDEX_op_rotl, ret, arg1, tcg_constant_i64(arg2));
2047 } else {
2055 - TCGv_i64 t0 = tcg_temp_ebb_new_i64();
2056 - TCGv_i64 t1 = tcg_temp_ebb_new_i64();
2057 - tcg_gen_shli_i64(t0, arg1, arg2);
2058 - tcg_gen_shri_i64(t1, arg1, 64 - arg2);
2059 - tcg_gen_or_i64(ret, t0, t1);
2060 - tcg_temp_free_i64(t0);
2061 - tcg_temp_free_i64(t1);
2048 + tcg_gen_rotri_i64(ret, arg1, -arg2 & 63);
2049 }
2050 }
2051
@@ -2086,7 +2073,16 @@ void tcg_gen_rotr_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2)
2073 void tcg_gen_rotri_i64(TCGv_i64 ret, TCGv_i64 arg1, int64_t arg2)
2074 {
2075 tcg_debug_assert(arg2 >= 0 && arg2 < 64);
2089 - tcg_gen_rotli_i64(ret, arg1, -arg2 & 63);
2076 + if (arg2 == 0) {
2077 + tcg_gen_mov_i64(ret, arg1);
2078 + } else if (tcg_op_supported(INDEX_op_rotr, TCG_TYPE_I64, 0)) {
2079 + tcg_gen_op3_i64(INDEX_op_rotr, ret, arg1, tcg_constant_i64(arg2));
2080 + } else if (tcg_op_supported(INDEX_op_rotl, TCG_TYPE_I64, 0)) {
2081 + tcg_gen_op3_i64(INDEX_op_rotl, ret, arg1, tcg_constant_i64(64 - arg2));
2082 + } else {
2083 + /* Do not recurse with the rotri simplification. */
2084 + tcg_gen_op4i_i64(INDEX_op_extract2, ret, arg1, arg1, arg2);
2085 + }
2086 }
2087
2088 void tcg_gen_deposit_i64(TCGv_i64 ret, TCGv_i64 arg1, TCGv_i64 arg2,