revert between 56095 -> 55830 in arch
[AROS.git] / rom / filesys / SFS / FS / asmsupport.h
blob2d84af27b20d08f985964f2d2b58ced55899a37e
1 #ifndef ASMSUPPORT_H_
2 #define ASMSUPPORT_H_
4 #ifdef __AROS__
5 #include <exec/rawfmt.h>
6 #endif
7 #ifdef __MORPHOS__
8 #include <exec/rawfmt.h>
9 #endif
10 #include <exec/types.h>
12 #if defined __i386__
13 static inline LONG fls(ULONG mask)
15 LONG bit = -1;
17 if (mask)
18 asm volatile("bsr %1, %0":"=r"(bit):"rm"(mask));
20 return (bit + 1);
22 #else
23 static inline LONG fls(ULONG mask)
25 LONG bit;
27 if (mask == 0)
28 return (0);
30 for (bit = 1; mask != 1; bit++)
31 mask = mask >> 1;
33 return (bit);
35 #endif
37 /* Finds first set bit in /data/ starting at /bitoffset/. This function
38 considers the MSB to be the first bit. */
39 static inline WORD bfffo(ULONG data, WORD bitoffset)
41 ULONG mask = 0xffffffff >> bitoffset;
42 data &= mask;
43 return data == 0 ? 32 : 32-fls(data);
46 /* Finds first zero bit in /data/ starting at /bitoffset/. This function
47 considers the MSB to be the first bit. */
48 static inline WORD bfffz(ULONG data, WORD bitoffset)
50 return bfffo(~data, bitoffset);
53 ULONG bfcnto(ULONG v);
54 ULONG bfcntz(ULONG v);
55 LONG bmflo(ULONG *bitmap, LONG bitoffset);
56 LONG bmflz(ULONG *bitmap, LONG bitoffset);
57 LONG bmffo(ULONG *bitmap, LONG longs, LONG bitoffset);
58 LONG bmffz(ULONG *bitmap, LONG longs, LONG bitoffset);
59 LONG bmclr(ULONG *bitmap, LONG longs, LONG bitoffset, LONG bits);
60 LONG bmset(ULONG *bitmap, LONG longs, LONG bitoffset, LONG bits);
61 BOOL bmtsto(ULONG *bitmap, LONG bitoffset, LONG bits);
62 BOOL bmtstz(ULONG *bitmap, LONG bitoffset, LONG bits);
63 ULONG bmcnto(ULONG *bitmap, LONG bitoffset, LONG bits);
64 ULONG bmcntz(ULONG *bitmap, LONG bitoffset, LONG bits);
66 ULONG CALCCHECKSUM(ULONG, ULONG *);
68 #ifdef RAWFMTFUNC_STRING
69 #define putChFunc RAWFMTFUNC_STRING
70 #else
71 #define putChFunc (void (*)())"\x16\xC0\x4E\x75"
72 #endif
74 #ifdef SFS_BE
75 #define BE2L AROS_BE2LONG
76 #define L2BE AROS_LONG2BE
77 #define BE2W AROS_BE2WORD
78 #define W2BE AROS_WORD2BE
79 #else
80 #define BE2L AROS_LE2LONG
81 #define L2BE AROS_LONG2LE
82 #define BE2W AROS_LE2WORD
83 #define W2BE AROS_WORD2LE
84 #endif
87 #ifdef __i386__
88 #define AROS_SWAP_BYTES_LONG_CPU(l) \
89 ({ ULONG v; __asm__ __volatile__("bswap %0":"=r"(v):"0"(l)); v;})
90 #define AROS_SWAP_BYTES_WORD_CPU(l) \
91 ({ UWORD w; __asm__ __volatile__("xchgb %b0,%h0":"=q"(w):"0"(l)); w;})
92 #endif
95 #endif /*ASMSUPPORT_H_*/