Sparse Code With Minimum Hamming Distance of Three for Spin-Torque Transfer Magnetic Random Access Memory

Spin-torque-transfer magnetic random access memory (STT-MRAM) has recently emerged as a promising technology to replace dynamic random access memory (DRAM). However, STT-MRAM faces challenges due to process variations and thermal fluctuations, resulting in independent errors during the writing and reading. The STT-MRAM systems employ encoder and decoder mechanisms to address these errors. In addition, to handle asymmetric write error probabilities, a sparse code approach was adopted. Here, we propose an innovative algorithm based on the Hamming code to encode a sparse code with a minimum Hamming distance (MHD) of three. Our encoder introduces a general method to directly generate sparse code with an MHD of three from the user data. Before multiplying the data vectors by the generator matrix, we preprocessed them using an inverse method to ensure that the output of the generator matrix remained sparse. Furthermore, by leveraging the sum-product and syndrome decoding algorithms, we designed decoders that complemented the encoder. The simulation results showed that our proposed model could improve the speed and performance of STT-MRAM devices while overcoming the complexity issue of previous studies.


I. INTRODUCTION
The demand for information storage has increased in recent decades.In addition, memory must reduce the energy consumption of mobile devices.Therefore, spin-torque transfer magnetic random access memory (STT-MRAM) was introduced to replace dynamic random access memory (DRAM).STT-MRAM is considered a promising candidate for nextgeneration non-volatile memory (NVM) technologies that can improve scalability, nanosecond writing/reading speed, virtually unlimited endurance, and zero standby power [1], [2], [3].In STT-MRAM, data are stored in a magnetic tunneling junction (MTJ).Digital information is modulated into current using an nMOS transistor as access control.The user The associate editor coordinating the review of this manuscript and approving it for publication was Pietro Savazzi .data were converted into resistance values in the MTJ.The MTJ comprised two ferromagnetic layers (reference layers) and a tunneling oxide layer (free layer).The reference layers have a fixed magnetization, and the magnetization of the free layer can be changed by passing a spin-polarized driving current.If the relative magnetization directions between the reference and free layers are antiparallel or parallel, the resistance states of the MTJ are high or low, respectively [4].
However, the MTJ has many challenges, such as a high write cost (write pulse width of 10 ns or longer) [5], thermal fluctuation problems, and process variation [6], [7].
To solve these problems, researchers have proposed several circuit designs and architecture-level solutions.In [8], the authors proposed a smaller-than-worst-case transistor-sizing approach to reduce write costs.In [8], a combined magnetic and circuit-level technique was proposed to explore the design methodology of STT-MRAM.Dong et al. introduced a hybrid memory design using static RAM (SRAM) and STT-MRAM [9].In [10], the authors discussed and added the write buffers.To analyze the effects of process variation, Wang et al. presented the thermal fluctuations of MTJ devices [11].Smullen et al. proposed a thermal noise model to estimate thermal fluctuations during the switching process of the MTJ resistance [12].
In addition to hardware-based solutions, errors in the writing and reading processes can be mitigated by error-correcting codes (ECC) in signal processing.A (71, 64) Hamming code was used for Everspin's 16 Mb MRAM in [13].In [14], BCH codes with multiple error-correction capabilities were introduced to improve storage density.Like in the other fields [15], [16], low-density paritycheck (LDPC) codes were used in STT-MRAM to closely approach the Shannon capacity [17].In [18] and [19], adaptive error-correcting schemes were proposed to reduce ECC redundancy.
Channel modeling was introduced to design and evaluate ECC for STT-MRAM [20], [21], [22], [23], [24], [25], [26], [27].Among these channels, the cascaded channel model in [27] can support error-rate simulations and be considered a communication channel model.Subsequently, based on the cascaded channel model, Nguyen discovered that the errors of STT-MRAM appear independently, with an asymmetric probability between 0 and 1 bit [28].Therefore, in [28], the authors proposed a 7/9 sparse code to solve the asymmetric error probability problem in STT-MRAM.The sparse code had more 0s than 1s for each codeword.To improve sparse code, Nguyen and Lee proposed a method to increase the minimum Hamming distance (MHD) to three for the sparse code [29].However, to encode the sparse code in [29], the authors used mapping methods based on Euclidean distance decoding, which requires more time and has a large memory capacity.Therefore, we propose an encoder based on a generator matrix to directly create sparse code with an MHD of three.First, a final bit is added to the user data to make it suitable for the generator matrix of the Hamming code.The data vectors were then multiplied by the generator matrix to create codewords.If the codewords are not sparse, we invert the data, adding a checking bit to the original user data word and multiplying it by the generator matrix.In addition, based on the sum-product and syndrome decoding algorithms, we designed a decoder to decode the proposed sparse code.In the decoder, the received signal is first handled as a Hamming code with sum-product or syndrome decoding algorithms.The position of the final bit is then detected and used to check the inversion of the user data.
We summarized our contributions in this article below: -We proposed a method for directly encoding sparse code with an MHD of three.-Based on the sum-product and syndrome decoding algorithms, we designed a decoder for sparse code with an MHD of three.
-We analyzed and proved that our proposed method can be applied to arbitrary code rates for sparse codes with an MHD of three.-With the proposed decoder, sparse code with an MHD of three can be decoded without the mapping method using Euclidean distance decoding.This helps reduce the complexity and save time for the decoder.-Finally, we provide simulation results to verify the performance of the proposed model.The remainder of this paper is organized as follows.In Section II, a cascaded channel for the STT-MRAM is introduced.Section III presents the proposed method to create sparse code based on the Hamming code theory.Section IV analyzes and discusses the simulation results.Section V describes the complexity of the proposed decoder.Finally, the conclusions are presented in Section VI.

