https://godbolt.org/z/bxT3aPjbd
The gmtime function always returns _gmtime.tm2 in HL. However, it seems that when localetime and gmtime are in the same translation unit, it decides to reload the value of _gmtime.tm2 into HL, even though HL will already always be set to that value.
struct tm *gmtime(const time_t *tp);
struct tm *localtime(const time_t *timer) {
time_t timer2 = *timer;
// subtracts zero since LOCALTIME_GMT_OFFSET is zero
timer2 -= LOCALTIME_GMT_OFFSET * SECS_PER_MIN;
return gmtime(&timer2);
}
Same translation unit as gmtime:
BB0_27:
ld (_gmtime.tm2), bc
ld hl, _gmtime.tm2
ld sp, ix
pop ix
ret
public _localtime
_localtime:
ld hl, -4
call __frameset
ld iy, (ix + 6)
ld hl, (iy)
ld a, (iy + 3)
ld (ix - 4), hl
ld (ix - 1), a
pea ix - 4
call _gmtime
pop hl
ld hl, _gmtime.tm2
ld sp, ix
pop ix
ret
Different translation units:
_localtime:
ld hl, -4
call __frameset
ld iy, (ix + 6)
ld hl, (iy)
ld a, (iy + 3)
ld (ix - 4), hl
ld (ix - 1), a
pea ix - 4
call _gmtime
ld sp, ix
pop ix
ret
``
https://godbolt.org/z/bxT3aPjbd
The
gmtimefunction always returns_gmtime.tm2in HL. However, it seems that whenlocaletimeandgmtimeare in the same translation unit, it decides to reload the value of_gmtime.tm2into HL, even though HL will already always be set to that value.Same translation unit as
gmtime:Different translation units: