Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

jfs: get rid of homegrown endianness helpers

Get rid of le24 stuff, along with the bitfields use - all that stuff
can be done with standard stuff, in sparse-verifiable manner. Moreover,
that way (shift-and-mask) often generates better code - gcc optimizer
sucks on bitfields...

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
Signed-off-by: Dave Kleikamp <dave.kleikamp@oracle.com>
----

authored by

Al Viro and committed by
Dave Kleikamp
e1f1fe79 53262d12

+44 -89
-49
fs/jfs/endian24.h
··· 1 - /* 2 - * Copyright (C) International Business Machines Corp., 2001 3 - * 4 - * This program is free software; you can redistribute it and/or modify 5 - * it under the terms of the GNU General Public License as published by 6 - * the Free Software Foundation; either version 2 of the License, or 7 - * (at your option) any later version. 8 - * 9 - * This program is distributed in the hope that it will be useful, 10 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 12 - * the GNU General Public License for more details. 13 - * 14 - * You should have received a copy of the GNU General Public License 15 - * along with this program; if not, write to the Free Software 16 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 - */ 18 - #ifndef _H_ENDIAN24 19 - #define _H_ENDIAN24 20 - 21 - /* 22 - * endian24.h: 23 - * 24 - * Endian conversion for 24-byte data 25 - * 26 - */ 27 - #define __swab24(x) \ 28 - ({ \ 29 - __u32 __x = (x); \ 30 - ((__u32)( \ 31 - ((__x & (__u32)0x000000ffUL) << 16) | \ 32 - (__x & (__u32)0x0000ff00UL) | \ 33 - ((__x & (__u32)0x00ff0000UL) >> 16) )); \ 34 - }) 35 - 36 - #if (defined(__KERNEL__) && defined(__LITTLE_ENDIAN)) || (defined(__BYTE_ORDER) && (__BYTE_ORDER == __LITTLE_ENDIAN)) 37 - #define __cpu_to_le24(x) ((__u32)(x)) 38 - #define __le24_to_cpu(x) ((__u32)(x)) 39 - #else 40 - #define __cpu_to_le24(x) __swab24(x) 41 - #define __le24_to_cpu(x) __swab24(x) 42 - #endif 43 - 44 - #ifdef __KERNEL__ 45 - #define cpu_to_le24 __cpu_to_le24 46 - #define le24_to_cpu __le24_to_cpu 47 - #endif 48 - 49 - #endif /* !_H_ENDIAN24 */
+2 -2
fs/jfs/jfs_dtree.c
··· 1040 1040 pxdlist.maxnpxd = 1; 1041 1041 pxdlist.npxd = 0; 1042 1042 pxd = &pxdlist.pxd[0]; 1043 - PXDaddress(pxd, nxaddr) 1044 - PXDlength(pxd, xlen + n); 1043 + PXDaddress(pxd, nxaddr); 1044 + PXDlength(pxd, xlen + n); 1045 1045 split->pxdlist = &pxdlist; 1046 1046 if ((rc = dtExtendPage(tid, ip, split, btstack))) { 1047 1047 nxaddr = addressPXD(pxd);
+33 -22
fs/jfs/jfs_types.h
··· 30 30 #include <linux/types.h> 31 31 #include <linux/nls.h> 32 32 33 - #include "endian24.h" 34 - 35 33 /* 36 34 * transaction and lock id's 37 35 * ··· 57 59 58 60 /* 59 61 * physical xd (pxd) 62 + * 63 + * The leftmost 24 bits of len_addr are the extent length. 64 + * The rightmost 8 bits of len_addr are the most signficant bits of 65 + * the extent address 60 66 */ 61 67 typedef struct { 62 - unsigned len:24; 63 - unsigned addr1:8; 68 + __le32 len_addr; 64 69 __le32 addr2; 65 70 } pxd_t; 66 71 67 72 /* xd_t field construction */ 68 73 69 - #define PXDlength(pxd, length32) ((pxd)->len = __cpu_to_le24(length32)) 70 - #define PXDaddress(pxd, address64)\ 71 - {\ 72 - (pxd)->addr1 = ((s64)address64) >> 32;\ 73 - (pxd)->addr2 = __cpu_to_le32((address64) & 0xffffffff);\ 74 + static inline void PXDlength(pxd_t *pxd, __u32 len) 75 + { 76 + pxd->len_addr = (pxd->len_addr & cpu_to_le32(~0xffffff)) | 77 + cpu_to_le32(len & 0xffffff); 78 + } 79 + 80 + static inline void PXDaddress(pxd_t *pxd, __u64 addr) 81 + { 82 + pxd->len_addr = (pxd->len_addr & cpu_to_le32(0xffffff)) | 83 + cpu_to_le32((addr >> 32)<<24); 84 + pxd->addr2 = cpu_to_le32(addr & 0xffffffff); 74 85 } 75 86 76 87 /* xd_t field extraction */ 77 - #define lengthPXD(pxd) __le24_to_cpu((pxd)->len) 78 - #define addressPXD(pxd)\ 79 - ( ((s64)((pxd)->addr1)) << 32 | __le32_to_cpu((pxd)->addr2)) 88 + static inline __u32 lengthPXD(pxd_t *pxd) 89 + { 90 + return le32_to_cpu((pxd)->len_addr) & 0xffffff; 91 + } 92 + 93 + static inline __u64 addressPXD(pxd_t *pxd) 94 + { 95 + __u64 n = le32_to_cpu(pxd->len_addr) & ~0xffffff; 96 + return (n << 8) + le32_to_cpu(pxd->addr2); 97 + } 80 98 81 99 #define MAXTREEHEIGHT 8 82 100 /* pxd list */ ··· 107 93 * data extent descriptor (dxd) 108 94 */ 109 95 typedef struct { 110 - unsigned flag:8; /* 1: flags */ 111 - unsigned rsrvd:24; 96 + __u8 flag; /* 1: flags */ 97 + __u8 rsrvd[3]; 112 98 __le32 size; /* 4: size in byte */ 113 - unsigned len:24; /* 3: length in unit of fsblksize */ 114 - unsigned addr1:8; /* 1: address in unit of fsblksize */ 115 - __le32 addr2; /* 4: address in unit of fsblksize */ 99 + pxd_t loc; /* 8: address and length in unit of fsblksize */ 116 100 } dxd_t; /* - 16 - */ 117 101 118 102 /* dxd_t flags */ ··· 121 109 #define DXD_CORRUPT 0x08 /* Inconsistency detected */ 122 110 123 111 /* dxd_t field construction 124 - * Conveniently, the PXD macros work for DXD 125 112 */ 126 - #define DXDlength PXDlength 127 - #define DXDaddress PXDaddress 128 - #define lengthDXD lengthPXD 129 - #define addressDXD addressPXD 113 + #define DXDlength(dxd, len) PXDlength(&(dxd)->loc, len) 114 + #define DXDaddress(dxd, addr) PXDaddress(&(dxd)->loc, addr) 115 + #define lengthDXD(dxd) lengthPXD(&(dxd)->loc) 116 + #define addressDXD(dxd) addressPXD(&(dxd)->loc) 130 117 #define DXDsize(dxd, size32) ((dxd)->size = cpu_to_le32(size32)) 131 118 #define sizeDXD(dxd) le32_to_cpu((dxd)->size) 132 119
+9 -16
fs/jfs/jfs_xtree.h
··· 29 29 * extent allocation descriptor (xad) 30 30 */ 31 31 typedef struct xad { 32 - unsigned flag:8; /* 1: flag */ 33 - unsigned rsvrd:16; /* 2: reserved */ 34 - unsigned off1:8; /* 1: offset in unit of fsblksize */ 35 - __le32 off2; /* 4: offset in unit of fsblksize */ 36 - unsigned len:24; /* 3: length in unit of fsblksize */ 37 - unsigned addr1:8; /* 1: address in unit of fsblksize */ 38 - __le32 addr2; /* 4: address in unit of fsblksize */ 32 + __u8 flag; /* 1: flag */ 33 + __u8 rsvrd[2]; /* 2: reserved */ 34 + __u8 off1; /* 1: offset in unit of fsblksize */ 35 + __le32 off2; /* 4: offset in unit of fsblksize */ 36 + pxd_t loc; /* 8: length and address in unit of fsblksize */ 39 37 } xad_t; /* (16) */ 40 38 41 39 #define MAXXLEN ((1 << 24) - 1) ··· 47 49 (xad)->off1 = ((u64)offset64) >> 32;\ 48 50 (xad)->off2 = __cpu_to_le32((offset64) & 0xffffffff);\ 49 51 } 50 - #define XADaddress(xad, address64)\ 51 - {\ 52 - (xad)->addr1 = ((u64)address64) >> 32;\ 53 - (xad)->addr2 = __cpu_to_le32((address64) & 0xffffffff);\ 54 - } 55 - #define XADlength(xad, length32) (xad)->len = __cpu_to_le24(length32) 52 + #define XADaddress(xad, address64) PXDaddress(&(xad)->loc, address64) 53 + #define XADlength(xad, length32) PXDlength(&(xad)->loc, length32) 56 54 57 55 /* xad_t field extraction */ 58 56 #define offsetXAD(xad)\ 59 57 ( ((s64)((xad)->off1)) << 32 | __le32_to_cpu((xad)->off2)) 60 - #define addressXAD(xad)\ 61 - ( ((s64)((xad)->addr1)) << 32 | __le32_to_cpu((xad)->addr2)) 62 - #define lengthXAD(xad) __le24_to_cpu((xad)->len) 58 + #define addressXAD(xad) addressPXD(&(xad)->loc) 59 + #define lengthXAD(xad) lengthPXD(&(xad)->loc) 63 60 64 61 /* xad list */ 65 62 struct xadlist {