II. CHANNEL MODEL A. STRUCTURE OF STT-MRAM
An STT-MRAM cell is presented in Figure 1.In Figure 1a, an STT-MRAM cell comprises an MTJ and an nMOS transistor used to control the current during the writing and reading processes [23].The MTJ structure included three layers: a free layer, an oxide barrier, and a reference layer.A free layer is used to store the bit data.This layer is relatively thin (2-4 nm); therefore, it can be switched by passing a spin-polarized current through it.An oxide barrier is a nonmagnetic layer with a thickness of 1 nm used to provide the means for recording and reading the memory state.Finally, the reference layer carries the magnetic direction and does not switch during memory operations.The magnetic directions in the free and reference layers are combined to create two states for the MTJ: the parallel (P) state in Figure 1b with a low resistance R P and the antiparallel (AP) state in Figure 1c with a high resistance R AP .Generally, R P represents data bit-0, and R AP represents data bit-1 in the reading and writing processes.
The writing process in an STT-MRAM cell is shown in Figure 2. To achieve the P state and write bit-0, we need to create a current from the free layer to the reference layer (write-0 direction), as shown in Figure 2a.Therefore, the voltage V DD is connected to the bit line (BL) and word line (WL), whereas the ground (GND) is connected to the source line (SL).To obtain the AP state and write bit-1, the current from the reference layer to the free layer (write-1 direction) was used, as in Figure 2b.When V DD is supplied to the SL and WL, BL is the GND.The reading process is illustrated in Figure 3.During the reading process, a low-level current was passed through the MTJ.The resistance of the MTJ was measured, and its state of MTJ was detected using a memory-sensing circuit.We can apply the write-0 or -1 direction to read the data.However, with fluctuations and process variations, the reading current values can exceed the switching values.This causes the reading current to become writing current.When using the current with write-0 direction, the switching error is '1' to '0', and there is no error '0' to '1.' Vice versa, if we use the write-1 direction current, the error is '0' to '1', and there is no error '1' to '0.' Therefore, the error probabilities between bit-1 and -0 were asymmetric.

