• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

SpiNNakerManchester / JavaSpiNNaker / 6233274834

19 Sep 2023 08:46AM UTC coverage: 36.409% (-0.6%) from 36.982%
6233274834

Pull #658

github

dkfellows
Merge branch 'master' into java-17
Pull Request #658: Update Java version to 17

1656 of 1656 new or added lines in 260 files covered. (100.0%)

8373 of 22997 relevant lines covered (36.41%)

0.36 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/SpiNNaker-machine/src/main/java/uk/ac/manchester/spinnaker/machine/MemoryLocation.java
1
/*
2
 * Copyright (c) 2022 The University of Manchester
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     https://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
package uk.ac.manchester.spinnaker.machine;
17

18
import static java.lang.Integer.compareUnsigned;
19
import static java.lang.String.format;
20

21
import com.google.errorprone.annotations.Immutable;
22

23
/**
24
 * A location in SpiNNaker or BMP memory. Does not say which address space this
25
 * is in.
26
 *
27
 * @author Donal Fellows
28
 * @param address
29
 *            The actual location.
30
 */
31
@Immutable
32
public record MemoryLocation(int address)
×
33
                implements Comparable<MemoryLocation> {
34
        /** Number of bytes in a SpiNNaker (ARM) word. */
35
        private static final int WORD_SIZE = 4;
36

37
        /** The zero memory location. Often means "no actual address". */
38
        public static final MemoryLocation NULL = new MemoryLocation(0);
×
39

40
        /**
41
         * @param address
42
         *            The actual location.
43
         */
44
        public MemoryLocation(long address) {
45
                this(convert(address));
×
46
        }
×
47

48
        /**
49
         * Add an offset to this location to get a new memory location.
50
         *
51
         * @param offset
52
         *            The offset to add.
53
         * @return The new memory location.
54
         */
55
        public MemoryLocation add(int offset) {
56
                return new MemoryLocation(address + offset);
×
57
        }
58

59
        /**
60
         * Get the difference between this location and another.
61
         *
62
         * @param other
63
         *            The other location.
64
         * @return This location's address minus the other location's address.
65
         */
66
        public int diff(MemoryLocation other) {
67
                return address - other.address;
×
68
        }
69

70
        /** @return Whether this location is really {@linkplain #NULL null}. */
71
        public boolean isNull() {
72
                return address == 0;
×
73
        }
74

75
        /**
76
         * How many bytes is this location's address above a word-aligned address?
77
         *
78
         * @return The number of bytes offset.
79
         */
80
        public int subWordAlignment() {
81
                return address % WORD_SIZE;
×
82
        }
83

84
        /** @return Whether this is a word-aligned location. */
85
        public boolean isAligned() {
86
                return subWordAlignment() == 0;
×
87
        }
88

89
        @Override
90
        public int hashCode() {
91
                return address;
×
92
        }
93

94
        @Override
95
        public boolean equals(Object other) {
96
                return (other instanceof MemoryLocation o) && (o.address == address);
×
97
        }
98

99
        @Override
100
        public int compareTo(MemoryLocation other) {
101
                return compareUnsigned(address, other.address);
×
102
        }
103

104
        /**
105
         * Test if this location is less than another location.
106
         *
107
         * @param other
108
         *            The other location.
109
         * @return True if this location's address comes before.
110
         */
111
        public boolean lessThan(MemoryLocation other) {
112
                return compareTo(other) < 0;
×
113
        }
114

115
        /**
116
         * Test if this location is greater than another location.
117
         *
118
         * @param other
119
         *            The other location.
120
         * @return True if this location's address comes after.
121
         */
122
        public boolean greaterThan(MemoryLocation other) {
123
                return compareTo(other) > 0;
×
124
        }
125

126
        @Override
127
        public String toString() {
128
                // Leading '0x' then exactly 8 hexadecimal characters; 10 chars total
129
                return format("%#010x", address);
×
130
        }
131

132
        /** Maximum legal SpiNNaker address. It's a 32-bit machine. */
133
        private static final long MAX_ADDR = 0xFFFFFFFFL;
134

135
        /**
136
         * Convert an address to a 32-bit integer.
137
         *
138
         * @param baseAddress
139
         *            The address as a long.
140
         * @return the address as an int.
141
         * @throws IllegalArgumentException
142
         *             if the value is outside the unsigned 32-bit integer range.
143
         */
144
        private static int convert(long baseAddress) {
145
                if (baseAddress < 0 || baseAddress > MAX_ADDR) {
×
146
                        throw new IllegalArgumentException(
×
147
                                        "address must be in 32-bit unsigned integer range");
148
                }
149
                return (int) baseAddress;
×
150
        }
151
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc