Add bswapr_us, bswapr_ui, and bswapr_ul API functions - lightning.git - Portable just-in-time compiler library

index : lightning.git
Portable just-in-time compiler library
summary refs log tree commit diff
path: root/lib/jit_arm-cpu.c
diff options
context:
space:
mode:
authorPaul Cercueil <paul@crapouillou.net>2022年05月25日 19:18:20 +0100
committerpcpa <paulo.cesar.pereira.de.andrade@gmail.com>2022年05月25日 16:23:11 -0300
commitc44a80ca20ed534f4cf49e656bd9b7989633f4ea (patch)
treee7370910582f58cde22629f0a3ac68d09c337905 /lib/jit_arm-cpu.c
parent44e8674a3aa32547b6161e2fb4212b7de2c0f707 (diff)
downloadlightning-c44a80ca20ed534f4cf49e656bd9b7989633f4ea.tar.gz
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 <paul@crapouillou.net>
Diffstat (limited to 'lib/jit_arm-cpu.c')
-rw-r--r--lib/jit_arm-cpu.c 28
1 files changed, 7 insertions, 21 deletions
diff --git a/lib/jit_arm-cpu.c b/lib/jit_arm-cpu.c
index c4a550d..14ba36b 100644
--- a/lib/jit_arm-cpu.c
+++ b/lib/jit_arm-cpu.c
@@ -1095,15 +1095,10 @@ static void _sti_i(jit_state_t*,jit_word_t,jit_int32_t);
static void _stxr_i(jit_state_t*,jit_word_t,jit_int32_t,jit_int32_t);
# define stxi_i(r0,r1,i0) _stxi_i(_jit,r0,r1,i0)
static void _stxi_i(jit_state_t*,jit_word_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);
-# else
-# define htonr_us(r0,r1) extr_us(r0,r1)
-# define htonr(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 extr_c(r0,r1) _extr_c(_jit,r0,r1)
static void _extr_c(jit_state_t*,jit_int32_t,jit_int32_t);
# define extr_uc(r0,r1) _extr_uc(_jit,r0,r1)
@@ -3609,11 +3604,9 @@ _stxi_i(jit_state_t *_jit, jit_word_t i0, jit_int32_t r0, jit_int32_t r1)
}
}
-# if __BYTE_ORDER == __LITTLE_ENDIAN
static void
-_htonr_us(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
+_bswapr_us(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
{
- jit_int32_t t0;
if (jit_thumb_p()) {
if ((r0|r1) < 8)
T1_REV(r0, r1);
@@ -3627,20 +3620,14 @@ _htonr_us(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
rshi_u(r0, r0, 16);
}
else {
- 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);
+ generic_bswapr_us(_jit, r0, r1);
}
}
}
/* inline glibc htonl (without register clobber) */
static void
-_htonr_ui(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
+_bswapr_ui(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
{
jit_int32_t reg;
if (jit_thumb_p()) {
@@ -3662,7 +3649,6 @@ _htonr_ui(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
}
}
}
-#endif
static void
_extr_c(jit_state_t *_jit, jit_int32_t r0, jit_int32_t r1)
generated by cgit v1.2.3 (git 2.39.1) at 2025年09月13日 01:58:21 +0000

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