B. CASCADED CHANNEL MODEL
In the STT-MRAM technology, data reliability is significantly affected by process variations and thermal fluctuations, leading to write and read errors [1], [30].Delving into write errors, switching from 0 to 1 demands a higher write current than the reverse transition from 1 to 0, owing to its lower spin-transfer efficiency.This asymmetry results in a distinct disparity in error probabilities: P 1 represents the write error rate for 1 → 0 switching, and P 0 represents the same for 0 → 1 switching.P 1 was markedly higher than P 0 [23], [31], [32].
Furthermore, integrating STT-MRAM caches, as shown in [33] and [34], where the STT-MRAM cells are grounded, introduces additional read and write operations through error detection and correction codes.This increases disturbances during read operations and increased area and energy overhead.However, for simplicity, we focus on individual STT-MRAM cells.Hence, our primary attention centers on the influence of different code types in reducing the count of '1' bits within our communication channel.Here, we used the cascaded model proposed in [27] to simulate an STT-MRAM channel.In the cascade model, the writing process is represented by a write-error model.The write error model is a binary asymmetric channel (BAC), while P 1 /2 and P 0 /2 are denoted as the write error rate for the crossover probabilities 1 → 0 and 0 → 1, respectively.Read errors are classified as read disturbance and read decision errors.To represent the read-disturbance error, we used a Z-channel with P r as the crossover probability 1 → 0 or 0 → 1 for reading in the write-0 or write-1 directions, respectively.In the read-decision error model, we used a Gaussian distribution, and the resistance values for data bit-0 and -1 are represented by R 0 and R 1 .R 0 has the mean µ 0 and variance σ 0 .R 1 has the mean µ 1 and variance σ 1 .We combined the three aforementioned models, including the BAC, Z-channel, and Gaussian mixture channel (GMC), into the cascade channel model.A cascade channel model was used to simulate STT-MRAM devices.A diagram of the cascaded model is shown in Figure 4.In addition, we can combine the BAC and Z-channel to achieve the simple model shown in Figure 5.
The write-0 and write-1 directions used the same simple channel models for reading.However, the probability parameters are different, as follows: -The reading with write-0 direction: -The reading with write-1 direction: Here, the parameters adopted in [6] were applied in the experiments.These parameters correspond to a 45 ×90 nm in-plane MTJ under a PTM 45-nm technology node, with µ 0 = 1 k , µ 1 = 2 k , and σ 0 /µ 0 = σ 1 /µ 1 .Finally, the current in the write-1 direction was used for reading.

III. PROPOSED ENCODER AND DECODER
The proposed model is illustrated in Figure 6.User data u ∈ {0, 1} are added to the final bit-0 to create signal a.The codewords from the multiplication of a and G were checked for sparse characteristics by counting the number of 1s in the codeword.If the codeword is not a sparse code, we invert signal a and multiply ā with matrix G to achieve the sparse codeword.The sparse code c is stored in the MRAM channel.The received signal y was collected from the resistance values of the in MRAM device.Signal y is detected by or sum-product to obtain signal â, which has the form of sparse codeword c.Then, the final bit, which is added to the user data, is detected to verify the inverse of the user data.Finally, user data û are extracted from signal â by removing the checking bit.

A. ENCODER
In [29], the authors showed that if we choose codewords from the Hamming code to achieve sparse code, the number of codewords is reduced by half.Based on the Hamming code, generator matrix G is created by choosing the length of the parity sequence m bits and listing all sequences with a weight greater than one.The proposed encoder comprises two processes.First, we add a checking bit-0 to user data u to create data a =[u 0].We then create codeword c from a by multiplying generator matrix G of the Hamming code.If the output of aG is not sparse, we invert signal ā and multiply it with G again.The details of this method are as follows. - If ω(c) < n/2, the output is c; otherwise, we proceed to the next step.-Step 6: The formula below is implemented to make the sparse code.
where ā is inverted vector of a.
From the above steps, we can observe that the code rate of the sparse code is (k -1)/n.c is always sparse, as written in the appendix.

B. DECODER
In the decoder, we first detect sparse codeword ĉ from the received signal y.In sparse code word ĉ, there are three parts: the user data word, checking bit, and parity sequence in the Hamming code.The user data contains information in the received sequence ĉ from ĉ0 to ĉk−2 .The checking bit is at position ĉk−1 in signal ĉ.The remainder of signal ĉ from ĉk to ĉn consists of comprises parity bits.If ĉk−1 is bit-1, we invert the bits from ĉ0 to ĉk−2 .We can see that the detection from y to ĉ is important for the decoder.Therefore, we propose two methods for this step: syndrome and sum-product decoding algorithms.The syndrome decoding algorithm is a simple method for detecting a codeword that is encoded before storage in the MRAM channel.However, the syndrome-decoding algorithm is exposed to quantization errors because it handles difficult decision values.Therefore, a sum-product algorithm was proposed to handle soft decision values and reduce quantization errors.
Method 1 (syndrome-decoding algorithm): First, we find the parity-check matrix H by exploiting generator matrix G in (3).Matrix P in G is retained, and matrix I is moved below matrix P as follows: In the syndrome decoding algorithm, received signal y is compared with threshold γ to convert y into bit signal x in Figure 7.The output of the multiplication xH T is used to look up the error table.The error table is used to correct one bit in x.After correcting the error in x, signal ĉ is obtained in the same form as sparse codeword c.We check ĉk−1 .If ĉk−1 = 0, we retain the values from ĉ0 to ĉk−2 as the original signal û.If ĉk−1 = 1, we invert the values from ĉ0 to ĉk−2 as original signal û.Finally, signals u and û are used to calculate the bit error rate (BER) performance.
Diagram of sum-product algorithm.
Method 2 (sum-product decoding algorithm): First, based on matrix H, we can present the bipartite graph, which includes check nodes with one node per column and variable nodes with one node per row.The logarithmic likelihood ratio is calculated as follows: where i = 0, 1, 2, . . ., n-1 denotes the index of the rows as an index of the variable nodes.To calculate messages from the variable nodes to the check nodes, we implemented the following: where j = 0, 1, 2, . . ., k -1 is the index of the columns as the index of the check nodes, and t is the number of loops in the iteration algorithm.When t = 1, the second term of equation ( 9) is ignored, that is, The message from the check nodes to the variable nodes is calculated using the following equation: Finally, in the t-th loop, we use messages from the variable nodes to calculate the logarithmic likelihood ratio as follows: Next, if l (t) i > 0, then x i = 1 else x i = 0. Using the binary value of signal x, we can implement a multiplication x T .If xH T = 0, the syndrome algorithm outputs x = ĉ.If xH T ̸ = 0, we use the error table, as in Method 1, to correct a bit in x to create signal ĉ.Method 2 can correct more than one bit compared with Method 1.

