From c44a80ca20ed534f4cf49e656bd9b7989633f4ea Mon Sep 17 00:00:00 2001 From: Paul Cercueil Date: 2022年5月25日 19:18:20 +0100 Subject: Add bswapr_us, bswapr_ui, and bswapr_ul API functions The difference between bswapr and htonr/ntohr, is that the operation performed by bswap does not depend on the endianness of the host CPU. On little-endian however, the new bswapr functions are functionally equal to the htonr/ntohr ones. The implementations of the latter ones have then be removed, and will resolve to the corresponding bswapr function on little-endian, or to movr/extr functions on big-endian. Optional generic bswapr implementations are provided in lightning.c, which can be used (or not) by the arch cpu.c files when there's nothing better to do. The bswapr implementations are generally following the previous htonr implementations on little-endian systems, with the exception of the IA-64 architecture, where the htonr implementation seemed sub-par, and a better (yet untested) implementation has been added. This change has been tested on MIPS, x86 and PowerPC. Signed-off-by: Paul Cercueil --- lib/jit_ia64-cpu.c | 72 ++++++++++++++---------------------------------------- 1 file changed, 19 insertions(+), 53 deletions(-) (limited to 'lib/jit_ia64-cpu.c') diff --git a/lib/jit_ia64-cpu.c b/lib/jit_ia64-cpu.c index 9953875..63bb92d 100644 --- a/lib/jit_ia64-cpu.c +++ b/lib/jit_ia64-cpu.c @@ -1311,17 +1311,11 @@ static jit_word_t _movi_p(jit_state_t*,jit_int32_t,jit_word_t); static void _movnr(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t); # define movzr(r0,r1,r2) _movzr(_jit,r0,r1,r2) static void _movzr(jit_state_t*,jit_int32_t,jit_int32_t,jit_int32_t); -#if __BYTE_ORDER == __LITTLE_ENDIAN -# define htonr_us(r0,r1) _htonr_us(_jit,r0,r1) -static void _htonr_us(jit_state_t*,jit_int32_t,jit_int32_t); -# define htonr_ui(r0,r1) _htonr_ui(_jit,r0,r1) -static void _htonr_ui(jit_state_t*,jit_int32_t,jit_int32_t); -# define htonr_ul(r0,r1) MUX1(r0,r1,MUX_REV) -#else -# define htonr_us(r0,r1) extr_us(r0,r1) -# define htonr_ui(r0,r1) extr_ui(r0,r1) -# define htonr_ul(r0,r1) movr(r0,r1) -#endif +# define bswapr_us(r0,r1) _bswapr_us(_jit,r0,r1) +static void _bswapr_us(jit_state_t*,jit_int32_t,jit_int32_t); +# define bswapr_ui(r0,r1) _bswapr_ui(_jit,r0,r1) +static void _bswapr_ui(jit_state_t*,jit_int32_t,jit_int32_t); +# define bswapr_ul(r0,r1) MUX1(r0,r1,MUX_REV) #define extr_c(r0,r1) SXT1(r0,r1) #define extr_uc(r0,r1) ZXT1(r0,r1) #define extr_s(r0,r1) SXT2(r0,r1) @@ -3505,6 +3499,20 @@ _movzr(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_int32_t r2) patch_at(w, _jit->pc.w); } +static void +_bswapr_us(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1) +{ + bswapr_ul(r0, r1); + rshi_u(r0, r0, 48); +} + +static void +_bswapr_ui(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1) +{ + bswapr_ul(r0, r1); + rshi_u(r0, r0, 32); +} + static void _addi(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0) { @@ -3971,48 +3979,6 @@ _xori(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0) } } -#if __BYTE_ORDER == __LITTLE_ENDIAN -static void -_htonr_us(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1) -{ - jit_int32_t t0; - t0 = jit_get_reg(jit_class_gpr); - rshi(rn(t0), r1, 8); - andi(r0, r1, 0xff); - andi(rn(t0), rn(t0), 0xff); - lshi(r0, r0, 8); - orr(r0, r0, rn(t0)); - jit_unget_reg(t0); -} - -static void -_htonr_ui(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1) -{ - jit_int32_t t0; - jit_int32_t t1; - jit_int32_t t2; - t0 = jit_get_reg(jit_class_gpr); - t1 = jit_get_reg(jit_class_gpr); - t2 = jit_get_reg(jit_class_gpr); - rshi(rn(t0), r1, 24); - rshi(rn(t1), r1, 16); - rshi(rn(t2), r1, 8); - andi(rn(t0), rn(t0), 0xff); - andi(rn(t1), rn(t1), 0xff); - andi(rn(t2), rn(t2), 0xff); - andi(r0, r1, 0xff); - lshi(r0, r0, 24); - lshi(rn(t1), rn(t1), 8); - orr(r0, r0, rn(t0)); - lshi(rn(t2), rn(t2), 16); - orr(r0, r0, rn(t1)); - orr(r0, r0, rn(t2)); - jit_unget_reg(t2); - jit_unget_reg(t1); - jit_unget_reg(t0); -} -#endif - static void _lshi(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1, jit_word_t i0) { -- cgit v1.2.3

AltStyle によって変換されたページ (->オリジナル) /