IV. RESULTS AND SIMULATION
We simulated the model shown in Figure 6.The user data u with the size of 1,440,000 are encoded into the sparse code c.Then, codeword c is stored in the MRAM device.Errors appear in codeword c when reading data in the MRAM device.The received signal y was collected as the resistance value of the MTJ in the MRAM device.The proposed decoders are used to decode signal y into original signal û.The BER performance was estimated by comparing signals u and û.We repeated the simulation from signal u to û 10 times.
Figure 9 shows that the proposed sparse code improves the BER of the STT-MRAM channel.However, there is a trade-off between the code rate and performance.When the code rate increases, the performance degrades.This problem is because when the code rate is increased, the total number of codewords must increase.This reduces the noise margin between the code words in the signal space.In the next simulation, we used the 56/63 sparse code with an MHD of three for comparison with previous studies.In Figure 10, we present the results of 7/9 sparse codes with an MHD of two in [28] and 16/22 sparse codes with an MHD of three in [29].The decoders in [28] and [29] are mapping methods determining the minimum Euclidean distances.We can observe that the proposed sparse code and decoder can improve the BER performance compared to previous studies.At a BER of 10 −4 , the proposed model can achieve a gain of 2% compared with the 7/9 sparse code.For the 16/22 sparse code, the proposed model can obtain a gain of 1% at a BER of 10 −6 .However, when the σ 0 /µ 0 is greater than 10%, the proposed code cannot improve the performance compared to 16/22 sparse code.Similarly, when the σ 0 /µ 0 is greater than 13%, our proposed code cannot improve the performance compared with 7/9 sparse code.This is because the mapping method works better when environmental conditions gradually deteriorate.However, sparse code using the mapping method is limited in increasing the code rate owing to the complexity issue, explained in Section V.The 56/63 and 57/63 codes used the same generator matrix G to create codewords.The codewords of the rate 56/63 code were obtained from the codewords of the rate 57/63 code with sparse characteristics.Because the number of codewords is reduced by half, and the sparse code is suitable for the MRAM channel, the 56/63 sparse code can improve the performance compared to the 57/63 non-sparse code.In the next simulation, we fix σ 0 /µ 0 = σ 1 /µ 1 = 9.5% and vary the writing error probability P 1 during the writing process [35].The results of the proposed code are shown in Figure 12.For each code, a critical error probability value exists at which the BER begins to deteriorate from a steady value.Finally, as in [36], we set up an environment with σ 0 /µ 0 = 9.5% and varied the mean offset µ off from -0.25 to -0.05.Figures 13 and 14 presented the results with σ off /µ 1 = 5% and 7%, respectively.
Figures 13 and 14 illustrate that the proposed code can improve the performance compared with 7/9 sparse code when the mean offset is more than -0.2 k .Code rates of 3/7 and 10/15 of the proposed code can perform better than the 16/22 sparse code.

V. COMPLEXITY OF THE PROPOSED CODE
In this section, to compare the complexity of the proposed decoder and previous studies, we counted the number of operations of the decoder based on the syndrome and sumproduct algorithms.These operations are used to decode one bit.In MATLAB 2023, the times required for the add and comparison operators were almost the same.Therefore, we counted and grouped the add and comparison operations as add operations to calculate the complexity.First, we count the operations in the decoder using a syndrome algorithm.We considered the forms of the received x and matrix H as follows.Next, we counted the number of operations in the decoder using the sum-product algorithm.In the sum-product algorithm, we can calculate equation ( 10) using the approximation below.
From equation ( 14), we can compare the check nodes.The number of check nodes equals the number of columns in H. Therefore, there are m comparison operations and m -1 multiplication operations.In each loop, equation ( 9) or ( 10) is used to calculate the message from the variable nodes, check the nodes, or output the results.Therefore, we have n additional operations.After stopping the iteration from the bipartite graph, we implemented ĉH T as a syndrome.Therefore, we have n × m multiplication operations, (n -1)m addition operations, and n -1 comparison operations.  1 lists the complexities of the proposed code and those of previous studies.The 7/9 and 16/22 sparse codes used the mapping method with the minimum Euclidean distance to decode the received signal.The 25/31 sparse codes have n = 31 and m = 5.The 56/63 sparse code has n = 63 and m = 6.In Section IV, the sum-product algorithm is set up with ten iterations.We can see that the proposed coding scheme can increase the code rate, whereas the mapping method cannot achieve a high code rate because of its complexity.

VI. CONCLUSION
We proposed a method to directly encode sparse code with a minimum Hamming distance of three for the STT-MRAM channel.This method is based on a Hamming code encoder.First, one bit is added to the user data, and the augmented user data are multiplied by a generator matrix.We then checked the sparsity of the codewords.If the codewords are not sparse, we invert the augmented user data and multiply them using the generator matrix.The resulting codewords have sparse characteristics.We can use a sum-product algorithm or syndrome decoder to detect codewords for decoding.The proposed scheme then checks for the added bits.If the added bit is zero, the user data were not inverted during the reading process.However, if it is 1, we invert the user data.
The results show that the proposed spare code can achieve a higher code rate and better BER performance than those in previous studies.We consider the branch that creates sparse code with signal a = [u 0], as shown in Figure 15. In For r = r, we must prove p 0 +p 1 + . . .+p k−2 = 0. We considered matrix P. Note that p i 's in P are vectors with two or more 1s (except all 1 vectors) because they are the parity part of the generator matrix of the Hamming code.We listed and added vectors of length m to equation (20).
Generally, the addition of vectors in equation (20) has four groups: • The first is (000. . .0).
• The second group weighed 1.The sum of all vectors in this group is (111. . .1).
• The third group is those with a weight of two or more, except for (111-1).This group corresponds to p 0 + p 1 + . . .+ p k−2 in matrix P.
• The final group is (111. . .1).The sum of the second and final scores was 0. The sum of all four groups was 0. Therefore, the third group was equal to 0. In other words, p 0 +p 1 + . . .+p k−2 = 0. Thus, Therefore, r=r and c=c.

FIGURE 10 .
FIGURE 10.BER performance of sparse code with MHDs of two and three.

FIGURE
FIGURE BER performance of sparse code and Hamming code.

Figure 11 ,
Figure 11, we present the BER performances of the 56/63 sparse and 57/63 Hamming codes.The 56/63 and 57/63 codes used the same generator matrix G to create codewords.The codewords of the rate 56/63 code were obtained from the codewords of the rate 57/63 code with sparse characteristics.Because the number of codewords is reduced by half, and the sparse code is suitable for the MRAM channel, the 56/63 sparse code can improve the performance compared to the 57/63 non-sparse code.

FIGURE 12 .
FIGURE 12. BER performance according to write error rate P 1 .

h
(n−1)0 h (n−1)1 h (n−1)2 . . .h (n−1)(m−1) decoding algorithm, xH T estimates the error position in x.Therefore, xH T includes n × m multiplications and (n -1)m addition operations.The results of xH T were compared with the error table.Because matrix H has n -1 rows, there are n -1 comparison operations when comparing xH T to the error table.

APPENDIX
Let us define the notations below.u = [u 0 u 1 . . .u k−2 ] is a vector of the user data.G k×(k+m) = [I|P] is the generator matrix.matrix.p i has the size of 1×m.1 is the matrix of ones and has the size of 1×m.

FIGURE 15 .
FIGURE 15.Diagram of encoder with signal a.

TABLE 1 .
Complexity corresponding to code rate and decoders.